DlgUndoRedo.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include "DlgUndoRedo.h"
00027 #include "Application.h"
00028 #include "MainWindow.h"
00029 #include "Document.h"
00030 #include "EditorView.h"
00031 
00032 using namespace Gui::Dialog;
00033 
00034 /* TRANSLATOR Gui::Dialog::UndoRedoDialog */
00035 
00040 UndoDialog::UndoDialog( QWidget* parent )
00041   : QMenu( parent )
00042 {
00043     connect(this, SIGNAL(aboutToShow()), this, SLOT(onFetchInfo()));
00044 }
00045 
00049 UndoDialog::~UndoDialog()
00050 {
00051     // no need to delete child widgets, Qt does it all for us
00052 }
00053 
00058 void UndoDialog::onFetchInfo() 
00059 {
00060     clear(); // Remove first all items
00061     Gui::Document* pcDoc = Application::Instance->activeDocument();
00062     if (pcDoc)
00063     {
00064         std::vector<std::string> vecUndos = pcDoc->getUndoVector();
00065         for (std::vector<std::string>::iterator i=vecUndos.begin(); i!=vecUndos.end(); i++)
00066             addAction(QString::fromUtf8((*i).c_str()), this, SLOT(onSelected()));
00067     }
00068     else
00069     {
00070         EditorView* view = qobject_cast<EditorView*>(getMainWindow()->activeWindow());
00071         if (view) {
00072             QStringList vecUndos = view->undoActions();
00073             for (QStringList::Iterator i=vecUndos.begin(); i!=vecUndos.end(); i++)
00074                 addAction(*i, this, SLOT(onSelected()));
00075         }
00076     }
00077 }
00078 
00080 void UndoDialog::onSelected()
00081 {
00082     QAction* a = static_cast<QAction*>(sender());
00083     QList<QAction*> acts = this->actions();
00084     for (QList<QAction*>::ConstIterator it = acts.begin(); it != acts.end(); ++it) {
00085         Gui::Application::Instance->sendMsgToActiveView("Undo");
00086         if (*it == a)
00087             break;
00088     }
00089 }
00090 
00091 /* TRANSLATOR Gui::Dialog::RedoDialog */
00092 
00097 RedoDialog::RedoDialog( QWidget* parent )
00098   : QMenu( parent )
00099 {
00100     connect(this, SIGNAL(aboutToShow()), this, SLOT(onFetchInfo()));
00101 }
00102 
00106 RedoDialog::~RedoDialog()
00107 {
00108     // no need to delete child widgets, Qt does it all for us
00109 }
00110 
00115 void RedoDialog::onFetchInfo() 
00116 {
00117     clear(); // Remove first all items
00118     Gui::Document* pcDoc = Application::Instance->activeDocument();
00119     if ( pcDoc )
00120     {
00121         std::vector<std::string> vecRedos = pcDoc->getRedoVector();
00122         for (std::vector<std::string>::iterator i=vecRedos.begin(); i!=vecRedos.end(); i++)
00123             addAction(QString::fromUtf8((*i).c_str()), this, SLOT(onSelected()));
00124     }
00125     else
00126     {
00127         EditorView* view = qobject_cast<EditorView*>(getMainWindow()->activeWindow());
00128         if (view) {
00129             QStringList vecRedos = view->redoActions();
00130             for (QStringList::Iterator i=vecRedos.begin(); i!=vecRedos.end(); i++)
00131                 addAction(*i, this, SLOT(onSelected()));
00132         }
00133     }
00134 }
00135 
00137 void RedoDialog::onSelected()
00138 {
00139     QAction* a = static_cast<QAction*>(sender());
00140     QList<QAction*> acts = this->actions();
00141     for (QList<QAction*>::ConstIterator it = acts.begin(); it != acts.end(); ++it) {
00142         Gui::Application::Instance->sendMsgToActiveView("Redo");
00143         if (*it == a)
00144             break;
00145     }
00146 }
00147 
00148 #include "moc_DlgUndoRedo.cpp"

Generated on Wed Nov 23 19:00:07 2011 for FreeCAD by  doxygen 1.6.1