From 309c6241144204b2a2c1cf23cb68f037833fb983 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 11 Apr 2014 12:29:45 +0400 Subject: [PATCH] Update command status method added --- src/PartSet/PartSet_Module.cpp | 4 +- src/XGUI/XGUI_Command.h | 2 +- src/XGUI/XGUI_MainMenu.cpp | 38 ++++++++++++++++++ src/XGUI/XGUI_MainMenu.h | 10 +++++ src/XGUI/XGUI_MainWindow.cpp | 12 ++---- src/XGUI/XGUI_MainWindow.h | 4 +- src/XGUI/XGUI_MenuGroupPanel.cpp | 10 +++++ src/XGUI/XGUI_MenuGroupPanel.h | 6 +++ src/XGUI/XGUI_Workbench.cpp | 20 ++++++++++ src/XGUI/XGUI_Workbench.h | 7 ++++ src/XGUI/XGUI_Workshop.cpp | 68 +++++++++++++++++++++++++++++++- src/XGUI/XGUI_Workshop.h | 4 ++ 12 files changed, 171 insertions(+), 14 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 409e38484..3a24568f4 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -40,7 +40,7 @@ void PartSet_Module::createFeatures() void PartSet_Module::featureCreated(XGUI_Command* theFeature) { - QString aFtId = theFeature->getId(); + QString aFtId = theFeature->id(); theFeature->connectTo(this, SLOT(onFeatureTriggered())); } @@ -53,7 +53,7 @@ void PartSet_Module::onFeatureTriggered() Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName); aWdgReader.readAll(); XGUI_Command* aCmd = dynamic_cast(sender()); - QString aCmdId = aCmd->getId(); + QString aCmdId = aCmd->id(); std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString()); //TODO(sbh): Implement static method to extract event id [SEID] static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent"); diff --git a/src/XGUI/XGUI_Command.h b/src/XGUI/XGUI_Command.h index 1bef9e0db..b1227ba2e 100644 --- a/src/XGUI/XGUI_Command.h +++ b/src/XGUI/XGUI_Command.h @@ -28,7 +28,7 @@ public: virtual void disable(); //! Returns Id of the command - virtual QString getId() const + virtual QString id() const { return myId; } diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index efce9ab2c..7d8e81f35 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -6,12 +6,15 @@ #include #include #include +#include XGUI_MainMenu::XGUI_MainMenu(XGUI_MainWindow *parent) : QObject(parent), myDesktop(parent) { parent->setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North); myGeneralPage = addWorkbench(tr("General")); + myGeneralPage->parentWidget()->setMaximumWidth(200); + myGeneralPage->installEventFilter(this); } XGUI_MainMenu::~XGUI_MainMenu(void) @@ -51,3 +54,38 @@ XGUI_Workbench* XGUI_MainMenu::findWorkbench(const QString& theObjName) { return myDesktop->findChild(theObjName); } + + +bool XGUI_MainMenu::eventFilter(QObject *theWatched, QEvent *theEvent) +{ + if (theWatched == myGeneralPage) { + if (theEvent->type() == QEvent::Show) { + myGeneralPage->parentWidget()->setMaximumWidth(16777215); + myGeneralPage->removeEventFilter(this); + } + } + return QObject::eventFilter(theWatched, theEvent); +} + +XGUI_Command* XGUI_MainMenu::feature(const QString& theId) const +{ + QList::const_iterator aIt; + for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) { + XGUI_Workbench* aWbn = static_cast((*aIt)->widget()); + XGUI_Command* aCmd = aWbn->feature(theId); + if (aCmd) + return aCmd; + } + return 0; +} + +QList XGUI_MainMenu::features() const +{ + QList aList; + QList::const_iterator aIt; + for (aIt = myMenuTabs.constBegin(); aIt != myMenuTabs.constEnd(); ++aIt) { + XGUI_Workbench* aWbn = static_cast((*aIt)->widget()); + aList.append(aWbn->features()); + } + return aList; +} \ No newline at end of file diff --git a/src/XGUI/XGUI_MainMenu.h b/src/XGUI/XGUI_MainMenu.h index 028f73b12..b683fc99e 100644 --- a/src/XGUI/XGUI_MainMenu.h +++ b/src/XGUI/XGUI_MainMenu.h @@ -13,6 +13,7 @@ class QTabWidget; class QLabel; class QAction; class QDockWidget; +class QEvent; /**\class XGUI_MainMenu * \ingroup GUI @@ -37,6 +38,15 @@ public: //! Rerturns last created workbench in dock widget container QDockWidget* getLastDockWindow() const { return myMenuTabs.last(); } + //! Returns already created command by its ID + XGUI_Command* feature(const QString& theId) const; + + //! Returns list of created commands + QList features() const; + +protected: + virtual bool eventFilter(QObject *theWatched, QEvent *theEvent); + private: XGUI_MainWindow* myDesktop; QList myMenuTabs; diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 25ea218c9..25516792e 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -28,9 +28,9 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), - myObjectBrowser(NULL), - myPythonConsole(NULL), - myPropertyPanelDock(NULL) + myObjectBrowser(0), + myPythonConsole(0), + myPropertyPanelDock(0) { setWindowTitle(tr("New Geom")); myMenuBar = new XGUI_MainMenu(this); @@ -40,7 +40,7 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) myViewer = new XGUI_Viewer(this); - createDockWidgets(); + //createDockWidgets(); } XGUI_MainWindow::~XGUI_MainWindow(void) @@ -75,11 +75,7 @@ void XGUI_MainWindow::showPythonConsole() aDoc->setMinimumHeight(0); aDoc->setWindowTitle("Console"); myPythonConsole = new PyConsole_EnhConsole( aDoc, new PyConsole_EnhInterp()); - //myPythonConsole = new QTextEdit(aDoc); - //myPythonConsole->setGeometry(0,0,200, 50); - //myPythonConsole->setText(">>>"); aDoc->setWidget(myPythonConsole); - //myPythonConsole->setMinimumHeight(0); addDockWidget(Qt::TopDockWidgetArea, aDoc); tabifyDockWidget(myMenuBar->getLastDockWindow(), aDoc); } diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 4cdbba52c..4f99979c9 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -43,6 +43,9 @@ public: return myViewer; } + // Creates Dock widgets: Object broewser and Property panel + void createDockWidgets(); + public slots: void showPythonConsole(); void hidePythonConsole(); @@ -52,7 +55,6 @@ public slots: void hideObjectBrowser(); private: - void createDockWidgets(); QDockWidget* createObjectBrowser(); QDockWidget* createPropertyPanel(); diff --git a/src/XGUI/XGUI_MenuGroupPanel.cpp b/src/XGUI/XGUI_MenuGroupPanel.cpp index 4f447117c..00d131278 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.cpp +++ b/src/XGUI/XGUI_MenuGroupPanel.cpp @@ -71,3 +71,13 @@ XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QStrin addCommand(aCommand); return aCommand; } + + +XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const +{ + QList::const_iterator aIt; + for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt) + if ((*aIt)->id() == theId) + return (*aIt); + return 0; +} \ No newline at end of file diff --git a/src/XGUI/XGUI_MenuGroupPanel.h b/src/XGUI/XGUI_MenuGroupPanel.h index 58fd7a797..fa3152ec0 100644 --- a/src/XGUI/XGUI_MenuGroupPanel.h +++ b/src/XGUI/XGUI_MenuGroupPanel.h @@ -21,6 +21,12 @@ public: XGUI_Command* addFeature(const QString& theId, const QString& theTitle, const QString& theTip, const QIcon& theIcon, const QKeySequence& theKeys = QKeySequence()); + //! Returns already created command by its ID + XGUI_Command* feature(const QString& theId) const; + + //! Returns list of created commands + QList features() const { return myActions; } + protected: virtual void resizeEvent(QResizeEvent *theEvent); diff --git a/src/XGUI/XGUI_Workbench.cpp b/src/XGUI/XGUI_Workbench.cpp index 996d5a7ae..468d8d0ce 100644 --- a/src/XGUI/XGUI_Workbench.cpp +++ b/src/XGUI/XGUI_Workbench.cpp @@ -170,4 +170,24 @@ bool XGUI_Workbench::eventFilter(QObject *theObj, QEvent *theEvent) } } return QWidget::eventFilter(theObj, theEvent); +} + +XGUI_Command* XGUI_Workbench::feature(const QString& theId) const +{ + QList::const_iterator aIt; + for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) { + XGUI_Command* aCmd = (*aIt)->feature(theId); + if (aCmd) + return aCmd; + } + return 0; +} + +QList XGUI_Workbench::features() const +{ + QList aList; + QList::const_iterator aIt; + for (aIt = myGroups.constBegin(); aIt != myGroups.constEnd(); ++aIt) + aList.append((*aIt)->features()); + return aList; } \ No newline at end of file diff --git a/src/XGUI/XGUI_Workbench.h b/src/XGUI/XGUI_Workbench.h index 57b17d3be..3c7443b3b 100644 --- a/src/XGUI/XGUI_Workbench.h +++ b/src/XGUI/XGUI_Workbench.h @@ -21,6 +21,12 @@ public: XGUI_MenuGroupPanel* addGroup(const QString& theId); XGUI_MenuGroupPanel* findGroup(const QString& theName); + //! Returns already created command by its ID + XGUI_Command* feature(const QString& theId) const; + + //! Returns list of created commands + QList features() const; + private slots: void onLeftScroll(); void onRightScroll(); @@ -29,6 +35,7 @@ protected: virtual void resizeEvent(QResizeEvent * theEvent); virtual bool eventFilter(QObject *theObj, QEvent *theEvent); + private: void addSeparator(); bool isExceedsLeft(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 0aa5bde71..4dbd97a53 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -66,6 +66,7 @@ void XGUI_Workshop::startApplication() activateModule(); myMainWindow->show(); + updateCommandStatus(); // Testing of document creation //std::shared_ptr aMgr = ModelAPI_PluginManager::get(); //std::shared_ptr aPoint1 = aMgr->rootDocument()->addFeature("Point"); @@ -96,9 +97,11 @@ void XGUI_Workshop::initMenu() aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"), QIcon(":pictures/undo.png"), QKeySequence::Undo); + aCommand->connectTo(this, SLOT(onUndo())); aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"), QIcon(":pictures/redo.png"), QKeySequence::Redo); + aCommand->connectTo(this, SLOT(onRedo())); aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"), QIcon(":pictures/rebuild.png")); @@ -146,6 +149,7 @@ void XGUI_Workshop::processEvent(const Event_Message* theMessage) if(aOperation->xmlRepresentation().isEmpty()) { //!< No need for property panel myCurrentOperation->start(); myCurrentOperation->commit(); + updateCommandStatus(); } else { fillPropertyPanel(aOperation); } @@ -247,30 +251,55 @@ void XGUI_Workshop::onExit() void XGUI_Workshop::onNew() { QApplication::setOverrideCursor(Qt::WaitCursor); + if (myMainWindow->objectBrowser() == 0) + myMainWindow->createDockWidgets(); myMainWindow->showObjectBrowser(); myMainWindow->showPythonConsole(); QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); aWnd->showMaximized(); + updateCommandStatus(); QApplication::restoreOverrideCursor(); } //****************************************************** void XGUI_Workshop::onOpen() { - QString aFileName = QFileDialog::getOpenFileName(mainWindow()); + //QString aFileName = QFileDialog::getOpenFileName(mainWindow()); + updateCommandStatus(); } //****************************************************** void XGUI_Workshop::onSave() { + updateCommandStatus(); } //****************************************************** void XGUI_Workshop::onSaveAs() { - QString aFileName = QFileDialog::getSaveFileName(mainWindow()); + //QString aFileName = QFileDialog::getSaveFileName(mainWindow()); + updateCommandStatus(); } +//****************************************************** +void XGUI_Workshop::onUndo() +{ + std::shared_ptr aMgr = ModelAPI_PluginManager::get(); + std::shared_ptr aDoc = aMgr->rootDocument(); + aDoc->undo(); + updateCommandStatus(); +} + +//****************************************************** +void XGUI_Workshop::onRedo() +{ + std::shared_ptr aMgr = ModelAPI_PluginManager::get(); + std::shared_ptr aDoc = aMgr->rootDocument(); + aDoc->redo(); + updateCommandStatus(); +} + + //****************************************************** XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule) { @@ -340,3 +369,38 @@ bool XGUI_Workshop::activateModule() myPartSetModule->createFeatures(); return true; } + +//****************************************************** +void XGUI_Workshop::updateCommandStatus() +{ + XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); + + QList aCommands = aMenuBar->features(); + QList::const_iterator aIt; + + std::shared_ptr aMgr = ModelAPI_PluginManager::get(); + if (aMgr->hasRootDocument()) { + XGUI_Command* aUndoCmd; + XGUI_Command* aRedoCmd; + for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) { + if ((*aIt)->id() == "UNDO_CMD") + aUndoCmd = (*aIt); + else if ((*aIt)->id() == "REDO_CMD") + aRedoCmd = (*aIt); + else // Enable all commands + (*aIt)->enable(); + } + std::shared_ptr aDoc = aMgr->rootDocument(); + aUndoCmd->setEnabled(aDoc->canUndo()); + aRedoCmd->setEnabled(aDoc->canRedo()); + } else { + for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) { + if ((*aIt)->id() == "NEW_CMD") + (*aIt)->enable(); + else if ((*aIt)->id() == "EXIT_CMD") + (*aIt)->enable(); + else + (*aIt)->disable(); + } + } +} \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 16c542543..31d87bbbc 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -50,11 +50,15 @@ public: virtual void processEvent(const Event_Message* theMessage); public slots: + void updateCommandStatus(); + void onNew(); void onOpen(); void onSave(); void onSaveAs(); void onExit(); + void onUndo(); + void onRedo(); protected: //Event-loop processing methods: -- 2.39.2