diff options
Diffstat (limited to 'examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout')
4 files changed, 35 insertions, 23 deletions
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo Binary files differindex c742274..cbd3b3e 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp index 728c225..1792696 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp @@ -131,13 +131,23 @@ void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item) setAlignment(item, alignment); QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment)), this, SLOT(updateAlignment(QGraphicsLayoutItem*, Qt::Alignment))); - //### need to disconnect when widget is removed? Re-implement removeAt()? } } +void QGraphicsGridLayoutObject::removeAt(int index) +{ + QGraphicsLayoutItem *item = itemAt(index); + if (item) { + GridLayoutAttached *obj = attachedProperties.value(item); + obj->disconnect(this); + attachedProperties.remove(item); + } + QGraphicsGridLayout::removeAt(index); +} + void QGraphicsGridLayoutObject::clearChildren() { - //### do I need to delete the removed items? And/or removed them from attachedProperties? + // do not delete the removed items; they will be deleted by the QML engine while (count() > 0) removeAt(count()-1); } @@ -146,7 +156,7 @@ qreal QGraphicsGridLayoutObject::spacing() const { if (verticalSpacing() == horizontalSpacing()) return verticalSpacing(); - return -1; //### + return -1; } qreal QGraphicsGridLayoutObject::contentsMargin() const @@ -170,11 +180,9 @@ void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::A GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj) { - // ### This is not allowed - you must attach to any object - if (!qobject_cast<QGraphicsLayoutItem*>(obj)) - return 0; GridLayoutAttached *rv = new GridLayoutAttached(obj); - attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); + if (qobject_cast<QGraphicsLayoutItem*>(obj)) + attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv); return rv; } diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h index 04f0148..cb8d9b7 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h @@ -69,6 +69,8 @@ public: qreal contentsMargin() const; void setContentsMargin(qreal); + void removeAt(int index); + static GridLayoutAttached *qmlAttachedProperties(QObject *); private slots: diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml index c3edf1d..5cb011f 100644 --- a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml +++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml @@ -49,46 +49,48 @@ Item { size.width: parent.width size.height: parent.height + /* + Below we create a grid layout using the GraphicsGridLayout item + (defined by the GraphicsGridLayoutObject class in gridlayout.h). + + The row, column etc. are set through attached properties on + GraphicsGridLayout, using the properties defined in the + GridLayoutAttached class (also defined in gridlayout.h). + */ + layout: QGraphicsGridLayout { - objectName: "layout" LayoutItem { QGraphicsGridLayout.row: 0 QGraphicsGridLayout.column: 0 - QGraphicsGridLayout.alignment: Qt.AlignLeft minimumSize: "100x100" maximumSize: "300x300" - preferredSize: "100x100" + preferredSize: "200x200" Rectangle { color: "red"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 - QGraphicsGridLayout.column: 0 + QGraphicsGridLayout.row: 0 + QGraphicsGridLayout.column: 1 minimumSize: "100x100" maximumSize: "200x200" - preferredSize: "100x100" + preferredSize: "200x200" Rectangle { color: "orange"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.row: 1 QGraphicsGridLayout.column: 0 + QGraphicsGridLayout.columnSpan: 2 minimumSize: "100x100" - maximumSize: "300x300" - preferredSize: "200x200" Rectangle { color: "yellow"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 0 - QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "200x200" + QGraphicsGridLayout.row: 2 + QGraphicsGridLayout.column: 0 preferredSize: "200x200" Rectangle { color: "green"; anchors.fill: parent } } LayoutItem { - QGraphicsGridLayout.row: 1 + QGraphicsGridLayout.row: 2 QGraphicsGridLayout.column: 1 - minimumSize: "100x100" - maximumSize: "400x400" preferredSize: "200x200" Rectangle { color: "blue"; anchors.fill: parent } } |