diff options
author | Luis Gabriel Lima <luis.gabriel@openbossa.org> | 2012-03-23 10:21:23 -0300 |
---|---|---|
committer | Anselmo L. S. Melo <anselmo.melo@openbossa.org> | 2012-03-27 16:42:08 +0200 |
commit | 31c80c4e522c438809f6081248f090eee7199a64 (patch) | |
tree | de9f4eae39250720bf76a7b20a21ff0507aba4f8 /src/imports/undo/uiquickundocommands_p.h | |
parent | bc6356e27d6dc134e3e822d32a68e287b38d30fe (diff) |
Add Undo Framework QML API
This commit introduces an initial implementation of a QML API for the
Undo Framework.
The QML plugin for this API exports three new QML elements: UndoStack,
UndoCommand and UndoPropertyCommand. The API for both the first and
the second are very similar to the QUndoStack and QUndoCommand C++
APIs. The thrid use the declarative nature of the QML elements to
undo/redo based on the values of a group of properties specified by
the user.
This commit also adds an example in 'examples/undo/quickundo' to show
how this API could be used.
Other patchs are expected soon to improve this API and also add more
examples/docs.
Change-Id: I9d290f514b360c721116c3937bd0e03d5f0eacbb
Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
Diffstat (limited to 'src/imports/undo/uiquickundocommands_p.h')
-rw-r--r-- | src/imports/undo/uiquickundocommands_p.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/imports/undo/uiquickundocommands_p.h b/src/imports/undo/uiquickundocommands_p.h new file mode 100644 index 0000000..f5d46c2 --- /dev/null +++ b/src/imports/undo/uiquickundocommands_p.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UIQUICKUNDOCOMMAND_H +#define UIQUICKUNDOCOMMAND_H + +#include <UiHelpers/UiUndoStack> +#include <QVariant> + +QT_USE_NAMESPACE_UIHELPERS; + +class UiQuickBaseUndoCommand : public QObject +{ + Q_OBJECT + +public: + UiQuickBaseUndoCommand(QObject *parent = 0); + ~UiQuickBaseUndoCommand(); +}; + +// ------- // + +class UiQuickUndoCommand : public UiQuickBaseUndoCommand +{ + Q_OBJECT + +public: + UiQuickUndoCommand(QObject *parent = 0); + ~UiQuickUndoCommand(); + +signals: + void undo(QObject *target); + void redo(QObject *target); + void commandDestroyed(QObject *target); +}; + +class UndoCommand : public UiUndoCommand +{ +public: + UndoCommand(QObject* target, UiQuickUndoCommand *m_qmlObject); + ~UndoCommand(); + + void undo(); + void redo(); + +private: + QObject *m_target; + UiQuickUndoCommand *m_qmlObject; +}; + +// -----------------// + +class UiQuickUndoPropertyCommand : public UiQuickBaseUndoCommand +{ + Q_OBJECT + + Q_PROPERTY(QVariantList properties READ properties WRITE setProperties NOTIFY propertiesChanged) + +public: + UiQuickUndoPropertyCommand(QObject *parent = 0); + ~UiQuickUndoPropertyCommand(); + + QVariantList properties() const; + void setProperties(const QVariantList& prop); + +signals: + void propertiesChanged(); + +private: + QVariantList m_properties; +}; + +typedef QPair<QByteArray, QVariant> PropertyState; +typedef QList<PropertyState> TargetState; + +class UndoPropertyCommand : public UiUndoCommand +{ + +public: + UndoPropertyCommand(QObject*, UiQuickUndoPropertyCommand*); + ~UndoPropertyCommand(); + + void undo(); + void redo(); + +private: + void saveState(TargetState& state); + void applyState(TargetState& state); + + TargetState m_undoState; + TargetState m_redoState; + QObject *m_target; + UiQuickUndoPropertyCommand *m_qmlObject; +}; + +#endif |