diff options
author | Luis Gabriel Lima <luis.gabriel@openbossa.org> | 2012-03-27 14:22:03 -0300 |
---|---|---|
committer | Anselmo L. S. Melo <anselmo.melo@openbossa.org> | 2012-03-27 20:32:40 +0200 |
commit | a81b088d16706ccc00c5d50f9e0f88955674a65f (patch) | |
tree | 4788d37d444bf9bbcae5166fde40d5f84e707d45 | |
parent | 20fef591aca17f4cec48e8b9816fd1d1c9363e9e (diff) |
Using d-pointer in UiQuickUndoStack
Using this pattern in order to follow the Qt code style/guidelines.
Change-Id: I52e1b305f4f1d1283e2a2934d0984f1e8c7ce19f
Reviewed-by: Daker Fernandes Pinheiro <daker.pinheiro@openbossa.org>
Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
-rw-r--r-- | src/imports/undo/uiquickundostack.cpp | 53 | ||||
-rw-r--r-- | src/imports/undo/uiquickundostack_p.h | 14 |
2 files changed, 37 insertions, 30 deletions
diff --git a/src/imports/undo/uiquickundostack.cpp b/src/imports/undo/uiquickundostack.cpp index 97adf9f..a69c3b5 100644 --- a/src/imports/undo/uiquickundostack.cpp +++ b/src/imports/undo/uiquickundostack.cpp @@ -42,59 +42,64 @@ #include "uiquickundostack_p.h" #include "uiquickundocommands_p.h" -UiQuickUndoStack::UiQuickUndoStack(QObject *parent) - : QObject(parent) - , m_stack(new UndoStack(this)) +UiQuickUndoStackPrivate::UiQuickUndoStackPrivate(QObject *parent) + : UiUndoStack(parent) + , currentCommand(0) { } -UiQuickUndoStack::~UiQuickUndoStack() +UiQuickUndoStackPrivate::~UiQuickUndoStackPrivate() { } -UndoStack::UndoStack(QObject *parent) - : UiUndoStack(parent) - , currentCommand(0) +void UiQuickUndoStackPrivate::commit() +{ + if (!currentCommand) + return; + + push(currentCommand); + currentCommand = 0; +} + + +UiQuickUndoStack::UiQuickUndoStack(QObject *parent) + : QObject(parent) + , d_ptr(new UiQuickUndoStackPrivate(this)) { } -UndoStack::~UndoStack() +UiQuickUndoStack::~UiQuickUndoStack() { } void UiQuickUndoStack::push(UiQuickBaseUndoCommand *cmd, QObject *target) { + Q_D(UiQuickUndoStack); + if (!cmd || !target) return; // XXX: notify error - m_stack->commit(); + d->commit(); UiQuickUndoPropertyCommand *upc = qobject_cast<UiQuickUndoPropertyCommand *>(cmd); if (upc) { - m_stack->currentCommand = new UndoPropertyCommand(target, upc); + d->currentCommand = new UndoPropertyCommand(target, upc); } else { UiQuickUndoCommand *uc = qobject_cast<UiQuickUndoCommand *>(cmd); - m_stack->push(new UndoCommand(target, uc)); + d->push(new UndoCommand(target, uc)); } } void UiQuickUndoStack::undo() { - m_stack->commit(); - m_stack->undo(); + Q_D(UiQuickUndoStack); + d->commit(); + d->undo(); } void UiQuickUndoStack::redo() { - m_stack->commit(); - m_stack->redo(); -} - -void UndoStack::commit() -{ - if (!currentCommand) - return; - - push(currentCommand); - currentCommand = 0; + Q_D(UiQuickUndoStack); + d->commit(); + d->redo(); } diff --git a/src/imports/undo/uiquickundostack_p.h b/src/imports/undo/uiquickundostack_p.h index f7b35d5..0d43360 100644 --- a/src/imports/undo/uiquickundostack_p.h +++ b/src/imports/undo/uiquickundostack_p.h @@ -48,9 +48,8 @@ QT_USE_NAMESPACE_UIHELPERS; -class UndoStack; class UiQuickBaseUndoCommand; - +class UiQuickUndoStackPrivate; class UiQuickUndoStack : public QObject { Q_OBJECT @@ -65,16 +64,19 @@ public slots: void redo(); private: - UndoStack *m_stack; + Q_DISABLE_COPY(UiQuickUndoStack) + Q_DECLARE_PRIVATE(UiQuickUndoStack) + + QScopedPointer<UiQuickUndoStackPrivate> d_ptr; }; -class UndoStack : public UiUndoStack +class UiQuickUndoStackPrivate : public UiUndoStack { Q_OBJECT public: - UndoStack(QObject *parent = 0); - ~UndoStack(); + UiQuickUndoStackPrivate(QObject *parent = 0); + ~UiQuickUndoStackPrivate(); void commit(); |