From 2c5108050afde4b6b0a480aab4b495cc809d6bfb Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Wed, 31 Oct 2012 09:59:47 +0100 Subject: [PATCH] Add template specialization of DeclarativeObjectProxy This allows us to differ between proxied objects that need a parent initializer (e.g. QAction) and objects where passing a '0' as parent initializer would be ambigous. --- declarativeobjects.cpp | 4 ++-- declarativeobjects_p.h | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/declarativeobjects.cpp b/declarativeobjects.cpp index cc3e02e..6cee37d 100644 --- a/declarativeobjects.cpp +++ b/declarativeobjects.cpp @@ -147,7 +147,7 @@ void AbstractDeclarativeObject::data_clear(QDeclarativeListProperty *pr //// Objects //// // DeclarativeAction -DeclarativeAction::DeclarativeAction(QObject *parent) : DeclarativeObjectProxy(parent) +DeclarativeAction::DeclarativeAction(QObject *parent) : DeclarativeObjectProxy(parent) { connectAllSignals(m_proxiedObject, this); } @@ -171,7 +171,7 @@ DeclarativeButtonGroup::DeclarativeButtonGroup(QObject *parent) : DeclarativeObj CUSTOM_METAOBJECT(DeclarativeButtonGroup, ButtonGroup) // DeclarativeSeparator -DeclarativeSeparator::DeclarativeSeparator(QObject *parent) : DeclarativeObjectProxy(parent) +DeclarativeSeparator::DeclarativeSeparator(QObject *parent) : DeclarativeObjectProxy(parent) { connectAllSignals(m_proxiedObject, this); } diff --git a/declarativeobjects_p.h b/declarativeobjects_p.h index 727da1c..9063756 100644 --- a/declarativeobjects_p.h +++ b/declarativeobjects_p.h @@ -87,12 +87,44 @@ class AbstractDeclarativeObject : public QObject static void data_clear(QDeclarativeListProperty *); }; -template +template class DeclarativeObjectProxy : public AbstractDeclarativeObject { +}; + +template +class DeclarativeObjectProxy : public AbstractDeclarativeObject +{ public: - DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T(0)) {} + DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T) {} + ~DeclarativeObjectProxy() { delete m_proxiedObject; } + + virtual QObject *object() const { return m_proxiedObject.data(); } + + protected: + virtual void dataAppend(QObject *object) + { + m_children.append(object); + } + + virtual int dataCount() const { return m_children.count(); } + virtual QObject *dataAt(int index) const { return m_children.at(index); } + virtual void dataClear() + { + qDeleteAll(m_children); + m_children.clear(); + } + + protected: + QPointer m_proxiedObject; + QVector m_children; +}; +template +class DeclarativeObjectProxy : public AbstractDeclarativeObject +{ + public: + DeclarativeObjectProxy(QObject *parent = 0) : AbstractDeclarativeObject(parent), m_proxiedObject(new T(0)) {} ~DeclarativeObjectProxy() { delete m_proxiedObject; } virtual QObject *object() const { return m_proxiedObject.data(); } @@ -236,7 +268,7 @@ class DeclarativeLayoutProxy : public DeclarativeObjectProxy }; //// Objects /// -class DeclarativeAction : public DeclarativeObjectProxy +class DeclarativeAction : public DeclarativeObjectProxy { DECLARATIVE_OBJECT @@ -253,7 +285,7 @@ class DeclarativeButtonGroup : public DeclarativeObjectProxy DeclarativeButtonGroup(QObject *parent = 0); }; -class DeclarativeSeparator : public DeclarativeObjectProxy +class DeclarativeSeparator : public DeclarativeObjectProxy { DECLARATIVE_OBJECT -- 1.7.2.5