void TimeAnalysisWidget::updateLegend() { std::vector<std::string> &labels = _selectedScalar->labels(); // removinb previous legend QFormLayout *layout = (QFormLayout *)_ui->legendGroupBox->layout(); QLayoutItem *child; while (layout->count()!=0 && (child = layout->takeAt(0)) != 0) { child->widget()->deleteLater(); delete child; } for (unsigned i=0; i<labels.size(); ++i) { QLabel *colorLabel = new QLabel; colorLabel->setAutoFillBackground(true); colorLabel->setMinimumSize(70, 15); QPalette palette = colorLabel->palette(); float denom = _selectedScalar->max() - _selectedScalar->min(); float normalizedValue = ( i - _selectedScalar->min() ) / ( denom == 0 ? 1.f : denom ); palette.setColor(colorLabel->backgroundRole(), _ui->projectionWidget->colorScale()->getColor(normalizedValue)); colorLabel->setPalette(palette); layout->addRow(new QLabel(labels[i].c_str()), colorLabel); } repaint(); }
void tst_QFormLayout::layoutAlone() { QWidget w; QFormLayout layout; layout.setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); w.setLayout(&layout); QLabel label("Here is a strange test case"); layout.setWidget(0, QFormLayout::LabelRole, &label); QHBoxLayout hlay; layout.setLayout(1, QFormLayout::LabelRole, &hlay); QCOMPARE(layout.count(), 2); w.show(); layout.activate(); QTest::qWait(500); }
void tst_QFormLayout::takeAt() { QFormLayout layout; QWidget w1; QWidget w2; QWidget w3; QWidget w4; QWidget w5; QHBoxLayout 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); for (int i = 6; i >= 0; --i) { layout.takeAt(0); QCOMPARE(layout.count(), i); } }
void tst_QFormLayout::itemAt() { QFormLayout layout; QWidget w1; QWidget w2; QWidget w3; QWidget w4; QWidget w5; QHBoxLayout 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); QBitArray scoreBoard(7); for (int i = 0; i < 7; ++i) { QLayoutItem *item = layout.itemAt(i); QVERIFY(item != 0); if (item->widget() == &w1) { scoreBoard[0] = true; } else if (item->widget() == &w2) { scoreBoard[1] = true; } else if (item->widget() == &w3) { scoreBoard[2] = true; } else if (item->widget() == &w4) { scoreBoard[3] = true; } else if (item->widget() == &w5) { scoreBoard[4] = true; } else if (item->layout() == &l6) { scoreBoard[5] = true; } else if (qobject_cast<QLabel *>(item->widget())) { scoreBoard[6] = true; } } QCOMPARE(scoreBoard.count(false), 0); }
void DonationWizard::createSectionMapping() { QFormLayout *layout = (QFormLayout *) importMapSections->layout(); QLayoutItem *item; while (layout->count() && (item = layout->takeAt(0)) != 0) { delete (item->widget()); delete item; } int i, idx; QMap<QString, QString>::iterator it; for (it = loadedSections.begin(); it != loadedSections.end(); it++) { QComboBox *b = new QComboBox; idx = -1; for (i = 0; i < sectionsList.size(); i++) { b->addItem(sectionsList[i], sectionsList[i]); if ( (idx < 0) && (it.key().indexOf(sectionsList[i], 0, Qt::CaseInsensitive) >= 0) ) { idx = i; } } b->setCurrentIndex(idx < 0 ? 0 : idx); layout->addRow(it.key(), b); } }
void VtkVisTabWidget::buildProportiesDialog(VtkVisPipelineItem* item) { QFormLayout* layout = static_cast<QFormLayout*>(this->scrollAreaWidgetContents->layout()); while(layout->count()) delete layout->takeAt(0)->widget(); QMap<QString, QVariant>* propMap = NULL; QMap<QString, QList<QVariant> >* propVecMap = NULL; VtkAlgorithmProperties* algProps = NULL; // Retrieve algorithm properties if (item->compositeFilter()) { algProps = item->compositeFilter(); propMap = item->compositeFilter()->GetAlgorithmUserProperties(); propVecMap = item->compositeFilter()->GetAlgorithmUserVectorProperties(); } else { algProps = dynamic_cast<VtkAlgorithmProperties*>(item->algorithm()); if (algProps) { propMap = algProps->GetAlgorithmUserProperties(); propVecMap = algProps->GetAlgorithmUserVectorProperties(); } } // Select appropriate GUI element and set connect for each property if (propMap && algProps) { QMapIterator<QString, QVariant> i(*propMap); while (i.hasNext()) { i.next(); QString key = i.key(); QVariant value = i.value(); VtkAlgorithmPropertyLineEdit* lineEdit; VtkAlgorithmPropertyCheckbox* checkbox; switch (value.type()) { case QVariant::Double: lineEdit = new VtkAlgorithmPropertyLineEdit(QString::number( value.toDouble()), key, QVariant::Double, algProps); connect(lineEdit, SIGNAL(editingFinished()), this, SIGNAL(requestViewUpdate())); layout->addRow(key, lineEdit); break; case QVariant::Int: lineEdit = new VtkAlgorithmPropertyLineEdit(QString::number( value.toInt()), key, QVariant::Int, algProps); connect(lineEdit, SIGNAL(editingFinished()), this, SIGNAL(requestViewUpdate())); layout->addRow(key, lineEdit); break; case QVariant::Bool: checkbox = new VtkAlgorithmPropertyCheckbox( value.toBool(), key, algProps); connect(checkbox, SIGNAL(stateChanged(int)), this, SIGNAL(requestViewUpdate())); layout->addRow(key, checkbox); break; default: break; } } }
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); } }
void tst_QFormLayout::insertRow_QWidget_QWidget() { QFormLayout layout; QLabel lbl1, lbl2, lbl3, lbl4; QLineEdit 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.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); 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(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(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::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); }