mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-21 22:13:25 -06:00
#1830 AppFwk : Expand tree if item count has changed
This commit is contained in:
parent
aef886a26e
commit
3633474dc2
@ -58,7 +58,7 @@ public:
|
||||
{
|
||||
CAF_PDM_InitObject("Small Demo Object", ":/images/win/filenew.png", "This object is a demo of the CAF framework", "This object is a demo of the CAF framework");
|
||||
|
||||
CAF_PDM_InitField(&m_toggleField, "Toggle", false, "Toggle Field", "", "Toggle Field tooltip", " Toggle Field whatsthis");
|
||||
CAF_PDM_InitField(&m_toggleField, "Toggle", false, "Add Items To Multi Select", "", "Toggle Field tooltip", " Toggle Field whatsthis");
|
||||
CAF_PDM_InitField(&m_doubleField, "BigNumber", 0.0, "Big Number", "", "Enter a big number here", "This is a place you can enter a big real value if you want" );
|
||||
CAF_PDM_InitField(&m_intField, "IntNumber", 0, "Small Number", "", "Enter some small number here", "This is a place you can enter a small integer value if you want");
|
||||
CAF_PDM_InitField(&m_textField, "TextField", QString(""), "Text", "", "Text tooltip", "This is a place you can enter a small integer value if you want");
|
||||
@ -138,20 +138,7 @@ public:
|
||||
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;
|
||||
int additionalSubItems = 2;
|
||||
for (auto i = 0; i < additionalSubItems; i++)
|
||||
{
|
||||
text = "Second_b_" + QString::number(i);
|
||||
@ -160,7 +147,18 @@ public:
|
||||
options.push_back(itemInfo);
|
||||
}
|
||||
|
||||
|
||||
static int s_additionalSubItems = 0;
|
||||
if (m_toggleField())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
text = "Third";
|
||||
options.push_back(caf::PdmOptionItemInfo(text, text));
|
||||
|
@ -87,9 +87,17 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
caf::PdmUiTreeSelectionQModel* treeSelectionQModel = dynamic_cast<caf::PdmUiTreeSelectionQModel*>(m_treeView->model());
|
||||
if (treeSelectionQModel)
|
||||
{
|
||||
bool itemCountHasChaged = false;
|
||||
if (treeSelectionQModel->optionItemCount() != options.size()) itemCountHasChaged = true;
|
||||
|
||||
// TODO: If the count is different between incoming and current list of items,
|
||||
// use cafQTreeViewStateSerializer to restore collapsed state
|
||||
treeSelectionQModel->setOptions(this, options);
|
||||
|
||||
if (itemCountHasChaged)
|
||||
{
|
||||
m_treeView->expandAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,10 @@ 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())
|
||||
bool itemCountHasChanged = false;
|
||||
if (optionItemCount() != options.size())
|
||||
{
|
||||
itemCountIsChanged = true;
|
||||
itemCountHasChanged = true;
|
||||
}
|
||||
|
||||
m_uiFieldHandle = field;
|
||||
@ -69,12 +69,20 @@ void caf::PdmUiTreeSelectionQModel::setOptions(caf::PdmUiFieldEditorHandle* fiel
|
||||
|
||||
computeOptionItemTreeData();
|
||||
|
||||
if (itemCountIsChanged)
|
||||
if (itemCountHasChanged)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int caf::PdmUiTreeSelectionQModel::optionItemCount() const
|
||||
{
|
||||
return m_options.size();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -198,8 +206,6 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
|
||||
|
||||
emit signalSelectionStateForIndexHasChanged(toOptionItemIndex(index), isSelected);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
|
||||
void setOptions(caf::PdmUiFieldEditorHandle* field, const QList<caf::PdmOptionItemInfo>& options);
|
||||
|
||||
int optionItemCount() const;
|
||||
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
Loading…
Reference in New Issue
Block a user