mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1935 AppFwk : Update model indices when configureAndUpdateUI is called
This commit is contained in:
parent
fa97db4465
commit
e8d04618af
@ -108,10 +108,11 @@ protected:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
|
||||
{
|
||||
QModelIndex index0 = sourceModel()->index(source_row, 0, source_parent);
|
||||
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||
|
||||
if (sourceModel()->hasChildren(index0))
|
||||
if (sourceModel()->hasChildren(index))
|
||||
{
|
||||
// Always include node if node has children
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -122,9 +122,7 @@ void caf::PdmUiTreeSelectionQModel::setCheckedStateForItems(const QModelIndexLis
|
||||
fieldValueSelection.push_back(QVariant(v));
|
||||
}
|
||||
|
||||
beginResetModel();
|
||||
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_uiFieldHandle->field(), fieldValueSelection);
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -159,6 +157,12 @@ void caf::PdmUiTreeSelectionQModel::setOptions(caf::PdmUiFieldEditorHandle* fiel
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Notify changed for all items in the model as UI can change even if the option item count is identical
|
||||
// It is possible to use beginResetModel and endResetModel, but this will also invalidate tree expand state
|
||||
notifyChangedForAllModelIndices();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -362,13 +366,8 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
|
||||
{
|
||||
if (value.toBool() == true)
|
||||
{
|
||||
// Reset model to make sure other check boxes are invalidated
|
||||
beginResetModel();
|
||||
|
||||
QVariant v = static_cast<unsigned int>(optionIndex(index));
|
||||
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_uiFieldHandle->field(), v);
|
||||
|
||||
endResetModel();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -419,8 +418,6 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
|
||||
|
||||
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_uiFieldHandle->field(), fieldValueSelection);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -461,6 +458,31 @@ void caf::PdmUiTreeSelectionQModel::buildOptionItemTree(int parentOptionIndex, T
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::PdmUiTreeSelectionQModel::notifyChangedForAllModelIndices()
|
||||
{
|
||||
recursiveNotifyChildren(QModelIndex());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void caf::PdmUiTreeSelectionQModel::recursiveNotifyChildren(const QModelIndex& index)
|
||||
{
|
||||
for (int r = 0; r < rowCount(index); r++)
|
||||
{
|
||||
QModelIndex mi = this->index(r, 0, index);
|
||||
recursiveNotifyChildren(mi);
|
||||
}
|
||||
|
||||
if (index.isValid())
|
||||
{
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -88,6 +88,9 @@ private:
|
||||
int optionIndex(const QModelIndex &index) const;
|
||||
void buildOptionItemTree(int optionIndex, TreeItemType* parentNode);
|
||||
|
||||
void notifyChangedForAllModelIndices();
|
||||
void recursiveNotifyChildren(const QModelIndex& index);
|
||||
|
||||
|
||||
private:
|
||||
QList<caf::PdmOptionItemInfo> m_options;
|
||||
|
Loading…
Reference in New Issue
Block a user