Caf: Added the possibility of "nothing" selected in a field using option values

p4#: 21490
This commit is contained in:
Jacob Støren
2013-04-30 11:04:51 +02:00
parent 35759e081d
commit d84d69ffc2
2 changed files with 26 additions and 12 deletions

View File

@@ -131,18 +131,26 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
QModelIndex currentItem = m_listView->selectionModel()->currentIndex();
QStringList texts = PdmOptionItemInfo::extractUiTexts(m_options);
strListModel->setStringList(texts);
QVariant fieldValue = field()->uiValue();
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
{
int col = 0;
int row = field()->uiValue().toInt();
QModelIndex mi = strListModel->index(row, col);
m_listView->selectionModel()->blockSignals(true);
m_listView->setSelectionMode(QAbstractItemView::SingleSelection);
m_listView->selectionModel()->select(mi, QItemSelectionModel::SelectCurrent);
m_listView->selectionModel()->setCurrentIndex(mi, QItemSelectionModel::SelectCurrent);
if (row >= 0 )
{
m_listView->selectionModel()->select(mi, QItemSelectionModel::SelectCurrent);
m_listView->selectionModel()->setCurrentIndex(mi, QItemSelectionModel::SelectCurrent);
}
else // A negative value (Undefined UInt ) is interpreted as no selection
{
m_listView->selectionModel()->clearSelection();
}
m_listView->selectionModel()->blockSignals(false);
}