From: vsv Date: Thu, 7 Dec 2017 12:18:58 +0000 (+0300) Subject: Issue #2340: Provide list of accessible Undo/Redo commands for widgets X-Git-Tag: V_2.10.0RC~80 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9c514651da1b6a7ecc068e6bc1e146f569873603;p=modules%2Fshaper.git Issue #2340: Provide list of accessible Undo/Redo commands for widgets --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index c63e684cb..18a201a39 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -252,6 +253,11 @@ Q_OBJECT /// Returns true if the event is processed. The default implementation is empty, returns false. virtual bool processAction(ModuleBase_ActionType theActionType); + /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list. + /// \param theActionType type of action. It can be ActionUndo or ActionRedo. + virtual QList actionsList(ModuleBase_ActionType theActionType) const + { return QList(); } + /// Sends Update and Redisplay for the given object /// \param theObj is updating object void updateObject(ObjectPtr theObj); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 15be27427..53350edaf 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -505,6 +505,7 @@ void ModuleBase_WidgetMultiSelector::appendSelectionInHistory() QList aSelected = getFilteredSelected(); myCurrentHistoryIndex++; mySelectedHistoryValues.append(aSelected); + int aNb = mySelectedHistoryValues.count(); myWorkshop->updateCommandStatus(); #ifdef DEBUG_UNDO_REDO @@ -882,3 +883,32 @@ bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject, } return aFound; } + +QList ModuleBase_WidgetMultiSelector::actionsList(ModuleBase_ActionType theActionType) const +{ + QList aList; + if (myCurrentHistoryIndex > -1) { + int i = 0; + QString aTitle("Selection %1 items"); + QIcon aIcon(":pictures/selection.png"); + switch (theActionType) { + case ActionUndo: + i = 1; + while (i <= myCurrentHistoryIndex) { + ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count())); + aList.append(aInfo); + i++; + } + break; + case ActionRedo: + i = mySelectedHistoryValues.length() - 1; + while (i > myCurrentHistoryIndex) { + ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count())); + aList.append(aInfo); + i--; + } + break; + } + } + return aList; +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 6b35b9380..96542e3f2 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -103,6 +103,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// \return a boolean value virtual bool isValidSelectionCustom(const std::shared_ptr& thePrs); + /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list. + /// \param theActionType type of action. It can be ActionUndo or ActionRedo. + virtual QList actionsList(ModuleBase_ActionType theActionType) const; + public slots: /// Slot is called on selection type changed void onSelectionTypeChanged(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5d935ad3f..e4fc24368 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1265,12 +1265,21 @@ void XGUI_Workshop::updateCommandStatus() //****************************************************** void XGUI_Workshop::updateHistory() { - std::list aUndoList = ModelAPI_Session::get()->undoList(); - QList aUndoRes = processHistoryList(aUndoList); - emit updateUndoHistory(aUndoRes); + bool isActionEnabled = false; + ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget(); + QList aUndoRes; + QList aRedoRes; + if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) { + aUndoRes = anActiveWidget->actionsList(ActionUndo); + aRedoRes = anActiveWidget->actionsList(ActionRedo); + } else { + std::list aUndoList = ModelAPI_Session::get()->undoList(); + aUndoRes = processHistoryList(aUndoList); - std::list aRedoList = ModelAPI_Session::get()->redoList(); - QList aRedoRes = processHistoryList(aRedoList); + std::list aRedoList = ModelAPI_Session::get()->redoList(); + aRedoRes = processHistoryList(aRedoList); + } + emit updateUndoHistory(aUndoRes); emit updateRedoHistory(aRedoRes); } diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index cc92ee6fb..14e55f367 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -68,5 +68,6 @@ pictures/insert_folder_before.png pictures/move_out_after.png pictures/move_out_before.png + pictures/selection.png diff --git a/src/XGUI/pictures/selection.png b/src/XGUI/pictures/selection.png new file mode 100644 index 000000000..4cc4088db Binary files /dev/null and b/src/XGUI/pictures/selection.png differ