summaryrefslogtreecommitdiffstats
path: root/tools/designer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-09-23 11:36:50 (GMT)
committerQt Commercial Integration <QtCommercial@digia.com>2012-01-31 10:25:05 (GMT)
commitc711e9c066ec3c05619463dc398e31ab70d8c591 (patch)
tree8247de212c0a3449c0d4b01df535e78c594f8deb /tools/designer
parentd9d5ad2302a4a9add88bf4e4108e27ab342c81fa (diff)
downloadQt-c711e9c066ec3c05619463dc398e31ab70d8c591.zip
Qt-c711e9c066ec3c05619463dc398e31ab70d8c591.tar.gz
Qt-c711e9c066ec3c05619463dc398e31ab70d8c591.tar.bz2
Designer/QFormBuilder::save(): Fix traversal of QGridLayout/QFormLayout
Remove redundant code in qdesigner_resource ass well. Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com> Task-number: QTBUG-13683
Diffstat (limited to 'tools/designer')
-rw-r--r--tools/designer/src/components/formeditor/qdesigner_resource.cpp28
-rw-r--r--tools/designer/src/lib/uilib/abstractformbuilder.cpp123
2 files changed, 95 insertions, 56 deletions
diff --git a/tools/designer/src/components/formeditor/qdesigner_resource.cpp b/tools/designer/src/components/formeditor/qdesigner_resource.cpp
index 3f5fbdc..8f958f1 100644
--- a/tools/designer/src/components/formeditor/qdesigner_resource.cpp
+++ b/tools/designer/src/components/formeditor/qdesigner_resource.cpp
@@ -1377,34 +1377,6 @@ DomLayoutItem *QDesignerResource::createDom(QLayoutItem *item, DomLayout *ui_lay
} else {
return 0;
}
-
- if (m_chain.size() && item->widget()) {
- if (QGridLayout *grid = qobject_cast<QGridLayout*>(m_chain.top())) {
- const int index = Utils::indexOfWidget(grid, item->widget());
-
- int row, column, rowspan, colspan;
- grid->getItemPosition(index, &row, &column, &rowspan, &colspan);
- ui_item->setAttributeRow(row);
- ui_item->setAttributeColumn(column);
-
- if (colspan != 1)
- ui_item->setAttributeColSpan(colspan);
-
- if (rowspan != 1)
- ui_item->setAttributeRowSpan(rowspan);
- } else {
- if (QFormLayout *form = qobject_cast<QFormLayout*>(m_chain.top())) {
- const int index = Utils::indexOfWidget(form, item->widget());
- int row, column, colspan;
- getFormLayoutItemPosition(form, index, &row, &column, 0, &colspan);
- ui_item->setAttributeRow(row);
- ui_item->setAttributeColumn(column);
- if (colspan != 1)
- ui_item->setAttributeColSpan(colspan);
- }
- }
- }
-
return ui_item;
}
diff --git a/tools/designer/src/lib/uilib/abstractformbuilder.cpp b/tools/designer/src/lib/uilib/abstractformbuilder.cpp
index 7e4bf38..eeb82fc 100644
--- a/tools/designer/src/lib/uilib/abstractformbuilder.cpp
+++ b/tools/designer/src/lib/uilib/abstractformbuilder.cpp
@@ -1381,9 +1381,83 @@ DomActionRef *QAbstractFormBuilder::createActionRefDom(QAction *action)
return ui_action_ref;
}
+// Struct to store layout item parameters for saving layout items
+struct FormBuilderSaveLayoutEntry {
+ explicit FormBuilderSaveLayoutEntry(QLayoutItem *li = 0) :
+ item(li), row(-1), column(-1), rowSpan(0), columnSpan(0) {}
+
+ QLayoutItem *item;
+ int row;
+ int column;
+ int rowSpan;
+ int columnSpan;
+};
+
+// Create list from standard box layout
+static QList<FormBuilderSaveLayoutEntry> saveLayoutEntries(const QLayout *layout)
+{
+ QList<FormBuilderSaveLayoutEntry> rc;
+ if (const int count = layout->count()) {
+ rc.reserve(count);
+ for (int idx = 0; idx < count; ++idx) {
+ QLayoutItem *item = layout->itemAt(idx);
+ rc.append(FormBuilderSaveLayoutEntry(item));
+ }
+ }
+ return rc;
+}
+
+// Create list from grid layout
+static QList<FormBuilderSaveLayoutEntry> saveGridLayoutEntries(QGridLayout *gridLayout)
+{
+ QList<FormBuilderSaveLayoutEntry> rc;
+ if (const int count = gridLayout->count()) {
+ rc.reserve(count);
+ for (int idx = 0; idx < count; ++idx) {
+ QLayoutItem *item = gridLayout->itemAt(idx);
+ FormBuilderSaveLayoutEntry entry(item);
+ gridLayout->getItemPosition(idx, &entry.row, &entry.column, &entry.rowSpan,&entry.columnSpan);
+ rc.append(entry);
+ }
+ }
+ return rc;
+}
+
+#ifndef QT_NO_FORMLAYOUT
+// Create list from form layout
+static QList<FormBuilderSaveLayoutEntry> saveFormLayoutEntries(const QFormLayout *formLayout)
+{
+ QList<FormBuilderSaveLayoutEntry> rc;
+ if (const int count = formLayout->count()) {
+ rc.reserve(count);
+ for (int idx = 0; idx < count; ++idx) {
+ QLayoutItem *item = formLayout->itemAt(idx);
+ QFormLayout::ItemRole role = QFormLayout::LabelRole;
+ FormBuilderSaveLayoutEntry entry(item);
+ formLayout->getItemPosition(idx, &entry.row, &role);
+ switch (role ) {
+ case QFormLayout::LabelRole:
+ entry.column = 0;
+ break;
+ case QFormLayout::FieldRole:
+ entry.column = 1;
+ break;
+ case QFormLayout::SpanningRole:
+ entry.column = 0;
+ entry.columnSpan = 2;
+ break;
+ }
+ rc.push_back(entry);
+ }
+ }
+ return rc;
+}
+#endif
+
/*!
\internal
*/
+
DomLayout *QAbstractFormBuilder::createDom(QLayout *layout, DomLayout *ui_layout, DomWidget *ui_parentWidget)
{
Q_UNUSED(ui_layout)
@@ -1394,37 +1468,30 @@ DomLayout *QAbstractFormBuilder::createDom(QLayout *layout, DomLayout *ui_layout
lay->setAttributeName(objectName);
lay->setElementProperty(computeProperties(layout));
- QList<DomLayoutItem*> ui_items;
-
- QMap<QObject *, QLayoutItem *> objectToItem;
- QList<QLayoutItem *> spacerItems;
- QList<QLayoutItem *> newList;
-
- for (int idx=0; layout->itemAt(idx); ++idx) {
- QLayoutItem *item = layout->itemAt(idx);
- if (item->widget())
- objectToItem[item->widget()] = item;
- else if (item->layout())
- objectToItem[item->layout()] = item;
- else if (item->spacerItem())
- spacerItems.append(item);
- newList.append(item);
- }
-
- if (qobject_cast<QGridLayout *>(layout)) {
- newList.clear();
- QList<QObject *> childrenList = layout->parentWidget()->children();
- foreach (QObject *o, childrenList) {
- if (objectToItem.contains(o))
- newList.append(objectToItem[o]);
- }
- newList += spacerItems;
+ QList<FormBuilderSaveLayoutEntry> newList;
+ if (QGridLayout *gridLayout = qobject_cast<QGridLayout *>(layout)) {
+ newList = saveGridLayoutEntries(gridLayout);
+#ifndef QT_NO_FORMLAYOUT
+ } else if (const QFormLayout *formLayout = qobject_cast<const QFormLayout *>(layout)) {
+ newList = saveFormLayoutEntries(formLayout);
+#endif
+ } else {
+ newList = saveLayoutEntries(layout);
}
- foreach (QLayoutItem *item, newList) {
- DomLayoutItem *ui_item = createDom(item, lay, ui_parentWidget);
- if (ui_item)
+ QList<DomLayoutItem*> ui_items;
+ foreach (const FormBuilderSaveLayoutEntry &item, newList) {
+ if (DomLayoutItem *ui_item = createDom(item.item, lay, ui_parentWidget)) {
+ if (item.row >= 0)
+ ui_item->setAttributeRow(item.row);
+ if (item.column >= 0)
+ ui_item->setAttributeColumn(item.column);
+ if (item.rowSpan > 1)
+ ui_item->setAttributeRowSpan(item.rowSpan);
+ if (item.columnSpan > 1)
+ ui_item->setAttributeColSpan(item.columnSpan);
ui_items.append(ui_item);
+ }
}
lay->setElementItem(ui_items);