Salome HOME
History menu: improvments and bugfixes
authorsbh <sergey.belash@opencascade.com>
Fri, 13 Feb 2015 13:39:14 +0000 (16:39 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 13 Feb 2015 13:41:26 +0000 (16:41 +0300)
12 files changed:
src/Model/Model_Session.h
src/ModelAPI/ModelAPI_Session.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_HistoryMenu.cpp
src/XGUI/XGUI_HistoryMenu.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 0ae8bc46aa44fe763f82023531cb27bc3be7aed7..ac1e4e1b0e3f3b5f0d182233b9a7622f86a3d62a 100644 (file)
@@ -48,7 +48,7 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   MODEL_EXPORT virtual void closeAll();
 
   //! Starts a new operation (opens a tansaction)
-  MODEL_EXPORT virtual void startOperation(const std::string& theId);
+  MODEL_EXPORT virtual void startOperation(const std::string& theId = "");
   //! Finishes the previously started operation (closes the transaction)
   MODEL_EXPORT virtual void finishOperation();
   //! Aborts the operation 
index 933dfc58689bb237d1fee40fa04dcf19a3e88a9b..613122a35a7e01ae0dbb312770127cce08926d5d 100644 (file)
@@ -46,7 +46,7 @@ class MODELAPI_EXPORT ModelAPI_Session
 
   //! Starts a new operation (opens a tansaction)
   //! \param theId of operation for history (optional)
-  virtual void startOperation(const std::string& theId) = 0;
+  virtual void startOperation(const std::string& theId = "") = 0;
   //! Finishes the previously started operation (closes the transaction)
   virtual void finishOperation() = 0;
   //! Aborts the operation 
index bfe58446d370168a50092075ea228460c6ca7c25..459af0553e89d741c535125a0c1013a4a416b1aa 100644 (file)
@@ -147,6 +147,9 @@ std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
 void ModuleBase_Operation::start()
 {
   QString anId = getDescription()->operationId();
+  if (myIsEditing) {
+      anId = anId.append(EditSuffix());
+  }
   ModelAPI_Session::get()->startOperation(anId.toStdString());
 
   if (!myIsEditing)
index 8842230b25a0f726d85989fee69a774dbfa25d19..f43ed76e18752ad394676cb25c6d03e983e74639 100644 (file)
@@ -50,6 +50,9 @@ class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
 Q_OBJECT
 
  public:
+
+  /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
+  static QString EditSuffix() { return "_E"; }
   /// Constructor
   /// \param theId the operation identifier
   /// \param theParent the QObject parent
index 05409232e51619b6b55f2f601d56f2cf0abb850b..a8be84bd87af50bc114983bc71c6aa5096524e43 100644 (file)
@@ -555,6 +555,7 @@ void PartSet_Module::deleteObjects()
     //}
   }
 
+  QString aDescription = tr("Delete");
   if (!aRefFeatures.empty()) {
     QStringList aRefNames;
     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
@@ -567,6 +568,7 @@ void PartSet_Module::deleteObjects()
     }
     if (!aRefNames.empty()) {
       QString aNames = aRefNames.join(", ");
+      aDescription += aNames.prepend(" ");
 
       QMainWindow* aDesktop = aWorkshop->desktop();
       QMessageBox::StandardButton aRes = QMessageBox::warning(
@@ -580,7 +582,7 @@ void PartSet_Module::deleteObjects()
   }
 
   SessionPtr aMgr = ModelAPI_Session::get();
-  aMgr->startOperation("DeletePartSet");
+  aMgr->startOperation(aDescription.toStdString());
   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
                                        aLast = aRefFeatures.end();
   for (; anIt != aLast; anIt++) {
index c3613d22b9a9eab202a4cdd7f00502afac90f377..0798bbc4809bb11e9c0a8fb59e9eea9949c8ae26 100644 (file)
@@ -228,9 +228,13 @@ QAction* XGUI_ActionsMgr::operationStateAction(OperationStateActionId theId, QOb
         aResult = new QAction(QIcon(":pictures/button_ok.png"), "", theParent);
         break;
       case Abort:
-      case AbortAll:
+      case AbortAll: {
         aResult = new QAction(QIcon(":pictures/button_cancel.png"), "", theParent);
-        break;
+        if(theId == Abort) {
+          aResult->setShortcut(QKeySequence(Qt::Key_Escape));
+        }
+      }
+      break;
       case Help:
         aResult = new QAction(QIcon(":pictures/button_help.png"), "", theParent);
         break;
@@ -242,6 +246,18 @@ QAction* XGUI_ActionsMgr::operationStateAction(OperationStateActionId theId, QOb
   return aResult;
 }
 
+ActionInfo XGUI_ActionsMgr::actionInfoById(const QString& theId)
+{
+  ActionInfo aResult;
+  if(myActions.contains(theId)) {
+    aResult.initFrom(myActions.value(theId));
+  } else {
+   aResult.id = theId;
+   aResult.text = theId;
+  }
+  return aResult;
+}
+
 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
 {
   foreach(QString eachAction, myActions.keys())
index cbff72d128403194a4c6858a045df346833b9326..00f6086efdb397fae4b389a5744343c67845895a 100644 (file)
@@ -12,6 +12,8 @@
 #include <Events_Listener.h>
 #include <ModelAPI_Feature.h>
 
+#include <ModuleBase_ActionInfo.h>
+
 #include <QObject>
 #include <QMap>
 #include <QList>
@@ -77,6 +79,8 @@ class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
   //! If there is no such action, it will be created.
   QAction* operationStateAction(OperationStateActionId theId, QObject* theParent = 0);
 
+  ActionInfo actionInfoById(const QString& theId);
+
  public slots:
   //! Update workbench actions according to OperationMgr state:
   //! No active operations: all actions but nested are available
index 7ae27d0b3c2946413a3a9e37902b4853f6666e5a..95c6ae802bd7811ce71fcc4d221a2bb1db4ae491 100644 (file)
@@ -66,14 +66,16 @@ void XGUI_HistoryMenu::setHistory(const QList<ActionInfo>& theActions)
   }
 }
 
+void XGUI_HistoryMenu::leaveEvent(QEvent* theEvent)
+{
+  setStackSelectedTo(NULL);
+  QMenu::leaveEvent(theEvent);
+}
 
 void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
 {
-  if (!theItem)
-    return;
-
   QListWidgetItem* eachItem = NULL;
-  bool isSelect = true;
+  bool isSelect = theItem != NULL;
   for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
     eachItem = myHistoryList->item(aRow);
     myHistoryList->setItemSelected(eachItem, isSelect);
@@ -82,6 +84,8 @@ void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
       isSelect = false;
     }
   }
+  // to avoid blinking caused by QMenu paint event (paints on top of the list)
+  myHistoryList->repaint();
 }
 
 void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
@@ -89,5 +93,4 @@ void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
   int selectedSize = myHistoryList->row(theItem) + 1;
   emit actionSelected(selectedSize);
   hide();
-  myHistoryList->clear();
 }
