Fix compilation for latest qt/master

QmlList has been replaced by QmlListProperty (33eb76f050b45718d87926).

Patch provided by Aaron Kennedy.

Reviewed-by: akennedy
This commit is contained in:
Kai Koehne
2010-02-23 10:39:44 +01:00
parent ec409dc4f3
commit 3f18859252
6 changed files with 110 additions and 161 deletions

View File

@@ -34,12 +34,12 @@ QT_BEGIN_NAMESPACE
QML_DEFINE_TYPE(Bauhaus,1,0,QBoxLayout,QBoxLayoutObject); QML_DEFINE_TYPE(Bauhaus,1,0,QBoxLayout,QBoxLayoutObject);
QBoxLayoutObject::QBoxLayoutObject(QObject *parent) QBoxLayoutObject::QBoxLayoutObject(QObject *parent)
: QLayoutObject(parent), _widgets(this), _layout(0) : QLayoutObject(parent), _layout(0)
{ {
} }
QBoxLayoutObject::QBoxLayoutObject(QBoxLayout *layout, QObject *parent) QBoxLayoutObject::QBoxLayoutObject(QBoxLayout *layout, QObject *parent)
: QLayoutObject(parent), _widgets(this), _layout(layout) : QLayoutObject(parent), _layout(layout)
{ {
} }

View File

@@ -43,7 +43,7 @@ class QBoxLayoutObject : public QLayoutObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QmlList<QWidget *> *children READ children) Q_PROPERTY(QmlListProperty<QWidget> children READ children)
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin) Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin)
Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin) Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin)
@@ -57,30 +57,22 @@ public:
explicit QBoxLayoutObject(QBoxLayout *, QObject *parent=0); explicit QBoxLayoutObject(QBoxLayout *, QObject *parent=0);
virtual QLayout *layout() const; virtual QLayout *layout() const;
QmlList<QWidget *> *children() { return &_widgets; } QmlListProperty<QWidget> children() {
return QmlListProperty<QWidget>(this, 0, children_append, 0, 0, children_clear);
}
private: private:
friend class WidgetList; friend class WidgetList;
void addWidget(QWidget *); void addWidget(QWidget *);
void clearWidget(); void clearWidget();
//XXX need to provide real implementations once QBoxLayoutObject is finished static void children_append(QmlListProperty<QWidget> *property, QWidget *widget) {
class WidgetList : public QmlList<QWidget *> static_cast<QBoxLayoutObject*>(property->object)->addWidget(widget);
{ }
public:
WidgetList(QBoxLayoutObject *o)
: obj(o) {}
virtual void append(QWidget *w) { obj->addWidget(w); } static void children_clear(QmlListProperty<QWidget> *property) {
virtual void clear() { obj->clearWidget(); } static_cast<QBoxLayoutObject*>(property->object)->clearWidget();
virtual int count() const { return 0; } }
virtual void removeAt(int) {}
virtual QWidget *at(int) const { return 0; }
virtual void insert(int, QWidget *) {}
private:
QBoxLayoutObject *obj;
};
void getMargins() void getMargins()
{ {
@@ -154,7 +146,6 @@ private:
_layout->setSpacing(spacing); _layout->setSpacing(spacing);
} }
WidgetList _widgets;
QBoxLayout *_layout; QBoxLayout *_layout;
int mTop, mLeft, mBottom, mRight; int mTop, mLeft, mBottom, mRight;

View File

