Commit 8b2f4d6d authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Slight modifications.

- remove virtual keyword when unnecessary
- move pointer to core parameter in the template intermediate class
- adapt child classes with respect to the above modifs
- add some cpp files to ensure compilation checks
- add export macro to child classes
- beautifying
parent ac379c41
......@@ -66,10 +66,10 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterBoolCheckBox.h
dtkWidgetsParameterDoubleSpinBox
dtkWidgetsParameterDoubleSpinBox.h
dtkWidgetsParameterIntSpinBox
dtkWidgetsParameterIntSpinBox.h
dtkWidgetsParameterFactory
dtkWidgetsParameterFactory.h
dtkWidgetsParameterIntSpinBox
dtkWidgetsParameterIntSpinBox.h
dtkWidgetsParameterMenuBarGenerator
dtkWidgetsParameterMenuBarGenerator.h
dtkWidgetsParameterStringListComboBox
......@@ -84,6 +84,7 @@ set(${PROJECT_NAME}_HEADERS
set(${PROJECT_NAME}_SOURCES
dtkApplication.cpp
dtkWidgets.cpp
dtkWidgetsAbstractParameter.cpp
dtkWidgetsColorButton.cpp
dtkWidgetsController.cpp
dtkWidgetsLayout.cpp
......@@ -101,7 +102,6 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsOverlayPaneManager.cpp
dtkWidgetsOverlayPaneSlider.cpp
dtkWidgetsOverlayRope.cpp
dtkWidgetsParameter.cpp
dtkWidgetsParameterBoolCheckBox.cpp
dtkWidgetsParameterDoubleSpinBox.cpp
dtkWidgetsParameterIntSpinBox.cpp
......
#include "dtkApplication.h"
#include "dtkWidgets.h"
#include "dtkWidgetsAbstractParameter.h"
#include "dtkWidgetsColorButton.h"
#include "dtkWidgetsController.h"
#include "dtkWidgetsHUD.h"
......@@ -17,6 +18,13 @@
#include "dtkWidgetsOverlayPaneManager.h"
#include "dtkWidgetsOverlayPaneSlider.h"
#include "dtkWidgetsOverlayRope.h"
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsParameterBoolCheckBox.h"
#include "dtkWidgetsParameterDoubleSpinBox.h"
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgetsParameterIntSpinBox.h"
#include "dtkWidgetsParameterMenuBarGenerator.h"
#include "dtkWidgetsParameterStringListComboBox.h"
#include "dtkWidgetsSettings.h"
#include "dtkWidgetsStylesheetParser.h"
#include "dtkWidgetsWidget.h"
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgets.h"
#include <dtkWidgetsConfig>
......@@ -18,6 +32,7 @@
// /////////////////////////////////////////////////////////////////
namespace dtk {
namespace widgets {
DTK_DEFINE_LAYER_MANAGER;
......@@ -40,7 +55,7 @@ namespace dtk {
else {
pathslist = realpath.split(":");
}
foreach (const QString &v_path, pathslist) {
for (const QString &v_path : pathslist) {
manager().initialize(v_path);
}
......@@ -68,5 +83,7 @@ namespace dtk {
}
}
}
//
// dtkWidgets.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include<dtkWidgetsExport.h>
......@@ -9,6 +23,7 @@
// ///////////////////////////////////////////////////////////////////
namespace dtk {
namespace widgets {
DTKWIDGETS_EXPORT dtkCoreLayerManager& manager(void);
......@@ -19,3 +34,6 @@ namespace dtk {
DTKWIDGETS_EXPORT void uninitialize(void);
}
}
//
// dtkWidgets.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsAbstractParameter.h"
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsAbstractParameter implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsAbstractParameter::dtkWidgetsAbstractParameter(QWidget *p) : QWidget(p)
{
}
//
// dtkWidgetsAbstractParameter.cpp ends here
......@@ -18,26 +18,22 @@
#include <QtWidgets>
#include <dtkCore>
class dtkCoreAbstractParameter;
#include <dtkCore/dtkCoreParameter>
class DTKWIDGETS_EXPORT dtkWidgetsAbstractParameter : public QWidget {
class DTKWIDGETS_EXPORT dtkWidgetsAbstractParameter : public QWidget
{
public:
dtkWidgetsAbstractParameter(QWidget *parent) : QWidget(parent) {};
virtual ~dtkWidgetsAbstractParameter() = default;
dtkWidgetsAbstractParameter(QWidget *);
~dtkWidgetsAbstractParameter(void) = default;
public:
virtual bool connect(dtkCoreAbstractParameter *) = 0;
public:
dtkCoreAbstractParameter *parameter(void) {
return this->m_parameter;
}
protected:
dtkCoreAbstractParameter *m_parameter = nullptr;
virtual dtkCoreAbstractParameter *parameter(void) const = 0;
};
Q_DECLARE_METATYPE(dtkWidgetsAbstractParameter *);
//
// dtkWidgetsAbstractParameter.h ends here
#include "dtkWidgetsParameter.h"
#include "dtkWidgets.h"
......@@ -18,19 +18,38 @@
#include <QtWidgets>
#include <dtkCore>
#include "dtkWidgetsAbstractParameter.h"
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameter declaration
// ///////////////////////////////////////////////////////////////////
template <typename T>
class DTKWIDGETS_EXPORT dtkWidgetsParameter : public dtkWidgetsAbstractParameter
{
public:
dtkWidgetsParameter(QWidget *parent) : dtkWidgetsAbstractParameter(parent) {};
dtkWidgetsParameter(QWidget *);
~dtkWidgetsParameter(void) = default;
dtkCoreAbstractParameter *parameter(void) const final;
protected:
T *m_parameter = nullptr;
};
DTK_DECLARE_OBJECT(dtkWidgetsAbstractParameter*);
// ///////////////////////////////////////////////////////////////////
template <typename T>
inline dtkWidgetsParameter<T>::dtkWidgetsParameter(QWidget *p) : dtkWidgetsAbstractParameter(p)
{
}
template <typename T>
inline dtkCoreAbstractParameter *dtkWidgetsParameter<T>::parameter(void) const
{
return m_parameter;
}
//
// dtkWidgetsParameter.h ends here
......@@ -16,7 +16,9 @@
#include <dtkLog>
#include <dtkCoreParameter>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterBoolCheckBoxPrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterBoolCheckBoxPrivate
{
......@@ -24,6 +26,8 @@ public:
QCheckBox *check_box = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterBoolCheckBox implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterBoolCheckBox::dtkWidgetsParameterBoolCheckBox(QWidget* parent) : dtkWidgetsParameter<dtk::d_bool>(parent), d(new dtkWidgetsParameterBoolCheckBoxPrivate)
......@@ -43,37 +47,44 @@ dtkWidgetsParameterBoolCheckBox::~dtkWidgetsParameterBoolCheckBox(void)
bool dtkWidgetsParameterBoolCheckBox::connect(dtkCoreAbstractParameter *p)
{
dtk::d_bool *p_bool = dynamic_cast<dtk::d_bool *>(p);
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_bool *>(p);
if(!p_bool) {
qWarning() << "The type of the parameter is not compatible with the widget dtkWidgetsParameterBoolCheckBox.";
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterBoolCheckBox.";
return false;
}
d->check_box->setToolTip(p_bool->documentation());
d->check_box->setToolTip(m_parameter->documentation());
if(p_bool->value()) {
if(m_parameter->value()) {
d->check_box->setCheckState(Qt::Checked);
} else {
d->check_box->setCheckState(Qt::Unchecked);
}
QObject::connect(p_bool, &dtk::d_bool::valueChanged, [=] (QVariant v) {
bool value = v.value<dtk::d_bool>().value();
d->check_box->blockSignals(true);
if(value) {
d->check_box->setCheckState(Qt::Checked);
} else {
d->check_box->setCheckState(Qt::Unchecked);
}
d->check_box->blockSignals(false);
});
QObject::connect(d->check_box, &QCheckBox::stateChanged, [=] (int state) {
p_bool->setValue(state == Qt::Checked);
});
dtkWidgetsAbstractParameter::m_parameter = p;
QObject::connect(m_parameter, &dtk::d_bool::valueChanged, [=] (QVariant v)
{
bool value = v.value<dtk::d_bool>().value();
d->check_box->blockSignals(true);
if (value) {
d->check_box->setCheckState(Qt::Checked);
} else {
d->check_box->setCheckState(Qt::Unchecked);
}
d->check_box->blockSignals(false);
});
QObject::connect(d->check_box, &QCheckBox::stateChanged, [=] (int state)
{
// m_parameter->block(true);
m_parameter->setValue(state == Qt::Checked);
// m_parameter->block(false);
});
return true;
}
......
......@@ -14,22 +14,28 @@
#pragma once
#include <dtkWidgetsExport>
#include <QtWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
class dtkWidgetsParameterBoolCheckBox : public dtkWidgetsParameter<dtk::d_bool>
class DTKWIDGETS_EXPORT dtkWidgetsParameterBoolCheckBox : public dtkWidgetsParameter<dtk::d_bool>
{
Q_OBJECT
public:
dtkWidgetsParameterBoolCheckBox(QWidget* parent = 0);
virtual ~dtkWidgetsParameterBoolCheckBox(void);
dtkWidgetsParameterBoolCheckBox(QWidget* parent = 0);
~dtkWidgetsParameterBoolCheckBox(void);
public:
virtual bool connect(dtkCoreAbstractParameter *) override;
bool connect(dtkCoreAbstractParameter *) override;
private:
using dtkWidgetsParameter<dtk::d_bool>::m_parameter;
class dtkWidgetsParameterBoolCheckBoxPrivate *d;
};
......
......@@ -16,7 +16,9 @@
#include <dtkLog>
#include <dtkCoreParameter>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterDoubleSpinBoxPrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterDoubleSpinBoxPrivate
{
......@@ -24,6 +26,8 @@ public:
QDoubleSpinBox *spin_box = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterDoubleSpinBox implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterDoubleSpinBox::dtkWidgetsParameterDoubleSpinBox(QWidget* parent) : dtkWidgetsParameter<dtk::d_real>(parent), d(new dtkWidgetsParameterDoubleSpinBoxPrivate)
......@@ -43,31 +47,38 @@ dtkWidgetsParameterDoubleSpinBox::~dtkWidgetsParameterDoubleSpinBox(void)
bool dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreAbstractParameter *p)
{
dtk::d_real *p_real = dynamic_cast<dtk::d_real *>(p);
if(!p_real) {
qWarning() << "The type of the parameter is not compatible with the widget dtkWidgetsParameterIntSpinBox.";
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
d->spin_box->setMinimum(p_real->min());
d->spin_box->setMaximum(p_real->max());
d->spin_box->setToolTip(p_real->documentation());
m_parameter = dynamic_cast<dtk::d_real *>(p);
d->spin_box->setValue(p_real->value());
QObject::connect(p_real, &dtk::d_real::valueChanged, [=] (QVariant v) {
d->spin_box->blockSignals(true);
double value = v.value<dtk::d_real>().value();
d->spin_box->setValue(value);
d->spin_box->blockSignals(false);
});
QObject::connect(d->spin_box, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double v) {
p_real->setValue(v);
});
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterIntSpinBox.";
return false;
}
dtkWidgetsAbstractParameter::m_parameter = p;
d->spin_box->setMinimum(m_parameter->min());
d->spin_box->setMaximum(m_parameter->max());
d->spin_box->setToolTip(m_parameter->documentation());
d->spin_box->setValue(m_parameter->value());
QObject::connect(m_parameter, &dtk::d_real::valueChanged, [=] (QVariant v)
{
d->spin_box->blockSignals(true);
double value = v.value<dtk::d_real>().value();
d->spin_box->setValue(value);
d->spin_box->blockSignals(false);
});
QObject::connect(d->spin_box, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double v)
{
//m_parameter->block(true);
m_parameter->setValue(v);
//m_parameter->block(false);
});
return true;
}
......
......@@ -14,21 +14,28 @@
#pragma once
#include <dtkWidgetsExport>
#include <QtWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsParameterDoubleSpinBox : public dtkWidgetsParameter<dtk::d_real>
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
class DTKWIDGETS_EXPORT dtkWidgetsParameterDoubleSpinBox : public dtkWidgetsParameter<dtk::d_real>
{
Q_OBJECT
public:
dtkWidgetsParameterDoubleSpinBox(QWidget* parent = 0);
virtual ~dtkWidgetsParameterDoubleSpinBox(void);
dtkWidgetsParameterDoubleSpinBox(QWidget* parent = 0);
~dtkWidgetsParameterDoubleSpinBox(void);
public:
virtual bool connect(dtkCoreAbstractParameter *) override;
bool connect(dtkCoreAbstractParameter *) override;
private:
using dtkWidgetsParameter<dtk::d_real>::m_parameter;
class dtkWidgetsParameterDoubleSpinBoxPrivate *d;
};
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgets.h"
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsAbstractParameter *dtkWidgetsParameterFactory::create(const QString& key)
{
dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
if(!widget) {
qWarning() << Q_FUNC_INFO << "The widget with key :" << key << "could not be instanciated by the factory.";
return nullptr;
}
return widget;
}
dtkWidgetsAbstractParameter *dtkWidgetsParameterFactory::create(dtkCoreAbstractParameter *parameter, const QString& key)
{
if (!parameter) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done. Return nullptr.";
return nullptr;
}
dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
if(!widget) {
qWarning() << Q_FUNC_INFO << "The widget with key :" << key << "could not be instanciated by the factory.";
return nullptr;
}
if(!widget->connect(parameter)) {
qWarning() << Q_FUNC_INFO << "The parameter could not be connected to the widget.";
}
return widget;
}
// ///////////////////////////////////////////////////////////////////
// Register to dtkWidgets layer implementation
// ///////////////////////////////////////////////////////////////////
namespace dtk
{
namespace widgets
......@@ -14,12 +65,12 @@ namespace dtk
dtkWidgetsParameterPluginManager manager;
}
dtkWidgetsParameterFactory& pluginFactory()
dtkWidgetsParameterFactory& pluginFactory(void)
{
return _private::factory;
}
dtkWidgetsParameterPluginManager& pluginManager()
dtkWidgetsParameterPluginManager& pluginManager(void)
{
return _private::manager;
}
......@@ -32,3 +83,6 @@ namespace dtk
}
}
}
//
// dtkWidgetsParameterFactory.cpp ends here
#pragma once
// Version: $Id$
//
//
#include<dtkWidgetsExport.h>
// Commentary:
//
//
#include "dtkWidgetsParameter.h"
// Change Log:
//
//
class DTKWIDGETS_EXPORT dtkWidgetsParameterPlugin : public dtkCorePluginBase {};
// Code:
Q_DECLARE_METATYPE(dtkWidgetsParameterPlugin*);
Q_DECLARE_INTERFACE(dtkWidgetsParameterPlugin, DTK_DECLARE_PLUGIN_INTERFACE(dtkWidgetsParameterPlugin));
#pragma once
class DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager : public dtkCorePluginManager<dtkWidgetsParameterPlugin> {};
#include<dtkWidgetsExport.h>
class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkCorePluginFactory<dtkWidgetsAbstractParameter> {
public:
dtkWidgetsAbstractParameter *create(const QString& key) {
#include <dtkCore>
dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
#include "dtkWidgetsAbstractParameter.h"
if(!widget) {
qWarning() << "The widget with key :" << key << "could not be instanciated by the factory.";
return nullptr;
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterPlugin declaration
// ///////////////////////////////////////////////////////////////////
return widget;
}
class DTKWIDGETS_EXPORT dtkWidgetsParameterPlugin : public dtkCorePluginBase {};
dtkWidgetsAbstractParameter *create(dtkCoreAbstractParameter *parameter, const QString& key) {
Q_DECLARE_METATYPE(dtkWidgetsParameterPlugin *);
Q_DECLARE_INTERFACE(dtkWidgetsParameterPlugin, DTK_DECLARE_PLUGIN_INTERFACE(dtkWidgetsParameterPlugin));
dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterPluginManager declaration
// ///////////////////////////////////////////////////////////////////
if(!widget) {
qWarning() << "The widget with key :" << key << "could not be instanciated by the factory.";
return nullptr;
}
class DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager : public dtkCorePluginManager<dtkWidgetsParameterPlugin> {};
if(!widget->connect(parameter)) {
qWarning() << "The parameter could not be connected to the widget.";
}
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterFactory declaration
// ///////////////////////////////////////////////////////////////////
return widget;
}
class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkCorePluginFactory<dtkWidgetsAbstractParameter>
{
public:
dtkWidgetsAbstractParameter *create(const QString& key);
dtkWidgetsAbstractParameter *create(dtkCoreAbstractParameter *parameter, const QString& key);
};
// /////////////////////////////////////////////////////////////////
// Register to dtkDiscretegeometry layer
// Register to dtkWidgets layer declaration
// /////////////////////////////////////////////////////////////////
namespace dtk {
namespace widgets {
namespace parameters {
DTKWIDGETS_EXPORT dtkWidgetsParameterFactory& pluginFactory();
DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager& pluginManager();
DTKWIDGETS_EXPORT dtkWidgetsParameterFactory& pluginFactory(void);
DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager& pluginManager(void);
}
}
}
//
// dtkWidgetsParameterFactory.h ends here
......@@ -16,7 +16,9 @@
#include <dtkLog>
#include <dtkCoreParameter>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterIntSpinBoxPrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterIntSpinBoxPrivate
{
......@@ -24,6 +26,8 @@ public:
QSpinBox *spin_box = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterIntSpinBox implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterIntSpinBox::dtkWidgetsParameterIntSpinBox(QWidget* parent) : dtkWidgetsParameter<dtk::d_int>(parent), d(new dtkWidgetsParameterIntSpinBoxPrivate)
......@@ -43,31 +47,38 @@ dtkWidgetsParameterIntSpinBox::~dtkWidgetsParameterIntSpinBox(void)
bool dtkWidgetsParameterIntSpinBox::connect(dtkCoreAbstractParameter *p)
{
dtk::d_int *p_int = dynamic_cast<dtk::d_int *>(p);
if(!p_int) {
qWarning() << "The type of the parameter is not compatible with the widget dtkWidgetsParameterIntSpinBox.";
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
d->spin_box->setMinimum(p_int->min());
d->spin_box->setMaximum(p_int->max());
d->spin_box->setToolTip(p_int->documentation());
m_parameter = dynamic_cast<dtk::d_int *>(p);
d->spin_box->setValue(p_int->value());
QObject::connect(p_int, &dtk::d_int::valueChanged, [=] (QVariant v) {
int value = v.value<dtk::d_int>().value();
d->spin_box->blockSignals(true);
d->spin_box->setValue(value);
d->spin_box->blockSignals(false);
});
QObject::connect(d->spin_box, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int v) {
p_int->setValue(v);
});
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterIntSpinBox.";
return false;
}
dtkWidgetsAbstractParameter::m_parameter = p;
d->spin_box->setMinimum(m_parameter->min());
d->spin_box->setMaximum(m_parameter->max());
d->spin_box->setToolTip(m_parameter->documentation());
d->spin_box->setValue(m_parameter->value());
QObject::connect(m_parameter, &dtk::d_int::valueChanged, [=] (QVariant v)
{
int value = v.value<dtk::d_int>().value();
d->spin_box->blockSignals(true);
d->spin_box->setValue(value);
d->spin_box->blockSignals(false);
});
QObject::connect(d->spin_box, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int v)
{
// m_parameter->block(true);
m_parameter->setValue(v);
// m_parameter->block(false);
});
return true;
}
......