mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Caf: Added the possibility of "nothing" selected in a field using option values
p4#: 21490
This commit is contained in:
parent
35759e081d
commit
d84d69ffc2
@ -142,7 +142,10 @@ QList<PdmOptionItemInfo> caf::PdmField<DataType>::valueOptions(bool* useOptionsO
|
|||||||
{
|
{
|
||||||
if (convertedFieldValue.type() != QVariant::List) // Single value field
|
if (convertedFieldValue.type() != QVariant::List) // Single value field
|
||||||
{
|
{
|
||||||
m_optionEntryCache.push_front(PdmOptionItemInfo(convertedFieldValue.toString(), convertedFieldValue, true, QIcon()));
|
if (!convertedFieldValue.toString().isEmpty())
|
||||||
|
{
|
||||||
|
m_optionEntryCache.push_front(PdmOptionItemInfo(convertedFieldValue.toString(), convertedFieldValue, true, QIcon()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // The field value is a list of values
|
else // The field value is a list of values
|
||||||
{
|
{
|
||||||
@ -155,7 +158,7 @@ QList<PdmOptionItemInfo> caf::PdmField<DataType>::valueOptions(bool* useOptionsO
|
|||||||
if (valuesSelectedInField[i] == m_optionEntryCache[opIdx].value) isFound = true;
|
if (valuesSelectedInField[i] == m_optionEntryCache[opIdx].value) isFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFound)
|
if (!isFound && !valuesSelectedInField[i].toString().isEmpty())
|
||||||
{
|
{
|
||||||
m_optionEntryCache.push_front(PdmOptionItemInfo(valuesSelectedInField[i].toString(), valuesSelectedInField[i], true, QIcon()));
|
m_optionEntryCache.push_front(PdmOptionItemInfo(valuesSelectedInField[i].toString(), valuesSelectedInField[i], true, QIcon()));
|
||||||
}
|
}
|
||||||
@ -176,7 +179,9 @@ QList<PdmOptionItemInfo> caf::PdmField<DataType>::valueOptions(bool* useOptionsO
|
|||||||
/// Extracts a QVariant representation of the data in the field to be used in the UI.
|
/// Extracts a QVariant representation of the data in the field to be used in the UI.
|
||||||
/// Note that for fields with a none empty valueOptions list the returned QVariant contains the
|
/// Note that for fields with a none empty valueOptions list the returned QVariant contains the
|
||||||
/// indexes to the selected options rather than the actual values, if they can be found.
|
/// indexes to the selected options rather than the actual values, if they can be found.
|
||||||
/// If we cant find them, the method asserts, forcing the valueOptions to always contain the field values
|
/// If this is a multivalue field, and we cant find all of the field values among the options,
|
||||||
|
/// the method asserts (For now), forcing the valueOptions to always contain the field values.
|
||||||
|
/// Single value fields will return -1 if the option is not found, allowing the concept of "nothing selected"
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
template<typename DataType >
|
template<typename DataType >
|
||||||
QVariant caf::PdmField<DataType>::uiValue() const
|
QVariant caf::PdmField<DataType>::uiValue() const
|
||||||
@ -184,16 +189,16 @@ QVariant caf::PdmField<DataType>::uiValue() const
|
|||||||
if (m_optionEntryCache.size())
|
if (m_optionEntryCache.size())
|
||||||
{
|
{
|
||||||
QVariant convertedFieldValue = PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
|
QVariant convertedFieldValue = PdmFieldTypeSpecialization<DataType>::convert(m_fieldValue);
|
||||||
std::vector<unsigned int> indexes;
|
std::vector<unsigned int> indexesToFoundOptions;
|
||||||
PdmOptionItemInfo::findValues(m_optionEntryCache, convertedFieldValue, indexes);
|
PdmOptionItemInfo::findValues(m_optionEntryCache, convertedFieldValue, indexesToFoundOptions);
|
||||||
if (convertedFieldValue.type() == QVariant::List)
|
if (convertedFieldValue.type() == QVariant::List)
|
||||||
{
|
{
|
||||||
if (indexes.size() == static_cast<size_t>(convertedFieldValue.toList().size()))
|
if (indexesToFoundOptions.size() == static_cast<size_t>(convertedFieldValue.toList().size()))
|
||||||
{
|
{
|
||||||
QList<QVariant> returnList;
|
QList<QVariant> returnList;
|
||||||
for(size_t i = 0; i < indexes.size(); ++i)
|
for(size_t i = 0; i < indexesToFoundOptions.size(); ++i)
|
||||||
{
|
{
|
||||||
returnList.push_back(QVariant(indexes[i]));
|
returnList.push_back(QVariant(indexesToFoundOptions[i]));
|
||||||
}
|
}
|
||||||
return QVariant(returnList);
|
return QVariant(returnList);
|
||||||
}
|
}
|
||||||
@ -201,7 +206,8 @@ QVariant caf::PdmField<DataType>::uiValue() const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (indexes.size() == 1) return QVariant(indexes.front());
|
if (indexesToFoundOptions.size() == 1) return QVariant(indexesToFoundOptions.front());
|
||||||
|
else return QVariant(-1); // Return -1 if not found instead of assert. Should result in clearing the selection
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -131,18 +131,26 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
QModelIndex currentItem = m_listView->selectionModel()->currentIndex();
|
QModelIndex currentItem = m_listView->selectionModel()->currentIndex();
|
||||||
QStringList texts = PdmOptionItemInfo::extractUiTexts(m_options);
|
QStringList texts = PdmOptionItemInfo::extractUiTexts(m_options);
|
||||||
strListModel->setStringList(texts);
|
strListModel->setStringList(texts);
|
||||||
|
|
||||||
QVariant fieldValue = field()->uiValue();
|
QVariant fieldValue = field()->uiValue();
|
||||||
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
|
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
|
||||||
{
|
{
|
||||||
int col = 0;
|
int col = 0;
|
||||||
int row = field()->uiValue().toInt();
|
int row = field()->uiValue().toInt();
|
||||||
|
|
||||||
QModelIndex mi = strListModel->index(row, col);
|
QModelIndex mi = strListModel->index(row, col);
|
||||||
|
|
||||||
m_listView->selectionModel()->blockSignals(true);
|
m_listView->selectionModel()->blockSignals(true);
|
||||||
m_listView->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_listView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
m_listView->selectionModel()->select(mi, QItemSelectionModel::SelectCurrent);
|
if (row >= 0 )
|
||||||
m_listView->selectionModel()->setCurrentIndex(mi, QItemSelectionModel::SelectCurrent);
|
{
|
||||||
|
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);
|
m_listView->selectionModel()->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user