@@ -51,39 +51,6 @@ QT_BEGIN_NAMESPACE
class QWidgetDeclarativeUI; class QWidgetDeclarativeUI;
class Actions : public QmlConcreteList<Action *>
{
public:
Actions(QObject *o) : widget(qobject_cast<QWidget*>(o)) {}
virtual void append(Action *o)
{
QmlConcreteList<Action *>::append(o);
o->setParent(widget);
widget->addAction(o);
}
virtual void clear()
{
QmlConcreteList<Action *>::clear();
while (!widget->actions().empty())
widget->removeAction(widget->actions().first());
//menu->clear();
}
virtual void removeAt(int i)
{
QmlConcreteList<Action *>::removeAt(i);
widget->removeAction(widget->actions().at(i));
}
virtual void insert(int i, Action *obj)
{
QmlConcreteList<Action *>::insert(i, obj);
obj->setParent(widget);
widget->addAction(obj);
}
private:
QWidget *widget;
};
class ResizeEventFilter : public QObject class ResizeEventFilter : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -104,9 +71,9 @@ class QWidgetDeclarativeUI : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QmlList<QObject *> *children READ children) Q_PROPERTY(QmlListProperty<QObject> children READ children)
Q_PROPERTY(QLayoutObject *layout READ layout WRITE setLayout) Q_PROPERTY(QLayoutObject *layout READ layout WRITE setLayout)
Q_PROPERTY(QmlList<Action *> *actions READ actions) Q_PROPERTY(QmlListProperty<Action> actions READ actions)
Q_PROPERTY(QFont font READ font CONSTANT) Q_PROPERTY(QFont font READ font CONSTANT)
Q_PROPERTY(QPoint pos READ pos) Q_PROPERTY(QPoint pos READ pos)
@@ -150,7 +117,7 @@ signals:
void opacityChanged(); void opacityChanged();
public: public:
QWidgetDeclarativeUI(QObject *other) : QObject(other), _children(other), _layout(0), _graphicsOpacityEffect(0), _actions(other) { QWidgetDeclarativeUI(QObject *other) : QObject(other), _layout(0), _graphicsOpacityEffect(0) {
q = qobject_cast<QWidget*>(other); q = qobject_cast<QWidget*>(other);
ResizeEventFilter *filter(new ResizeEventFilter(q)); ResizeEventFilter *filter(new ResizeEventFilter(q));
filter->setTarget(q); filter->setTarget(q);
@@ -162,38 +129,6 @@ public:
virtual ~QWidgetDeclarativeUI() { virtual ~QWidgetDeclarativeUI() {
} }
class Children : public QmlConcreteList<QObject *>
{
public:
Children(QObject *widget) : q(qobject_cast<QWidget *>(widget)) {}
virtual void append(QObject *o)
{
insert(-1, o);
}
virtual void clear()
{
for (int i = 0; i < count(); ++i)
at(i)->setParent(0);
QmlConcreteList<QObject *>::clear();
}
virtual void removeAt(int i)
{
at(i)->setParent(0);
QmlConcreteList<QObject *>::removeAt(i);
}
virtual void insert(int i, QObject *o)
{
QmlConcreteList<QObject *>::insert(i, o);
if (QWidget *w = qobject_cast<QWidget *>(o))
w->setParent(static_cast<QWidget *>(q));
else
o->setParent(q);
}
private:
QWidget *q;
};
public: public:
void setMouseOver(bool _mouseOver) void setMouseOver(bool _mouseOver)
@@ -223,7 +158,9 @@ public:
emit mouseOverChanged(); emit mouseOverChanged();
} }
QmlList<QObject *> *children() { return &_children; } QmlListProperty<QObject> children() {
return QmlListProperty<QObject>(this, 0, children_append, children_count, children_at, children_clear);
}
QLayoutObject *layout() const { return _layout; } QLayoutObject *layout() const { return _layout; }
void setLayout(QLayoutObject *lo) void setLayout(QLayoutObject *lo)
@@ -440,18 +377,73 @@ public:
} }
QmlListProperty<Action> actions() {
QmlList<Action *> *actions() { return &_actions; } return QmlListProperty<Action>(this, 0, actions_append, actions_count, actions_at, actions_clear);
}
private: private:
QWidget *q; QWidget *q;
Children _children;
QLayoutObject *_layout; QLayoutObject *_layout;
QFont _font; QFont _font;
QUrl _styleSheetFile; QUrl _styleSheetFile;
QGraphicsOpacityEffect *_graphicsOpacityEffect; QGraphicsOpacityEffect *_graphicsOpacityEffect;
bool m_mouseOver; bool m_mouseOver;
Actions _actions;
static void children_append(QmlListProperty<QObject> *property, QObject *o) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *q = p->q;
if (QWidget *w = qobject_cast<QWidget *>(o))
w->setParent(static_cast<QWidget *>(q));
else
o->setParent(q);
}
static int children_count(QmlListProperty<QObject> *property) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *q = p->q;
return q->children().count();
}
static QObject * children_at(QmlListProperty<QObject> *property, int index) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *q = p->q;
return q->children().at(index);
}
static void children_clear(QmlListProperty<QObject> *property) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *q = p->q;
QObjectList c = q->children();
for (int i = 0; i < c.count(); ++i)
c.at(i)->setParent(0);
}
// ### Original had an insert, and removeAt
static void actions_append(QmlListProperty<Action> *property, Action *o) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *w = p->q;
o->setParent(w);
w->addAction(o);
}
static int actions_count(QmlListProperty<Action> *property) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *w = p->q;
return w->actions().count();
}
static Action *actions_at(QmlListProperty<Action> *property, int index) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *w = p->q;
return qobject_cast<Action *>(w->actions().at(index));
}
static void actions_clear(QmlListProperty<Action> *property) {
QWidgetDeclarativeUI *p = static_cast<QWidgetDeclarativeUI *>(property->object);
QWidget *w = p->q;
while (!w->actions().empty())
w->removeAction(w->actions().first());
}
}; };
bool ResizeEventFilter::eventFilter(QObject *obj, QEvent *event) bool ResizeEventFilter::eventFilter(QObject *obj, QEvent *event)
@@ -1113,50 +1105,28 @@ class QTabWidgetDeclarativeUI : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QmlList<QTabObject *> *tabs READ tabs) Q_PROPERTY(QmlListProperty<QTabObject> tabs READ tabs)
Q_CLASSINFO("DefaultProperty", "tabs") Q_CLASSINFO("DefaultProperty", "tabs")
public: public:
QTabWidgetDeclarativeUI(QObject *other) : QObject(other), _tabs(other) {} QTabWidgetDeclarativeUI(QObject *other) : QObject(other) {}
QmlList<QTabObject *> *tabs() { return &_tabs; } QmlListProperty<QTabObject> tabs() {
return QmlListProperty<QTabObject>(this, 0, tabs_append, 0, 0, tabs_clear);
}
private: private:
//if not for the at() function, we could use QmlList instead static void tabs_append(QmlListProperty<QTabObject> *property, QTabObject *o) {
class Tabs : public QmlConcreteList<QTabObject *> QTabWidget *tw = static_cast<QTabWidget*>(property->object->parent());
{
public:
Tabs(QObject *o) : tw(o) {}
virtual void append(QTabObject *o)
{
QmlConcreteList<QTabObject *>::append(o);
//XXX can we insertTab(-1, o) instead?
if (!o->icon().isNull()) if (!o->icon().isNull())
static_cast<QTabWidget *>(tw)->addTab(o->content(), o->icon(), o->label()); tw->addTab(o->content(), o->icon(), o->label());
else else
static_cast<QTabWidget *>(tw)->addTab(o->content(), o->label()); tw->addTab(o->content(), o->label());
} }
virtual void clear()
{ static void tabs_clear(QmlListProperty<QTabObject> *property) {
QmlConcreteList<QTabObject *>::clear(); QTabWidget *tw = static_cast<QTabWidget*>(property->object->parent());
static_cast<QTabWidget *>(tw)->clear(); tw->clear();
} }
virtual void removeAt(int i)
{
QmlConcreteList<QTabObject *>::removeAt(i);
static_cast<QTabWidget *>(tw)->removeTab(i);
}
virtual void insert(int i, QTabObject *obj)
{
QmlConcreteList<QTabObject *>::insert(i, obj);
if (!obj->icon().isNull())
static_cast<QTabWidget *>(tw)->insertTab(i, obj->content(), obj->icon(), obj->label());
else
static_cast<QTabWidget *>(tw)->insertTab(i, obj->content(), obj->label());
}
private:
QObject *tw;
};
Tabs _tabs;
}; };

