Skip to content
Snippets Groups Projects
Commit 38647d5f authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

file -> local ns

parent a4b23260
No related branches found
No related tags found
1 merge request!2117Merge some files concerned with font sizes; rectify '@brief' lines in file headers
......@@ -14,10 +14,85 @@
#include "GUI/View/FitObjective/FitParameterDelegate.h"
#include "Base/Util/Assert.h"
#include "GUI/Model/Job/FitParameterItem.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Support/Data/ComboProperty.h"
#include "GUI/Support/Util/CustomEventFilters.h"
#include "GUI/View/Numeric/ScientificSpinBox.h"
#include "GUI/View/PropertyEditor/CustomEditors.h"
#include "GUI/View/PropertyEditor/PropertyEditorFactory.h"
#include <QApplication>
#include <QModelIndex>
#include <QSpinBox>
namespace {
double getStep(double val)
{
return val == 0.0 ? 1.0 : val / 100.;
}
bool isDoubleProperty(const QVariant& variant)
{
return variant.type() == QVariant::Double;
}
bool isComboProperty(const QVariant& variant)
{
return variant.canConvert<ComboProperty>();
}
bool hasStringRepresentation(const QModelIndex& index)
{
auto variant = index.data();
if (isComboProperty(variant))
return true;
if (isDoubleProperty(variant) && index.internalPointer())
return true;
return false;
}
QString toString(const QModelIndex& index)
{
auto variant = index.data();
if (isComboProperty(variant))
return variant.value<ComboProperty>().label();
if (isDoubleProperty(variant) && index.internalPointer()) {
auto* item = static_cast<QObject*>(index.internalPointer());
FitDoubleItem* doubleItem = dynamic_cast<FitDoubleItem*>(item);
// only "Scientific SpinBoxes" in Fit-Window
return ScientificSpinBox::toString(doubleItem->value(), doubleItem->decimals());
}
return "";
}
QWidget* createEditor(QObject* item, QWidget* parent)
{
CustomEditor* result(nullptr);
if (FitDoubleItem* doubleItem = dynamic_cast<FitDoubleItem*>(item)) {
// only Scientific SpinBoxes in Fit-Window
auto* editor = new ScientificSpinBoxEditor;
editor->setLimits(doubleItem->limits());
editor->setDecimals(doubleItem->decimals());
editor->setSingleStep(getStep(doubleItem->value()));
result = editor;
} else if (dynamic_cast<FitTypeItem*>(item))
result = new ComboPropertyEditor;
if (parent && result) {
result->setParent(parent);
QObject::connect(result, &CustomEditor::dataChanged,
[=] { gProjectDocument.value()->setModified(); });
}
return result;
}
} // namespace
FitParameterDelegate::FitParameterDelegate(QObject* parent)
: QStyledItemDelegate(parent)
......@@ -27,8 +102,8 @@ FitParameterDelegate::FitParameterDelegate(QObject* parent)
void FitParameterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
if (PropertyEditorFactory::hasStringRepresentation(index)) {
QString text = PropertyEditorFactory::toString(index);
if (::hasStringRepresentation(index)) {
QString text = ::toString(index);
paintCustomLabel(painter, option, index, text);
} else
QStyledItemDelegate::paint(painter, option, index);
......@@ -105,7 +180,7 @@ QWidget* FitParameterDelegate::createEditorFromIndex(const QModelIndex& index,
{
if (index.internalPointer()) {
auto* item = static_cast<QObject*>(index.internalPointer());
return PropertyEditorFactory::CreateEditor(item, parent);
return ::createEditor(item, parent);
}
return nullptr;
}
......
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/PropertyEditor/PropertyEditorFactory.cpp
//! @brief Implements PropertyEditorFactory namespace
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/PropertyEditor/PropertyEditorFactory.h"
#include "GUI/Model/Job/FitParameterItem.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/Support/Data/ComboProperty.h"
#include "GUI/View/Numeric/ScientificSpinBox.h"
#include "GUI/View/PropertyEditor/CustomEditors.h"
#include <QModelIndex>
#include <QSpinBox>
namespace {
double getStep(double val)
{
return val == 0.0 ? 1.0 : val / 100.;
}
bool isDoubleProperty(const QVariant& variant)
{
return variant.type() == QVariant::Double;
}
bool isComboProperty(const QVariant& variant)
{
return variant.canConvert<ComboProperty>();
}
} // namespace
bool PropertyEditorFactory::hasStringRepresentation(const QModelIndex& index)
{
auto variant = index.data();
if (isComboProperty(variant))
return true;
if (isDoubleProperty(variant) && index.internalPointer())
return true;
return false;
}
QString PropertyEditorFactory::toString(const QModelIndex& index)
{
auto variant = index.data();
if (isComboProperty(variant))
return variant.value<ComboProperty>().label();
if (isDoubleProperty(variant) && index.internalPointer()) {
auto* item = static_cast<QObject*>(index.internalPointer());
FitDoubleItem* doubleItem = dynamic_cast<FitDoubleItem*>(item);
// only "Scientific SpinBoxes" in Fit-Window
return ScientificSpinBox::toString(doubleItem->value(), doubleItem->decimals());
}
return "";
}
QWidget* PropertyEditorFactory::CreateEditor(QObject* item, QWidget* parent)
{
CustomEditor* result(nullptr);
if (FitDoubleItem* doubleItem = dynamic_cast<FitDoubleItem*>(item)) {
// only Scientific SpinBoxes in Fit-Window
auto* editor = new ScientificSpinBoxEditor;
editor->setLimits(doubleItem->limits());
editor->setDecimals(doubleItem->decimals());
editor->setSingleStep(getStep(doubleItem->value()));
result = editor;
} else if (dynamic_cast<FitTypeItem*>(item))
result = new ComboPropertyEditor;
if (parent && result) {
result->setParent(parent);
QObject::connect(result, &CustomEditor::dataChanged,
[=] { gProjectDocument.value()->setModified(); });
}
return result;
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/PropertyEditor/PropertyEditorFactory.h
//! @brief Defines namespace PropertyEditorFactory
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_PROPERTYEDITORFACTORY_H
#define BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_PROPERTYEDITORFACTORY_H
#include <QWidget>
//! Creates editors for SessionItems.
namespace PropertyEditorFactory {
//! Returns true if the index data has known (custom) conversion to string.
bool hasStringRepresentation(const QModelIndex& index);
//! Provides string representation of index data.
QString toString(const QModelIndex& index);
//! Creates an editor suitable for editing of item.value()
QWidget* CreateEditor(QObject* item, QWidget* parent = nullptr);
} // namespace PropertyEditorFactory
#endif // BORNAGAIN_GUI_VIEW_PROPERTYEDITOR_PROPERTYEDITORFACTORY_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment