#7347 Property Editor : Enable undo/redo of field changed operations

This commit is contained in:
Magne Sjaastad 2021-02-09 13:31:27 +01:00
parent 14c09f30cf
commit bcdba1bb8f
22 changed files with 265 additions and 74 deletions

View File

@ -230,6 +230,8 @@
<file>ObjectiveFunctionWeight.svg</file>
<file>CellFilter_UserDefined.png</file>
<file>CellFilter_Polygon.png</file>
<file>undo.png</file>
<file>redo.png</file>
</qresource>
<qresource prefix="/Shader">
<file>fs_CellFace.glsl</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B

View File

@ -103,6 +103,7 @@
#include "RiuViewer.h"
#include "cafAppEnum.h"
#include "cafCmdExecCommandManager.h"
#include "cafEffectGenerator.h"
#include "cafFixedAtlasFont.h"
#include "cafPdmUiModelChangeDetector.h"
@ -944,6 +945,12 @@ RiuPlotMainWindow* RiaGuiApplication::getOrCreateMainPlotWindow()
void RiaGuiApplication::createMainWindow()
{
CVF_ASSERT( m_mainWindow == nullptr );
if ( RiaPreferences::current()->useUndoRedo() )
{
caf::CmdExecCommandManager::instance()->enableUndoCommandSystem( true );
}
m_mainWindow = new RiuMainWindow;
QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)";
m_mainWindow->setWindowTitle( "ResInsight " + platform );
@ -973,6 +980,11 @@ void RiaGuiApplication::createMainPlotWindow()
{
CVF_ASSERT( m_mainPlotWindow == nullptr );
if ( RiaPreferences::current()->useUndoRedo() )
{
caf::CmdExecCommandManager::instance()->enableUndoCommandSystem( true );
}
m_mainPlotWindow = new RiuPlotMainWindow;
m_mainPlotWindow->setWindowTitle( "Plots - ResInsight" );
m_mainPlotWindow->setDefaultWindowSize();

View File

@ -337,6 +337,9 @@ RiaPreferences::RiaPreferences( void )
CAF_PDM_InitField( &m_showProgressBar, "showProgressBar", true, "Show Progress Bar", "", "", "" );
m_showProgressBar.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
CAF_PDM_InitField( &m_useUndoRedo, "useUndoRedo", false, "Use Undo/Redo", "", "", "" );
m_useUndoRedo.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
CAF_PDM_InitFieldNoDefault( &m_plotTemplateFolders, "plotTemplateFolders", "Plot Template Folder(s)", "", "", "" );
m_plotTemplateFolders.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
CAF_PDM_InitField( &m_searchPlotTemplateFoldersRecursively,
@ -448,7 +451,7 @@ void RiaPreferences::defineEditorAttribute( const caf::PdmFieldHandle* field,
field == &m_showLegendBackground || field == &m_showSummaryTimeAsLongString ||
field == &m_showViewIdInProjectTree || field == &m_useMultipleThreadsWhenLoadingSummaryData ||
field == &m_enableFaultsByDefault || field == &m_showProgressBar || field == &m_openExportedPdfInViewer ||
field == &m_showInfoBox || field == &m_showGridBox )
field == &m_showInfoBox || field == &m_showGridBox || field == &m_useUndoRedo )
{
caf::PdmUiCheckBoxEditorAttribute* myAttr = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>( attribute );
if ( myAttr )
@ -622,6 +625,7 @@ void RiaPreferences::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
uiOrdering.add( &m_showTestToolbar );
uiOrdering.add( &m_includeFractureDebugInfoFile );
uiOrdering.add( &m_holoLensExportFolder );
uiOrdering.add( &m_useUndoRedo );
}
uiOrdering.skipRemainingFields( true );
@ -906,6 +910,14 @@ QString RiaPreferences::gtestFilter() const
return m_gtestFilter();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaPreferences::useUndoRedo() const
{
return m_useUndoRedo();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -96,6 +96,7 @@ public:
bool useShaders() const;
bool show3dInformation() const;
QString gtestFilter() const;
bool useUndoRedo() const;
const QString& dateFormat() const;
const QString& timeFormat() const;
@ -216,6 +217,7 @@ private:
caf::PdmField<bool> m_useMultipleThreadsWhenLoadingSummaryData;
caf::PdmField<bool> m_showProgressBar;
caf::PdmField<QString> m_gtestFilter;
caf::PdmField<bool> m_useUndoRedo;
caf::PdmField<caf::AppEnum<RiaDefines::ThemeEnum>> m_guiTheme;

View File

@ -32,7 +32,12 @@
//--------------------------------------------------------------------------------------------------
QString RicDeleteItemExec::name()
{
return m_commandData->classKeyword();
if ( !m_commandData.m_description().isEmpty() )
{
return m_commandData.m_description();
}
return m_commandData.classKeyword();
}
//--------------------------------------------------------------------------------------------------
@ -41,7 +46,7 @@ QString RicDeleteItemExec::name()
void RicDeleteItemExec::redo()
{
caf::PdmFieldHandle* field =
caf::PdmReferenceHelper::fieldFromReference( m_commandData->m_rootObject, m_commandData->m_pathToField );
caf::PdmReferenceHelper::fieldFromReference( m_commandData.m_rootObject, m_commandData.m_pathToField );
caf::PdmChildArrayFieldHandle* listField = dynamic_cast<caf::PdmChildArrayFieldHandle*>( field );
if ( listField )
@ -49,20 +54,20 @@ void RicDeleteItemExec::redo()
std::vector<caf::PdmObjectHandle*> children;
listField->childObjects( &children );
caf::PdmObjectHandle* obj = children[m_commandData->m_indexToObject];
caf::PdmObjectHandle* obj = children[m_commandData.m_indexToObject];
caf::SelectionManager::instance()->removeObjectFromAllSelections( obj );
std::vector<caf::PdmObjectHandle*> referringObjects;
obj->objectsWithReferringPtrFields( referringObjects );
if ( m_commandData->m_deletedObjectAsXml().isEmpty() )
if ( m_commandData.m_deletedObjectAsXml().isEmpty() )
{
m_commandData->m_deletedObjectAsXml = xmlObj( obj )->writeObjectToXmlString();
m_commandData.m_deletedObjectAsXml = xmlObj( obj )->writeObjectToXmlString();
}
delete obj;
listField->erase( m_commandData->m_indexToObject );
listField->erase( m_commandData.m_indexToObject );
caf::PdmObjectHandle* parentObj = listField->ownerObject();
parentObj->uiCapability()->updateConnectedEditors();
@ -76,23 +81,33 @@ void RicDeleteItemExec::redo()
void RicDeleteItemExec::undo()
{
caf::PdmFieldHandle* field =
caf::PdmReferenceHelper::fieldFromReference( m_commandData->m_rootObject, m_commandData->m_pathToField );
caf::PdmReferenceHelper::fieldFromReference( m_commandData.m_rootObject, m_commandData.m_pathToField );
caf::PdmChildArrayFieldHandle* listField = dynamic_cast<caf::PdmChildArrayFieldHandle*>( field );
if ( listField )
{
caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( m_commandData->m_deletedObjectAsXml(),
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( m_commandData.m_deletedObjectAsXml(),
caf::PdmDefaultObjectFactory::instance(),
false );
listField->insertAt( m_commandData->m_indexToObject, obj );
listField->insertAt( m_commandData.m_indexToObject, obj );
obj->xmlCapability()->initAfterReadRecursively();
obj->xmlCapability()->resolveReferencesRecursively();
listField->uiCapability()->updateConnectedEditors();
listField->ownerObject()->uiCapability()->updateConnectedEditors();
caf::PdmObjectHandle* parentObj = listField->ownerObject();
if ( parentObj )
{
std::vector<caf::PdmObjectHandle*> referringObjects;
// TODO: Here we need a different concept like onChildAdded()
parentObj->onChildDeleted( listField, referringObjects );
}
if ( m_notificationCenter ) m_notificationCenter->notifyObservers();
}
}
@ -103,13 +118,12 @@ void RicDeleteItemExec::undo()
RicDeleteItemExec::RicDeleteItemExec( caf::NotificationCenter* notificationCenter )
: CmdExecuteCommand( notificationCenter )
{
m_commandData = new RicDeleteItemExecData;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicDeleteItemExecData* RicDeleteItemExec::commandData()
RicDeleteItemExecData& RicDeleteItemExec::commandData()
{
return m_commandData;
}

View File

@ -19,10 +19,9 @@
#pragma once
#include "RicDeleteItemExecData.h"
#include "cafCmdExecuteCommand.h"
class RicDeleteItemExecData;
//==================================================================================================
///
//==================================================================================================
@ -31,12 +30,12 @@ class RicDeleteItemExec : public caf::CmdExecuteCommand
public:
explicit RicDeleteItemExec( caf::NotificationCenter* notificationCenter );
RicDeleteItemExecData* commandData();
RicDeleteItemExecData& commandData();
QString name() override;
void redo() override;
void undo() override;
private:
RicDeleteItemExecData* m_commandData;
RicDeleteItemExecData m_commandData;
};

View File

@ -37,7 +37,8 @@ public:
"CmdDeleteItemExecData tooltip",
"CmdDeleteItemExecData whatsthis" );
CAF_PDM_InitField( &m_pathToField, "PathToField", QString(), "PathToField", "", "PathToField tooltip", "PathToField whatsthis" );
CAF_PDM_InitFieldNoDefault( &m_pathToField, "PathToField", "PathToField", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_description, "Description", "Description", "", "", "" );
CAF_PDM_InitField( &m_indexToObject,
"indexToObject",
-1,
@ -56,6 +57,7 @@ public:
caf::PdmPointer<caf::PdmObjectHandle> m_rootObject;
caf::PdmField<QString> m_description;
caf::PdmField<QString> m_pathToField;
caf::PdmField<int> m_indexToObject;
caf::PdmField<QString> m_deletedObjectAsXml;

View File

@ -95,14 +95,39 @@ void RicDeleteItemFeature::onActionTriggered( bool isChecked )
RicDeleteItemExec* executeCmd = new RicDeleteItemExec( caf::SelectionManager::instance()->notificationCenter() );
RicDeleteItemExecData* data = executeCmd->commandData();
data->m_rootObject = caf::PdmReferenceHelper::findRoot( childArrayFieldHandle );
data->m_pathToField =
caf::PdmReferenceHelper::referenceFromRootToField( data->m_rootObject, childArrayFieldHandle );
data->m_indexToObject = indexAfter;
RicDeleteItemExecData& data = executeCmd->commandData();
data.m_rootObject = caf::PdmReferenceHelper::findRoot( childArrayFieldHandle );
data.m_pathToField = caf::PdmReferenceHelper::referenceFromRootToField( data.m_rootObject, childArrayFieldHandle );
data.m_indexToObject = indexAfter;
{
QString desc;
if ( currentPdmObject->userDescriptionField() )
{
desc = currentPdmObject->userDescriptionField()->uiCapability()->uiValue().toString();
}
else
{
desc = currentPdmObject->uiName();
}
data.m_description = desc + " (delete)";
}
// When the delete feature is ready for redo/undo, activate by using the line below
// Temporarily do not insert these object into undo/redo system as this requires a lot of testing
// for reinserting objects.
bool useUndoRedo = false;
if ( useUndoRedo )
{
caf::CmdExecCommandManager::instance()->processExecuteCommand( executeCmd );
}
else
{
executeCmd->redo();
delete executeCmd;
}
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -1140,7 +1140,6 @@ bool operator<( const RifEclipseSummaryAddress& first, const RifEclipseSummaryAd
//--------------------------------------------------------------------------------------------------
QTextStream& operator<<( QTextStream& str, const RifEclipseSummaryAddress& sobj )
{
CVF_ASSERT( false );
return str;
}
@ -1149,6 +1148,5 @@ QTextStream& operator<<( QTextStream& str, const RifEclipseSummaryAddress& sobj
//--------------------------------------------------------------------------------------------------
QTextStream& operator>>( QTextStream& str, RifEclipseSummaryAddress& sobj )
{
CVF_ASSERT( false );
return str;
}

View File

@ -92,6 +92,14 @@ QString RiuDockWidgetTools::mohrsCirclePlotName()
return "dockMohrsCirclePlot";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuDockWidgetTools::undoStackName()
{
return "dockUndoStack";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -116,6 +124,14 @@ QString RiuDockWidgetTools::plotMainWindowMessagesName()
return "plotMainWindow_dockMessages";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuDockWidgetTools::plotMainWindowUndoStackName()
{
return "plotMainWindow_dockUndoStack";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -139,6 +155,7 @@ QMap<QString, QVariant> RiuDockWidgetTools::widgetVisibilitiesForEclipse()
widgetVisibility[RiuDockWidgetTools::relPermPlotName()] = true;
widgetVisibility[RiuDockWidgetTools::pvtPlotName()] = true;
widgetVisibility[RiuDockWidgetTools::messagesName()] = true;
widgetVisibility[RiuDockWidgetTools::undoStackName()] = false;
widgetVisibility[RiuDockWidgetTools::mohrsCirclePlotName()] = false;
@ -160,6 +177,7 @@ QMap<QString, QVariant> RiuDockWidgetTools::widgetVisibilitiesForGeoMech()
widgetVisibility[RiuDockWidgetTools::relPermPlotName()] = false;
widgetVisibility[RiuDockWidgetTools::pvtPlotName()] = false;
widgetVisibility[RiuDockWidgetTools::messagesName()] = true;
widgetVisibility[RiuDockWidgetTools::undoStackName()] = false;
widgetVisibility[RiuDockWidgetTools::mohrsCirclePlotName()] = true;

View File

@ -45,10 +45,12 @@ public:
static QString pvtPlotName();
static QString messagesName();
static QString mohrsCirclePlotName();
static QString undoStackName();
static QString plotMainWindowProjectTreeName();
static QString plotMainWindowPropertyEditorName();
static QString plotMainWindowMessagesName();
static QString plotMainWindowUndoStackName();
static QAction* toggleActionForWidget( const QObject* parent, const QString& dockWidgetName );

View File

@ -95,6 +95,7 @@
#include <QToolButton>
#include <QTreeView>
#include <QUndoStack>
#include <QUndoView>
#include <QDebug>
@ -132,11 +133,12 @@ RiuMainWindow::RiuMainWindow()
m_dragDropInterface = std::unique_ptr<caf::PdmUiDragDropInterface>( new RiuDragDrop() );
initializeGuiNewProjectLoaded();
m_undoView->setStack( caf::CmdExecCommandManager::instance()->undoStack() );
connect( caf::CmdExecCommandManager::instance()->undoStack(),
SIGNAL( indexChanged( int ) ),
SLOT( slotRefreshUndoRedoActions() ) );
// Enabling the line below will activate the undo stack
// When enableUndoCommandSystem is set false, all commands are executed and deleted immediately
// caf::CmdExecCommandManager::instance()->enableUndoCommandSystem(true);
initializeGuiNewProjectLoaded();
m_memoryCriticalWarning = new QLabel( "" );
m_memoryUsedButton = new QToolButton( nullptr );
@ -203,7 +205,7 @@ void RiuMainWindow::initializeGuiNewProjectLoaded()
}
slotRefreshFileActions();
slotRefreshEditActions();
slotRefreshUndoRedoActions();
slotRefreshViewActions();
refreshAnimationActions();
refreshDrawStyleActions();
@ -502,7 +504,14 @@ void RiuMainWindow::createMenus()
editMenu->addSeparator();
editMenu->addAction( cmdFeatureMgr->action( "RicEditPreferencesFeature" ) );
connect( editMenu, SIGNAL( aboutToShow() ), SLOT( slotRefreshEditActions() ) );
if ( RiaPreferences::current()->useUndoRedo() )
{
editMenu->addSeparator();
editMenu->addAction( m_undoAction );
editMenu->addAction( m_redoAction );
}
connect( editMenu, SIGNAL( aboutToShow() ), SLOT( slotRefreshUndoRedoActions() ) );
// View menu
QMenu* viewMenu = menuBar()->addMenu( "&View" );
@ -574,6 +583,14 @@ void RiuMainWindow::createToolBars()
toolbar->addAction( cmdFeatureMgr->action( "RicSaveProjectFeature" ) );
}
if ( RiaPreferences::current()->useUndoRedo() )
{
QToolBar* toolbar = addToolBar( tr( "Edit" ) );
toolbar->setObjectName( toolbar->windowTitle() );
toolbar->addAction( m_undoAction );
toolbar->addAction( m_redoAction );
}
{
QToolBar* toolbar = addToolBar( tr( "Import" ) );
toolbar->setObjectName( toolbar->windowTitle() );
@ -822,6 +839,17 @@ void RiuMainWindow::createDockPanels()
dockWidget->hide();
}
if ( RiaPreferences::current()->useUndoRedo() )
{
QDockWidget* dockWidget = new QDockWidget( "Undo Stack", this );
dockWidget->setObjectName( RiuDockWidgetTools::undoStackName() );
dockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
dockWidget->setWidget( m_undoView );
addDockWidget( Qt::RightDockWidgetArea, dockWidget );
dockWidget->hide();
}
setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea );
@ -880,15 +908,6 @@ void RiuMainWindow::slotRefreshFileActions()
cmdFeatureMgr->refreshStates( commandIdList );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindow::slotRefreshEditActions()
{
// RiaApplication* app = RiaApplication::instance();
// RISceneManager* proj = app->project();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1389,6 +1408,7 @@ void RiuMainWindow::slotBuildWindowActions()
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::propertyEditorName() );
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::messagesName() );
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::processMonitorName() );
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::undoStackName() );
m_windowMenu->addSeparator();
@ -1472,7 +1492,7 @@ void RiuMainWindow::selectedObjectsChanged()
refreshDrawStyleActions();
refreshAnimationActions();
slotRefreshFileActions();
slotRefreshEditActions();
slotRefreshUndoRedoActions();
slotRefreshViewActions();
// The only way to get to this code is by selection change initiated from the project tree view

View File

@ -195,7 +195,6 @@ private slots:
void slotRefreshFileActions();
// Edit slots
void slotRefreshEditActions();
void slotNewObjectPropertyView();
// View slots
@ -250,8 +249,6 @@ public:
private:
std::unique_ptr<caf::PdmUiDragDropInterface> m_dragDropInterface;
QUndoView* m_undoView;
caf::PdmObject* m_pdmRoot;
caf::PdmUiPropertyView* m_pdmUiPropertyView;

View File

@ -30,10 +30,14 @@
#include "cafPdmUiTreeView.h"
#include "cafCmdFeatureManager.h"
#include <QAction>
#include <QDockWidget>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QSettings>
#include <QUndoStack>
#include <QUndoView>
//--------------------------------------------------------------------------------------------------
///
@ -46,6 +50,16 @@ RiuMainWindowBase::RiuMainWindowBase()
, m_blockSubWindowProjectTreeSelection( false )
{
setDockNestingEnabled( true );
m_undoView = new QUndoView( this );
m_undoAction = new QAction( QIcon( ":/undo.png" ), tr( "Undo" ), this );
m_undoAction->setShortcut( QKeySequence::Undo );
connect( m_undoAction, SIGNAL( triggered() ), SLOT( slotUndo() ) );
m_redoAction = new QAction( QIcon( ":/redo.png" ), tr( "Redo" ), this );
m_redoAction->setShortcut( QKeySequence::Redo );
connect( m_redoAction, SIGNAL( triggered() ), SLOT( slotRedo() ) );
}
//--------------------------------------------------------------------------------------------------
@ -410,3 +424,34 @@ void RiuMainWindowBase::slotRefreshHelpActions()
{
caf::CmdFeatureManager::instance()->action( "RicSearchHelpFeature" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowBase::slotRedo()
{
if ( m_undoView->stack() && m_undoView->stack()->canRedo() )
{
m_undoView->stack()->redo();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowBase::slotUndo()
{
if ( m_undoView->stack() && m_undoView->stack()->canUndo() )
{
m_undoView->stack()->undo();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowBase::slotRefreshUndoRedoActions()
{
m_redoAction->setDisabled( !m_undoView->stack()->canRedo() );
m_undoAction->setDisabled( !m_undoView->stack()->canUndo() );
}

View File

@ -32,6 +32,7 @@ class PdmUiItem;
class QMdiArea;
class QMdiSubWindow;
class QUndoView;
//==================================================================================================
///
@ -94,10 +95,19 @@ protected slots:
void slotDockWidgetToggleViewActionTriggered();
void slotRefreshHelpActions();
void slotRedo();
void slotUndo();
void slotRefreshUndoRedoActions();
protected:
caf::PdmUiTreeView* m_projectTreeView;
bool m_allowActiveViewChangeFromSelection; // To be used in selectedObjectsChanged() to control
// whether to select the corresponding active view or not
QAction* m_undoAction;
QAction* m_redoAction;
QUndoView* m_undoView;
private:
QString registryFolderName();

View File

@ -50,6 +50,7 @@
#include "RiuTreeViewEventFilter.h"
#include "RiuWellAllocationPlot.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmObjectHandle.h"
#include "cafPdmUiPropertyView.h"
@ -65,6 +66,8 @@
#include <QMenuBar>
#include <QToolBar>
#include <QTreeView>
#include <QUndoStack>
#include <QUndoView>
//--------------------------------------------------------------------------------------------------
///
@ -86,9 +89,10 @@ RiuPlotMainWindow::RiuPlotMainWindow()
m_dragDropInterface = std::unique_ptr<caf::PdmUiDragDropInterface>( new RiuDragDrop() );
// Enabling the line below will activate the undo stack
// When enableUndoCommandSystem is set false, all commands are executed and deleted immediately
// caf::CmdExecCommandManager::instance()->enableUndoCommandSystem(true);
m_undoView->setStack( caf::CmdExecCommandManager::instance()->undoStack() );
connect( caf::CmdExecCommandManager::instance()->undoStack(),
SIGNAL( indexChanged( int ) ),
SLOT( slotRefreshUndoRedoActions() ) );
}
//--------------------------------------------------------------------------------------------------
@ -306,6 +310,15 @@ void RiuPlotMainWindow::createMenus()
editMenu->addSeparator();
editMenu->addAction( cmdFeatureMgr->action( "RicEditPreferencesFeature" ) );
if ( RiaPreferences::current()->useUndoRedo() )
{
editMenu->addSeparator();
editMenu->addAction( m_undoAction );
editMenu->addAction( m_redoAction );
}
connect( editMenu, SIGNAL( aboutToShow() ), SLOT( slotRefreshUndoRedoActions() ) );
// View menu
QMenu* viewMenu = menuBar()->addMenu( "&View" );
viewMenu->addAction( cmdFeatureMgr->action( "RicViewZoomAllFeature" ) );
@ -399,6 +412,14 @@ void RiuPlotMainWindow::createToolBars()
m_multiPlotToolBarEditor = new caf::PdmUiToolBarEditor( "Multi Plot", this );
m_multiPlotToolBarEditor->hide();
if ( RiaPreferences::current()->useUndoRedo() )
{
QToolBar* toolbar = addToolBar( tr( "Edit" ) );
toolbar->setObjectName( toolbar->windowTitle() );
toolbar->addAction( m_undoAction );
toolbar->addAction( m_redoAction );
}
}
//--------------------------------------------------------------------------------------------------
@ -474,6 +495,18 @@ void RiuPlotMainWindow::createDockPanels()
dockWidget->hide();
}
if ( RiaPreferences::current()->useUndoRedo() )
{
QDockWidget* dockWidget = new QDockWidget( "Undo Stack", this );
dockWidget->setObjectName( RiuDockWidgetTools::plotMainWindowUndoStackName() );
dockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
dockWidget->setWidget( m_undoView );
addDockWidget( Qt::RightDockWidgetArea, dockWidget );
dockWidget->hide();
}
setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea );

View File

@ -137,7 +137,7 @@ QUndoStack* CmdExecCommandManager::undoStack()
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommand( CmdExecuteCommand* executeCommand )
{
if ( isUndoEnabledForCurrentCommand( executeCommand ) )
if ( isUndoEnabledForCommand( executeCommand ) )
{
// Transfer ownership of execute command to wrapper object
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( executeCommand );
@ -156,29 +156,29 @@ void CmdExecCommandManager::processExecuteCommand( CmdExecuteCommand* executeCom
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommandsAsMacro( const QString& macroName,
std::vector<CmdExecuteCommand*>& commands )
void CmdExecCommandManager::processExecuteCommandsAsMacro( const std::vector<CmdExecuteCommand*>& commands )
{
if ( commands.size() == 0 )
if ( !commands.empty() && isUndoEnabledForCommand( commands.front() ) )
{
return;
}
auto firstCommand = commands.front();
if ( isUndoEnabledForCommand( firstCommand ) )
{
QString macroName = firstCommand->name() + " (multiple objects)";
if ( isUndoEnabledForCurrentCommand( commands[0] ) )
{
m_undoStack->beginMacro( macroName );
for ( size_t i = 0; i < commands.size(); i++ )
for ( auto command : commands )
{
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( commands[i] );
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( command );
m_undoStack->push( undoRedoWrapper );
}
m_undoStack->endMacro();
return;
}
else
}
for ( caf::CmdExecuteCommand* executeCommand : commands )
{
for ( size_t i = 0; i < commands.size(); i++ )
{
CmdExecuteCommand* executeCommand = commands[i];
if ( executeCommand )
{
executeCommand->redo();
@ -186,12 +186,11 @@ void CmdExecCommandManager::processExecuteCommandsAsMacro( const QString&
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdExecCommandManager::isUndoEnabledForCurrentCommand( CmdExecuteCommand* command )
bool CmdExecCommandManager::isUndoEnabledForCommand( CmdExecuteCommand* command )
{
bool useUndo = false;

View File

@ -68,7 +68,7 @@ public:
// If undo is not possible (undo system not enabled, or pdm object has disabled undo),
// the PdmExecuteCommand is executed and deleted
void processExecuteCommand( CmdExecuteCommand* executeCommand );
void processExecuteCommandsAsMacro( const QString& macroName, std::vector<CmdExecuteCommand*>& commands );
void processExecuteCommandsAsMacro( const std::vector<CmdExecuteCommand*>& commands );
private:
CmdExecCommandManager();
@ -80,7 +80,7 @@ private:
void activateCommandSystem();
void deactivateCommandSystem();
bool isUndoEnabledForCurrentCommand( CmdExecuteCommand* command );
bool isUndoEnabledForCommand( CmdExecuteCommand* command );
friend class CmdExecCommandSystemActivator;
friend class CmdExecCommandSystemDeactivator;

View File

@ -212,6 +212,7 @@ void CmdFieldChangeExec::readFieldValueFromValidXmlDocument( QXmlStreamReader& x
tt = xmlStream.readNext();
}
xmlFieldHandle->readFieldData( xmlStream, PdmDefaultObjectFactory::instance() );
xmlFieldHandle->resolveReferences();
}
} // end namespace caf

View File

@ -115,7 +115,7 @@ void CmdUiCommandSystemImpl::fieldChangedCommand( const std::vector<PdmFieldHand
}
else
{
CmdExecCommandManager::instance()->processExecuteCommandsAsMacro( "Multiple Field Change", commands );
CmdExecCommandManager::instance()->processExecuteCommandsAsMacro( commands );
}
if ( uiOwnerObjectHandle && !uiOwnerObjectHandle->useUndoRedoForFieldChanged() )