mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3779 Implement AICD ui and settings
This commit is contained in:
@@ -50,6 +50,7 @@ set (MOC_HEADER_FILES
|
||||
cafPdmUiTreeSelectionQModel.h
|
||||
cafPdmUiFormLayoutObjectEditor.h
|
||||
cafPdmUiDoubleValueEditor.h
|
||||
cafPdmUniqueIdValidator.h
|
||||
)
|
||||
|
||||
if ( NOT CMAKE_AUTOMOC )
|
||||
@@ -152,6 +153,7 @@ set( PROJECT_FILES
|
||||
cafQTreeViewStateSerializer.cpp
|
||||
cafMemoryInspector.h
|
||||
cafMemoryInspector.cpp
|
||||
cafPdmUniqueIdValidator.cpp
|
||||
)
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "cafPdmUiDefaultObjectEditor.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafPdmUniqueIdValidator.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QApplication>
|
||||
@@ -56,96 +57,6 @@
|
||||
#include <QString>
|
||||
|
||||
|
||||
|
||||
|
||||
class PdmUniqueIdValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
PdmUniqueIdValidator(const std::set<int>& usedIds, bool multipleSelectionOfSameFieldsSelected, const QString& errorMessage, QObject* parent)
|
||||
: QValidator(parent),
|
||||
m_usedIds(usedIds),
|
||||
m_nextValidValue(0),
|
||||
m_multipleSelectionOfSameFieldsSelected(multipleSelectionOfSameFieldsSelected),
|
||||
m_errorMessage(errorMessage)
|
||||
{
|
||||
computeNextValidId();
|
||||
}
|
||||
|
||||
State validate(QString& currentString, int &) const override
|
||||
{
|
||||
if (m_multipleSelectionOfSameFieldsSelected)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentString.isEmpty())
|
||||
{
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
bool isValidInteger = false;
|
||||
int currentValue = currentString.toInt(&isValidInteger);
|
||||
|
||||
if (!isValidInteger)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentValue < 0)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (m_usedIds.find(currentValue) != m_usedIds.end())
|
||||
{
|
||||
foreach(QWidget* widget, QApplication::topLevelWidgets())
|
||||
{
|
||||
if (widget->inherits("QMainWindow"))
|
||||
{
|
||||
QMainWindow* mainWindow = qobject_cast<QMainWindow*>(widget);
|
||||
if (mainWindow && mainWindow->statusBar())
|
||||
{
|
||||
mainWindow->statusBar()->showMessage(m_errorMessage, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
void fixup(QString& editorText) const override
|
||||
{
|
||||
editorText = QString::number(m_nextValidValue);
|
||||
}
|
||||
|
||||
private:
|
||||
int computeNextValidId()
|
||||
{
|
||||
if (!m_usedIds.empty())
|
||||
{
|
||||
m_nextValidValue = *m_usedIds.rbegin();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nextValidValue = 1;
|
||||
}
|
||||
|
||||
return m_nextValidValue;
|
||||
}
|
||||
|
||||
private:
|
||||
std::set<int> m_usedIds;
|
||||
|
||||
int m_nextValidValue;
|
||||
bool m_multipleSelectionOfSameFieldsSelected;
|
||||
QString m_errorMessage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
@@ -209,33 +120,14 @@ void PdmUiLineEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &leab);
|
||||
}
|
||||
|
||||
if (leab.useRangeValidator)
|
||||
if (leab.validator)
|
||||
{
|
||||
m_lineEdit->setValidator(new QIntValidator(leab.minValue, leab.maxValue, this));
|
||||
m_lineEdit->setValidator(leab.validator);
|
||||
}
|
||||
|
||||
m_lineEdit->setAvoidSendingEnterEventToParentWidget(leab.avoidSendingEnterEventToParentWidget);
|
||||
}
|
||||
|
||||
{
|
||||
PdmUiLineEditorAttributeUniqueValues leab;
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj(uiField()->fieldHandle()->ownerObject());
|
||||
if (uiObject)
|
||||
{
|
||||
uiObject->editorAttribute(uiField()->fieldHandle(), uiConfigName, &leab);
|
||||
}
|
||||
if (leab.usedIds.size() > 0)
|
||||
{
|
||||
if (isMultipleFieldsWithSameKeywordSelected(uiField()->fieldHandle()))
|
||||
{
|
||||
QMessageBox::information(nullptr, "Invalid operation", "The field you are manipulating is defined to have unique values. A selection of multiple fields is detected. Please select a single item.");
|
||||
}
|
||||
|
||||
m_lineEdit->setValidator(new PdmUniqueIdValidator(leab.usedIds, isMultipleFieldsWithSameKeywordSelected(uiField()->fieldHandle()), leab.errorMessage, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool fromMenuOnly = true;
|
||||
QList<PdmOptionItemInfo> enumNames = uiField()->valueOptions(&fromMenuOnly);
|
||||
CAF_ASSERT(fromMenuOnly); // Not supported
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QValidator>
|
||||
#include <QWidget>
|
||||
|
||||
class QGridLayout;
|
||||
@@ -59,31 +60,11 @@ public:
|
||||
PdmUiLineEditorAttribute()
|
||||
{
|
||||
avoidSendingEnterEventToParentWidget = false;
|
||||
useRangeValidator = false;
|
||||
minValue = 0;
|
||||
maxValue = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
bool avoidSendingEnterEventToParentWidget;
|
||||
bool useRangeValidator;
|
||||
int minValue;
|
||||
int maxValue;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class PdmUiLineEditorAttributeUniqueValues : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiLineEditorAttributeUniqueValues()
|
||||
{}
|
||||
|
||||
public:
|
||||
std::set<int> usedIds;
|
||||
QString errorMessage;
|
||||
QPointer<QValidator> validator;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
132
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.cpp
Normal file
132
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUniqueIdValidator.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QStatusBar>
|
||||
|
||||
using namespace caf;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUniqueIdValidator::PdmUniqueIdValidator(const std::set<int>& usedIds,
|
||||
bool multipleSelectionOfSameFieldsSelected,
|
||||
const QString& errorMessage,
|
||||
QObject* parent)
|
||||
: QValidator(parent)
|
||||
, m_usedIds(usedIds)
|
||||
, m_nextValidValue(0)
|
||||
, m_multipleSelectionOfSameFieldsSelected(multipleSelectionOfSameFieldsSelected)
|
||||
, m_errorMessage(errorMessage)
|
||||
{
|
||||
computeNextValidId();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QValidator::State PdmUniqueIdValidator::validate(QString& currentString, int&) const
|
||||
{
|
||||
if (m_multipleSelectionOfSameFieldsSelected)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentString.isEmpty())
|
||||
{
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
bool isValidInteger = false;
|
||||
int currentValue = currentString.toInt(&isValidInteger);
|
||||
|
||||
if (!isValidInteger)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (currentValue < 0)
|
||||
{
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
|
||||
if (m_usedIds.find(currentValue) != m_usedIds.end())
|
||||
{
|
||||
foreach (QWidget* widget, QApplication::topLevelWidgets())
|
||||
{
|
||||
if (widget->inherits("QMainWindow"))
|
||||
{
|
||||
QMainWindow* mainWindow = qobject_cast<QMainWindow*>(widget);
|
||||
if (mainWindow && mainWindow->statusBar())
|
||||
{
|
||||
mainWindow->statusBar()->showMessage(m_errorMessage, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUniqueIdValidator::fixup(QString& editorText) const
|
||||
{
|
||||
editorText = QString::number(m_nextValidValue);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int PdmUniqueIdValidator::computeNextValidId()
|
||||
{
|
||||
if (!m_usedIds.empty())
|
||||
{
|
||||
m_nextValidValue = *m_usedIds.rbegin();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nextValidValue = 1;
|
||||
}
|
||||
|
||||
return m_nextValidValue;
|
||||
}
|
||||
62
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.h
Normal file
62
Fwk/AppFwk/cafUserInterface/cafPdmUniqueIdValidator.h
Normal file
@@ -0,0 +1,62 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#pragma once
|
||||
|
||||
#include <QValidator>
|
||||
#include <set>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmUniqueIdValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
PdmUniqueIdValidator(const std::set<int>& usedIds, bool multipleSelectionOfSameFieldsSelected, const QString& errorMessage, QObject* parent);
|
||||
|
||||
State validate(QString& currentString, int &) const override;
|
||||
|
||||
void fixup(QString& editorText) const override;
|
||||
|
||||
private:
|
||||
int computeNextValidId();
|
||||
|
||||
private:
|
||||
std::set<int> m_usedIds;
|
||||
|
||||
int m_nextValidValue;
|
||||
bool m_multipleSelectionOfSameFieldsSelected;
|
||||
QString m_errorMessage;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user