tst_formlayout: Fix top level widget leaks.
Instantiate widgets on stack and add cleanup function for the check. Change all functions instantiating a QFormLayout without widget on the stack to use a toplevel widget and pointer variables since otherwise, the labels automatically created by a call like QFormLayout::addRow("bla", widget) leak. Change-Id: I72a7a9c3175b5793a9450c6fcb970012ccd2274b Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
This commit is contained in:
parent
e849e2c162
commit
0d5744d740
@ -60,17 +60,8 @@ class tst_QFormLayout : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QFormLayout();
|
||||
~tst_QFormLayout();
|
||||
|
||||
public slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
private slots:
|
||||
void cleanup();
|
||||
void rowCount();
|
||||
void buddies();
|
||||
void getItemPosition();
|
||||
@ -132,34 +123,15 @@ private slots:
|
||||
|
||||
};
|
||||
|
||||
tst_QFormLayout::tst_QFormLayout()
|
||||
{
|
||||
}
|
||||
|
||||
tst_QFormLayout::~tst_QFormLayout()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QFormLayout::initTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QFormLayout::cleanupTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QFormLayout::init()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QFormLayout::cleanup()
|
||||
{
|
||||
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
||||
}
|
||||
|
||||
void tst_QFormLayout::rowCount()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
QFormLayout *fl = new QFormLayout(w);
|
||||
QWidget w;
|
||||
QFormLayout *fl = new QFormLayout(&w);
|
||||
|
||||
fl->addRow(tr("Label 1"), new QLineEdit);
|
||||
fl->addRow(tr("Label 2"), new QLineEdit);
|
||||
@ -174,14 +146,12 @@ void tst_QFormLayout::rowCount()
|
||||
QCOMPARE(fl->rowCount(), 6);
|
||||
|
||||
//TODO: remove items
|
||||
|
||||
delete w;
|
||||
}
|
||||
|
||||
void tst_QFormLayout::buddies()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
QFormLayout *fl = new QFormLayout(w);
|
||||
QWidget w;
|
||||
QFormLayout *fl = new QFormLayout(&w);
|
||||
|
||||
//normal buddy case
|
||||
QLineEdit *le = new QLineEdit;
|
||||
@ -204,14 +174,12 @@ void tst_QFormLayout::buddies()
|
||||
QVERIFY(label3 == 0);
|
||||
|
||||
//TODO: empty label?
|
||||
|
||||
delete w;
|
||||
}
|
||||
|
||||
void tst_QFormLayout::getItemPosition()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
QFormLayout *fl = new QFormLayout(w);
|
||||
QWidget w;
|
||||
QFormLayout *fl = new QFormLayout(&w);
|
||||
|
||||
QList<QLabel*> labels;
|
||||
QList<QLineEdit*> fields;
|
||||
@ -249,14 +217,12 @@ void tst_QFormLayout::getItemPosition()
|
||||
QCOMPARE(row, 2);
|
||||
QCOMPARE(role, QFormLayout::FieldRole);
|
||||
}
|
||||
|
||||
delete w;
|
||||
}
|
||||
|
||||
void tst_QFormLayout::wrapping()
|
||||
{
|
||||
QWidget *w = new QWidget;
|
||||
QFormLayout *fl = new QFormLayout(w);
|
||||
QWidget w;
|
||||
QFormLayout *fl = new QFormLayout(&w);
|
||||
fl->setRowWrapPolicy(QFormLayout::WrapLongRows);
|
||||
|
||||
QLineEdit *le = new QLineEdit;
|
||||
@ -264,14 +230,13 @@ void tst_QFormLayout::wrapping()
|
||||
le->setMinimumWidth(200);
|
||||
fl->addRow(lbl, le);
|
||||
|
||||
w->setFixedWidth(240);
|
||||
w->show();
|
||||
w.setFixedWidth(240);
|
||||
w.setWindowTitle(QTest::currentTestFunction());
|
||||
w.show();
|
||||
|
||||
QCOMPARE(le->geometry().y() > lbl->geometry().y(), true);
|
||||
|
||||
//TODO: additional tests covering different wrapping cases
|
||||
|
||||
delete w;
|
||||
}
|
||||
|
||||
class CustomLayoutStyle : public QProxyStyle
|
||||
@ -309,12 +274,12 @@ int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * opti
|
||||
void tst_QFormLayout::spacing()
|
||||
{
|
||||
//TODO: confirm spacing behavior
|
||||
QWidget *w = new QWidget;
|
||||
CustomLayoutStyle *style = new CustomLayoutStyle;
|
||||
QWidget w;
|
||||
QScopedPointer<CustomLayoutStyle> style(new CustomLayoutStyle);
|
||||
style->hspacing = 5;
|
||||
style->vspacing = 10;
|
||||
w->setStyle(style);
|
||||
QFormLayout *fl = new QFormLayout(w);
|
||||
w.setStyle(style.data());
|
||||
QFormLayout *fl = new QFormLayout(&w);
|
||||
QCOMPARE(style->hspacing, fl->horizontalSpacing());
|
||||
QCOMPARE(style->vspacing, fl->verticalSpacing());
|
||||
|
||||
@ -351,12 +316,10 @@ void tst_QFormLayout::spacing()
|
||||
QCheckBox *checkBox = new QCheckBox(tr("Yes"));
|
||||
fl->setWidget(0, QFormLayout::LabelRole, label);
|
||||
fl->setWidget(1, QFormLayout::FieldRole, checkBox);
|
||||
w->resize(200, 100);
|
||||
w->show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(w));
|
||||
|
||||
delete w;
|
||||
delete style;
|
||||
w.resize(200, 100);
|
||||
w.setWindowTitle(QTest::currentTestFunction());
|
||||
w.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&w));
|
||||
}
|
||||
|
||||
void tst_QFormLayout::contentsRect()
|
||||
@ -366,6 +329,7 @@ void tst_QFormLayout::contentsRect()
|
||||
QFormLayout form;
|
||||
w.setLayout(&form);
|
||||
form.addRow("Label", new QPushButton(&w));
|
||||
w.setWindowTitle(QTest::currentTestFunction());
|
||||
w.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&w));
|
||||
int l, t, r, b;
|
||||
@ -505,33 +469,39 @@ void tst_QFormLayout::setFormAlignment()
|
||||
|
||||
void tst_QFormLayout::addRow()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QWidget w1, w2, w3;
|
||||
QHBoxLayout l1, l2, l3;
|
||||
QLabel lbl1, lbl2;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
QWidget *w1 = new QWidget(&topLevel);
|
||||
QWidget *w2 = new QWidget(&topLevel);
|
||||
QWidget *w3 = new QWidget(&topLevel);
|
||||
QHBoxLayout *l1 = new QHBoxLayout;
|
||||
QHBoxLayout *l2 = new QHBoxLayout;
|
||||
QHBoxLayout *l3 = new QHBoxLayout;
|
||||
QLabel *lbl1 = new QLabel(&topLevel);
|
||||
QLabel *lbl2 = new QLabel(&topLevel);
|
||||
|
||||
QCOMPARE(layout.rowCount(), 0);
|
||||
QCOMPARE(layout->rowCount(), 0);
|
||||
|
||||
layout.addRow(&lbl1, &w1);
|
||||
layout.addRow(&lbl2, &l1);
|
||||
layout.addRow("Foo:", &w2);
|
||||
layout.addRow("Bar:", &l2);
|
||||
layout.addRow(&w3);
|
||||
layout.addRow(&l3);
|
||||
layout->addRow(lbl1, w1);
|
||||
layout->addRow(lbl2, l1);
|
||||
layout->addRow("Foo:", w2);
|
||||
layout->addRow("Bar:", l2);
|
||||
layout->addRow(w3);
|
||||
layout->addRow(l3);
|
||||
|
||||
QCOMPARE(layout.rowCount(), 6);
|
||||
QCOMPARE(layout->rowCount(), 6);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2);
|
||||
QVERIFY(layout.itemAt(2, QFormLayout::LabelRole)->widget()->property("text") == "Foo:");
|
||||
QVERIFY(layout.itemAt(3, QFormLayout::LabelRole)->widget()->property("text") == "Bar:");
|
||||
QVERIFY(layout.itemAt(4, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout.itemAt(5, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
|
||||
QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget()->property("text") == "Foo:");
|
||||
QVERIFY(layout->itemAt(3, QFormLayout::LabelRole)->widget()->property("text") == "Bar:");
|
||||
QVERIFY(layout->itemAt(4, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout->itemAt(5, QFormLayout::LabelRole) == 0);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::FieldRole)->widget() == &w1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::FieldRole)->layout() == &l1);
|
||||
QVERIFY(layout.itemAt(2, QFormLayout::FieldRole)->widget() == &w2);
|
||||
QVERIFY(layout.itemAt(3, QFormLayout::FieldRole)->layout() == &l2);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->widget() == w1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->layout() == l1);
|
||||
QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->widget() == w2);
|
||||
QVERIFY(layout->itemAt(3, QFormLayout::FieldRole)->layout() == l2);
|
||||
// ### should have a third role, FullRowRole?
|
||||
// QVERIFY(layout.itemAt(4, QFormLayout::FieldRole) == 0);
|
||||
// QVERIFY(layout.itemAt(5, QFormLayout::FieldRole) == 0);
|
||||
@ -539,17 +509,24 @@ void tst_QFormLayout::addRow()
|
||||
|
||||
void tst_QFormLayout::insertRow_QWidget_QWidget()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QLabel lbl1, lbl2, lbl3, lbl4;
|
||||
QLineEdit fld1, fld2, fld3, fld4;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
QLabel *lbl1 = new QLabel(&topLevel);
|
||||
QLabel *lbl2 = new QLabel(&topLevel);
|
||||
QLabel *lbl3 = new QLabel(&topLevel);
|
||||
QLabel *lbl4 = new QLabel(&topLevel);
|
||||
QLineEdit *fld1 = new QLineEdit(&topLevel);
|
||||
QLineEdit *fld2 = new QLineEdit(&topLevel);
|
||||
QLineEdit *fld3 = new QLineEdit(&topLevel);
|
||||
QLineEdit *fld4 = new QLineEdit(&topLevel);
|
||||
|
||||
layout.insertRow(0, &lbl1, &fld1);
|
||||
QCOMPARE(layout.rowCount(), 1);
|
||||
layout->insertRow(0, lbl1, fld1);
|
||||
QCOMPARE(layout->rowCount(), 1);
|
||||
|
||||
{
|
||||
int row = -1;
|
||||
QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
|
||||
layout.getWidgetPosition(&lbl1, &row, &role);
|
||||
layout->getWidgetPosition(lbl1, &row, &role);
|
||||
QCOMPARE(row, 0);
|
||||
QCOMPARE(int(role), int(QFormLayout::LabelRole));
|
||||
}
|
||||
@ -557,63 +534,68 @@ void tst_QFormLayout::insertRow_QWidget_QWidget()
|
||||
{
|
||||
int row = -1;
|
||||
QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
|
||||
layout.getWidgetPosition(&fld1, &row, &role);
|
||||
layout->getWidgetPosition(fld1, &row, &role);
|
||||
QCOMPARE(row, 0);
|
||||
QCOMPARE(int(role), int(QFormLayout::FieldRole));
|
||||
}
|
||||
|
||||
// check that negative values append
|
||||
layout.insertRow(-2, &lbl2, &fld2);
|
||||
QCOMPARE(layout.rowCount(), 2);
|
||||
layout->insertRow(-2, lbl2, fld2);
|
||||
QCOMPARE(layout->rowCount(), 2);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
|
||||
|
||||
// check that too large values append
|
||||
layout.insertRow(100, &lbl3, &fld3);
|
||||
QCOMPARE(layout.rowCount(), 3);
|
||||
QCOMPARE(layout.count(), 6);
|
||||
layout->insertRow(100, lbl3, fld3);
|
||||
QCOMPARE(layout->rowCount(), 3);
|
||||
QCOMPARE(layout->count(), 6);
|
||||
|
||||
layout.insertRow(3, (QWidget *)0, (QWidget *)0);
|
||||
QCOMPARE(layout.rowCount(), 4);
|
||||
QCOMPARE(layout.count(), 6);
|
||||
layout->insertRow(3, (QWidget *)0, (QWidget *)0);
|
||||
QCOMPARE(layout->rowCount(), 4);
|
||||
QCOMPARE(layout->count(), 6);
|
||||
|
||||
layout.insertRow(4, (QWidget *)0, &fld4);
|
||||
QCOMPARE(layout.rowCount(), 5);
|
||||
QCOMPARE(layout.count(), 7);
|
||||
layout->insertRow(4, (QWidget *)0, fld4);
|
||||
QCOMPARE(layout->rowCount(), 5);
|
||||
QCOMPARE(layout->count(), 7);
|
||||
|
||||
layout.insertRow(5, &lbl4, (QWidget *)0);
|
||||
QCOMPARE(layout.rowCount(), 6);
|
||||
QCOMPARE(layout.count(), 8);
|
||||
layout->insertRow(5, lbl4, (QWidget *)0);
|
||||
QCOMPARE(layout->rowCount(), 6);
|
||||
QCOMPARE(layout->count(), 8);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2);
|
||||
QVERIFY(layout.itemAt(2, QFormLayout::LabelRole)->widget() == &lbl3);
|
||||
QVERIFY(layout.itemAt(3, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout.itemAt(4, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout.itemAt(5, QFormLayout::LabelRole)->widget() == &lbl4);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
|
||||
QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget() == lbl3);
|
||||
QVERIFY(layout->itemAt(3, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout->itemAt(4, QFormLayout::LabelRole) == 0);
|
||||
QVERIFY(layout->itemAt(5, QFormLayout::LabelRole)->widget() == lbl4);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::FieldRole)->widget() == &fld1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::FieldRole)->widget() == &fld2);
|
||||
QVERIFY(layout.itemAt(2, QFormLayout::FieldRole)->widget() == &fld3);
|
||||
QVERIFY(layout.itemAt(3, QFormLayout::FieldRole) == 0);
|
||||
QVERIFY(layout.itemAt(4, QFormLayout::FieldRole)->widget() == &fld4);
|
||||
QVERIFY(layout.itemAt(5, QFormLayout::FieldRole) == 0);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->widget() == fld1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->widget() == fld2);
|
||||
QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->widget() == fld3);
|
||||
QVERIFY(layout->itemAt(3, QFormLayout::FieldRole) == 0);
|
||||
QVERIFY(layout->itemAt(4, QFormLayout::FieldRole)->widget() == fld4);
|
||||
QVERIFY(layout->itemAt(5, QFormLayout::FieldRole) == 0);
|
||||
}
|
||||
|
||||
void tst_QFormLayout::insertRow_QWidget_QLayout()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QLabel lbl1, lbl2, lbl3, lbl4;
|
||||
QHBoxLayout fld1, fld2, fld3, fld4;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
QLabel *lbl1 = new QLabel(&topLevel);
|
||||
QLabel *lbl2 = new QLabel(&topLevel);
|
||||
QLabel *lbl3 = new QLabel(&topLevel);
|
||||
QHBoxLayout *fld1 = new QHBoxLayout;
|
||||
QHBoxLayout *fld2 = new QHBoxLayout;
|
||||
QHBoxLayout *fld3 = new QHBoxLayout;
|
||||
|
||||
layout.insertRow(0, &lbl1, &fld1);
|
||||
QCOMPARE(layout.rowCount(), 1);
|
||||
layout->insertRow(0, lbl1, fld1);
|
||||
QCOMPARE(layout->rowCount(), 1);
|
||||
|
||||
{
|
||||
int row = -1;
|
||||
QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
|
||||
layout.getWidgetPosition(&lbl1, &row, &role);
|
||||
layout->getWidgetPosition(lbl1, &row, &role);
|
||||
QCOMPARE(row, 0);
|
||||
QCOMPARE(int(role), int(QFormLayout::LabelRole));
|
||||
}
|
||||
@ -621,77 +603,83 @@ void tst_QFormLayout::insertRow_QWidget_QLayout()
|
||||
{
|
||||
int row = -1;
|
||||
QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
|
||||
layout.getLayoutPosition(&fld1, &row, &role);
|
||||
layout->getLayoutPosition(fld1, &row, &role);
|
||||
QCOMPARE(row, 0);
|
||||
QCOMPARE(int(role), int(QFormLayout::FieldRole));
|
||||
}
|
||||
|
||||
// check that negative values append
|
||||
layout.insertRow(-2, &lbl2, &fld2);
|
||||
QCOMPARE(layout.rowCount(), 2);
|
||||
layout->insertRow(-2, lbl2, fld2);
|
||||
QCOMPARE(layout->rowCount(), 2);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
|
||||
|
||||
// check that too large values append
|
||||
layout.insertRow(100, &lbl3, &fld3);
|
||||
QCOMPARE(layout.rowCount(), 3);
|
||||
layout->insertRow(100, lbl3, fld3);
|
||||
QCOMPARE(layout->rowCount(), 3);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::LabelRole)->widget() == &lbl1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::LabelRole)->widget() == &lbl2);
|
||||
QVERIFY(layout.itemAt(2, QFormLayout::LabelRole)->widget() == &lbl3);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::LabelRole)->widget() == lbl1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::LabelRole)->widget() == lbl2);
|
||||
QVERIFY(layout->itemAt(2, QFormLayout::LabelRole)->widget() == lbl3);
|
||||
|
||||
QVERIFY(layout.itemAt(0, QFormLayout::FieldRole)->layout() == &fld1);
|
||||
QVERIFY(layout.itemAt(1, QFormLayout::FieldRole)->layout() == &fld2);
|
||||
QVERIFY(layout.itemAt(2, QFormLayout::FieldRole)->layout() == &fld3);
|
||||
QVERIFY(layout->itemAt(0, QFormLayout::FieldRole)->layout() == fld1);
|
||||
QVERIFY(layout->itemAt(1, QFormLayout::FieldRole)->layout() == fld2);
|
||||
QVERIFY(layout->itemAt(2, QFormLayout::FieldRole)->layout() == fld3);
|
||||
}
|
||||
|
||||
void tst_QFormLayout::insertRow_QString_QWidget()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QLineEdit fld1, fld2, fld3;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
QLineEdit *fld1 = new QLineEdit(&topLevel);
|
||||
QLineEdit *fld2 = new QLineEdit(&topLevel);
|
||||
QLineEdit *fld3 = new QLineEdit(&topLevel);
|
||||
|
||||
layout.insertRow(-5, "&Name:", &fld1);
|
||||
QLabel *label1 = qobject_cast<QLabel *>(layout.itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
layout->insertRow(-5, "&Name:", fld1);
|
||||
QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
QVERIFY(label1 != 0);
|
||||
QVERIFY(label1->buddy() == &fld1);
|
||||
QVERIFY(label1->buddy() == fld1);
|
||||
|
||||
layout.insertRow(0, "&Email:", &fld2);
|
||||
QLabel *label2 = qobject_cast<QLabel *>(layout.itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
layout->insertRow(0, "&Email:", fld2);
|
||||
QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
QVERIFY(label2 != 0);
|
||||
QVERIFY(label2->buddy() == &fld2);
|
||||
QVERIFY(label2->buddy() == fld2);
|
||||
|
||||
layout.insertRow(5, "&Age:", &fld3);
|
||||
QLabel *label3 = qobject_cast<QLabel *>(layout.itemAt(2, QFormLayout::LabelRole)->widget());
|
||||
layout->insertRow(5, "&Age:", fld3);
|
||||
QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
|
||||
QVERIFY(label3 != 0);
|
||||
QVERIFY(label3->buddy() == &fld3);
|
||||
QVERIFY(label3->buddy() == fld3);
|
||||
}
|
||||
|
||||
void tst_QFormLayout::insertRow_QString_QLayout()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QHBoxLayout fld1, fld2, fld3;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
QHBoxLayout *fld1 = new QHBoxLayout;
|
||||
QHBoxLayout *fld2 = new QHBoxLayout;
|
||||
QHBoxLayout *fld3 = new QHBoxLayout;
|
||||
|
||||
layout.insertRow(-5, "&Name:", &fld1);
|
||||
QLabel *label1 = qobject_cast<QLabel *>(layout.itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
layout->insertRow(-5, "&Name:", fld1);
|
||||
QLabel *label1 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
QVERIFY(label1 != 0);
|
||||
QVERIFY(label1->buddy() == 0);
|
||||
|
||||
QCOMPARE(layout.rowCount(), 1);
|
||||
QCOMPARE(layout->rowCount(), 1);
|
||||
|
||||
layout.insertRow(0, "&Email:", &fld2);
|
||||
QLabel *label2 = qobject_cast<QLabel *>(layout.itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
layout->insertRow(0, "&Email:", fld2);
|
||||
QLabel *label2 = qobject_cast<QLabel *>(layout->itemAt(0, QFormLayout::LabelRole)->widget());
|
||||
QVERIFY(label2 != 0);
|
||||
QVERIFY(label2->buddy() == 0);
|
||||
|
||||
QCOMPARE(layout.rowCount(), 2);
|
||||
QCOMPARE(layout->rowCount(), 2);
|
||||
|
||||
layout.insertRow(5, "&Age:", &fld3);
|
||||
QLabel *label3 = qobject_cast<QLabel *>(layout.itemAt(2, QFormLayout::LabelRole)->widget());
|
||||
layout->insertRow(5, "&Age:", fld3);
|
||||
QLabel *label3 = qobject_cast<QLabel *>(layout->itemAt(2, QFormLayout::LabelRole)->widget());
|
||||
QVERIFY(label3 != 0);
|
||||
QVERIFY(label3->buddy() == 0);
|
||||
|
||||
QCOMPARE(layout.rowCount(), 3);
|
||||
QCOMPARE(layout->rowCount(), 3);
|
||||
}
|
||||
|
||||
void tst_QFormLayout::insertRow_QWidget()
|
||||
@ -840,39 +828,40 @@ void tst_QFormLayout::setLayout()
|
||||
|
||||
void tst_QFormLayout::itemAt()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
|
||||
QWidget w1;
|
||||
QWidget w2;
|
||||
QWidget w3;
|
||||
QWidget w4;
|
||||
QWidget w5;
|
||||
QHBoxLayout l6;
|
||||
QWidget *w1 = new QWidget(&topLevel);
|
||||
QWidget *w2 = new QWidget(&topLevel);
|
||||
QWidget *w3 = new QWidget(&topLevel);
|
||||
QWidget *w4 = new QWidget(&topLevel);
|
||||
QWidget *w5 = new QWidget(&topLevel);
|
||||
QHBoxLayout *l6 = new QHBoxLayout;
|
||||
|
||||
layout.setWidget(5, QFormLayout::LabelRole, &w1);
|
||||
layout.setWidget(3, QFormLayout::FieldRole, &w2);
|
||||
layout.setWidget(3, QFormLayout::LabelRole, &w3);
|
||||
layout.addRow(&w4, &w5);
|
||||
layout.addRow("Foo:", &l6);
|
||||
layout->setWidget(5, QFormLayout::LabelRole, w1);
|
||||
layout->setWidget(3, QFormLayout::FieldRole, w2);
|
||||
layout->setWidget(3, QFormLayout::LabelRole, w3);
|
||||
layout->addRow(w4, w5);
|
||||
layout->addRow("Foo:", l6);
|
||||
|
||||
QCOMPARE(layout.count(), 7);
|
||||
QCOMPARE(layout->count(), 7);
|
||||
|
||||
QBitArray scoreBoard(7);
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
QLayoutItem *item = layout.itemAt(i);
|
||||
QLayoutItem *item = layout->itemAt(i);
|
||||
QVERIFY(item != 0);
|
||||
|
||||
if (item->widget() == &w1) {
|
||||
if (item->widget() == w1) {
|
||||
scoreBoard[0] = true;
|
||||
} else if (item->widget() == &w2) {
|
||||
} else if (item->widget() == w2) {
|
||||
scoreBoard[1] = true;
|
||||
} else if (item->widget() == &w3) {
|
||||
} else if (item->widget() == w3) {
|
||||
scoreBoard[2] = true;
|
||||
} else if (item->widget() == &w4) {
|
||||
} else if (item->widget() == w4) {
|
||||
scoreBoard[3] = true;
|
||||
} else if (item->widget() == &w5) {
|
||||
} else if (item->widget() == w5) {
|
||||
scoreBoard[4] = true;
|
||||
} else if (item->layout() == &l6) {
|
||||
} else if (item->layout() == l6) {
|
||||
scoreBoard[5] = true;
|
||||
} else if (qobject_cast<QLabel *>(item->widget())) {
|
||||
scoreBoard[6] = true;
|
||||
@ -883,26 +872,27 @@ void tst_QFormLayout::itemAt()
|
||||
|
||||
void tst_QFormLayout::takeAt()
|
||||
{
|
||||
QFormLayout layout;
|
||||
QWidget topLevel;
|
||||
QFormLayout *layout = new QFormLayout(&topLevel);
|
||||
|
||||
QWidget w1;
|
||||
QWidget w2;
|
||||
QWidget w3;
|
||||
QWidget w4;
|
||||
QWidget w5;
|
||||
QHBoxLayout l6;
|
||||
QWidget *w1 = new QWidget(&topLevel);
|
||||
QWidget *w2 = new QWidget(&topLevel);
|
||||
QWidget *w3 = new QWidget(&topLevel);
|
||||
QWidget *w4 = new QWidget(&topLevel);
|
||||
QWidget *w5 = new QWidget(&topLevel);
|
||||
QHBoxLayout *l6 = new QHBoxLayout;
|
||||
|
||||
layout.setWidget(5, QFormLayout::LabelRole, &w1);
|
||||
layout.setWidget(3, QFormLayout::FieldRole, &w2);
|
||||
layout.setWidget(3, QFormLayout::LabelRole, &w3);
|
||||
layout.addRow(&w4, &w5);
|
||||
layout.addRow("Foo:", &l6);
|
||||
layout->setWidget(5, QFormLayout::LabelRole, w1);
|
||||
layout->setWidget(3, QFormLayout::FieldRole, w2);
|
||||
layout->setWidget(3, QFormLayout::LabelRole, w3);
|
||||
layout->addRow(w4, w5);
|
||||
layout->addRow("Foo:", l6);
|
||||
|
||||
QCOMPARE(layout.count(), 7);
|
||||
QCOMPARE(layout->count(), 7);
|
||||
|
||||
for (int i = 6; i >= 0; --i) {
|
||||
layout.takeAt(0);
|
||||
QCOMPARE(layout.count(), i);
|
||||
layout->takeAt(0);
|
||||
QCOMPARE(layout->count(), i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -917,6 +907,7 @@ void tst_QFormLayout::layoutAlone()
|
||||
QHBoxLayout hlay;
|
||||
layout.setLayout(1, QFormLayout::LabelRole, &hlay);
|
||||
QCOMPARE(layout.count(), 2);
|
||||
w.setWindowTitle(QTest::currentTestFunction());
|
||||
w.show();
|
||||
layout.activate();
|
||||
QTest::qWait(500);
|
||||
|
Loading…
Reference in New Issue
Block a user