index bc45f7a4d9c14b9db5b29bafaa2655eb789068a5..563689e43b2805a906a439153f08092269166a13 100644 (file)
@@ -31,11 +31,15 @@ class XGUI_EXPORT XGUI_HistoryMenu : public QMenu
  public slots:
   void setHistory(const QList<ActionInfo>&);
 
+ protected:
+  virtual void leaveEvent(QEvent *);
+
  protected slots:
   void setStackSelectedTo(QListWidgetItem *);
   void onItemPressed(QListWidgetItem *);
   void initMenu();
 
+
  private:
   QListWidget* myHistoryList;
 };
index 243e98eafff67da3f6ace9ef8a0520d03c33e68b..348eb2a31c8d30d6fffe169f8a0439eb702d0bd9 100644 (file)
@@ -80,7 +80,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
     QString aRes = aEditor->text();
     ObjectPtr aFeature = mySelectedData.first();
     SessionPtr aMgr = ModelAPI_Session::get();
-    aMgr->startOperation("RenameFeature");
+    aMgr->startOperation("Rename");
     aFeature->data()->setName(qPrintable(aRes));
     aMgr->finishOperation();
   }
index 9d4e1ccbf09f3ad3824e650609843d2e5a714aa7..ded693fcf6894aace0670d1b8a44ae95c3594fae 100644 (file)
@@ -1077,11 +1077,10 @@ void XGUI_Workshop::updateCommandStatus()
         // Enable all commands
         aCmd->setEnabled(true);
     }
