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