Esempio n. 1
0
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;
}
Esempio n. 2
0
void tst_QFormLayout::insertRow_QWidget_QLayout()
{
    QFormLayout layout;
    QLabel lbl1, lbl2, lbl3, lbl4;
    QHBoxLayout fld1, fld2, fld3, fld4;

    layout.insertRow(0, &lbl1, &fld1);
    QCOMPARE(layout.rowCount(), 1);

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getWidgetPosition(&lbl1, &row, &role);
        QCOMPARE(row, 0);
        QCOMPARE(int(role), int(QFormLayout::LabelRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        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);

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

    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);
}
Esempio n. 3
0
void tst_QFormLayout::setLayout()
{
    QFormLayout layout;

    QHBoxLayout l1;
    QHBoxLayout l2;
    QHBoxLayout l3;
    QHBoxLayout l4;

    QCOMPARE(layout.count(), 0);
    QCOMPARE(layout.rowCount(), 0);

    layout.setLayout(5, QFormLayout::LabelRole, &l1);
    QCOMPARE(layout.count(), 1);
    QCOMPARE(layout.rowCount(), 6);

    layout.setLayout(3, QFormLayout::FieldRole, &l2);
    layout.setLayout(3, QFormLayout::LabelRole, &l3);
    QCOMPARE(layout.count(), 3);
    QCOMPARE(layout.rowCount(), 6);

    // should be ignored and generate warnings
    layout.setLayout(3, QFormLayout::FieldRole, &l4);
    layout.setLayout(-1, QFormLayout::FieldRole, &l4);
    QCOMPARE(layout.count(), 3);
    QCOMPARE(layout.rowCount(), 6);

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l1, &row, &role);
        QCOMPARE(row, 5);
        QCOMPARE(int(role), int(QFormLayout::LabelRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l2, &row, &role);
        QCOMPARE(row, 3);
        QCOMPARE(int(role), int(QFormLayout::FieldRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l3, &row, &role);
        QCOMPARE(row, 3);
        QCOMPARE(int(role), int(QFormLayout::LabelRole));
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(&l4, &row, &role);
        QCOMPARE(row, -1);
        QCOMPARE(int(role), -123);
    }

    {
        int row = -1;
        QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
        layout.getLayoutPosition(0, &row, &role);
        QCOMPARE(row, -1);
        QCOMPARE(int(role), -123);
    }
}
Esempio n. 4
0
QFormLayout::ItemRole getLayoutRole(const QFormLayout& layout, QLayout* layout2) {
    int row;
    QFormLayout::ItemRole role;
    layout.getLayoutPosition(layout2, &row, &role);
    return role;
}