From: vsv Date: Thu, 11 Sep 2014 08:19:22 +0000 (+0400) Subject: Show save document status in window title X-Git-Tag: V_0.4.4~69^2~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dfff6a74d6586208bf47699b3f434252cc524d2d;p=modules%2Fshaper.git Show save document status in window title --- diff --git a/src/NewGeom/NewGeom_DataModel.cpp b/src/NewGeom/NewGeom_DataModel.cpp index 99327c50c..cfe084655 100644 --- a/src/NewGeom/NewGeom_DataModel.cpp +++ b/src/NewGeom/NewGeom_DataModel.cpp @@ -1,7 +1,8 @@ #include "NewGeom_DataModel.h" +#include "NewGeom_Module.h" -NewGeom_DataModel::NewGeom_DataModel(CAM_Module* theModule) - : LightApp_DataModel(theModule) +NewGeom_DataModel::NewGeom_DataModel(NewGeom_Module* theModule) + : LightApp_DataModel(theModule), myModule(theModule) { } diff --git a/src/NewGeom/NewGeom_DataModel.h b/src/NewGeom/NewGeom_DataModel.h index 7beaf392f..fbd90dd44 100644 --- a/src/NewGeom/NewGeom_DataModel.h +++ b/src/NewGeom/NewGeom_DataModel.h @@ -5,11 +5,13 @@ #include "NewGeom.h" #include +class NewGeom_Module; + class NewGeom_EXPORT NewGeom_DataModel : public LightApp_DataModel { Q_OBJECT public: - NewGeom_DataModel(CAM_Module* theModule); + NewGeom_DataModel(NewGeom_Module* theModule); virtual ~NewGeom_DataModel(); virtual bool open(const QString& thePath, CAM_Study* theStudy, QStringList theFiles); @@ -25,7 +27,7 @@ class NewGeom_EXPORT NewGeom_DataModel : public LightApp_DataModel private: QString myStudyPath; - + NewGeom_Module* myModule; }; #endif diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index b4b52e626..86c32772c 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -75,6 +75,8 @@ Q_OBJECT virtual void createPreferences(); virtual void preferencesChanged(const QString& theSection, const QString& theParam); + XGUI_Workshop* workshop() const { return myWorkshop; } + public slots: virtual bool activateModule(SUIT_Study* theStudy); virtual bool deactivateModule(SUIT_Study* theStudy); diff --git a/src/XGUI/XGUI_IPrefMgr.h b/src/XGUI/XGUI_IPrefMgr.h index 1a4f8481c..af0752d6f 100644 --- a/src/XGUI/XGUI_IPrefMgr.h +++ b/src/XGUI/XGUI_IPrefMgr.h @@ -9,13 +9,28 @@ #include #include +/** +* An interface class which provides incapsulation of SUIT_PreferenceMgr class instance +* It is used in order to make common interface to Preference manager in Salome +* and this application +*/ class XGUI_IPrefMgr { public: + /** + * Add preference item into preference dialog box + * \param theLbl - label of the item + * \param pId - id of container item + * \param theType - type of the item + * \param theSection - resouce section name + * \param theName - name of the resource + * Returns Id of the ctreated item + */ virtual int addPreference(const QString& theLbl, int pId, SUIT_PreferenceMgr::PrefItemType theType, const QString& theSection, const QString& theName ) = 0; + /// Returns incapsulated preference manager virtual SUIT_PreferenceMgr* prefMgr() const = 0; }; diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index b1171dc64..67edcd059 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -16,11 +16,13 @@ #include #include + XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), - myPythonConsole(0) + myPythonConsole(0), myIsModified(false) { - setWindowTitle(tr("New Geom")); + myTitle = tr("New Geom"); + updateTitle(); createMainMenu(); QMdiArea* aMdiArea = new QMdiArea(this); aMdiArea->setContextMenuPolicy(Qt::ActionsContextMenu); @@ -250,6 +252,31 @@ void XGUI_MainWindow::createMainMenu() addDockWidget(Qt::TopDockWidgetArea, aMenuDock); } + +void XGUI_MainWindow::updateTitle() +{ + QString aTitle = myTitle; + if (!myCurrentDir.isNull()) + aTitle += ":" + myCurrentDir; + if (myIsModified) + aTitle += "*"; + setWindowTitle(aTitle); +} + +void XGUI_MainWindow::setCurrentDir(const QString& theDir, bool toUpdate) +{ + myCurrentDir = theDir; + if (toUpdate) + updateTitle(); +} + +void XGUI_MainWindow::setModifiedState(bool isModified, bool toUpdate) +{ + myIsModified = isModified; + if (toUpdate) + updateTitle(); +} + CloseEventWatcher::CloseEventWatcher(QObject* theParent) : QObject(theParent) { diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index a8a067cf6..3294f58ac 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -51,6 +51,17 @@ Q_OBJECT void createSubWindow(); + /// Add name of current directory into title of desktop window + void setCurrentDir(const QString& theDir, bool toUpdate = true); + + /// Add asterisk to a title of the window + void setModifiedState(bool isModified, bool toUpdate = true); + + /// Returns current state of modification + bool isModifiedState() const { return myIsModified; } + + void updateTitle(); + private slots: void cascadeWindows(); void onViewCreated(XGUI_ViewWindow* theWindow); @@ -69,6 +80,10 @@ signals: XGUI_MainMenu* myMenuBar; XGUI_Viewer* myViewer; + QString myTitle; + QString myCurrentDir; + bool myIsModified; + PyConsole_EnhConsole* myPythonConsole; }; diff --git a/src/XGUI/XGUI_Preferences.h b/src/XGUI/XGUI_Preferences.h index 2493414bf..a6fbc8a2b 100644 --- a/src/XGUI/XGUI_Preferences.h +++ b/src/XGUI/XGUI_Preferences.h @@ -98,12 +98,14 @@ Q_OBJECT virtual void accept(); private: - void createEditors(); - void createViewerPage(int thePageId); - void createMenuPage(int thePageId); - //void createCustomPage(int thePageId); - - void updateCustomProps(); + /// Create editors for aplication properties + void createEditors(); + + /// Create a viewer page in dialog box + void createViewerPage(int thePageId); + + /// Create menu properties page in the dialog box + void createMenuPage(int thePageId); XGUI_PreferencesMgr* myPreferences; bool myIsChanged; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 4bd292de7..967f560f2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -237,11 +237,10 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) if (!aFeatureMsg->isInternal()) { addFeature(aFeatureMsg); } - return; } // Process creation of Part - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); onFeatureCreatedMsg(aUpdMsg); @@ -250,48 +249,42 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) mySalomeConnector->createPreferences(); myUpdatePrefs = false; } - return; } - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) { + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) { myUpdatePrefs = true; - return; } // Redisplay feature - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) { + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) { const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); onFeatureRedisplayMsg(aUpdMsg); - return; } //Update property panel on corresponding message. If there is no current operation (no //property panel), or received message has different feature to the current - do nothing. - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { const ModelAPI_ObjectUpdatedMessage* anUpdateMsg = dynamic_cast(theMessage); onFeatureUpdatedMsg(anUpdateMsg); - return; } - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { const ModelAPI_ObjectDeletedMessage* aDelMsg = dynamic_cast(theMessage); onObjectDeletedMsg(aDelMsg); - return; } - if (theMessage->eventID() == Events_LongOp::eventID()) { + else if (theMessage->eventID() == Events_LongOp::eventID()) { if (Events_LongOp::isPerformed()) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); //QTimer::singleShot(10, this, SLOT(onStartWaiting())); else QApplication::restoreOverrideCursor(); - return; } //An operation passed by message. Start it, process and commit. - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) { + else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) { const Config_PointerMessage* aPartSetMsg = dynamic_cast(theMessage); //myPropertyPanel->cleanContent(); @@ -304,12 +297,18 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) updateCommandStatus(); } } - return; + } else { + //Show error dialog if error message received. + const Events_Error* anAppError = dynamic_cast(theMessage); + if (anAppError) { + emit errorOccurred(QString::fromLatin1(anAppError->description())); + } } - //Show error dialog if error message received. - const Events_Error* anAppError = dynamic_cast(theMessage); - if (anAppError) { - emit errorOccurred(QString::fromLatin1(anAppError->description())); + if (!isSalomeMode()) { + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + DocumentPtr aDoc = aMgr->rootDocument(); + if (aDoc->isModified() != myMainWindow->isModifiedState()) + myMainWindow->setModifiedState(aDoc->isModified()); } } @@ -528,13 +527,12 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation) /* * Saves document with given name. */ -void XGUI_Workshop::saveDocument(QString theName) +void XGUI_Workshop::saveDocument(const QString& theName, std::list& theFileNames) { QApplication::restoreOverrideCursor(); PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); DocumentPtr aDoc = aMgr->rootDocument(); - std::list aFileNames; - aDoc->save(theName.toLatin1().constData(), aFileNames); + aDoc->save(theName.toLatin1().constData(), theFileNames); QApplication::restoreOverrideCursor(); } @@ -624,8 +622,10 @@ bool XGUI_Workshop::onSave() if (myCurrentDir.isEmpty()) { return onSaveAs(); } - saveDocument(myCurrentDir); + std::list aFiles; + saveDocument(myCurrentDir, aFiles); updateCommandStatus(); + myMainWindow->setModifiedState(false); return true; } @@ -656,6 +656,10 @@ bool XGUI_Workshop::onSaveAs() } } myCurrentDir = aTempDir; + if (!isSalomeMode()) { + myMainWindow->setCurrentDir(myCurrentDir, false); + myMainWindow->setModifiedState(false); + } return onSave(); } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index dbf160d15..cf1c709a0 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -162,6 +162,19 @@ Q_OBJECT return myModule; } + /// Returns current directory whic contains data files + QString currentDataDir() const { return myCurrentDir; } + + /// Returns current directory whic contains data files + void setCurrentDataDir(const QString& theDir) { myCurrentDir = theDir; } + + /** + * Save the current document into a directory + * \param theName - path to the directory + * \param theFileNames - returned file names created in this directory + */ + void saveDocument(const QString& theName, std::list& theFileNames); + signals: void salomeViewerSelection(); void errorOccurred(const QString&); @@ -193,7 +206,6 @@ signals: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*); void connectWithOperation(ModuleBase_Operation* theOperation); - void saveDocument(QString theName); void onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg); void onFeatureCreatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);