View File

@@ -52,7 +52,6 @@
#include <QEvent> #include <QEvent>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QmlContext> #include <QmlContext>
#include <QmlList>
#include <QmlError> #include <QmlError>
#include <QmlBinding> #include <QmlBinding>
#include <QmlMetaType> #include <QmlMetaType>
@@ -327,7 +326,7 @@ QPair<QString, NodeInstance> ObjectNodeInstance::anchor(const QString &/*name*/)
static bool isList(const QmlMetaProperty &metaProperty) static bool isList(const QmlMetaProperty &metaProperty)
{ {
return metaProperty.propertyCategory() == QmlMetaProperty::List || metaProperty.propertyCategory() == QmlMetaProperty::QmlList; return metaProperty.propertyCategory() == QmlMetaProperty::List;
} }
static bool isObject(const QmlMetaProperty &metaProperty) static bool isObject(const QmlMetaProperty &metaProperty)
@@ -342,15 +341,7 @@ static QVariant objectToVariant(QObject *object)
static void removeObjectFromList(const QmlMetaProperty &metaProperty, QObject *object, QmlEngine *engine) static void removeObjectFromList(const QmlMetaProperty &metaProperty, QObject *object, QmlEngine *engine)
{ {
QmlListAccessor listAccessor; // ### Very few QML lists ever responded to removes
listAccessor.setList(metaProperty.read(), engine);
for (int i = 0; i < listAccessor.count(); ++i) {
if (QmlMetaType::toQObject(listAccessor.at(i)) == object) {
listAccessor.removeAt(i);
break;
}
}
} }
void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty) void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty)
@@ -371,9 +362,8 @@ void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, c
QmlMetaProperty metaProperty = QmlMetaProperty::createProperty(newParent, newParentProperty, context()); QmlMetaProperty metaProperty = QmlMetaProperty::createProperty(newParent, newParentProperty, context());
if (isList(metaProperty)) { if (isList(metaProperty)) {
QmlListAccessor listAccessor; QmlListReference list = qvariant_cast<QmlListReference>(metaProperty.read());
listAccessor.setList(metaProperty.read(), nodeInstanceView()->engine()); list.append(object);
listAccessor.append(objectToVariant(object));
} else if (isObject(metaProperty)) { } else if (isObject(metaProperty)) {
metaProperty.write(objectToVariant(object)); metaProperty.write(objectToVariant(object));
} }
@@ -438,14 +428,13 @@ void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &
void ObjectNodeInstance::deleteObjectsInList(const QmlMetaProperty &metaProperty) void ObjectNodeInstance::deleteObjectsInList(const QmlMetaProperty &metaProperty)
{ {
QObjectList objectList; QObjectList objectList;
QmlListAccessor listAccessor; QmlListReference list = qvariant_cast<QmlListReference>(metaProperty.read());
listAccessor.setList(metaProperty.read());
for(int i = 0; i < listAccessor.count(); i++) { for(int i = 0; i < list.count(); i++) {
objectList += QmlMetaType::toQObject(listAccessor.at(i)); objectList += list.at(i);
} }
listAccessor.clear(); list.clear();
} }
void ObjectNodeInstance::resetProperty(const QString &name) void ObjectNodeInstance::resetProperty(const QString &name)
@@ -489,9 +478,8 @@ void ObjectNodeInstance::resetProperty(QObject *object, const QString &propertyN
if (qmlMetaProperty.read() == resetValue(propertyName)) if (qmlMetaProperty.read() == resetValue(propertyName))
return; return;
qmlMetaProperty.write(resetValue(propertyName)); qmlMetaProperty.write(resetValue(propertyName));
} else if (QmlMetaType::isList(qmlMetaProperty.propertyType()) || } else if (qmlMetaProperty.propertyCategory() == QmlMetaProperty::List) {
QmlMetaType::isQmlList(qmlMetaProperty.propertyType())) { qvariant_cast<QmlListReference>(qmlMetaProperty.read()).clear();
QmlMetaType::clear(object->property(propertyName.toLatin1()));
} }
} }

