#3779 Implement AICD ui and settings

This commit is contained in:
Gaute Lindkvist
2018-12-05 12:52:36 +01:00
parent e67a9ef12a
commit 29c3e10617
10 changed files with 496 additions and 132 deletions

View File

@@ -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}

View File

@@ -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

View File

@@ -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;
};
//--------------------------------------------------------------------------------------------------

View 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;
}

View 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;
};
}