-----------------------------------------------------------------------------
| 506 | |
| 507 | //----------------------------------------------------------------------------- |
| 508 | void pqDisplayColorWidget::refreshColorArrayNames() |
| 509 | { |
| 510 | // Simply update the this->Variables combo-box with values from the domain. |
| 511 | // Try to preserve the current text if possible. |
| 512 | const QVariant current = |
| 513 | pqDisplayColorWidget::PropertyLinksConnection::convert(this->arraySelection()); |
| 514 | |
| 515 | const bool prev = this->Variables->blockSignals(true); |
| 516 | |
| 517 | this->Variables->clear(); |
| 518 | this->Internals->OutOfDomainEntryIndex = -1; |
| 519 | |
| 520 | // add solid color, but disable for some representations. |
| 521 | this->Variables->addItem(*this->SolidColorIcon, tr("Solid Color"), QVariant()); |
| 522 | if (this->Representation && this->Internals->NoSolidColor.contains(this->representationText())) |
| 523 | { |
| 524 | const auto model = qobject_cast<QStandardItemModel*>(this->Variables->model()); |
| 525 | QStandardItem* item = model->item(0); |
| 526 | item->setFlags(item->flags() & ~Qt::ItemIsEnabled); |
| 527 | } |
| 528 | |
| 529 | vtkSMArrayListDomain* domain = this->Internals->Domain; |
| 530 | assert(domain); |
| 531 | for (unsigned int cc = 0, max = domain->GetNumberOfStrings(); cc < max; cc++) |
| 532 | { |
| 533 | const int icon_association = domain->GetDomainAssociation(cc); |
| 534 | const int association = domain->GetFieldAssociation(cc); |
| 535 | const QString name = domain->GetString(cc); |
| 536 | const QString label = !domain->IsArrayPartial(cc) ? name : QString("%1 (partial)").arg(name); |
| 537 | const QIcon* icon = this->itemIcon(icon_association, name); |
| 538 | const QVariant idata = this->itemData(association, name); |
| 539 | const QString key = QString("%1.%2").arg(association).arg(name); |
| 540 | this->Variables->addItem(*icon, label, idata); |
| 541 | } |
| 542 | // doing this here, instead of in the constructor ensures that the |
| 543 | // popup menu shows reasonably on OsX. |
| 544 | this->Variables->setMaxVisibleItems(this->Variables->count() + 1); |
| 545 | |
| 546 | const int idx = this->Variables->findData(current); |
| 547 | if (idx > 0) |
| 548 | { |
| 549 | this->Variables->setCurrentIndex(idx); |
| 550 | } |
| 551 | else if (current.isValid()) |
| 552 | { |
| 553 | // The previous value set on the widget is no longer available in the |
| 554 | // "domain". This happens when the pipeline is modified, for example. In |
| 555 | // that case, the UI still needs to reflect the value. So we add it. |
| 556 | const QPair<int, QString> currentColoring = |
| 557 | pqDisplayColorWidget::PropertyLinksConnection::convert(current); |
| 558 | this->Variables->setCurrentIndex( |
| 559 | this->addOutOfDomainEntry(currentColoring.first, currentColoring.second)); |
| 560 | } |
| 561 | this->Variables->blockSignals(prev); |
| 562 | this->Variables->setEnabled(this->Variables->count() > 0); |
| 563 | |
| 564 | // since a change in domain could mean a change in components too, |
| 565 | // we should refresh those as well. |
no test coverage detected