From 9c514651da1b6a7ecc068e6bc1e146f569873603 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 7 Dec 2017 15:18:58 +0300 Subject: [PATCH] Issue #2340: Provide list of accessible Undo/Redo commands for widgets --- src/ModuleBase/ModuleBase_ModelWidget.h | 6 ++++ .../ModuleBase_WidgetMultiSelector.cpp | 30 ++++++++++++++++++ .../ModuleBase_WidgetMultiSelector.h | 4 +++ src/XGUI/XGUI_Workshop.cpp | 19 ++++++++--- src/XGUI/XGUI_pictures.qrc | 1 + src/XGUI/pictures/selection.png | Bin 0 -> 393 bytes 6 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/XGUI/pictures/selection.png 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 0000000000000000000000000000000000000000..4cc4088dbda7539a3ca3a3dc1351862a7c45ea2a GIT binary patch literal 393 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=fts&@Fyn;$$~izm$r9IylHmNblJdl&REC1Y%)Ao4ywnl}6Fmbx zL(41IHl+X+{q%Hk46*QkI$1xApMcTU=%8v7|i5EbJrSp$EJ^Zut*I zTO@2+BswNU9QnD9Z)y9xeNU$Ej@$oV|9aM(;+FtHbvoQ&v&dr1ln_gt96j^g(+jWr zd04(~3Q}NdWWF}>p!I&1N+)5BuTu{<<os_VJJw_MD2Hz#hidaw!@2n?RCelF{r5}E*(?UgwI literal 0 HcmV?d00001 -- 2.39.2