View File

@@ -14,7 +14,7 @@ public:
QList<QmlFileFilterItem*> qmlFileFilters() const; QList<QmlFileFilterItem*> qmlFileFilters() const;
// content property // content property
QmlConcreteList<QmlProjectContentItem*> content; QList<QmlProjectContentItem*> content;
}; };
QList<QmlFileFilterItem*> QmlProjectItemPrivate::qmlFileFilters() const QList<QmlFileFilterItem*> QmlProjectItemPrivate::qmlFileFilters() const
@@ -45,10 +45,10 @@ QmlProjectItem::~QmlProjectItem()
delete d_ptr; delete d_ptr;
} }
QmlList<QmlProjectContentItem*> *QmlProjectItem::content() QmlListProperty<QmlProjectContentItem> QmlProjectItem::content()
{ {
Q_D(QmlProjectItem); Q_D(QmlProjectItem);
return &d->content; return QmlListProperty<QmlProjectContentItem>(this, d->content);
} }
QString QmlProjectItem::sourceDirectory() const QString QmlProjectItem::sourceDirectory() const

View File

@@ -21,7 +21,7 @@ class QmlProjectItem : public QObject {
Q_DECLARE_PRIVATE(QmlProjectItem) Q_DECLARE_PRIVATE(QmlProjectItem)
Q_DISABLE_COPY(QmlProjectItem) Q_DISABLE_COPY(QmlProjectItem)
Q_PROPERTY(QmlList<QmlProjectManager::QmlProjectContentItem*> *content READ content DESIGNABLE false) Q_PROPERTY(QmlListProperty<QmlProjectManager::QmlProjectContentItem> content READ content DESIGNABLE false)
Q_PROPERTY(QString sourceDirectory READ sourceDirectory NOTIFY sourceDirectoryChanged) Q_PROPERTY(QString sourceDirectory READ sourceDirectory NOTIFY sourceDirectoryChanged)
Q_PROPERTY(QStringList libraryPaths READ libraryPaths WRITE setLibraryPaths NOTIFY libraryPathsChanged) Q_PROPERTY(QStringList libraryPaths READ libraryPaths WRITE setLibraryPaths NOTIFY libraryPathsChanged)
@@ -31,7 +31,7 @@ public:
QmlProjectItem(QObject *parent = 0); QmlProjectItem(QObject *parent = 0);
~QmlProjectItem(); ~QmlProjectItem();
QmlList<QmlProjectContentItem*> *content(); QmlListProperty<QmlProjectContentItem> content();
QString sourceDirectory() const; QString sourceDirectory() const;
void setSourceDirectory(const QString &directoryPath); void setSourceDirectory(const QString &directoryPath);