Salome HOME
Fix for a bug with "Move to end" command and undo
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 20 Nov 2015 14:36:33 +0000 (17:36 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 20 Nov 2015 14:36:33 +0000 (17:36 +0300)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 7c40774ddf0edbc0d0206e3ca33c9a0de7a1b15d..0327796b471d875ff30038f17e443adb8eb00b03 100644 (file)
@@ -69,7 +69,7 @@ void XGUI_ContextMenuMgr::createActions()
   addAction("RENAME_CMD", aAction);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRename()));
 
-  aAction = new QAction(QIcon(":pictures/move.png"), tr("Move to the end"), this);
+  aAction = new QAction(QIcon(":pictures/move.png"), XGUI_Workshop::MOVE_TO_END_COMMAND, this);
   addAction("MOVE_CMD", aAction);
 
   aAction = new QAction(QIcon(":pictures/color.png"), tr("Color..."), this);
index 009da57c60a8bd076f6b23b7bd6e2feb63d10503..426779d2716290cdc938c80af61a7e325fe7fd81 100644 (file)
@@ -259,7 +259,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
         aParent = createIndex(folderId(aGroup, aDoc.get()), 0, aDoc.get());
     }
     int aChildNb = rowCount(aParent);
-    rebuildBranch(aStartId, aChildNb - aStartId);
+    rebuildBranch(aStartId, aChildNb - aStartId, aParent);
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
     DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument();
     if (aDoc != aRootDoc) {
index 0d9750e0804022017534d738fe6bd1a19879ecfb..7eb50de3409ce79f2c8a48199da60345c0a26c93 100644 (file)
@@ -444,10 +444,33 @@ void XGUI_ObjectsBrowser::onEditItem()
   }
 }
 
+//***************************************************
+QModelIndexList XGUI_ObjectsBrowser::expandedItems(const QModelIndex& theParent) const
+{
+  QModelIndexList aIndexes;
+  QModelIndex aIndex;
+  for (int i = 0; i < myDocModel->rowCount(); i++) {
+    aIndex = myDocModel->index(i, 0, theParent);
+    if (myDocModel->hasChildren(aIndex)) {
+      if (myTreeView->isExpanded(aIndex)) {
+        aIndexes.append(aIndex);
+        QModelIndexList aSubIndexes = expandedItems(aIndex);
+        if (!aSubIndexes.isEmpty())
+          aIndexes.append(aSubIndexes);
+      }
+    }
+  }
+  return aIndexes;
+}
+
 //***************************************************
 void XGUI_ObjectsBrowser::rebuildDataTree()
 {
+  QModelIndexList aIndexList = expandedItems();
   myDocModel->rebuildDataTree();
+  foreach(QModelIndex aIndex, aIndexList) {
+    myTreeView->setExpanded(aIndex, true);
+  }
   update();
 }
 
index b376969bc4e0cc09003ba5dc2edd213332c6e097..b1a70d487ec1cab3f2d1c6bdc6baf1e8bc89df45 100644 (file)
@@ -207,6 +207,7 @@ signals:
   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
 
  private:
+  QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
 
   //! Internal model
   XGUI_DataModel* myDocModel;
index 3e1eff31c320ec4fdf51f7022522796bb920e683..f8a81b03f701a6753fbb71fbde764f8fbfa7109e 100755 (executable)
 #include <dlfcn.h>
 #endif
 
+
+QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
+
 //#define DEBUG_DELETE
 
 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
@@ -804,14 +807,18 @@ void XGUI_Workshop::onUndo(int theTimes)
 {
   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
   SessionPtr aMgr = ModelAPI_Session::get();
+  std::list<std::string> aUndoList = aMgr->undoList();
   if (aMgr->isOperation()) {
     /// this is important for nested operations
     /// when sketch operation is active, this condition is false and
     /// the sketch operation is not aborted
     operationMgr()->onAbortOperation();
   }
-  for (int i = 0; i < theTimes; ++i) {
+  std::list<std::string>::const_iterator aIt = aUndoList.cbegin();
+  for (int i = 0; (i < theTimes) && (aIt != aUndoList.cend()); ++i, ++aIt) {
     aMgr->undo();
+    if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
+      myObjectBrowser->rebuildDataTree();
   }
 
   operationMgr()->updateApplyOfOperations();
@@ -829,14 +836,18 @@ void XGUI_Workshop::onRedo(int theTimes)
 
   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
   SessionPtr aMgr = ModelAPI_Session::get();
+  std::list<std::string> aRedoList = aMgr->redoList();
   if (aMgr->isOperation()) {
     /// this is important for nested operations
     /// when sketch operation is active, this condition is false and
     /// the sketch operation is not aborted
     operationMgr()->onAbortOperation();
   }
-  for (int i = 0; i < theTimes; ++i) {
+  std::list<std::string>::const_iterator aIt = aRedoList.cbegin();
+  for (int i = 0; (i < theTimes) && (aIt != aRedoList.cend()); ++i, ++aIt) {
     aMgr->redo();
+    if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
+      myObjectBrowser->rebuildDataTree();
   }
   operationMgr()->updateApplyOfOperations();
   updateCommandStatus();
index 505bf5370343d4e909078c396582b47d94198c12..1d1fa3fee64bc14fcc6fd586c3a385d904fe9b65 100755 (executable)
@@ -47,6 +47,7 @@ class QMainWindow;
 
 class QAction;
 
+
 /**\class XGUI_Workshop
  * \ingroup GUI
  * \brief Class which defines a configuration of the application (Workshop) and launches it.
@@ -258,6 +259,10 @@ Q_OBJECT
   /// \param theUpdateViewer update viewer flag
   void synchronizeGroupInViewer(const DocumentPtr& theDoc, const std::string& theGroup, bool theUpdateViewer);
 
+  /// A constant string used for "Move to end" command definition
+  /// It is used for specific processing of Undo/Redo for this command.
+  static QString MOVE_TO_END_COMMAND;
+
 signals:
   /// Emitted when selection happens in Salome viewer
   void salomeViewerSelection();