1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
// qtractorCommand.h
//
/****************************************************************************
Copyright (C) 2005-2022, rncbc aka Rui Nuno Capela. All rights reserved.
This program 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 2
of the License, or (at your option) any later version.
This program 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 for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#ifndef __qtractorCommand_h
#define __qtractorCommand_h
#include "qtractorList.h"
#include <QObject>
#include <QString>
// Forward declarations.
class QAction;
//----------------------------------------------------------------------
// class qtractorCommand - declaration.
//
class qtractorCommand : public qtractorList<qtractorCommand>::Link
{
public:
// Constructor.
qtractorCommand(const QString& sName)
: m_sName(sName), m_flags(Refresh) {}
// Virtual destructor.
virtual ~qtractorCommand() {}
// Descriptive command name accessors.
void setName(const QString& sName) { m_sName = sName; }
const QString& name() const { return m_sName; }
// Command flags.
enum Flag {
None = 0, AutoDelete = 1, Refresh = 2,
Clear = 4, Select = 8, Reset = 16,
ClearSelect = Clear | Select,
ClearSelectReset = ClearSelect | Reset
};
// Command flags accessor.
unsigned int flags() const { return m_flags; }
// Auto-removal/deletion flag accessors.
void setAutoDelete(bool bAutoDelete)
{ setFlags(AutoDelete, bAutoDelete); }
bool isAutoDelete() const
{ return isFlags(AutoDelete); }
// Contents-refresh accessors.
void setRefresh(bool bRefresh)
{ setFlags(Refresh, bRefresh); }
bool isRefresh() const
{ return isFlags(Refresh); }
// Selection clear/reset accessors.
void setClearSelect(bool bClearSelect)
{ setFlags(ClearSelect, bClearSelect); }
bool isClearSelect() const
{ return isFlags(ClearSelect); }
void setClearSelectReset(bool bClearSelectReset)
{ setFlags(ClearSelectReset, bClearSelectReset); }
bool isClearSelectReset() const
{ return isFlags(ClearSelectReset); }
// Cannonical command methods.
virtual bool redo() = 0;
virtual bool undo() = 0;
protected:
// Discrete flag accessors.
void setFlags(unsigned int flags, bool bOn = true)
{ if (bOn) m_flags |= flags; else m_flags &= ~flags; }
bool isFlags(unsigned int flags) const
{ return ((m_flags & flags) == flags); }
private:
// Instance variables.
QString m_sName;
unsigned int m_flags;
};
//----------------------------------------------------------------------
// class qtractorCommandList - declaration.
//
class qtractorCommandList : public QObject
{
Q_OBJECT
public:
// Constructor.
qtractorCommandList();
// Destructor.
virtual ~qtractorCommandList();
// Command stack cleaner.
void clear();
// Command cursor accessors.
qtractorCommand *lastCommand() const;
qtractorCommand *nextCommand() const;
// Remove last command from command chain.
void removeLastCommand();
// Special backout method.
void backout(qtractorCommand *pCommand);
// Cannonical command methods.
bool push(qtractorCommand *pCommand);
bool exec(qtractorCommand *pCommand);
bool undo();
bool redo();
// Command action update helper.
void updateAction(QAction *pAction, qtractorCommand *pCommand) const;
signals:
// Command update notification.
void updateNotifySignal(unsigned int);
private:
// Instance variables.
qtractorList<qtractorCommand> m_commands;
qtractorCommand *m_pLastCommand;
};
#endif // __qtractorCommand_h
// end of qtractorCommand.h
|