1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
33
// This file is not part of the Qt API. It exists for the convenience
34
// of Qt Designer. This header
35
// file may change from version to version without notice, or even be removed.
43
#include "shared_global_p.h"
45
#include <QAbstractItemModel>
46
#include <QtCore/QMap>
47
#include <QtCore/QList>
48
#include <QStringList>
55
class QT_SHARED_EXPORT QtCommand : public QObject
59
friend class QtUndoStack;
62
enum Type { Command, MacroBegin, MacroEnd };
64
QtCommand(Type type, const QString &description = QString(),
65
bool canMerge = false);
66
QtCommand(const QString &description = QString(),
67
bool canMerge = true);
69
virtual void redo() {};
70
virtual void undo() {};
72
QString description() const
73
{ return m_description; }
74
void setDescription(const QString &s)
75
{ m_description = s; }
77
{ return m_can_merge; }
78
void setCanMerge(bool b)
83
bool isMacroBegin() const
84
{ return m_type == MacroBegin; }
85
bool isMacroEnd() const
86
{ return m_type == MacroEnd; }
87
bool isCommand() const
88
{ return m_type == Command; }
91
virtual bool mergeMeWith(QtCommand *other);
97
QString m_description;
101
class QtMultiCommand : public QtCommand
104
QtMultiCommand(const QString &description = QString());
105
QtMultiCommand(const QList<QtCommand*> &command_list,
106
const QString &description = QString());
111
void append(QtCommand *command);
113
QtCommand *command(int i) const;
116
QList<QtCommand*> m_command_list;
121
class QT_SHARED_EXPORT QtUndoStack : public QObject, private QList<QtCommand*>
125
friend class QtUndoManager;
128
QtUndoStack(QObject *parent = 0);
129
void push(QtCommand *command);
130
bool canUndo() const;
131
bool canRedo() const;
132
QString undoDescription() const;
133
QString redoDescription() const;
134
QStringList undoList() const;
135
QStringList redoList() const;
136
bool isClean() const;
140
QAction *createUndoAction(QObject *parent) const;
141
QAction *createRedoAction(QObject *parent) const;
143
inline int currentIndex() const { return m_current_iter; }
146
void undo(int count = 1);
147
void redo(int count = 1);
153
void cleanChanged(bool clean);
154
void commandExecuted();
156
void undoDescriptionChanged(const QString &newDescription);
157
void redoDescriptionChanged(const QString &newDescription);
158
void canUndoChanged(bool enabled);
159
void canRedoChanged(bool enabled);
162
typedef int CommandIter;
166
CommandIter findMacroBegin(CommandIter it) const;
167
CommandIter findMacroEnd(CommandIter it) const;
169
void beforeChange(QtUndoState &state);
170
void afterChange(const QtUndoState &state);
172
// *m_current_iter == 0 means "one-before-first"
173
CommandIter m_current_iter;
177
bool m_have_clean_command;
178
const QtCommand *m_clean_command;
180
QtCommand *commandAt(CommandIter it) const;
183
class QT_SHARED_EXPORT QtUndoManager : public QObject
190
QAction *createUndoAction(QObject *parent) const;
191
QAction *createRedoAction(QObject *parent) const;
193
void associateView(QObject *obj, QtUndoStack *stack);
194
void disassociateView(QObject *obj);
196
bool canUndo() const;
197
bool canRedo() const;
198
QString undoDescription() const;
199
QString redoDescription() const;
200
void setUndoLimit(uint i);
201
uint undoLimit() const;
202
QStringList undoList() const;
203
QStringList redoList() const;
204
QtUndoStack *currentStack() const;
205
void setCurrentStack(QtUndoStack *stack);
207
static QtUndoManager *manager();
210
void undo(int count = 1);
211
void redo(int count = 1);
213
void updateActions();
218
void undoDescriptionChanged(const QString &newDescription);
219
void redoDescriptionChanged(const QString &newDescription);
220
void canUndoChanged(bool enabled);
221
void canRedoChanged(bool enabled);
224
void stackDestroyed(QObject *stack);
225
void viewDestroyed(QObject *view);
228
typedef QMap<QObject*, QtUndoStack*> StackMap;
230
StackMap m_stack_map;
231
QtUndoStack *m_current_stack;
233
static QtUndoManager *m_manager; // singleton
234
static uint m_undo_limit;
236
bool m_can_undo, m_can_redo;
237
QString m_undo_description, m_redo_description;
240
class QT_SHARED_EXPORT QtUndoListModel: public QAbstractItemModel
244
QtUndoListModel(QObject *parent = 0);
245
virtual ~QtUndoListModel();
247
inline int undoIndex() const { return m_undoIndex; }
249
virtual int rowCount(const QModelIndex &parent) const;
250
virtual int columnCount(const QModelIndex &parent) const;
251
virtual bool hasChildren(const QModelIndex &parent) const
252
{ return rowCount(parent) > 0; }
254
virtual QModelIndex parent(const QModelIndex &index) const;
255
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
256
virtual QVariant data(const QModelIndex &index, int role) const;
266
class QT_SHARED_EXPORT QtUndoListView: public QListView
270
QtUndoListView(QWidget *parent = 0);
271
virtual ~QtUndoListView();
272
virtual void reset();