void tst_QFormLayout::getPosition() { QWidget *w = new QWidget; QFormLayout *fl = new QFormLayout(w); QList<QLabel*> labels; QList<QLineEdit*> fields; for (int i = 0; i < 5; ++i) { labels.append(new QLabel(QString("Label %1").arg(i+1))); fields.append(new QLineEdit); fl->addRow(labels[i], fields[i]); } //a field { int row; QFormLayout::ItemRole role; fl->getWidgetPosition(fields[3], &row, &role); QCOMPARE(row, 3); QCOMPARE(role, QFormLayout::FieldRole); int old_row = row; QFormLayout::ItemRole old_role = role; fl->getItemPosition(3*2 + 1, &row, &role); QCOMPARE(row, old_row); QCOMPARE(role, old_role); } //a label { int row; QFormLayout::ItemRole role; fl->getWidgetPosition(labels[2], &row, &role); QCOMPARE(row, 2); QCOMPARE(role, QFormLayout::LabelRole); int old_row = row; QFormLayout::ItemRole old_role = role; fl->getItemPosition(2*2, &row, &role); QCOMPARE(row, old_row); QCOMPARE(role, old_role); } //a layout that's been inserted { QVBoxLayout *vbl = new QVBoxLayout; fl->insertRow(2, "Label 1.5", vbl); int row; QFormLayout::ItemRole role; fl->getLayoutPosition(vbl, &row, &role); QCOMPARE(row, 2); QCOMPARE(role, QFormLayout::FieldRole); int old_row = row; QFormLayout::ItemRole old_role = role; fl->getItemPosition(labels.count()*2 + 1, &row, &role); QCOMPARE(row, old_row); QCOMPARE(role, old_role); } delete w; }
QFormLayout::ItemRole getItemRole(const QFormLayout& layout, int index) { int row; QFormLayout::ItemRole role; layout.getItemPosition(index, &row, &role); return role; }