From 7e41eed10855896f9d3425ce5169e034a11ff667 Mon Sep 17 00:00:00 2001 From: "Anselmo L. S. Melo" Date: Wed, 26 Mar 2014 00:18:16 -0300 Subject: Fix the build system. Updated pro files. Change-Id: I990d4c4630ee293ac6a1ac234066194ed81c709e Reviewed-by: Anselmo L. S. Melo --- imports/imports.pro | 3 + imports/models/models.pro | 20 +++ imports/models/plugin.cpp | 64 ++++++++++ imports/models/qmldir | 1 + imports/models/uiqmlmodelsplugin.json | 1 + imports/models/uiquickcompletionmodel.cpp | 117 +++++++++++++++++ imports/models/uiquickcompletionmodel_p.h | 77 +++++++++++ imports/undo/plugin.cpp | 69 ++++++++++ imports/undo/qmldir | 1 + imports/undo/uiqmlundoframeworkplugin.json | 1 + imports/undo/uiquickbaseundocommand.cpp | 56 ++++++++ imports/undo/uiquickbaseundocommand_p.h | 68 ++++++++++ imports/undo/uiquickundocommand.cpp | 99 ++++++++++++++ imports/undo/uiquickundocommand_p.h | 63 +++++++++ imports/undo/uiquickundopropertycommand.cpp | 158 +++++++++++++++++++++++ imports/undo/uiquickundopropertycommand_p.h | 77 +++++++++++ imports/undo/uiquickundostack.cpp | 192 ++++++++++++++++++++++++++++ imports/undo/uiquickundostack_p.h | 93 ++++++++++++++ imports/undo/undo.pro | 27 ++++ 19 files changed, 1187 insertions(+) create mode 100644 imports/imports.pro create mode 100644 imports/models/models.pro create mode 100644 imports/models/plugin.cpp create mode 100644 imports/models/qmldir create mode 100644 imports/models/uiqmlmodelsplugin.json create mode 100644 imports/models/uiquickcompletionmodel.cpp create mode 100644 imports/models/uiquickcompletionmodel_p.h create mode 100644 imports/undo/plugin.cpp create mode 100644 imports/undo/qmldir create mode 100644 imports/undo/uiqmlundoframeworkplugin.json create mode 100644 imports/undo/uiquickbaseundocommand.cpp create mode 100644 imports/undo/uiquickbaseundocommand_p.h create mode 100644 imports/undo/uiquickundocommand.cpp create mode 100644 imports/undo/uiquickundocommand_p.h create mode 100644 imports/undo/uiquickundopropertycommand.cpp create mode 100644 imports/undo/uiquickundopropertycommand_p.h create mode 100644 imports/undo/uiquickundostack.cpp create mode 100644 imports/undo/uiquickundostack_p.h create mode 100644 imports/undo/undo.pro (limited to 'imports') diff --git a/imports/imports.pro b/imports/imports.pro new file mode 100644 index 0000000..9818f86 --- /dev/null +++ b/imports/imports.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS += undo models diff --git a/imports/models/models.pro b/imports/models/models.pro new file mode 100644 index 0000000..a83bade --- /dev/null +++ b/imports/models/models.pro @@ -0,0 +1,20 @@ +TEMPLATE = lib +TARGET = qmlmodelsplugin +TARGETPATH = Playground/UiHelpers/Models + +QT += qml uihelpers + +CONFIG += qt plugin + +SOURCES += plugin.cpp + +SOURCES += uiquickcompletionmodel.cpp + +HEADERS += uiquickcompletionmodel_p.h + +target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +qmldir.files += $$PWD/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +INSTALLS += target qmldir diff --git a/imports/models/plugin.cpp b/imports/models/plugin.cpp new file mode 100644 index 0000000..d2567c1 --- /dev/null +++ b/imports/models/plugin.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT). +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "uiquickcompletionmodel_p.h" +#include "uitextfilemodel.h" + +class QmlModelsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionPlugin" FILE "uiqmlmodelsplugin.json") + +public: + virtual void registerTypes(const char* uri); +}; + +void QmlModelsPlugin::registerTypes(const char* uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("Playground.UiHelpers.Models")); + + qmlRegisterType(uri, 1, 0, "CompletionModel"); + qmlRegisterType(uri, 1, 0, "TextFileModel"); +} + +#include "plugin.moc" diff --git a/imports/models/qmldir b/imports/models/qmldir new file mode 100644 index 0000000..9e4d18c --- /dev/null +++ b/imports/models/qmldir @@ -0,0 +1 @@ +plugin qmlmodelsplugin diff --git a/imports/models/uiqmlmodelsplugin.json b/imports/models/uiqmlmodelsplugin.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/imports/models/uiqmlmodelsplugin.json @@ -0,0 +1 @@ +{} diff --git a/imports/models/uiquickcompletionmodel.cpp b/imports/models/uiquickcompletionmodel.cpp new file mode 100644 index 0000000..9f69399 --- /dev/null +++ b/imports/models/uiquickcompletionmodel.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT). +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "uiquickcompletionmodel_p.h" +#include + +class UiQuickCompletionModelPrivate +{ +public: + UiQuickCompletionModelPrivate(UiQuickCompletionModel *parent) + : proxy(new UiProxyQmlModel(parent)) {} + + QVariant source; + QString roleName; + UiProxyQmlModel *proxy; +}; + + +UiQuickCompletionModel::UiQuickCompletionModel(QObject *parent) + : UiCompletionModel(parent) + , d_ptr(new UiQuickCompletionModelPrivate(this)) +{ +} + +UiQuickCompletionModel::~UiQuickCompletionModel() +{ +} + +QVariant UiQuickCompletionModel::source() const +{ + Q_D(const UiQuickCompletionModel); + + return d->source; +} + +void UiQuickCompletionModel::setSource(const QVariant& source) +{ + Q_D(UiQuickCompletionModel); + + if (source == d->source) + return; + + setSourceModel(0); // Disconnect all signals from old model + UiProxyQmlModel::ListType type = d->proxy->updateSource(source); + if (type == UiProxyQmlModel::ArrayList) + setCompletionRole(Qt::DisplayRole); + else if (type == UiProxyQmlModel::QuickList) { + int role = d->proxy->roleNames().key(d->roleName.toAscii(), -1); + if (role != -1) + setCompletionRole(role); + } + setSourceModel(d->proxy); + + d->source = source; + emit sourceModelChanged(); +} + + +QString UiQuickCompletionModel::completionRoleName() const +{ + Q_D(const UiQuickCompletionModel); + + return d->roleName; +} + +void UiQuickCompletionModel::setCompletionRoleName(const QString &roleName) +{ + Q_D(UiQuickCompletionModel); + + if (roleName == d->roleName) + return; + + int role = d->proxy->roleNames().key(roleName.toAscii(), -1); + if (role != -1) + setCompletionRole(role); + + d->roleName = roleName; + emit completionRoleNameChanged(); +} diff --git a/imports/models/uiquickcompletionmodel_p.h b/imports/models/uiquickcompletionmodel_p.h new file mode 100644 index 0000000..bb50c68 --- /dev/null +++ b/imports/models/uiquickcompletionmodel_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT). +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UIQUICKCOMPLETIONMODEL_H +#define UIQUICKCOMPLETIONMODEL_H + +#include + +QT_USE_NAMESPACE_UIHELPERS; + +class UiQuickCompletionModelPrivate; +class UiQuickCompletionModel : public UiCompletionModel +{ + Q_OBJECT + + Q_PROPERTY(QVariant sourceModel READ source WRITE setSource NOTIFY sourceModelChanged) + Q_PROPERTY(QString completionRoleName READ completionRoleName WRITE setCompletionRoleName NOTIFY completionRoleNameChanged) + +public: + UiQuickCompletionModel(QObject *parent = 0); + ~UiQuickCompletionModel(); + + QVariant source() const; + void setSource(const QVariant &source); + QString completionRoleName() const; + void setCompletionRoleName(const QString &roleName); + +Q_SIGNALS: + void sourceModelChanged(); + void completionRoleNameChanged(); + +private: + Q_DISABLE_COPY(UiQuickCompletionModel) + Q_DECLARE_PRIVATE(UiQuickCompletionModel) + + QScopedPointer d_ptr; +}; + +#endif diff --git a/imports/undo/plugin.cpp b/imports/undo/plugin.cpp new file mode 100644 index 0000000..d34558d --- /dev/null +++ b/imports/undo/plugin.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "uiquickundostack_p.h" +#include "uiquickundocommand_p.h" +#include "uiquickundopropertycommand_p.h" + +class QmlUndoFrameworkPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionPlugin" FILE "uiqmlundoframeworkplugin.json") + +public: + virtual void registerTypes(const char* uri); +}; + +void QmlUndoFrameworkPlugin::registerTypes(const char* uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("Playground.UiHelpers.UndoFramework")); + + qmlRegisterType(uri, 1, 0, "UndoStack"); + qmlRegisterUncreatableType(uri, 1, 0, "", ""); + qmlRegisterType(uri, 1, 0, "UndoCommand"); + qmlRegisterType(uri, 1, 0, "UndoPropertyCommand"); +} + +#include "plugin.moc" + +//Q_EXPORT_PLUGIN2(qmlundoframeworkplugin, QT_PREPEND_NAMESPACE(QmlUndoFrameworkPlugin)) diff --git a/imports/undo/qmldir b/imports/undo/qmldir new file mode 100644 index 0000000..e04cfa3 --- /dev/null +++ b/imports/undo/qmldir @@ -0,0 +1 @@ +plugin qmlundoframeworkplugin diff --git a/imports/undo/uiqmlundoframeworkplugin.json b/imports/undo/uiqmlundoframeworkplugin.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/imports/undo/uiqmlundoframeworkplugin.json @@ -0,0 +1 @@ +{} diff --git a/imports/undo/uiquickbaseundocommand.cpp b/imports/undo/uiquickbaseundocommand.cpp new file mode 100644 index 0000000..98718a8 --- /dev/null +++ b/imports/undo/uiquickbaseundocommand.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "uiquickbaseundocommand_p.h" + +BaseUndoCommand::BaseUndoCommand() + : UiUndoCommand() +{ +} + +UiQuickBaseUndoCommand::UiQuickBaseUndoCommand(QObject *parent) + : QObject(parent) +{ +} + +UiQuickBaseUndoCommand::~UiQuickBaseUndoCommand() +{ +} diff --git a/imports/undo/uiquickbaseundocommand_p.h b/imports/undo/uiquickbaseundocommand_p.h new file mode 100644 index 0000000..14fd93e --- /dev/null +++ b/imports/undo/uiquickbaseundocommand_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UIQUICKBASEUNDOCOMMAND_H +#define UIQUICKBASEUNDOCOMMAND_H + +#include + +QT_USE_NAMESPACE_UIHELPERS; + +class BaseUndoCommand : public UiUndoCommand +{ +public: + BaseUndoCommand(); + + virtual bool delayPush() const = 0; +}; + +class UiQuickBaseUndoCommand : public QObject +{ + Q_OBJECT + +public: + UiQuickBaseUndoCommand(QObject *parent = 0); + ~UiQuickBaseUndoCommand(); + + virtual BaseUndoCommand *create(QObject *target = 0) = 0; +}; + +#endif // UIQUICKBASEUNDOCOMMAND_H diff --git a/imports/undo/uiquickundocommand.cpp b/imports/undo/uiquickundocommand.cpp new file mode 100644 index 0000000..27b381a --- /dev/null +++ b/imports/undo/uiquickundocommand.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "uiquickundocommand_p.h" + +class UndoCommand : public BaseUndoCommand +{ +public: + UndoCommand(QObject* target, UiQuickUndoCommand *m_qmlObject); + ~UndoCommand(); + + void undo(); + void redo(); + + bool delayPush() const; + +private: + QObject *m_target; + UiQuickUndoCommand *m_qmlObject; +}; + +UndoCommand::UndoCommand(QObject* target, UiQuickUndoCommand *qmlObject) + : BaseUndoCommand() + , m_target(target) + , m_qmlObject(qmlObject) +{ +} + +UndoCommand::~UndoCommand() +{ + emit m_qmlObject->commandDestroyed(m_target); +} + +void UndoCommand::undo() +{ + emit m_qmlObject->undo(m_target); +} + +void UndoCommand::redo() +{ + emit m_qmlObject->redo(m_target); +} + +bool UndoCommand::delayPush() const +{ + return false; +} + +UiQuickUndoCommand::UiQuickUndoCommand(QObject *parent) + : UiQuickBaseUndoCommand(parent) +{ +} + +UiQuickUndoCommand::~UiQuickUndoCommand() +{ +} + +BaseUndoCommand *UiQuickUndoCommand::create(QObject *target) +{ + return new UndoCommand(target, this); +} diff --git a/imports/undo/uiquickundocommand_p.h b/imports/undo/uiquickundocommand_p.h new file mode 100644 index 0000000..f69c4e9 --- /dev/null +++ b/imports/undo/uiquickundocommand_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UIQUICKUNDOCOMMAND_H +#define UIQUICKUNDOCOMMAND_H + +#include "uiquickbaseundocommand_p.h" + +class UiQuickUndoCommand : public UiQuickBaseUndoCommand +{ + Q_OBJECT + +public: + UiQuickUndoCommand(QObject *parent = 0); + ~UiQuickUndoCommand(); + + BaseUndoCommand *create(QObject *target = 0); + +signals: + void undo(QObject *target); + void redo(QObject *target); + void commandDestroyed(QObject *target); +}; + +#endif // UIQUICKUNDOCOMMAND_H diff --git a/imports/undo/uiquickundopropertycommand.cpp b/imports/undo/uiquickundopropertycommand.cpp new file mode 100644 index 0000000..6f6bb30 --- /dev/null +++ b/imports/undo/uiquickundopropertycommand.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "uiquickundopropertycommand_p.h" + +typedef QPair PropertyState; +typedef QList TargetState; + +class UiQuickUndoPropertyCommandPrivate +{ +public: + UiQuickUndoPropertyCommandPrivate(); + + QVariantList properties; +}; + +UiQuickUndoPropertyCommandPrivate::UiQuickUndoPropertyCommandPrivate() + : properties() +{ +} + +class UndoPropertyCommand : public BaseUndoCommand +{ +public: + UndoPropertyCommand(QObject*, UiQuickUndoPropertyCommand*); + ~UndoPropertyCommand(); + + void undo(); + void redo(); + + bool delayPush() const; + +private: + void saveState(TargetState& state); + void applyState(TargetState& state); + + TargetState m_undoState; + TargetState m_redoState; + QObject *m_target; + UiQuickUndoPropertyCommand *m_qmlObject; +}; + +UndoPropertyCommand::UndoPropertyCommand(QObject* t, UiQuickUndoPropertyCommand *q) + : BaseUndoCommand() + , m_undoState(TargetState()) + , m_redoState(TargetState()) + , m_target(t) + , m_qmlObject(q) +{ + saveState(m_undoState); +} + +UndoPropertyCommand::~UndoPropertyCommand() +{ +} + +void UndoPropertyCommand::saveState(TargetState& state) +{ + foreach (const QVariant& var, m_qmlObject->properties()) { + QByteArray propertyName = var.toByteArray(); + state.append(qMakePair(propertyName, m_target->property(propertyName.data()))); + } +} + +void UndoPropertyCommand::applyState(TargetState& state) +{ + foreach (PropertyState pair, state) + m_target->setProperty(pair.first, pair.second); +} + +void UndoPropertyCommand::undo() +{ + applyState(m_undoState); +} + +void UndoPropertyCommand::redo() +{ + if (m_redoState.empty()) + saveState(m_redoState); + else + applyState(m_redoState); +} + +bool UndoPropertyCommand::delayPush() const +{ + return true; +} + +UiQuickUndoPropertyCommand::UiQuickUndoPropertyCommand(QObject *parent) + : UiQuickBaseUndoCommand(parent) + , d_ptr(new UiQuickUndoPropertyCommandPrivate()) +{ +} + +UiQuickUndoPropertyCommand::~UiQuickUndoPropertyCommand() +{ +} + +QVariantList UiQuickUndoPropertyCommand::properties() const +{ + Q_D(const UiQuickUndoPropertyCommand); + + return d->properties; +} + +void UiQuickUndoPropertyCommand::setProperties(const QVariantList& prop) +{ + Q_D(UiQuickUndoPropertyCommand); + + if (prop == d->properties) + return; + + d->properties = prop; + emit propertiesChanged(); +} + +BaseUndoCommand *UiQuickUndoPropertyCommand::create(QObject *target) +{ + return new UndoPropertyCommand(target, this); +} diff --git a/imports/undo/uiquickundopropertycommand_p.h b/imports/undo/uiquickundopropertycommand_p.h new file mode 100644 index 0000000..aa02c5c --- /dev/null +++ b/imports/undo/uiquickundopropertycommand_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UIQUICKUNDOPROPERTYCOMMAND_H +#define UIQUICKUNDOPROPERTYCOMMAND_H + +#include +#include "uiquickbaseundocommand_p.h" + +QT_USE_NAMESPACE_UIHELPERS; + +class UiQuickUndoPropertyCommandPrivate; + +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); + + BaseUndoCommand *create(QObject *target = 0); + +signals: + void propertiesChanged(); + +private: + Q_DISABLE_COPY(UiQuickUndoPropertyCommand) + Q_DECLARE_PRIVATE(UiQuickUndoPropertyCommand) + + QScopedPointer d_ptr; +}; + +#endif // UIQUICKUNDOPROPERTYCOMMAND_H diff --git a/imports/undo/uiquickundostack.cpp b/imports/undo/uiquickundostack.cpp new file mode 100644 index 0000000..c8a715e --- /dev/null +++ b/imports/undo/uiquickundostack.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "uiquickundostack_p.h" +#include "uiquickundocommand_p.h" +#include "uiquickundopropertycommand_p.h" + +#include + +class UiQuickUndoStackPrivate : public UiUndoStack +{ + Q_DECLARE_PUBLIC(UiQuickUndoStack) + +public: + UiQuickUndoStackPrivate(UiQuickUndoStack *q); + ~UiQuickUndoStackPrivate(); + + void setCurrentCommand(UiUndoCommand *cmd); + void commit(); + + UiQuickUndoStack *q_ptr; + UiUndoCommand *currentCommand; +}; + +UiQuickUndoStackPrivate::UiQuickUndoStackPrivate(UiQuickUndoStack *q) + : UiUndoStack(q) + , q_ptr(q) + , currentCommand(0) +{ +} + +UiQuickUndoStackPrivate::~UiQuickUndoStackPrivate() +{ +} + +void UiQuickUndoStackPrivate::setCurrentCommand(UiUndoCommand *cmd) +{ + Q_Q(UiQuickUndoStack); + currentCommand = cmd; + + if (!canUndo()) + emit q->canUndoChanged(); +} + +void UiQuickUndoStackPrivate::commit() +{ + if (!currentCommand) + return; + + push(currentCommand); + setCurrentCommand(0); +} + + +UiQuickUndoStack::UiQuickUndoStack(QObject *parent) + : QObject(parent) + , d_ptr(new UiQuickUndoStackPrivate(this)) +{ + Q_D(const UiQuickUndoStack); + connect(d, SIGNAL(canUndoChanged(bool)), SIGNAL(canUndoChanged())); + connect(d, SIGNAL(canRedoChanged(bool)), SIGNAL(canRedoChanged())); +} + +UiQuickUndoStack::~UiQuickUndoStack() +{ +} + +int UiQuickUndoStack::undoLimit() const +{ + Q_D(const UiQuickUndoStack); + return d->undoLimit(); +} + +void UiQuickUndoStack::setUndoLimit(int limit) +{ + Q_D(UiQuickUndoStack); + + int temp = d->undoLimit(); + d->setUndoLimit(limit); + + if (temp != limit) + emit undoLimitChanged(); +} + +bool UiQuickUndoStack::canUndo() const +{ + Q_D(const UiQuickUndoStack); + return d->canUndo() || (d->currentCommand != 0); +} + +bool UiQuickUndoStack::canRedo() const +{ + Q_D(const UiQuickUndoStack); + return d->canRedo(); +} + +int UiQuickUndoStack::count() const +{ + Q_D(const UiQuickUndoStack); + if ((d->undoLimit() && (d->count() == d->undoLimit())) || !d->currentCommand) + return d->count(); + else + return d->count() + 1; +} + +void UiQuickUndoStack::clear() +{ + Q_D(UiQuickUndoStack); + d->clear(); + d->setCurrentCommand(0); + emit countChanged(); +} + +void UiQuickUndoStack::push(UiQuickBaseUndoCommand *quickCommand, QObject *target) +{ + Q_D(UiQuickUndoStack); + + if (!quickCommand) { + qmlInfo(this) << tr("Invalid (null) command passed to push()."); + return; + } + + if (!target) { + qmlInfo(this) << tr("Invalid (null) target passed to push()."); + return; + } + + d->commit(); + + int countTemp = count(); + + BaseUndoCommand *undoCommand = quickCommand->create(target); + if (undoCommand->delayPush()) + d->setCurrentCommand(undoCommand); + else + d->push(undoCommand); + + if (countTemp != count()) + emit countChanged(); +} + +void UiQuickUndoStack::undo() +{ + Q_D(UiQuickUndoStack); + d->commit(); + d->undo(); +} + +void UiQuickUndoStack::redo() +{ + Q_D(UiQuickUndoStack); + d->commit(); + d->redo(); +} diff --git a/imports/undo/uiquickundostack_p.h b/imports/undo/uiquickundostack_p.h new file mode 100644 index 0000000..abd1664 --- /dev/null +++ b/imports/undo/uiquickundostack_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Instituto Nokia de Tecnologia (INdT) +** Contact: http://www.qt-project.org/ +** +** This file is part of the UiHelpers playground module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UIQUICKUNDOSTACK_H +#define UIQUICKUNDOSTACK_H + +#include +#include + + +QT_USE_NAMESPACE_UIHELPERS; + +class UiQuickBaseUndoCommand; +class UiQuickUndoStackPrivate; +class UiQuickUndoStack : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit NOTIFY undoLimitChanged) + Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged) + Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) + +public: + UiQuickUndoStack(QObject *parent = 0); + ~UiQuickUndoStack(); + + int undoLimit() const; + void setUndoLimit(int limit); + + bool canUndo() const; + bool canRedo() const; + int count() const; + + Q_INVOKABLE void clear(); + +public slots: + void push(UiQuickBaseUndoCommand *cmd, QObject *target); + void undo(); + void redo(); + +Q_SIGNALS: + void undoLimitChanged(); + void canUndoChanged(); + void canRedoChanged(); + void countChanged(); + +private: + Q_DISABLE_COPY(UiQuickUndoStack) + Q_DECLARE_PRIVATE(UiQuickUndoStack) + + QScopedPointer d_ptr; +}; + +#endif diff --git a/imports/undo/undo.pro b/imports/undo/undo.pro new file mode 100644 index 0000000..1bf778d --- /dev/null +++ b/imports/undo/undo.pro @@ -0,0 +1,27 @@ +TEMPLATE = lib +TARGET = qmlundoframeworkplugin +TARGETPATH = Playground/UiHelpers/UndoFramework + +QT += qml uihelpers + +CONFIG += qt plugin + +SOURCES += plugin.cpp + +SOURCES += uiquickbaseundocommand.cpp \ + uiquickundocommand.cpp \ + uiquickundopropertycommand.cpp \ + uiquickundostack.cpp + +HEADERS += uiquickbaseundocommand_p.h \ + uiquickundocommand_p.h \ + uiquickundopropertycommand_p.h \ + uiquickundostack_p.h + + +target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +qmldir.files += $$PWD/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +INSTALLS += target qmldir -- cgit v1.2.3