mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2112 Step two of performance fixing: Avoid unneccessary calls to uiValue from the treeSelectionQMode by caching it temporarily
This commit is contained in:
parent
6ee03340a5
commit
9070a97815
@ -175,17 +175,19 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
|
||||
bool itemCountHasChaged = false;
|
||||
if (m_model->optionItemCount() != options.size()) itemCountHasChaged = true;
|
||||
|
||||
QVariant fieldValue = field()->uiValue();
|
||||
m_model->setUiValueCache(&fieldValue);
|
||||
|
||||
// TODO: If the count is different between incoming and current list of items,
|
||||
// use cafQTreeViewStateSerializer to restore collapsed state
|
||||
m_model->setOptions(this, options);
|
||||
|
||||
|
||||
if (itemCountHasChaged)
|
||||
{
|
||||
m_treeView->expandAll();
|
||||
}
|
||||
|
||||
QVariant fieldValue = field()->uiValue();
|
||||
if (PdmUiTreeSelectionQModel::isSingleValueField(fieldValue))
|
||||
{
|
||||
m_textFilterLineEdit->hide();
|
||||
@ -251,6 +253,8 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_model->resetUiValueCache();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -50,7 +50,9 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmUiTreeSelectionQModel::PdmUiTreeSelectionQModel(QObject *parent /*= 0*/) : QAbstractItemModel(parent)
|
||||
caf::PdmUiTreeSelectionQModel::PdmUiTreeSelectionQModel(QObject *parent /*= 0*/)
|
||||
: QAbstractItemModel(parent),
|
||||
m_uiValueCache(nullptr)
|
||||
{
|
||||
m_uiFieldHandle = nullptr;
|
||||
m_tree = nullptr;
|
||||
@ -148,7 +150,7 @@ int caf::PdmUiTreeSelectionQModel::optionItemCount() const
|
||||
void caf::PdmUiTreeSelectionQModel::setOptions(caf::PdmUiFieldEditorHandle* field, const QList<caf::PdmOptionItemInfo>& options)
|
||||
{
|
||||
m_uiFieldHandle = field;
|
||||
|
||||
|
||||
if (m_options.size() != options.size())
|
||||
{
|
||||
beginResetModel();
|
||||
@ -307,7 +309,9 @@ QVariant caf::PdmUiTreeSelectionQModel::data(const QModelIndex &index, int role
|
||||
{
|
||||
if (m_uiFieldHandle && m_uiFieldHandle->field())
|
||||
{
|
||||
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
||||
// Avoid calling the seriously heavy uiValue method if we have a temporary valid cache.
|
||||
|
||||
QVariant fieldValue = m_uiValueCache ? *m_uiValueCache : m_uiFieldHandle->field()->uiValue();
|
||||
if (isSingleValueField(fieldValue))
|
||||
{
|
||||
int row = fieldValue.toInt();
|
||||
@ -387,7 +391,6 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
|
||||
|
||||
if (!m_singleSelectionMode)
|
||||
{
|
||||
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
||||
QList<QVariant> fieldValueSelection = fieldValue.toList();
|
||||
|
||||
for (auto v : fieldValueSelection)
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
|
||||
int optionItemCount() const;
|
||||
void setOptions(caf::PdmUiFieldEditorHandle* field, const QList<caf::PdmOptionItemInfo>& options);
|
||||
void setUiValueCache(const QVariant* uiValuesCache ) {m_uiValueCache = uiValuesCache; }
|
||||
void resetUiValueCache() { m_uiValueCache = nullptr; }
|
||||
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
@ -96,6 +98,8 @@ private:
|
||||
QList<caf::PdmOptionItemInfo> m_options;
|
||||
caf::PdmUiFieldEditorHandle* m_uiFieldHandle;
|
||||
|
||||
const QVariant* m_uiValueCache;
|
||||
|
||||
TreeItemType* m_tree;
|
||||
|
||||
bool m_singleSelectionMode;
|
||||
|
Loading…
Reference in New Issue
Block a user