mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1895 Curve Creator : Add support for single value fields
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "cafAssert.h"
|
#include "cafAssert.h"
|
||||||
#include "cafPdmObject.h"
|
#include "cafPdmObject.h"
|
||||||
|
#include "cafPdmUiCommandSystemProxy.h"
|
||||||
#include "cafPdmUiTreeSelectionQModel.h"
|
#include "cafPdmUiTreeSelectionQModel.h"
|
||||||
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
@@ -125,11 +126,6 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
|
|
||||||
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
||||||
|
|
||||||
// Tree view
|
|
||||||
|
|
||||||
bool optionsOnly = true;
|
|
||||||
QList<PdmOptionItemInfo> options = field()->valueOptions(&optionsOnly);
|
|
||||||
|
|
||||||
if (!m_model)
|
if (!m_model)
|
||||||
{
|
{
|
||||||
m_model = new caf::PdmUiTreeSelectionQModel(m_treeView);
|
m_model = new caf::PdmUiTreeSelectionQModel(m_treeView);
|
||||||
@@ -139,8 +135,14 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
|
||||||
m_treeView->setModel(m_proxyModel);
|
m_treeView->setModel(m_proxyModel);
|
||||||
|
|
||||||
|
connect(m_treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
||||||
|
this, SLOT(slotCurrentChanged(QModelIndex, QModelIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool optionsOnly = true;
|
||||||
|
QList<PdmOptionItemInfo> options = field()->valueOptions(&optionsOnly);
|
||||||
|
|
||||||
bool itemCountHasChaged = false;
|
bool itemCountHasChaged = false;
|
||||||
if (m_model->optionItemCount() != options.size()) itemCountHasChaged = true;
|
if (m_model->optionItemCount() != options.size()) itemCountHasChaged = true;
|
||||||
|
|
||||||
@@ -153,41 +155,54 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
m_treeView->expandAll();
|
m_treeView->expandAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
PdmUiTreeSelectionEditorAttribute attributes;
|
QVariant fieldValue = field()->uiValue();
|
||||||
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
|
if (PdmUiTreeSelectionQModel::isSingleValueField(fieldValue))
|
||||||
if (uiObject)
|
|
||||||
{
|
|
||||||
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!attributes.showTextFilter)
|
|
||||||
{
|
{
|
||||||
m_textFilterLineEdit->hide();
|
m_textFilterLineEdit->hide();
|
||||||
}
|
|
||||||
|
|
||||||
if (!attributes.showToggleAllCheckbox)
|
|
||||||
{
|
|
||||||
m_toggleAllCheckBox->hide();
|
m_toggleAllCheckBox->hide();
|
||||||
}
|
}
|
||||||
else
|
else if (PdmUiTreeSelectionQModel::isMultipleValueField(fieldValue))
|
||||||
{
|
{
|
||||||
if (options.size() == 0)
|
m_treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
|
connect(m_treeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(customMenuRequested(QPoint)));
|
||||||
|
|
||||||
|
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
|
||||||
|
if (uiObject)
|
||||||
{
|
{
|
||||||
m_toggleAllCheckBox->setChecked(false);
|
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &m_attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_attributes.showTextFilter)
|
||||||
|
{
|
||||||
|
m_textFilterLineEdit->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_attributes.showToggleAllCheckbox)
|
||||||
|
{
|
||||||
|
m_toggleAllCheckBox->hide();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool allItemsChecked = true;
|
if (options.size() == 0)
|
||||||
QModelIndexList indices = allVisibleSourceModelIndices();
|
|
||||||
for (auto mi : indices)
|
|
||||||
{
|
{
|
||||||
if (m_model->data(mi, Qt::CheckStateRole).toBool() == false)
|
m_toggleAllCheckBox->setChecked(false);
|
||||||
{
|
|
||||||
allItemsChecked = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool allItemsChecked = true;
|
||||||
|
QModelIndexList indices = allVisibleSourceModelIndices();
|
||||||
|
for (auto mi : indices)
|
||||||
|
{
|
||||||
|
if (m_model->data(mi, Qt::CheckStateRole).toBool() == false)
|
||||||
|
{
|
||||||
|
allItemsChecked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_toggleAllCheckBox->setChecked(allItemsChecked);
|
m_toggleAllCheckBox->setChecked(allItemsChecked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,12 +237,7 @@ QWidget* PdmUiTreeSelectionEditor::createEditorWidget(QWidget* parent)
|
|||||||
|
|
||||||
QTreeViewHeightHint* treeViewHeightHint = new QTreeViewHeightHint(parent);
|
QTreeViewHeightHint* treeViewHeightHint = new QTreeViewHeightHint(parent);
|
||||||
treeViewHeightHint->setHeightHint(2000);
|
treeViewHeightHint->setHeightHint(2000);
|
||||||
|
|
||||||
treeViewHeightHint->setHeaderHidden(true);
|
treeViewHeightHint->setHeaderHidden(true);
|
||||||
treeViewHeightHint->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
||||||
treeViewHeightHint->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
|
|
||||||
connect(treeViewHeightHint, SIGNAL(customContextMenuRequested(QPoint)), SLOT(customMenuRequested(QPoint)));
|
|
||||||
|
|
||||||
m_treeView = treeViewHeightHint;
|
m_treeView = treeViewHeightHint;
|
||||||
|
|
||||||
@@ -394,6 +404,21 @@ void PdmUiTreeSelectionEditor::slotTextFilterChanged()
|
|||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void PdmUiTreeSelectionEditor::slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous)
|
||||||
|
{
|
||||||
|
if (m_attributes.highLightField)
|
||||||
|
{
|
||||||
|
QVariant v = m_proxyModel->data(current, PdmUiTreeSelectionQModel::optionItemValueRole());
|
||||||
|
|
||||||
|
//m_attributes.highLightField->fieldHandle()->setvalue();
|
||||||
|
|
||||||
|
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_attributes.highLightField, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class QCheckBox;
|
|||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
class QItemSelection;
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
@@ -61,11 +62,15 @@ public:
|
|||||||
bool showTextFilter;
|
bool showTextFilter;
|
||||||
bool showToggleAllCheckbox;
|
bool showToggleAllCheckbox;
|
||||||
|
|
||||||
|
caf::PdmUiFieldHandle* highLightField;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PdmUiTreeSelectionEditorAttribute()
|
PdmUiTreeSelectionEditorAttribute()
|
||||||
{
|
{
|
||||||
showTextFilter = true;
|
showTextFilter = true;
|
||||||
showToggleAllCheckbox = true;
|
showToggleAllCheckbox = true;
|
||||||
|
|
||||||
|
highLightField = nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,6 +103,8 @@ private slots:
|
|||||||
|
|
||||||
void slotTextFilterChanged();
|
void slotTextFilterChanged();
|
||||||
|
|
||||||
|
void slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkAllItems();
|
void checkAllItems();
|
||||||
void unCheckAllItems();
|
void unCheckAllItems();
|
||||||
@@ -114,6 +121,8 @@ private:
|
|||||||
|
|
||||||
PdmUiTreeSelectionQModel* m_model;
|
PdmUiTreeSelectionQModel* m_model;
|
||||||
QSortFilterProxyModel* m_proxyModel;
|
QSortFilterProxyModel* m_proxyModel;
|
||||||
|
|
||||||
|
PdmUiTreeSelectionEditorAttribute m_attributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace caf
|
} // end namespace caf
|
||||||
|
|||||||
@@ -75,6 +75,14 @@ int caf::PdmUiTreeSelectionQModel::headingRole()
|
|||||||
return Qt::UserRole + 1;
|
return Qt::UserRole + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
int caf::PdmUiTreeSelectionQModel::optionItemValueRole()
|
||||||
|
{
|
||||||
|
return Qt::UserRole + 2;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -287,16 +295,28 @@ QVariant caf::PdmUiTreeSelectionQModel::data(const QModelIndex &index, int role
|
|||||||
if (m_uiFieldHandle && m_uiFieldHandle->field())
|
if (m_uiFieldHandle && m_uiFieldHandle->field())
|
||||||
{
|
{
|
||||||
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
||||||
QList<QVariant> valuesSelectedInField = fieldValue.toList();
|
if (isSingleValueField(fieldValue))
|
||||||
|
|
||||||
int opIndex = optionIndex(index);
|
|
||||||
|
|
||||||
for (QVariant v : valuesSelectedInField)
|
|
||||||
{
|
{
|
||||||
int indexInField = v.toInt();
|
int row = fieldValue.toInt();
|
||||||
if (indexInField == opIndex)
|
|
||||||
|
if (row == optionIndex(index))
|
||||||
|
{
|
||||||
|
return Qt::Checked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isMultipleValueField(fieldValue))
|
||||||
|
{
|
||||||
|
QList<QVariant> valuesSelectedInField = fieldValue.toList();
|
||||||
|
|
||||||
|
int opIndex = optionIndex(index);
|
||||||
|
|
||||||
|
for (QVariant v : valuesSelectedInField)
|
||||||
{
|
{
|
||||||
return Qt::Checked;
|
int indexInField = v.toInt();
|
||||||
|
if (indexInField == opIndex)
|
||||||
|
{
|
||||||
|
return Qt::Checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,6 +337,12 @@ QVariant caf::PdmUiTreeSelectionQModel::data(const QModelIndex &index, int role
|
|||||||
{
|
{
|
||||||
return optionItemInfo->isHeading();
|
return optionItemInfo->isHeading();
|
||||||
}
|
}
|
||||||
|
else if (role == optionItemValueRole())
|
||||||
|
{
|
||||||
|
QVariant v = optionItemInfo->value();
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -331,53 +357,72 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar
|
|||||||
|
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::CheckStateRole)
|
||||||
{
|
{
|
||||||
std::vector<unsigned int> selectedIndices;
|
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
||||||
|
if (isSingleValueField(fieldValue))
|
||||||
{
|
{
|
||||||
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
if (value.toBool() == true)
|
||||||
QList<QVariant> fieldValueSelection = fieldValue.toList();
|
|
||||||
|
|
||||||
for (auto v : fieldValueSelection)
|
|
||||||
{
|
{
|
||||||
selectedIndices.push_back(v.toUInt());
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (isMultipleValueField(fieldValue))
|
||||||
bool setSelected = value.toBool();
|
|
||||||
|
|
||||||
unsigned int opIndex = static_cast<unsigned int>(optionIndex(index));
|
|
||||||
|
|
||||||
if (setSelected)
|
|
||||||
{
|
{
|
||||||
bool isIndexPresent = false;
|
std::vector<unsigned int> selectedIndices;
|
||||||
for (auto indexInField : selectedIndices)
|
|
||||||
{
|
{
|
||||||
if (indexInField == opIndex)
|
QVariant fieldValue = m_uiFieldHandle->field()->uiValue();
|
||||||
|
QList<QVariant> fieldValueSelection = fieldValue.toList();
|
||||||
|
|
||||||
|
for (auto v : fieldValueSelection)
|
||||||
{
|
{
|
||||||
isIndexPresent = true;
|
selectedIndices.push_back(v.toUInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isIndexPresent)
|
bool setSelected = value.toBool();
|
||||||
|
|
||||||
|
unsigned int opIndex = static_cast<unsigned int>(optionIndex(index));
|
||||||
|
|
||||||
|
if (setSelected)
|
||||||
{
|
{
|
||||||
selectedIndices.push_back(opIndex);
|
bool isIndexPresent = false;
|
||||||
|
for (auto indexInField : selectedIndices)
|
||||||
|
{
|
||||||
|
if (indexInField == opIndex)
|
||||||
|
{
|
||||||
|
isIndexPresent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isIndexPresent)
|
||||||
|
{
|
||||||
|
selectedIndices.push_back(opIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selectedIndices.erase(std::remove(selectedIndices.begin(), selectedIndices.end(), opIndex), selectedIndices.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QVariant> fieldValueSelection;
|
||||||
|
for (auto v : selectedIndices)
|
||||||
|
{
|
||||||
|
fieldValueSelection.push_back(QVariant(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_uiFieldHandle->field(), fieldValueSelection);
|
||||||
|
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
selectedIndices.erase(std::remove(selectedIndices.begin(), selectedIndices.end(), opIndex), selectedIndices.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QVariant> fieldValueSelection;
|
|
||||||
for (auto v : selectedIndices)
|
|
||||||
{
|
|
||||||
fieldValueSelection.push_back(QVariant(v));
|
|
||||||
}
|
|
||||||
|
|
||||||
PdmUiCommandSystemProxy::instance()->setUiValueToField(m_uiFieldHandle->field(), fieldValueSelection);
|
|
||||||
|
|
||||||
emit dataChanged(index, index);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -416,3 +461,29 @@ void caf::PdmUiTreeSelectionQModel::buildOptionItemTree(int parentOptionIndex, T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool caf::PdmUiTreeSelectionQModel::isSingleValueField(const QVariant& fieldValue)
|
||||||
|
{
|
||||||
|
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool caf::PdmUiTreeSelectionQModel::isMultipleValueField(const QVariant& fieldValue)
|
||||||
|
{
|
||||||
|
if (fieldValue.type() == QVariant::List)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
~PdmUiTreeSelectionQModel();
|
~PdmUiTreeSelectionQModel();
|
||||||
|
|
||||||
static int headingRole();
|
static int headingRole();
|
||||||
|
static int optionItemValueRole();
|
||||||
|
|
||||||
void setCheckedStateForItems(const QModelIndexList& indices, bool checked);
|
void setCheckedStateForItems(const QModelIndexList& indices, bool checked);
|
||||||
|
|
||||||
@@ -76,6 +77,10 @@ public:
|
|||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
|
||||||
|
// Consider moving these functions to PdmUiFieldHandle
|
||||||
|
static bool isSingleValueField(const QVariant& fieldValue);
|
||||||
|
static bool isMultipleValueField(const QVariant& fieldValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef caf::UiTreeItem<int> TreeItemType;
|
typedef caf::UiTreeItem<int> TreeItemType;
|
||||||
|
|
||||||
@@ -83,6 +88,7 @@ private:
|
|||||||
int optionIndex(const QModelIndex &index) const;
|
int optionIndex(const QModelIndex &index) const;
|
||||||
void buildOptionItemTree(int optionIndex, TreeItemType* parentNode);
|
void buildOptionItemTree(int optionIndex, TreeItemType* parentNode);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<caf::PdmOptionItemInfo> m_options;
|
QList<caf::PdmOptionItemInfo> m_options;
|
||||||
caf::PdmUiFieldEditorHandle* m_uiFieldHandle;
|
caf::PdmUiFieldEditorHandle* m_uiFieldHandle;
|
||||||
|
|||||||
Reference in New Issue
Block a user