Commit 40545bf7 authored by LE BRETON Come's avatar LE BRETON Come

Adds default int spin box and test.

parent 80b2d317
......@@ -60,6 +60,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsOverlayRope.h
dtkWidgetsParameter
dtkWidgetsParameter.h
dtkWidgetsParameterIntSpinBox
dtkWidgetsParameterIntSpinBox.h
dtkWidgetsParameterFactory
dtkWidgetsParameterFactory.h
dtkWidgetsSettings
......@@ -90,6 +92,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsOverlayPaneSlider.cpp
dtkWidgetsOverlayRope.cpp
dtkWidgetsParameter.cpp
dtkWidgetsParameterIntSpinBox.cpp
dtkWidgetsParameterFactory.cpp
dtkWidgetsSettings.cpp
dtkWidgetsStylesheetParser.cpp
......
......@@ -4,6 +4,10 @@
#include <QtCore>
#include "dtkWidgetsParameterIntSpinBox.h"
#include "dtkWidgetsParameterFactory.h"
// /////////////////////////////////////////////////////////////////
// Layer methods implementations
// /////////////////////////////////////////////////////////////////
......@@ -39,7 +43,7 @@ namespace dtk {
// ///////////////////////////////////////////////////////////////////
// Initializes default plugins
// ///////////////////////////////////////////////////////////////////
// dtkWidgets::blabla::pluginFactory().record("blabla", blablaCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSpinBox", dtkWidgetsParameterIntSpinBoxCreator);
}
void setVerboseLoading(bool b)
{
......
#include "dtkWidgetsParameterIntSpinBox.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterIntSpinBox.h"
#include <dtkLog>
#include <dtkCoreParameter>
class dtkWidgetsParameterIntSpinBoxPrivate
{
public:
QSpinBox *spin_box = nullptr;
};
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterIntSpinBox::dtkWidgetsParameterIntSpinBox(QWidget* parent) : dtkWidgetsParameter<dtk::d_int>(parent), d(new dtkWidgetsParameterIntSpinBoxPrivate)
{
d->spin_box = new QSpinBox;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->spin_box);
this->setLayout(layout);
}
dtkWidgetsParameterIntSpinBox::~dtkWidgetsParameterIntSpinBox(void)
{
delete d;
}
void dtkWidgetsParameterIntSpinBox::connect(dtk::d_int *parameter)
{
d->spin_box->setMinimum(parameter->min());
d->spin_box->setMaximum(parameter->max());
d->spin_box->setToolTip(parameter->documentation());
QObject::connect(parameter, &dtk::d_int::valueChanged, [=] (QVariant v) {
int value = v.value<dtk::d_int>().value();
d->spin_box->setValue(value);
});
QObject::connect(d->spin_box, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int v) {
parameter->setValue(v);
});
}
//
// dtkWidgetsParameterIntSpinBoxWidget.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsParameterIntSpinBox : public dtkWidgetsParameter<dtk::d_int>
{
Q_OBJECT
public:
dtkWidgetsParameterIntSpinBox(QWidget* parent = 0);
virtual ~dtkWidgetsParameterIntSpinBox(void);
public:
virtual void connect(dtk::d_int *);
private:
class dtkWidgetsParameterIntSpinBoxPrivate *d;
};
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsAbstractParameter *dtkWidgetsParameterIntSpinBoxCreator(void)
{
return new dtkWidgetsParameterIntSpinBox();
}
//
// dtkWidgetsParameterIntSpinBox.h ends here
......@@ -25,11 +25,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
## ###################################################################
set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterTest.h
dtkWidgetsParametersTest.h
)
set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameterTest.cpp
dtkWidgetsParametersTest.cpp
)
## ###################################################################
......@@ -64,7 +64,7 @@ target_link_libraries(${PROJECT_NAME} Qt5::Test)
## Test rules
## ###################################################################
add_test(dtkWidgetsParameterTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} dtkWidgetsParameterTest)
add_test(dtkWidgetsParametersTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} dtkWidgetsParametersTest)
######################################################################
### CMakeLists.txt ends here
......@@ -13,13 +13,13 @@
// Code:
#include "dtkWidgetsParameterTest.h"
#include "dtkWidgetsParametersTest.h"
#include <dtkWidgetsTest>
#include <dtkCore/dtkCoreParameter>
#include <dtkWidgets/dtkWidgets>
#include <dtkWidgets/dtkWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
#include <dtkWidgets/dtkWidgetsParameterFactory>
......@@ -27,7 +27,7 @@
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterTestCasePrivate
class dtkWidgetsParametersTestCasePrivate
{
};
......@@ -36,7 +36,7 @@ class dtkWidgetsParameterTestCasePrivate
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterTestCase::dtkWidgetsParameterTestCase(void) : d(new dtkWidgetsParameterTestCasePrivate)
dtkWidgetsParametersTestCase::dtkWidgetsParametersTestCase(void) : d(new dtkWidgetsParametersTestCasePrivate)
{
dtkLogger::instance().attachConsole();
dtkLogger::instance().setLevel("trace");
......@@ -45,41 +45,59 @@ dtkWidgetsParameterTestCase::dtkWidgetsParameterTestCase(void) : d(new dtkWidget
dtk::widgets::initialize("");
}
dtkWidgetsParameterTestCase::~dtkWidgetsParameterTestCase(void)
dtkWidgetsParametersTestCase::~dtkWidgetsParametersTestCase(void)
{
delete d;
}
void dtkWidgetsParameterTestCase::initTestCase(void)
void dtkWidgetsParametersTestCase::initTestCase(void)
{
}
void dtkWidgetsParameterTestCase::init(void)
void dtkWidgetsParametersTestCase::init(void)
{
}
void dtkWidgetsParameterTestCase::testBasic(void)
void dtkWidgetsParametersTestCase::testBasic(void)
{
//////////////////// dtkWidgetsParameterDoubleSpinBox ////////////////////
dtk::d_real real_parameter = 0.;
dtkWidgetsAbstractParameter *spin_box = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBox");
Q_ASSERT(spin_box);
//////////////////// dtkWidgetsParameterIntSpinBox ////////////////////
dtk::d_int int_parameter = 0.;
dtkWidgetsAbstractParameter *int_spin_box = dtk::widgets::parameters::pluginFactory().create(&int_parameter, "dtkWidgetsParameterIntSpinBox");
Q_ASSERT(spin_box);
dtk::d_real wrong_type_parameter = 0.;
dtkWidgetsAbstractParameter *wrong_type_parameter_spin_box = dtk::widgets::parameters::pluginFactory().create(&wrong_type_parameter, "dtkWidgetsParameterIntSpinBox");
Q_ASSERT(wrong_type_parameter_spin_box == nullptr);
//////////////////// ////////////////////
}
void dtkWidgetsParameterTestCase::cleanup(void)
void dtkWidgetsParametersTestCase::cleanup(void)
{
}
void dtkWidgetsParameterTestCase::cleanupTestCase(void)
void dtkWidgetsParametersTestCase::cleanupTestCase(void)
{
}
DTKWIDGETSTEST_MAIN(dtkWidgetsParameterTest, dtkWidgetsParameterTestCase)
DTKWIDGETSTEST_MAIN(dtkWidgetsParametersTest, dtkWidgetsParametersTestCase)
//
// dtkWidgetsParameterTest.cpp ends here
// dtkWidgetsParametersTest.cpp ends here
......@@ -16,13 +16,13 @@
#include <dtkWidgetsTest>
class dtkWidgetsParameterTestCase : public QObject
class dtkWidgetsParametersTestCase : public QObject
{
Q_OBJECT
public:
dtkWidgetsParameterTestCase(void);
~dtkWidgetsParameterTestCase(void);
dtkWidgetsParametersTestCase(void);
~dtkWidgetsParametersTestCase(void);
private slots:
void initTestCase(void);
......@@ -36,8 +36,8 @@ private slots:
void cleanup(void);
private:
class dtkWidgetsParameterTestCasePrivate *d;
class dtkWidgetsParametersTestCasePrivate *d;
};
//
// dtkWidgetsParameterTest.h ends here
// dtkWidgetsParametersTest.h ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment