void tst_QFormLayout::addRow() { QFormLayout layout; QWidget w1, w2, w3; QHBoxLayout l1, l2, l3; QLabel lbl1, lbl2; 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); 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::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); }
void tst_QFormLayout::insertRow_QString_QLayout() { QFormLayout layout; QHBoxLayout fld1, fld2, fld3; 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); 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); 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); }
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); }
void tst_QFormLayout::rowCount() { QWidget *w = new QWidget; QFormLayout *fl = new QFormLayout(w); fl->addRow(tr("Label 1"), new QLineEdit); fl->addRow(tr("Label 2"), new QLineEdit); fl->addRow(tr("Label 3"), new QLineEdit); QCOMPARE(fl->rowCount(), 3); fl->addRow(new QWidget); fl->addRow(new QHBoxLayout); QCOMPARE(fl->rowCount(), 5); fl->insertRow(1, tr("Label 0.5"), new QLineEdit); QCOMPARE(fl->rowCount(), 6); //TODO: remove items delete w; }
QmitkFileReaderWriterOptionsWidget::Options QmitkFileReaderWriterOptionsWidget::GetOptions() const { Options options; QFormLayout* layout = qobject_cast<QFormLayout*>(this->layout()); const int rows = layout->rowCount(); for(int i = 0; i < rows; ++i) { QmitkAnyAdapter* anyAdapter = dynamic_cast<QmitkAnyAdapter*>(layout->itemAt(i, QFormLayout::FieldRole)->widget()); if (anyAdapter) { options.insert(std::make_pair(anyAdapter->GetName(), anyAdapter->GetAny())); } } return options; }
dmz::V8Value dmz::JsModuleUiV8QtBasic::_form_layout_row_count (const v8::Arguments &Args) { v8::HandleScope scope; V8Value result = v8::Undefined (); JsModuleUiV8QtBasic *self = _to_self (Args); if (self) { QWidget *widget = self->_to_qwidget (Args[0]); if (widget) { QFormLayout *layout = new QFormLayout (widget); if (layout) { result = v8::Number::New (layout->rowCount ()); } } } return scope.Close (result); }
void DonationWizard::previewImport() { tableWidget->clear(); if (tableWidget->columnCount() < 5) { tableWidget->setColumnCount(5); } tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem()); tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem()); tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem()); tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem()); tableWidget->setHorizontalHeaderItem(4, new QTableWidgetItem()); tableWidget->horizontalHeaderItem(0)->setText(QApplication::translate("DonationImportForm", "Member", 0, QApplication::UnicodeUTF8)); tableWidget->horizontalHeaderItem(1)->setText(QApplication::translate("DonationImportForm", "Name, Surname", 0, QApplication::UnicodeUTF8)); tableWidget->horizontalHeaderItem(2)->setText(QApplication::translate("DonationImportForm", "UID", 0, QApplication::UnicodeUTF8)); tableWidget->horizontalHeaderItem(3)->setText(QApplication::translate("DonationImportForm", "Amount", 0, QApplication::UnicodeUTF8)); tableWidget->horizontalHeaderItem(4)->setText(QApplication::translate("DonationImportForm", "Section", 0, QApplication::UnicodeUTF8)); QLocale locale; QHash<QString, QString> sectionMapping; qint32 pos = 0; QFormLayout *layout = (QFormLayout *) importMapSections->layout(); QLabel *label; QComboBox *box; while (pos < layout->rowCount()) { label = (QLabel *) layout->itemAt(pos, QFormLayout::LabelRole)->widget(); box = (QComboBox *) layout->itemAt(pos, QFormLayout::FieldRole)->widget(); sectionMapping.insert(label->text(), box->itemData(box->currentIndex()).toString()); pos++; } PPSPerson person; qint32 sectionColum = importSectionColumn->value() - 1; qint32 column = importColumnMaster->value() - 1; qint32 amountColum = importAmountColumn->value() - 1; qint32 dbField = importColumnMemberfields->currentIndex(); QString uid, amount, section; for (int row = 0; row < tablePreviewImport->rowCount(); row++) { uid = tablePreviewImport->item(row, column)->text(); amount = tablePreviewImport->item(row, amountColum)->text(); section = tablePreviewImport->item(row, sectionColum)->text(); bool found(false); switch (dbField) { case 1: found = person.loadByPersonsFields(uid); break; case 2: found = person.loadByTelephone(uid); break; case 3: found = person.loadByEmail(uid); break; default: found = person.loadByAnyField(uid); } tableWidget->insertRow(row); if (found) { tableWidget->setItem(row, 0, new QTableWidgetItem(person.uid())); tableWidget->setItem(row, 1, new QTableWidgetItem(person.givenName() + " " + person.familyName())); } else { tableWidget->setItem(row, 0, new QTableWidgetItem("")); tableWidget->setItem(row, 1, new QTableWidgetItem("")); } tableWidget->setItem(row, 2, new QTableWidgetItem(uid)); tableWidget->setItem(row, 3, new QTableWidgetItem(locale.toString(amount.toFloat()))); tableWidget->setItem(row, 4, new QTableWidgetItem(sectionMapping.value(section))); } }
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); } }
void tst_QFormLayout::setWidget() { QFormLayout layout; QWidget w1; QWidget w2; QWidget w3; QWidget w4; QCOMPARE(layout.count(), 0); QCOMPARE(layout.rowCount(), 0); layout.setWidget(5, QFormLayout::LabelRole, &w1); QCOMPARE(layout.count(), 1); QCOMPARE(layout.rowCount(), 6); layout.setWidget(3, QFormLayout::FieldRole, &w2); layout.setWidget(3, QFormLayout::LabelRole, &w3); QCOMPARE(layout.count(), 3); QCOMPARE(layout.rowCount(), 6); // should be ignored and generate warnings layout.setWidget(3, QFormLayout::FieldRole, &w4); layout.setWidget(-1, QFormLayout::FieldRole, &w4); { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getWidgetPosition(&w1, &row, &role); QCOMPARE(row, 5); QCOMPARE(int(role), int(QFormLayout::LabelRole)); } { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getWidgetPosition(&w2, &row, &role); QCOMPARE(row, 3); QCOMPARE(int(role), int(QFormLayout::FieldRole)); } { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getWidgetPosition(&w3, &row, &role); QCOMPARE(row, 3); QCOMPARE(int(role), int(QFormLayout::LabelRole)); } { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getWidgetPosition(&w4, &row, &role); QCOMPARE(row, -1); QCOMPARE(int(role), -123); } { int row = -1; QFormLayout::ItemRole role = QFormLayout::ItemRole(-123); layout.getWidgetPosition(0, &row, &role); QCOMPARE(row, -1); QCOMPARE(int(role), -123); } }
QWidget* AutoImportWindow::setupStatusContinaer() { safeIntervalBox->setValue(ProjectPreferences().importSafeInterval()); connect(safeIntervalBox, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=] (int i){ ProjectPreferences().setImportSafeInterval(i); }); QHBoxLayout* buttonLayout = new QHBoxLayout(); buttonLayout->addStretch(0); buttonLayout->addWidget(importButton_, 0); buttonLayout->addWidget(refreshButton_, 0); buttonLayout->addStretch(1); QVBoxLayout* statusLayout = new QVBoxLayout; statusLayout->addWidget(statusLabel_, 0); statusLayout->addLayout(buttonLayout, 0); statusLayout->addWidget(deleteLabel_, 0); GroupContainer* statusContainer = new GroupContainer; statusContainer->setTitle("Current Status"); statusContainer->setContainerLayout(statusLayout); filePatternLabel_->setText(FileNameParserDialog::expectedFileNamePattern()); filePatternLabel_->setWordWrap(true); QPushButton* changeButton = new QPushButton("Change Pattern"); connect(changeButton, &QPushButton::clicked, [=]{ if(fileNameParser_->exec()) { filePatternLabel_->setText(FileNameParserDialog::expectedFileNamePattern()); } }); QHBoxLayout* fileNameParserLayout = new QHBoxLayout(); fileNameParserLayout->addStretch(0); fileNameParserLayout->addWidget(filePatternLabel_, 0); fileNameParserLayout->addWidget(changeButton, 0); fileNameParserLayout->addStretch(1); QHBoxLayout* timerLayout = new QHBoxLayout(); timerLayout->addStretch(0); timerLayout->addWidget(new QLabel("Number of seconds to wait before starting import of fresh (newly created) images"), 0); timerLayout->addWidget(safeIntervalBox, 0); timerLayout->addStretch(1); QFormLayout* optionsLayout = new QFormLayout(); optionsLayout->setRowWrapPolicy(QFormLayout::WrapAllRows); optionsLayout->addRow("Parameters to be deduced from file names: ", fileNameParserLayout); optionsLayout->addRow("Import delay time: ", timerLayout); //Make the labels bold for(int i=0; i< optionsLayout->rowCount(); ++i) { QLabel* label = static_cast<QLabel*>(optionsLayout->itemAt(i, QFormLayout::LabelRole)->widget()); QFont font = label->font(); font.setBold(true); label->setFont(font); } GroupContainer* optionsContainer = new GroupContainer; optionsContainer->setTitle("Import Options"); optionsContainer->setContainerLayout(optionsLayout); QHBoxLayout* resultsLayout = new QHBoxLayout(); resultsLayout->addWidget(resultsTable_, 1); GroupContainer* resultsContainer = new GroupContainer; resultsContainer->setTitle("Import Folder Details"); resultsContainer->setContainerLayout(resultsLayout); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setMargin(0); mainLayout->setSpacing(0); mainLayout->addWidget(statusContainer, 0); mainLayout->addWidget(optionsContainer, 0); mainLayout->addWidget(resultsContainer, 1); QWidget* mainWid = new QWidget(); mainWid->setLayout(mainLayout); return mainWid; }