dtkWidgetsParameterDoubleSpinBox.cpp 1.64 KB
Newer Older
LE BRETON Come's avatar
LE BRETON Come committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
// Version: $Id$
//
//

// Commentary:
//
//

// Change Log:
//
//

// Code:

#include "dtkWidgetsParameterDoubleSpinBox.h"

#include <dtkLog>

#include <dtkCoreParameter>

class dtkWidgetsParameterDoubleSpinBoxPrivate
{
public:
    QDoubleSpinBox *spin_box = nullptr;
};

// ///////////////////////////////////////////////////////////////////

dtkWidgetsParameterDoubleSpinBox::dtkWidgetsParameterDoubleSpinBox(QWidget* parent) : dtkWidgetsParameterDouble(parent), d(new dtkWidgetsParameterDoubleSpinBoxPrivate)
{
    d->spin_box = new QDoubleSpinBox;

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(d->spin_box);

    this->setLayout(layout);
}

dtkWidgetsParameterDoubleSpinBox::~dtkWidgetsParameterDoubleSpinBox(void)
{
    delete d;
}

44
void dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreAbstractParameter *parameter)
LE BRETON Come's avatar
LE BRETON Come committed
45
{
46
    dtk::d_real *double_parameter = dynamic_cast<dtk::d_real *>(parameter);
LE BRETON Come's avatar
LE BRETON Come committed
47

48 49 50 51 52 53 54 55 56 57
    if(!double_parameter) {
        qWarning() << "Could not connect the parameter to the widget, the parameter is not of type dtk::d_real";
        return;
    }

    d->spin_box->setMinimum(double_parameter->min());
    d->spin_box->setMaximum(double_parameter->max());
    d->spin_box->setToolTip(double_parameter->documentation());

    QObject::connect(double_parameter, &dtk::d_real::valueChanged, [=] (QVariant v) {
LE BRETON Come's avatar
LE BRETON Come committed
58 59 60 61 62
            double value = v.value<dtk::d_real>().value();
            d->spin_box->setValue(value);
        });

    QObject::connect(d->spin_box, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double v) {
63
            double_parameter->setValue(v);
LE BRETON Come's avatar
LE BRETON Come committed
64 65 66 67 68
        });
}

//
// dtkWidgetsParameterDoubleSpinBoxWidget.cpp ends here