QScreen manual test improvements: fields resize, better formatting

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>
This commit is contained in:
Shawn Rutledge 2012-10-04 15:43:11 +02:00 committed by The Qt Project
parent 47881a7144
commit 78f946f6dc
4 changed files with 24 additions and 11 deletions

View 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");

View 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;
}

View 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);
}

View 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