[Fwk] Integrated improvements to command mananger

This commit is contained in:
Magne Sjaastad 2015-12-22 13:00:13 +01:00
parent ed3951fd0d
commit 33c53830f6
2 changed files with 58 additions and 20 deletions

View File

@ -114,8 +114,17 @@ void CmdExecCommandManager::activateCommandSystem()
if (!m_commandFeatureInterface)
{
m_commandFeatureInterface = new CmdUiCommandSystemImpl;
PdmUiCommandSystemProxy::instance()->setCommandInterface(m_commandFeatureInterface);
}
PdmUiCommandSystemProxy::instance()->setCommandInterface(m_commandFeatureInterface);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::deactivateCommandSystem()
{
PdmUiCommandSystemProxy::instance()->setCommandInterface(NULL);
}
//--------------------------------------------------------------------------------------------------
@ -141,18 +150,7 @@ QUndoStack* CmdExecCommandManager::undoStack()
//--------------------------------------------------------------------------------------------------
void CmdExecCommandManager::processExecuteCommand(CmdExecuteCommand* executeCommand)
{
bool useUndo = false;
if (dynamic_cast<CmdFieldChangeExec*>(executeCommand) && m_commandFeatureInterface->disableUndoForFieldChange())
{
useUndo = false;
}
else if (m_commandFeatureInterface && m_commandFeatureInterface->isUndoEnabled())
{
useUndo = true;
}
if (useUndo)
if (isUndoEnabledForCurrentCommand(executeCommand))
{
// Transfer ownership of execute command to wrapper object
UndoRedoWrapper* undoRedoWrapper = new UndoRedoWrapper(executeCommand);
@ -178,7 +176,7 @@ void CmdExecCommandManager::processExecuteCommandsAsMacro(const QString& macroNa
return;
}
if (m_commandFeatureInterface && m_commandFeatureInterface->isUndoEnabled())
if (isUndoEnabledForCurrentCommand(commands[0]))
{
m_undoStack->beginMacro(macroName);
for (size_t i = 0; i < commands.size(); i++)
@ -202,5 +200,24 @@ void CmdExecCommandManager::processExecuteCommandsAsMacro(const QString& macroNa
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdExecCommandManager::isUndoEnabledForCurrentCommand(CmdExecuteCommand* command)
{
bool useUndo = false;
if (dynamic_cast<CmdFieldChangeExec*>(command) && m_commandFeatureInterface->disableUndoForFieldChange())
{
useUndo = false;
}
else if (m_commandFeatureInterface && m_commandFeatureInterface->isUndoEnabled())
{
useUndo = true;
}
return useUndo;
}
} // end namespace caf

View File

@ -55,12 +55,6 @@ class CmdExecCommandManager
public:
static CmdExecCommandManager* instance();
// Creates the object (CmdUiCommandSystemImpl) used to communicate from UI editors to advanced parts of the command system
// This includes support for undo system and default command features for add/delete of items in PdmChildArrayFieldHandle
// and creation of field changed commands so a change in an editor can be put into undo/redo
// CmdUiCommandSystemImpl is a requirement for using the undo system
void activateCommandSystem();
// When the undoFeature is enabled, execute commands are inserted in the undo stack
// The application can use the QUndoStack to display/modify execute commands wrapped in QUndoCommand objects
void enableUndoCommandSystem(bool enable);
@ -75,12 +69,39 @@ public:
private:
CmdExecCommandManager();
// Creates the object (CmdUiCommandSystemImpl) used to communicate from UI editors to advanced parts of the command system
// This includes support for undo system and default command features for add/delete of items in PdmChildArrayFieldHandle
// and creation of field changed commands so a change in an editor can be put into undo/redo
// CmdUiCommandSystemImpl is a requirement for using the undo system
void activateCommandSystem();
void deactivateCommandSystem();
bool isUndoEnabledForCurrentCommand(CmdExecuteCommand* command);
friend class CmdExecCommandSystemDeactivator;
private:
QUndoStack* m_undoStack;
CmdUiCommandSystemImpl* m_commandFeatureInterface;
};
//==================================================================================================
/// Helper class used to temporarily disable the command system including undo/redo functionality
//==================================================================================================
class CmdExecCommandSystemDeactivator
{
public:
CmdExecCommandSystemDeactivator()
{
CmdExecCommandManager::instance()->deactivateCommandSystem();
}
~CmdExecCommandSystemDeactivator()
{
CmdExecCommandManager::instance()->activateCommandSystem();
}
};
} // end namespace caf