Don't store the alignment attribute for spacers
authorJarek Kobus <jkobus@trolltech.com>
Fri, 23 Sep 2011 10:19:02 +0000 (12:19 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Sep 2011 18:42:34 +0000 (20:42 +0200)
And for QLayoutWidget as it is not allowed and will create
a code which doesn't compile

Reviewed-by: con <qtc-committer@nokia.com>
Task-number: QTBUG-21575

(cherry-picked from commit a6f87c60ed135c8f92a0de846dba5734fa7cf6c6)

Change-Id: Ifb0afe488a028565ca1ff4a7e8b2150b4ef1d4c8
Reviewed-on: http://codereview.qt-project.org/5556
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
src/designer/src/lib/uilib/abstractformbuilder.cpp

index da64a5e..d5f656d 100644 (file)
@@ -1463,6 +1463,8 @@ struct FormBuilderSaveLayoutEntry {
     explicit FormBuilderSaveLayoutEntry(QLayoutItem *li = 0) :
         item(li), row(-1), column(-1), rowSpan(0), columnSpan(0), alignment(0) {}
 
+    void setAlignment(Qt::Alignment al);
+
     QLayoutItem *item;
     int row;
     int column;
@@ -1471,6 +1473,20 @@ struct FormBuilderSaveLayoutEntry {
     Qt::Alignment alignment;
 };
 
+// filter out the case of "Spacer" and "QLayoutWidget" widgets
+void FormBuilderSaveLayoutEntry::setAlignment(Qt::Alignment al)
+{
+    if (!item->widget())
+        return;
+
+    const QString className = item->widget()->metaObject()->className();
+    if (className == QLatin1String("Spacer")
+            || className == QLatin1String("QLayoutWidget"))
+        return;
+
+    alignment = al;
+}
+
 // Create list from standard box layout
 static QList<FormBuilderSaveLayoutEntry> saveLayoutEntries(const QLayout *layout)
 {
@@ -1480,7 +1496,7 @@ static QList<FormBuilderSaveLayoutEntry> saveLayoutEntries(const QLayout *layout
         for (int idx = 0; idx < count; ++idx) {
             QLayoutItem *item = layout->itemAt(idx);
             FormBuilderSaveLayoutEntry entry(item);
-            entry.alignment = item->alignment();
+            entry.setAlignment(item->alignment());
             rc.append(entry);
         }
     }
@@ -1497,7 +1513,7 @@ static QList<FormBuilderSaveLayoutEntry> saveGridLayoutEntries(QGridLayout *grid
             QLayoutItem *item = gridLayout->itemAt(idx);
             FormBuilderSaveLayoutEntry entry(item);
             gridLayout->getItemPosition(idx, &entry.row, &entry.column, &entry.rowSpan,&entry.columnSpan);
-            entry.alignment = item->alignment();
+            entry.setAlignment(item->alignment());
             rc.append(entry);
         }
     }