summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-09-23 11:36:50 (GMT)
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-09-23 11:36:50 (GMT)
commit0402309e1e3fc30e9d7f643e135aa9af26cca99b (patch)
treebe1db60caa5864ebd9a9d765128c2f9107c2a715
parent82b4fff07dc21382274bc92e480a9eff897dabf1 (diff)
downloadQt-0402309e1e3fc30e9d7f643e135aa9af26cca99b.zip
Qt-0402309e1e3fc30e9d7f643e135aa9af26cca99b.tar.gz
Qt-0402309e1e3fc30e9d7f643e135aa9af26cca99b.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
-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 a29bc1f..7fabf68 100644
--- a/tools/designer/src/components/formeditor/qdesigner_resource.cpp
+++ b/tools/designer/src/components/formeditor/qdesigner_resource.cpp
@@ -1381,34 +1381,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 ad2aa05..3f40d81 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);