#1969 Curve Calculator : Support single select in tree selection editor

This commit is contained in:
Magne Sjaastad 2017-10-13 08:54:06 +02:00
parent 069d5ddf3b
commit d02274a897
5 changed files with 54 additions and 7 deletions

View File

@ -757,15 +757,17 @@ void RiuSummaryCurveDefSelection::buildAddressListForCategoryRecursively(RifEcli
//--------------------------------------------------------------------------------------------------
void RiuSummaryCurveDefSelection::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
if (&m_selectedSummaryCategories == field)
caf::PdmUiTreeSelectionEditorAttribute* attrib = dynamic_cast<caf::PdmUiTreeSelectionEditorAttribute*> (attribute);
if (attrib)
{
caf::PdmUiTreeSelectionEditorAttribute* attrib = dynamic_cast<caf::PdmUiTreeSelectionEditorAttribute*> (attribute);
if (attrib)
if (&m_selectedSummaryCategories == field)
{
attrib->fieldToReceiveCurrentItemValue = &m_currentSummaryCategory;
attrib->showTextFilter = false;
attrib->showToggleAllCheckbox = false;
}
attrib->singleSelectionMode = true;
}
}

View File

@ -193,8 +193,6 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
}
else if (PdmUiTreeSelectionQModel::isMultipleValueField(fieldValue))
{
m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_treeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(customMenuRequested(QPoint)));
@ -204,12 +202,27 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &m_attributes);
}
if (m_attributes.singleSelectionMode)
{
m_treeView->setSelectionMode(QAbstractItemView::SingleSelection);
m_treeView->setContextMenuPolicy(Qt::NoContextMenu);
m_model->enableSingleSelectionMode(m_attributes.singleSelectionMode);
connect(m_treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(slotClicked(QModelIndex)));
}
else
{
m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
}
if (!m_attributes.showTextFilter)
{
m_textFilterLineEdit->hide();
}
if (!m_attributes.showToggleAllCheckbox)
if (m_attributes.singleSelectionMode || !m_attributes.showToggleAllCheckbox)
{
m_toggleAllCheckBox->hide();
}
@ -442,6 +455,11 @@ void PdmUiTreeSelectionEditor::slotTextFilterChanged()
//--------------------------------------------------------------------------------------------------
void PdmUiTreeSelectionEditor::slotCurrentChanged(const QModelIndex& current, const QModelIndex& previous)
{
if (m_attributes.singleSelectionMode)
{
m_proxyModel->setData(current, true, Qt::CheckStateRole);
}
if (m_attributes.fieldToReceiveCurrentItemValue)
{
PdmUiFieldHandle* uiFieldHandle = m_attributes.fieldToReceiveCurrentItemValue->uiCapability();
@ -454,6 +472,14 @@ void PdmUiTreeSelectionEditor::slotCurrentChanged(const QModelIndex& current, co
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiTreeSelectionEditor::slotClicked(const QModelIndex& current)
{
m_treeView->setCurrentIndex(current);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -61,6 +61,7 @@ class PdmUiTreeSelectionEditorAttribute : public PdmUiEditorAttribute
public:
bool showTextFilter;
bool showToggleAllCheckbox;
bool singleSelectionMode;
/// fieldToReceiveCurrentFieldValue is used to communicate the value of current item in the tree view
/// This is useful when displaying a list of appEnums, and a dependent view is displaying content based on
@ -73,6 +74,7 @@ public:
{
showTextFilter = true;
showToggleAllCheckbox = true;
singleSelectionMode = false;
fieldToReceiveCurrentItemValue = nullptr;
}
@ -108,6 +110,7 @@ private slots:
void slotTextFilterChanged();
void slotCurrentChanged(const QModelIndex& current, const QModelIndex& previous);
void slotClicked(const QModelIndex& current);
private:
void checkAllItems();

View File

@ -54,6 +54,7 @@ caf::PdmUiTreeSelectionQModel::PdmUiTreeSelectionQModel(QObject *parent /*= 0*/)
{
m_uiFieldHandle = nullptr;
m_tree = nullptr;
m_singleSelectionMode = false;
}
//--------------------------------------------------------------------------------------------------
@ -125,6 +126,14 @@ void caf::PdmUiTreeSelectionQModel::setCheckedStateForItems(const QModelIndexLis
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_uiFieldHandle->field(), fieldValueSelection);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::PdmUiTreeSelectionQModel::enableSingleSelectionMode(bool enable)
{
m_singleSelectionMode = enable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -375,6 +384,8 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
else if (isMultipleValueField(fieldValue))
{
std::vector<unsigned int> selectedIndices;
if (!m_singleSelectionMode)
{
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
QList<QVariant> fieldValueSelection = fieldValue.toList();
@ -387,6 +398,9 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
bool setSelected = value.toBool();
// Do not allow empty selection in single selection mode
if (m_singleSelectionMode) setSelected = true;
unsigned int opIndex = static_cast<unsigned int>(optionIndex(index));
if (setSelected)

View File

@ -65,6 +65,7 @@ public:
static int optionItemValueRole();
void setCheckedStateForItems(const QModelIndexList& indices, bool checked);
void enableSingleSelectionMode(bool enable);
int optionItemCount() const;
void setOptions(caf::PdmUiFieldEditorHandle* field, const QList<caf::PdmOptionItemInfo>& options);
@ -91,12 +92,13 @@ private:
void notifyChangedForAllModelIndices();
void recursiveNotifyChildren(const QModelIndex& index);
private:
QList<caf::PdmOptionItemInfo> m_options;
caf::PdmUiFieldEditorHandle* m_uiFieldHandle;
TreeItemType* m_tree;
bool m_singleSelectionMode;
};