From: vsv Date: Fri, 20 Nov 2015 14:36:33 +0000 (+0300) Subject: Fix for a bug with "Move to end" command and undo X-Git-Tag: V_2.1.0~249 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=825f6bb93bb05174728f82025d3a959068b476fe;p=modules%2Fshaper.git Fix for a bug with "Move to end" command and undo --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 7c40774dd..0327796b4 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -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); diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 009da57c6..426779d27 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -259,7 +259,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& 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) { diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 0d9750e08..7eb50de34 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -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(); } diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index b376969bc..b1a70d487 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -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; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 3e1eff31c..f8a81b03f 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -104,6 +104,9 @@ #include #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 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::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 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::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(); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 505bf5370..1d1fa3fee 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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();