#1935 AppFwk : Update model indices when configureAndUpdateUI is called

This commit is contained in:
Magne Sjaastad 2017-09-26 15:09:27 +02:00
parent fa97db4465
commit e8d04618af
3 changed files with 37 additions and 11 deletions

View File

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

View File

@ -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);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

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