on xenial help sign in
use qmlquicklistproperty for children surfaces
1e08db9Nick Dedekind
tests/mocks/Unity/Application/ApplicationDBusAdaptor.cpp+6−11
@@ -33,17 +33,12 @@ MirSurfaceItem* topSurface(MirSurfaceItem* surface)
33 if (!surface)
33 if (!surface)
34 return nullptr;
34 return nullptr;
35
35
36− QList<QObject*> children = surface->childSurfaces();
36+ MirSurfaceItem* child = NULL;
37− if (children.count() > 0) {
37+ surface->foreachChildSurface([&](MirSurfaceItem* childSurface) {
38− MirSurfaceItem* child = nullptr;
39− int i = 0;
40− while(!child && i < children.count()) {
41− child = qobject_cast<MirSurfaceItem*>(children[i++]);
42− }
43− if (child)
38+ if (!child)
44− return topSurface(child);
39+ child = topSurface(childSurface);
45− }
40+ });
46− return surface;
41+ return child ? child : surface;
47}
42}
48
43
49quint32 ApplicationDBusAdaptor::addChildSurface(const QString &appId, const QString &surfaceImage)
44quint32 ApplicationDBusAdaptor::addChildSurface(const QString &appId, const QString &surfaceImage)
tests/mocks/Unity/Application/MirSurfaceItem.cpp+26−4
@@ -118,15 +118,37 @@ void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
118 Q_EMIT childSurfacesChanged();
118 Q_EMIT childSurfacesChanged();
119}
119}
120
120
121−QList<QObject*> MirSurfaceItem::childSurfaces() const
121+void MirSurfaceItem::foreachChildSurface(std::function<void(MirSurfaceItem*)> f) const
122{
122{
123− QList<QObject*> children;
124 for(MirSurfaceItem* child : m_children) {
123 for(MirSurfaceItem* child : m_children) {
125− children.append(child);
124+ f(child);
126 }
125 }
127− return children;
128}
126}
129
127
128+QQmlListProperty<MirSurfaceItem> MirSurfaceItem::childSurfaces()
129+{
130+ return QQmlListProperty<MirSurfaceItem>(this,
131+ 0,
132+ MirSurfaceItem::childSurfaceCount,
133+ MirSurfaceItem::childSurfaceAt);
134+}
135+
136+int MirSurfaceItem::childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
137+{
138+ MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
139+ return p->m_children.count();
140+}
141+
142+MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
143+{
144+ MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
145+
146+ if (index < 0 || index >= p->m_children.count())
147+ return nullptr;
148+ return p->m_children[index];
149+}
150+
151+
130void MirSurfaceItem::touchEvent(QTouchEvent * event)
152void MirSurfaceItem::touchEvent(QTouchEvent * event)
131{
153{
132 if (event->type() == QEvent::TouchBegin && hasFocus()) {
154 if (event->type() == QEvent::TouchBegin && hasFocus()) {
tests/mocks/Unity/Application/MirSurfaceItem.h+6−2
@@ -32,7 +32,7 @@ class MirSurfaceItem : public QQuickPaintedItem
32 Q_PROPERTY(State state READ state NOTIFY stateChanged)
32 Q_PROPERTY(State state READ state NOTIFY stateChanged)
33 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
33 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
34 Q_PROPERTY(MirSurfaceItem* parentSurface READ parentSurface NOTIFY parentSurfaceChanged)
34 Q_PROPERTY(MirSurfaceItem* parentSurface READ parentSurface NOTIFY parentSurfaceChanged)
35− Q_PROPERTY(QList<QObject*> childSurfaces READ childSurfaces NOTIFY childSurfacesChanged)
35+ Q_PROPERTY(QQmlListProperty<MirSurfaceItem> childSurfaces READ childSurfaces NOTIFY childSurfacesChanged DESIGNABLE false)
36
36
37public:
37public:
38 enum Type {
38 enum Type {
@@ -68,7 +68,7 @@ public:
68 State state() const { return m_state; }
68 State state() const { return m_state; }
69 QString name() const { return m_name; }
69 QString name() const { return m_name; }
70 MirSurfaceItem* parentSurface() const { return m_parentSurface; }
70 MirSurfaceItem* parentSurface() const { return m_parentSurface; }
71− QList<QObject*> childSurfaces() const;
71+ void foreachChildSurface(std::function<void(MirSurfaceItem*)> f) const;
72
72
73 void setState(State newState);
73 void setState(State newState);
74 void setApplication(ApplicationInfo* item);
74 void setApplication(ApplicationInfo* item);
@@ -101,6 +101,10 @@ private:
101 void addChildSurface(MirSurfaceItem* surface);
101 void addChildSurface(MirSurfaceItem* surface);
102 void removeChildSurface(MirSurfaceItem* surface);
102 void removeChildSurface(MirSurfaceItem* surface);
103
103
104+ QQmlListProperty<MirSurfaceItem> childSurfaces();
105+ static int childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
106+ static MirSurfaceItem* childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
107+
104 ApplicationInfo* m_application;
108 ApplicationInfo* m_application;
105 const QString m_name;
109 const QString m_name;
106 const Type m_type;
110 const Type m_type;