#1830 AppFwk : Invalidate only relevant QModelIndex when selecting items

This commit is contained in:
Magne Sjaastad 2017-09-06 14:46:32 +02:00
parent d3a37aa1d8
commit 71db603e11
3 changed files with 79 additions and 37 deletions

View File

@ -114,38 +114,60 @@ public:
{
QList<caf::PdmOptionItemInfo> options;
QString text;
text = "First";
options.push_back(caf::PdmOptionItemInfo(text, text));
text = "Second";
options.push_back(caf::PdmOptionItemInfo(text, text));
if (fieldNeedingOptions == &m_multiSelectList)
{
text = "Second_a";
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
itemInfo.setLevel(1);
options.push_back(itemInfo);
QString text;
text = "First";
options.push_back(caf::PdmOptionItemInfo(text, text));
text = "Second";
options.push_back(caf::PdmOptionItemInfo(text, text));
{
text = "Second_a";
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
itemInfo.setLevel(1);
options.push_back(itemInfo);
}
{
text = "Second_b";
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
itemInfo.setLevel(1);
options.push_back(itemInfo);
}
static int s_additionalSubItems = 0;
s_additionalSubItems++;
for (auto i = 0; i < s_additionalSubItems; i++)
{
text = "Second_b_" + QString::number(i);
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
itemInfo.setLevel(1);
options.push_back(itemInfo);
}
int additionalSubItems = 0;
for (auto i = 0; i < additionalSubItems; i++)
{
text = "Second_b_" + QString::number(i);
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
itemInfo.setLevel(1);
options.push_back(itemInfo);
}
text = "Third";
options.push_back(caf::PdmOptionItemInfo(text, text));
text = "Fourth";
options.push_back(caf::PdmOptionItemInfo(text, text));
}
if (1)
{
text = "Second_b";
caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text);
itemInfo.setLevel(1);
options.push_back(itemInfo);
}
text = "Third";
options.push_back(caf::PdmOptionItemInfo(text, text));
text = "Fourth";
options.push_back(caf::PdmOptionItemInfo(text, text));
return options;
}

View File

@ -40,6 +40,8 @@
#include "cafPdmObject.h"
#include "cafPdmUiTreeSelectionQModel.h"
#include "cafQTreeViewStateSerializer.h"
#include <QTreeView>
#include <QLabel>
@ -75,15 +77,20 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
bool optionsOnly = true;
QList<PdmOptionItemInfo> options = field()->valueOptions(&optionsOnly);
caf::PdmUiTreeSelectionQModel* model = new caf::PdmUiTreeSelectionQModel(m_treeView);
m_treeView->setModel(model);
if (!m_treeView->model())
{
caf::PdmUiTreeSelectionQModel* model = new caf::PdmUiTreeSelectionQModel(m_treeView);
m_treeView->setModel(model);
connect(model, SIGNAL(signalSelectionStateForIndexHasChanged(int, bool)), this, SLOT(slotSetSelectionStateForIndex(int, bool)));
}
connect(model, SIGNAL(signalSelectionStateForIndexHasChanged(int, bool)), this, SLOT(slotSetSelectionStateForIndex(int, bool)));
model->setOptions(this, options);
// TODO: Try to merge expanded state with newly generated tree
//m_treeView->expandAll();
caf::PdmUiTreeSelectionQModel* treeSelectionQModel = dynamic_cast<caf::PdmUiTreeSelectionQModel*>(m_treeView->model());
if (treeSelectionQModel)
{
// TODO: If the count is different between incoming and current list of items,
// use cafQTreeViewStateSerializer to restore collapsed state
treeSelectionQModel->setOptions(this, options);
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -58,10 +58,21 @@ caf::PdmUiTreeSelectionQModel::PdmUiTreeSelectionQModel(QObject *parent /*= 0*/)
//--------------------------------------------------------------------------------------------------
void caf::PdmUiTreeSelectionQModel::setOptions(caf::PdmUiFieldEditorHandle* field, const QList<caf::PdmOptionItemInfo>& options)
{
bool itemCountIsChanged = false;
if (m_options.size() != options.size())
{
itemCountIsChanged = true;
}
m_uiFieldHandle = field;
m_options = options;
computeOptionItemTreeData();
if (itemCountIsChanged)
{
reset();
}
}
//--------------------------------------------------------------------------------------------------
@ -175,6 +186,8 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
emit signalSelectionStateForIndexHasChanged(toOptionItemIndex(index), isSelected);
emit dataChanged(index, index);
return true;
}