QScreen manual test improvements: fields resize, better formatting
authorShawn Rutledge <shawn.rutledge@digia.com>
Thu, 4 Oct 2012 13:43:11 +0000 (15:43 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Oct 2012 15:31:31 +0000 (17:31 +0200)
It's necessary to set the fieldGrowthPolicy on the QFormLayout in order
to have expanding fields on the Mac.  Geometry formatting with
negative x and y values looks better.  Display fewer
decimal digits for double fields.

Change-Id: Icb252c0c3fb7b605253e04c3361beba124570840
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
tests/manual/qscreen/main.cpp
tests/manual/qscreen/propertyfield.cpp
tests/manual/qscreen/propertywatcher.cpp
tests/manual/qscreen/propertywatcher.h

index 4f7ff8c..460fdc3 100644 (file)
@@ -62,8 +62,8 @@ void updateSiblings(PropertyWatcher* w)
 void screenAdded(QScreen* screen)
 {
     screen->setOrientationUpdateMask((Qt::ScreenOrientations)0x0F);
-    qDebug("\nscreenAdded %s siblings %d first %s", qPrintable(screen->name()),
-        screen->virtualSiblings().count(), qPrintable(screen->virtualSiblings().first()->name()));
+    qDebug("\nscreenAdded %s siblings %d first %s", qPrintable(screen->name()), screen->virtualSiblings().count(),
+        (screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
     PropertyWatcher *w = new PropertyWatcher(screen, QString::number(i++));
     QLineEdit *siblingsField = new QLineEdit();
     siblingsField->setObjectName("siblings");
index 6ac63b3..c5e9442 100644 (file)
@@ -56,14 +56,26 @@ PropertyField::PropertyField(QObject* subject, const QMetaProperty& prop, QWidge
 
 QString PropertyField::valueToString(QVariant val)
 {
-    QString text = val.toString();
-    if (val.type() == QVariant::Size)
+    QString text;
+    switch (val.type()) {
+    case QVariant::Double:
+        text = QString("%1").arg(val.toReal(), 0, 'f', 4);
+        break;
+    case QVariant::Size:
         text = QString("%1 x %2").arg(val.toSize().width()).arg(val.toSize().height());
-    else if (val.type() == QVariant::SizeF)
+        break;
+    case QVariant::SizeF:
         text = QString("%1 x %2").arg(val.toSizeF().width()).arg(val.toSizeF().height());
-    else if (val.type() == QVariant::Rect)
-        text = QString("%1 x %2 +%3 +%4").arg(val.toRect().width())
-                .arg(val.toRect().height()).arg(val.toRect().x()).arg(val.toRect().y());
+        break;
+    case QVariant::Rect: {
+        QRect rect = val.toRect();
+        text = QString("%1 x %2 %3%4 %5%6").arg(rect.width())
+                .arg(rect.height()).arg(rect.x() < 0 ? "" : "+").arg(rect.x())
+                .arg(rect.y() < 0 ? "" : "+").arg(rect.y());
+        } break;
+    default:
+        text = val.toString();
+    }
     return text;
 }
 
index d342a94..ee037a0 100644 (file)
@@ -63,6 +63,7 @@ PropertyWatcher::PropertyWatcher(QObject *subject, QString annotation, QWidget *
     QPushButton *updateButton = new QPushButton("update");
     connect(updateButton, &QPushButton::clicked, this, &PropertyWatcher::updateAllFields);
     m_layout->addRow("", updateButton);
+    m_layout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
     setLayout(m_layout);
     connect(subject, &QObject::destroyed, this, &PropertyWatcher::subjectDestroyed);
 }
index c55776e..63c828f 100644 (file)
@@ -39,8 +39,8 @@
 **
 ****************************************************************************/
 
-#ifndef WIDGET_H
-#define WIDGET_H
+#ifndef PROPERTY_WATCHER_H
+#define PROPERTY_WATCHER_H
 
 #include <QWidget>
 
@@ -69,4 +69,4 @@ protected:
     QFormLayout * m_layout;
 };
 
-#endif // WIDGET_H
+#endif // PROPERTY_WATCHER_H