--- /dev/null
+#include "declarativelayoutextension.h"
+
+#include <QLayout>
+#include <QWidget>
+
+DeclarativeLayoutExtension::DeclarativeLayoutExtension(QObject *parent)
+ : DeclarativeObjectExtension(parent)
+{
+ parent->setParent(0); // otherwise first call to parentWidget() will complain about wrong parent class
+}
+
+QLayout *DeclarativeLayoutExtension::extendedLayout() const
+{
+ QLayout *parentLayout = qobject_cast<QLayout*>(parent());
+ Q_ASSERT(parentLayout);
+ Q_UNUSED(parentLayout);
+
+ return parentLayout;
+}
+
+void DeclarativeLayoutExtension::dataAppend(QObject *object)
+{
+ DeclarativeObjectExtension::dataAppend(object);
+
+ QWidget *widget = qobject_cast<QWidget*>(object);
+ if (widget) {
+ addWidget(widget);
+ return;
+ }
+
+ QLayout *layout = qobject_cast<QLayout*>(object);
+ if (layout) {
+ addLayout(layout);
+ return;
+ }
+}
--- /dev/null
+#ifndef DECLARATIVELAYOUTEXTENSION_H
+#define DECLARATIVELAYOUTEXTENSION_H
+
+#include "declarativeobjectextension.h"
+
+class QLayout;
+class QWidget;
+
+class DeclarativeLayoutExtension : public DeclarativeObjectExtension
+{
+ Q_OBJECT
+
+ // repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class
+ Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
+
+ Q_CLASSINFO("DefaultProperty", "data")
+
+ public:
+ DeclarativeLayoutExtension(QObject *parent);
+
+ QLayout *extendedLayout() const;
+
+ protected:
+ void dataAppend(QObject *object);
+
+ virtual void addLayout(QLayout *layout) = 0;
+ virtual void addWidget(QWidget *widget) = 0;
+};
+
+#endif // DECLARATIVELAYOUTEXTENSION_H
--- /dev/null
+#include "declarativeobjectextension.h"
+
+DeclarativeObjectExtension::DeclarativeObjectExtension(QObject *parent)
+ : QObject(parent)
+{
+}
+
+DeclarativeObjectExtension::~DeclarativeObjectExtension()
+{
+}
+
+QDeclarativeListProperty<QObject> DeclarativeObjectExtension::data()
+{
+ return QDeclarativeListProperty<QObject>(this, 0, DeclarativeObjectExtension::data_append,
+ DeclarativeObjectExtension::data_count,
+ DeclarativeObjectExtension::data_at,
+ DeclarativeObjectExtension::data_clear);
+}
+
+void DeclarativeObjectExtension::dataAppend(QObject *object)
+{
+ m_children.append(object);
+}
+
+int DeclarativeObjectExtension::dataCount() const
+{
+ return m_children.count();
+}
+
+QObject* DeclarativeObjectExtension::dataAt(int index) const
+{
+ return m_children.at(index);
+}
+
+void DeclarativeObjectExtension::dataClear()
+{
+ m_children.clear();
+}
+
+void DeclarativeObjectExtension::data_append(QDeclarativeListProperty<QObject> *property, QObject *object)
+{
+ if (!object)
+ return;
+
+ DeclarativeObjectExtension *that = qobject_cast<DeclarativeObjectExtension*>(property->object);
+ if (that)
+ that->dataAppend(object);
+ else
+ qWarning("cast went wrong in data_append");
+}
+
+int DeclarativeObjectExtension::data_count(QDeclarativeListProperty<QObject> *property)
+{
+ DeclarativeObjectExtension *that = qobject_cast<DeclarativeObjectExtension*>(property->object);
+ if (that)
+ return that->dataCount();
+ else {
+ qWarning("cast went wrong in data_count");
+ return 0;
+ }
+}
+
+QObject* DeclarativeObjectExtension::data_at(QDeclarativeListProperty<QObject> *property, int index)
+{
+ DeclarativeObjectExtension *that = qobject_cast<DeclarativeObjectExtension*>(property->object);
+ if (that)
+ return that->dataAt(index);
+ else {
+ qWarning("cast went wrong in data_at");
+ return 0;
+ }
+}
+
+void DeclarativeObjectExtension::data_clear(QDeclarativeListProperty<QObject> *property)
+{
+ DeclarativeObjectExtension *that = qobject_cast<DeclarativeObjectExtension*>(property->object);
+ if (that)
+ that->dataClear();
+ else
+ qWarning("cast went wrong in data_clear");
+}
--- /dev/null
+#ifndef DECLARATIVEOBJECTEXTENSION_H
+#define DECLARATIVEOBJECTEXTENSION_H
+
+#include <QDeclarativeListProperty>
+#include <QObject>
+
+class DeclarativeObjectExtension : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
+
+ Q_CLASSINFO("DefaultProperty", "data")
+
+ public:
+ explicit DeclarativeObjectExtension(QObject *parent = 0);
+ ~DeclarativeObjectExtension();
+
+ QObject *extendedObject() const { return parent(); }
+
+ protected:
+ QObjectList m_children;
+
+ virtual void dataAppend(QObject *object);
+ virtual int dataCount() const;
+ virtual QObject *dataAt(int index) const;
+ virtual void dataClear();
+
+ QDeclarativeListProperty<QObject> data();
+
+ private:
+ static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
+ static int data_count(QDeclarativeListProperty<QObject> *);
+ static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
+ static void data_clear(QDeclarativeListProperty<QObject> *);
+};
+
+#endif // DECLARATIVEOBJECTEXTENSION_H
--- /dev/null
+#include "declarativewidgetextension.h"
+
+#include <QAction>
+#include <QDeclarativeInfo>
+#include <QLayout>
+#include <QWidget>
+
+DeclarativeWidgetExtension::DeclarativeWidgetExtension(QObject *parent)
+ : DeclarativeObjectExtension(parent)
+{
+}
+
+QWidget *DeclarativeWidgetExtension::extendedWidget() const
+{
+ QWidget *parentWidget = qobject_cast<QWidget*>(parent());
+ Q_ASSERT(parentWidget);
+ Q_UNUSED(parentWidget);
+
+ return parentWidget;
+}
+
+void DeclarativeWidgetExtension::dataAppend(QObject *object)
+{
+ DeclarativeObjectExtension::dataAppend(object);
+
+ QWidget *widget = qobject_cast<QWidget*>(object);
+ if (widget) {
+ addWidget(widget);
+ return;
+ }
+
+ QLayout *layout = qobject_cast<QLayout*>(object);
+ if (layout) {
+ setLayout(layout);
+ return;
+ }
+
+ QAction *action = qobject_cast<QAction*>(object);
+ if (action) {
+ addAction(action);
+ return;
+ }
+}
+
+void DeclarativeWidgetExtension::addAction(QAction *action)
+{
+ extendedWidget()->addAction(action);
+}
+
+void DeclarativeWidgetExtension::setLayout(QLayout *layout)
+{
+ if (extendedWidget()->layout()){
+ qmlInfo(this) << "Cannot add a second layout";
+ return;
+ }
+
+ extendedWidget()->setLayout(layout);
+}
+
+void DeclarativeWidgetExtension::addWidget(QWidget *widget)
+{
+ widget->setParent(extendedWidget());
+}
--- /dev/null
+#ifndef DECLARATIVEWIDGETEXTENSION_H
+#define DECLARATIVEWIDGETEXTENSION_H
+
+#include "declarativeobjectextension.h"
+
+class QAction;
+class QLayout;
+class QWidget;
+
+class DeclarativeWidgetExtension : public DeclarativeObjectExtension
+{
+ Q_OBJECT
+
+ // repeat property declarations, qmlRegisterExtendedType doesn't see the ones from base class
+ Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
+
+ Q_CLASSINFO("DefaultProperty", "data")
+
+ public:
+ DeclarativeWidgetExtension(QObject *parent);
+
+ QWidget *extendedWidget() const;
+
+ protected:
+ void dataAppend(QObject *object);
+
+ virtual void addAction(QAction *action);
+ virtual void setLayout(QLayout *layout);
+ virtual void addWidget(QWidget *widget);
+};
+
+#endif // DECLARATIVEWIDGETEXTENSION_H
AbstractDeclarativeObject *declarativeObject = dynamic_cast<AbstractDeclarativeObject*>(object);
if (!declarativeObject) {
+ QWidget *widget = qobject_cast<QWidget*>(object);
+ if (widget) return widget;
qWarning("Root element is no AbstractDeclarativeObject subclass");
return 0;
}
declarativehboxlayout_p.h \
declarativeinputdialog_p.h \
declarativelabel_p.h \
+ declarativelayoutextension.h \
declarativelayoutproxy_p.h \
declarativelcdnumber_p.h \
declarativelineedit_p.h \
declarativemenubar_p.h \
declarativemenu_p.h \
declarativemessagebox_p.h \
+ declarativeobjectextension.h \
declarativeobjectproxy_p.h \
declarativeplaintextedit_p.h \
declarativeprogressbar_p.h \
declarativetreeview_p.h \
declarativevboxlayout_p.h \
declarativewebview_p.h \
+ declarativewidgetextension.h \
declarativewidget_p.h \
declarativewidgetproxy_p.h \
declarativewidgetsdocument.h \
declarativehboxlayout.cpp \
declarativeinputdialog.cpp \
declarativelabel.cpp \
+ declarativelayoutextension.cpp \
declarativelcdnumber.cpp \
declarativelineedit.cpp \
declarativelistview.cpp \
declarativemenubar.cpp \
declarativemenu.cpp \
declarativemessagebox.cpp \
+ declarativeobjectextension.cpp \
declarativeplaintextedit.cpp \
declarativeprogressbar.cpp \
declarativepushbutton.cpp \
declarativevboxlayout.cpp \
declarativewebview.cpp \
declarativewidget.cpp \
+ declarativewidgetextension.cpp \
declarativewidgetsdocument.cpp \
objectadaptors.cpp \
qmetaobjectbuilder.cpp \
staticdialogmethodattached.cpp
-