#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>ObjectiveFunctionWeight.svg</file>
<file>CellFilter_UserDefined.png</file> <file>CellFilter_UserDefined.png</file>
<file>CellFilter_Polygon.png</file> <file>CellFilter_Polygon.png</file>
<file>undo.png</file>
<file>redo.png</file>
</qresource> </qresource>
<qresource prefix="/Shader"> <qresource prefix="/Shader">
<file>fs_CellFace.glsl</file> <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 "RiuViewer.h"
#include "cafAppEnum.h" #include "cafAppEnum.h"
#include "cafCmdExecCommandManager.h"
#include "cafEffectGenerator.h" #include "cafEffectGenerator.h"
#include "cafFixedAtlasFont.h" #include "cafFixedAtlasFont.h"
#include "cafPdmUiModelChangeDetector.h" #include "cafPdmUiModelChangeDetector.h"
@ -944,6 +945,12 @@ RiuPlotMainWindow* RiaGuiApplication::getOrCreateMainPlotWindow()
void RiaGuiApplication::createMainWindow() void RiaGuiApplication::createMainWindow()
{ {
CVF_ASSERT( m_mainWindow == nullptr ); CVF_ASSERT( m_mainWindow == nullptr );
if ( RiaPreferences::current()->useUndoRedo() )
{
caf::CmdExecCommandManager::instance()->enableUndoCommandSystem( true );
}
m_mainWindow = new RiuMainWindow; m_mainWindow = new RiuMainWindow;
QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)"; QString platform = cvf::System::is64Bit() ? "(64bit)" : "(32bit)";
m_mainWindow->setWindowTitle( "ResInsight " + platform ); m_mainWindow->setWindowTitle( "ResInsight " + platform );
@ -973,6 +980,11 @@ void RiaGuiApplication::createMainPlotWindow()
{ {
CVF_ASSERT( m_mainPlotWindow == nullptr ); CVF_ASSERT( m_mainPlotWindow == nullptr );
if ( RiaPreferences::current()->useUndoRedo() )
{
caf::CmdExecCommandManager::instance()->enableUndoCommandSystem( true );
}
m_mainPlotWindow = new RiuPlotMainWindow; m_mainPlotWindow = new RiuPlotMainWindow;
m_mainPlotWindow->setWindowTitle( "Plots - ResInsight" ); m_mainPlotWindow->setWindowTitle( "Plots - ResInsight" );
m_mainPlotWindow->setDefaultWindowSize(); m_mainPlotWindow->setDefaultWindowSize();

View File

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

View File

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

View File

@ -32,7 +32,12 @@
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QString RicDeleteItemExec::name() 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() void RicDeleteItemExec::redo()
{ {
caf::PdmFieldHandle* field = 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 ); caf::PdmChildArrayFieldHandle* listField = dynamic_cast<caf::PdmChildArrayFieldHandle*>( field );
if ( listField ) if ( listField )
@ -49,20 +54,20 @@ void RicDeleteItemExec::redo()
std::vector<caf::PdmObjectHandle*> children; std::vector<caf::PdmObjectHandle*> children;
listField->childObjects( &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 ); caf::SelectionManager::instance()->removeObjectFromAllSelections( obj );
std::vector<caf::PdmObjectHandle*> referringObjects; std::vector<caf::PdmObjectHandle*> referringObjects;
obj->objectsWithReferringPtrFields( 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; delete obj;
listField->erase( m_commandData->m_indexToObject ); listField->erase( m_commandData.m_indexToObject );
caf::PdmObjectHandle* parentObj = listField->ownerObject(); caf::PdmObjectHandle* parentObj = listField->ownerObject();
parentObj->uiCapability()->updateConnectedEditors(); parentObj->uiCapability()->updateConnectedEditors();
@ -76,23 +81,33 @@ void RicDeleteItemExec::redo()
void RicDeleteItemExec::undo() void RicDeleteItemExec::undo()
{ {
caf::PdmFieldHandle* field = 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 ); caf::PdmChildArrayFieldHandle* listField = dynamic_cast<caf::PdmChildArrayFieldHandle*>( field );
if ( listField ) if ( listField )
{ {
caf::PdmObjectHandle* obj = caf::PdmObjectHandle* obj =
caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( m_commandData->m_deletedObjectAsXml(), caf::PdmXmlObjectHandle::readUnknownObjectFromXmlString( m_commandData.m_deletedObjectAsXml(),
caf::PdmDefaultObjectFactory::instance(), caf::PdmDefaultObjectFactory::instance(),
false ); false );
listField->insertAt( m_commandData->m_indexToObject, obj ); listField->insertAt( m_commandData.m_indexToObject, obj );
obj->xmlCapability()->initAfterReadRecursively(); obj->xmlCapability()->initAfterReadRecursively();
obj->xmlCapability()->resolveReferencesRecursively();
listField->uiCapability()->updateConnectedEditors(); listField->uiCapability()->updateConnectedEditors();
listField->ownerObject()->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(); if ( m_notificationCenter ) m_notificationCenter->notifyObservers();
} }
} }
@ -103,13 +118,12 @@ void RicDeleteItemExec::undo()
RicDeleteItemExec::RicDeleteItemExec( caf::NotificationCenter* notificationCenter ) RicDeleteItemExec::RicDeleteItemExec( caf::NotificationCenter* notificationCenter )
: CmdExecuteCommand( notificationCenter ) : CmdExecuteCommand( notificationCenter )
{ {
m_commandData = new RicDeleteItemExecData;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RicDeleteItemExecData* RicDeleteItemExec::commandData() RicDeleteItemExecData& RicDeleteItemExec::commandData()
{ {
return m_commandData; return m_commandData;
} }

View File

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

View File

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

View File

@ -95,13 +95,38 @@ void RicDeleteItemFeature::onActionTriggered( bool isChecked )
RicDeleteItemExec* executeCmd = new RicDeleteItemExec( caf::SelectionManager::instance()->notificationCenter() ); RicDeleteItemExec* executeCmd = new RicDeleteItemExec( caf::SelectionManager::instance()->notificationCenter() );
RicDeleteItemExecData* data = executeCmd->commandData(); RicDeleteItemExecData& data = executeCmd->commandData();
data->m_rootObject = caf::PdmReferenceHelper::findRoot( childArrayFieldHandle ); data.m_rootObject = caf::PdmReferenceHelper::findRoot( childArrayFieldHandle );
data->m_pathToField = data.m_pathToField = caf::PdmReferenceHelper::referenceFromRootToField( data.m_rootObject, childArrayFieldHandle );
caf::PdmReferenceHelper::referenceFromRootToField( data->m_rootObject, childArrayFieldHandle ); data.m_indexToObject = indexAfter;
data->m_indexToObject = indexAfter;
caf::CmdExecCommandManager::instance()->processExecuteCommand( executeCmd ); {
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 ) QTextStream& operator<<( QTextStream& str, const RifEclipseSummaryAddress& sobj )
{ {
CVF_ASSERT( false );
return str; return str;
} }
@ -1149,6 +1148,5 @@ QTextStream& operator<<( QTextStream& str, const RifEclipseSummaryAddress& sobj
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QTextStream& operator>>( QTextStream& str, RifEclipseSummaryAddress& sobj ) QTextStream& operator>>( QTextStream& str, RifEclipseSummaryAddress& sobj )
{ {
CVF_ASSERT( false );
return str; return str;
} }

View File

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

View File

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

View File

@ -95,6 +95,7 @@
#include <QToolButton> #include <QToolButton>
#include <QTreeView> #include <QTreeView>
#include <QUndoStack> #include <QUndoStack>
#include <QUndoView>
#include <QDebug> #include <QDebug>
@ -132,11 +133,12 @@ RiuMainWindow::RiuMainWindow()
m_dragDropInterface = std::unique_ptr<caf::PdmUiDragDropInterface>( new RiuDragDrop() ); 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 initializeGuiNewProjectLoaded();
// When enableUndoCommandSystem is set false, all commands are executed and deleted immediately
// caf::CmdExecCommandManager::instance()->enableUndoCommandSystem(true);
m_memoryCriticalWarning = new QLabel( "" ); m_memoryCriticalWarning = new QLabel( "" );
m_memoryUsedButton = new QToolButton( nullptr ); m_memoryUsedButton = new QToolButton( nullptr );
@ -203,7 +205,7 @@ void RiuMainWindow::initializeGuiNewProjectLoaded()
} }
slotRefreshFileActions(); slotRefreshFileActions();
slotRefreshEditActions(); slotRefreshUndoRedoActions();
slotRefreshViewActions(); slotRefreshViewActions();
refreshAnimationActions(); refreshAnimationActions();
refreshDrawStyleActions(); refreshDrawStyleActions();
@ -502,7 +504,14 @@ void RiuMainWindow::createMenus()
editMenu->addSeparator(); editMenu->addSeparator();
editMenu->addAction( cmdFeatureMgr->action( "RicEditPreferencesFeature" ) ); 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 // View menu
QMenu* viewMenu = menuBar()->addMenu( "&View" ); QMenu* viewMenu = menuBar()->addMenu( "&View" );
@ -574,6 +583,14 @@ void RiuMainWindow::createToolBars()
toolbar->addAction( cmdFeatureMgr->action( "RicSaveProjectFeature" ) ); 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" ) ); QToolBar* toolbar = addToolBar( tr( "Import" ) );
toolbar->setObjectName( toolbar->windowTitle() ); toolbar->setObjectName( toolbar->windowTitle() );
@ -822,6 +839,17 @@ void RiuMainWindow::createDockPanels()
dockWidget->hide(); 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::BottomLeftCorner, Qt::LeftDockWidgetArea );
setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea ); setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea );
@ -880,15 +908,6 @@ void RiuMainWindow::slotRefreshFileActions()
cmdFeatureMgr->refreshStates( commandIdList ); 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::propertyEditorName() );
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::messagesName() ); appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::messagesName() );
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::processMonitorName() ); appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::processMonitorName() );
appendToggleActionForDockingWidget( m_windowMenu, this, RiuDockWidgetTools::undoStackName() );
m_windowMenu->addSeparator(); m_windowMenu->addSeparator();
@ -1472,7 +1492,7 @@ void RiuMainWindow::selectedObjectsChanged()
refreshDrawStyleActions(); refreshDrawStyleActions();
refreshAnimationActions(); refreshAnimationActions();
slotRefreshFileActions(); slotRefreshFileActions();
slotRefreshEditActions(); slotRefreshUndoRedoActions();
slotRefreshViewActions(); slotRefreshViewActions();
// The only way to get to this code is by selection change initiated from the project tree view // 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(); void slotRefreshFileActions();
// Edit slots // Edit slots
void slotRefreshEditActions();
void slotNewObjectPropertyView(); void slotNewObjectPropertyView();
// View slots // View slots
@ -250,8 +249,6 @@ public:
private: private:
std::unique_ptr<caf::PdmUiDragDropInterface> m_dragDropInterface; std::unique_ptr<caf::PdmUiDragDropInterface> m_dragDropInterface;
QUndoView* m_undoView;
caf::PdmObject* m_pdmRoot; caf::PdmObject* m_pdmRoot;
caf::PdmUiPropertyView* m_pdmUiPropertyView; caf::PdmUiPropertyView* m_pdmUiPropertyView;