+
     aUndoCmd->setEnabled(myModule->canUndo());
     aRedoCmd->setEnabled(myModule->canRedo());
-
     updateHistory();
-
   } else {
     foreach(QAction* aCmd, aCommands) {
       QString aId = aCmd->data().toString();
@@ -1100,28 +1099,12 @@ void XGUI_Workshop::updateCommandStatus()
 void XGUI_Workshop::updateHistory()
 {
   std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
-  std::list<std::string>::iterator it = aUndoList.begin();
-  QList<ActionInfo> aUndoRes;
-  for ( ; it != aUndoList.end(); it++) {
-    QString anId = QString::fromStdString(*it);
-    QIcon aIcon;
-    if (myIcons.contains(anId))
-      aIcon = QIcon(myIcons[anId]);
-    aUndoRes << ActionInfo(aIcon, anId);
-  }
+  QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
   emit updateUndoHistory(aUndoRes);
 
   std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
-  it = aRedoList.begin();
-  QList<ActionInfo> aRedoRes;
-  for ( ; it != aRedoList.end(); it++) {
-    QString anId = QString::fromStdString(*it);
-    QIcon aIcon;
-    if (myIcons.contains(anId))
-      aIcon = QIcon(myIcons[anId]);
-    aRedoRes << ActionInfo(aIcon, anId);
-  }
-  emit updateRedoHistory(aUndoRes);
+  QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
+  emit updateRedoHistory(aRedoRes);
 }
 
 //******************************************************
@@ -1345,7 +1328,15 @@ These features will be deleted also. Would you like to continue?")).arg(aNames),
   }
 
   SessionPtr aMgr = ModelAPI_Session::get();
-  aMgr->startOperation("DeleteObjects");
+  QString aDescription = tr("Delete %1");
+  QStringList aObjectNames;
+  foreach (ObjectPtr aObj, theList) {
+    if (!aObj->data().get())
+      continue;
+    aObjectNames << QString::fromStdString(aObj->data()->name());
+  }
+  aDescription = aDescription.arg(aObjectNames.join(", "));
+  aMgr->startOperation(aDescription.toStdString());
   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
                                        aLast = aRefFeatures.end();
   for (; anIt != aLast; anIt++) {
@@ -1373,6 +1364,7 @@ These features will be deleted also. Would you like to continue?")).arg(aNames),
 
   myDisplayer->updateViewer();
   aMgr->finishOperation();
+  updateCommandStatus();
 }
 
 //**************************************************************
@@ -1487,5 +1479,23 @@ void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, co
   }
   connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
   connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
+}
 
+QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
+{
+  QList<ActionInfo> aResult;
+  std::list<std::string>::const_iterator it = theList.cbegin();
+  for (; it != theList.cend(); it++) {
+    QString anId = QString::fromStdString(*it);
+    bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
+    if (isEditing) {
+      anId.chop(ModuleBase_Operation::EditSuffix().size());
+    }
+    ActionInfo anInfo = myActionsMgr->actionInfoById(anId);
+    if (isEditing) {
+      anInfo.text = anInfo.text.prepend("Modify ");
+    }
+    aResult << anInfo;
+  }
+  return aResult;
 }
index b492fa1134d3bf225c9ef7dd0b4a19d7feb88f15..6ef022dfbc1dc8bfc18800935be88cbf45deaa28 100644 (file)
@@ -389,6 +389,9 @@ signals:
   //! \param theSlot - onUndo(int) or onRedo(int) SLOT
   void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
 
+  //! Creates list of actions (commands) by given history list from session
+  QList<ActionInfo> processHistoryList(const std::list<std::string>&) const;
+
 private:
   AppElements_MainWindow* myMainWindow;
   ModuleBase_IModule* myModule;