ResInsight/Fwk/AppFwk/cafCommand/cafCmdExecCommandManager.h

131 lines
4.9 KiB
C
Raw Normal View History

2013-10-28 05:58:49 -05:00
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2013 Ceetron AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QPointer>
#include <vector>
2013-10-28 05:58:49 -05:00
class QUndoStack;
class QString;
2013-10-28 05:58:49 -05:00
namespace caf
2013-10-28 05:58:49 -05:00
{
class CmdExecuteCommand;
class CmdUiCommandSystemImpl;
2013-10-28 05:58:49 -05:00
//==================================================================================================
///
2013-10-28 05:58:49 -05:00
//==================================================================================================
class CmdExecCommandManager
2013-10-28 05:58:49 -05:00
{
public:
static CmdExecCommandManager* instance();
CmdExecCommandManager(const CmdExecCommandManager&) = delete;
CmdExecCommandManager& operator=(const CmdExecCommandManager&) = delete;
// 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);
QUndoStack* undoStack();
// If undo system is enabled, the PdmExecuteCommand is wrapped in a QUndoCommand and inserted in the QUndoStack.
// 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);
2013-10-28 05:58:49 -05:00
private:
CmdExecCommandManager();
2013-10-28 05:58:49 -05:00
// 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 CmdExecCommandSystemActivator;
friend class CmdExecCommandSystemDeactivator;
2013-10-28 05:58:49 -05:00
private:
QPointer<QUndoStack> m_undoStack;
CmdUiCommandSystemImpl* m_commandFeatureInterface;
2013-10-28 05:58:49 -05:00
};
//==================================================================================================
/// Helper class used to temporarily disable the command system including undo/redo functionality
//==================================================================================================
class CmdExecCommandSystemDeactivator
{
public:
CmdExecCommandSystemDeactivator()
{
CmdExecCommandManager::instance()->deactivateCommandSystem();
}
~CmdExecCommandSystemDeactivator()
{
CmdExecCommandManager::instance()->activateCommandSystem();
}
};
2013-10-28 05:58:49 -05:00
//==================================================================================================
/// Helper class used to temporarily enable the command system including undo/redo functionality
//==================================================================================================
class CmdExecCommandSystemActivator
{
public:
CmdExecCommandSystemActivator()
{
CmdExecCommandManager::instance()->activateCommandSystem();
}
~CmdExecCommandSystemActivator()
{
CmdExecCommandManager::instance()->deactivateCommandSystem();
}
};
2013-10-28 05:58:49 -05:00
} // end namespace caf