View File

@ -30,10 +30,14 @@
#include "cafPdmUiTreeView.h" #include "cafPdmUiTreeView.h"
#include "cafCmdFeatureManager.h" #include "cafCmdFeatureManager.h"
#include <QAction>
#include <QDockWidget> #include <QDockWidget>
#include <QMdiArea> #include <QMdiArea>
#include <QMdiSubWindow> #include <QMdiSubWindow>
#include <QSettings> #include <QSettings>
#include <QUndoStack>
#include <QUndoView>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -46,6 +50,16 @@ RiuMainWindowBase::RiuMainWindowBase()
, m_blockSubWindowProjectTreeSelection( false ) , m_blockSubWindowProjectTreeSelection( false )
{ {
setDockNestingEnabled( true ); 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" ); 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 QMdiArea;
class QMdiSubWindow; class QMdiSubWindow;
class QUndoView;
//================================================================================================== //==================================================================================================
/// ///
@ -94,10 +95,19 @@ protected slots:
void slotDockWidgetToggleViewActionTriggered(); void slotDockWidgetToggleViewActionTriggered();
void slotRefreshHelpActions(); void slotRefreshHelpActions();
void slotRedo();
void slotUndo();
void slotRefreshUndoRedoActions();
protected: protected:
caf::PdmUiTreeView* m_projectTreeView; caf::PdmUiTreeView* m_projectTreeView;
bool m_allowActiveViewChangeFromSelection; // To be used in selectedObjectsChanged() to control bool m_allowActiveViewChangeFromSelection; // To be used in selectedObjectsChanged() to control
// whether to select the corresponding active view or not // whether to select the corresponding active view or not
QAction* m_undoAction;
QAction* m_redoAction;
QUndoView* m_undoView;
private: private:
QString registryFolderName(); QString registryFolderName();

View File

@ -50,6 +50,7 @@
#include "RiuTreeViewEventFilter.h" #include "RiuTreeViewEventFilter.h"
#include "RiuWellAllocationPlot.h" #include "RiuWellAllocationPlot.h"
#include "cafCmdExecCommandManager.h"
#include "cafCmdFeatureManager.h" #include "cafCmdFeatureManager.h"
#include "cafPdmObjectHandle.h" #include "cafPdmObjectHandle.h"
#include "cafPdmUiPropertyView.h" #include "cafPdmUiPropertyView.h"
@ -65,6 +66,8 @@
#include <QMenuBar> #include <QMenuBar>
#include <QToolBar> #include <QToolBar>
#include <QTreeView> #include <QTreeView>
#include <QUndoStack>
#include <QUndoView>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -86,9 +89,10 @@ RiuPlotMainWindow::RiuPlotMainWindow()
m_dragDropInterface = std::unique_ptr<caf::PdmUiDragDropInterface>( new RiuDragDrop() ); m_dragDropInterface = std::unique_ptr<caf::PdmUiDragDropInterface>( new RiuDragDrop() );
// Enabling the line below will activate the undo stack m_undoView->setStack( caf::CmdExecCommandManager::instance()->undoStack() );
// When enableUndoCommandSystem is set false, all commands are executed and deleted immediately connect( caf::CmdExecCommandManager::instance()->undoStack(),
// caf::CmdExecCommandManager::instance()->enableUndoCommandSystem(true); SIGNAL( indexChanged( int ) ),
SLOT( slotRefreshUndoRedoActions() ) );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -306,6 +310,15 @@ void RiuPlotMainWindow::createMenus()
editMenu->addSeparator(); editMenu->addSeparator();
editMenu->addAction( cmdFeatureMgr->action( "RicEditPreferencesFeature" ) ); 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 // View menu
QMenu* viewMenu = menuBar()->addMenu( "&View" ); QMenu* viewMenu = menuBar()->addMenu( "&View" );
viewMenu->addAction( cmdFeatureMgr->action( "RicViewZoomAllFeature" ) ); viewMenu->addAction( cmdFeatureMgr->action( "RicViewZoomAllFeature" ) );
@ -399,6 +412,14 @@ void RiuPlotMainWindow::createToolBars()
m_multiPlotToolBarEditor = new caf::PdmUiToolBarEditor( "Multi Plot", this ); m_multiPlotToolBarEditor = new caf::PdmUiToolBarEditor( "Multi Plot", this );
m_multiPlotToolBarEditor->hide(); 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(); 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::BottomLeftCorner, Qt::LeftDockWidgetArea );
setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea ); setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea );

View File

@ -137,7 +137,7 @@ QUndoStack* CmdExecCommandManager::undoStack()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommand( CmdExecuteCommand* executeCommand ) void CmdExecCommandManager::processExecuteCommand( CmdExecuteCommand* executeCommand )
{ {
if ( isUndoEnabledForCurrentCommand( executeCommand ) ) if ( isUndoEnabledForCommand( executeCommand ) )
{ {
// Transfer ownership of execute command to wrapper object // Transfer ownership of execute command to wrapper object
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( executeCommand ); UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( executeCommand );
@ -156,34 +156,33 @@ void CmdExecCommandManager::processExecuteCommand( CmdExecuteCommand* executeCom
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommandsAsMacro( const QString& macroName, void CmdExecCommandManager::processExecuteCommandsAsMacro( const std::vector<CmdExecuteCommand*>& commands )
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)";
m_undoStack->beginMacro( macroName );
for ( auto command : commands )
{
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( command );
m_undoStack->push( undoRedoWrapper );
}
m_undoStack->endMacro();
return;
}
} }
if ( isUndoEnabledForCurrentCommand( commands[0] ) ) for ( caf::CmdExecuteCommand* executeCommand : commands )
{ {
m_undoStack->beginMacro( macroName ); if ( executeCommand )
for ( size_t i = 0; i < commands.size(); i++ )
{ {
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper( commands[i] ); executeCommand->redo();
m_undoStack->push( undoRedoWrapper ); delete executeCommand;
}
m_undoStack->endMacro();
}
else
{
for ( size_t i = 0; i < commands.size(); i++ )
{
CmdExecuteCommand* executeCommand = commands[i];
if ( executeCommand )
{
executeCommand->redo();
delete executeCommand;
}
} }
} }
} }
@ -191,7 +190,7 @@ void CmdExecCommandManager::processExecuteCommandsAsMacro( const QString&
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool CmdExecCommandManager::isUndoEnabledForCurrentCommand( CmdExecuteCommand* command ) bool CmdExecCommandManager::isUndoEnabledForCommand( CmdExecuteCommand* command )
{ {
bool useUndo = false; 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), // If undo is not possible (undo system not enabled, or pdm object has disabled undo),
// the PdmExecuteCommand is executed and deleted // the PdmExecuteCommand is executed and deleted
void processExecuteCommand( CmdExecuteCommand* executeCommand ); void processExecuteCommand( CmdExecuteCommand* executeCommand );
void processExecuteCommandsAsMacro( const QString& macroName, std::vector<CmdExecuteCommand*>& commands ); void processExecuteCommandsAsMacro( const std::vector<CmdExecuteCommand*>& commands );
private: private:
CmdExecCommandManager(); CmdExecCommandManager();
@ -80,7 +80,7 @@ private:
void activateCommandSystem(); void activateCommandSystem();
void deactivateCommandSystem(); void deactivateCommandSystem();
bool isUndoEnabledForCurrentCommand( CmdExecuteCommand* command ); bool isUndoEnabledForCommand( CmdExecuteCommand* command );
friend class CmdExecCommandSystemActivator; friend class CmdExecCommandSystemActivator;
friend class CmdExecCommandSystemDeactivator; friend class CmdExecCommandSystemDeactivator;

View File

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

View File

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