Commit 6f590f96 authored by CABEL Tristan's avatar CABEL Tristan

add long long spin box

parent 986bdecc
...@@ -54,6 +54,14 @@ int main(int argc, char **argv) ...@@ -54,6 +54,14 @@ int main(int argc, char **argv)
printf("scientific_parameter(XXX) = %.12f\n", value); printf("scientific_parameter(XXX) = %.12f\n", value);
}); });
dtk::d_int longlong_parameter("A long long parameter", 666, 665, 800); // doc, value, min, max, decimals
dtkWidgetsParameter *longlong_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&longlong_parameter, "dtkWidgetsParameterLongLongSpinBox");
longlong_parameter.connect([=] (QVariant v) {
long long value = v.value<dtk::d_int>().value();
printf("longlong_parameter(XXX) = %lld\n", value);
});
QList<QString> available_strings; QList<QString> available_strings;
available_strings.append("FirstString"); available_strings.append("FirstString");
available_strings.append("SecondString"); available_strings.append("SecondString");
...@@ -93,6 +101,8 @@ int main(int argc, char **argv) ...@@ -93,6 +101,8 @@ int main(int argc, char **argv)
central_layout->addWidget(new QSplitter); central_layout->addWidget(new QSplitter);
central_layout->addWidget(scientific_parameter_widget); central_layout->addWidget(scientific_parameter_widget);
central_layout->addWidget(new QSplitter); central_layout->addWidget(new QSplitter);
central_layout->addWidget(longlong_parameter_widget);
central_layout->addWidget(new QSplitter);
central_layout->addWidget(inliststring_parameter_widget); central_layout->addWidget(inliststring_parameter_widget);
central_layout->addWidget(new QSplitter); central_layout->addWidget(new QSplitter);
central_layout->addWidget(bool_parameter_widget); central_layout->addWidget(bool_parameter_widget);
......
...@@ -88,6 +88,8 @@ set(${PROJECT_NAME}_HEADERS ...@@ -88,6 +88,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterIntSlider.h dtkWidgetsParameterIntSlider.h
dtkWidgetsParameterIntSpinBox dtkWidgetsParameterIntSpinBox
dtkWidgetsParameterIntSpinBox.h dtkWidgetsParameterIntSpinBox.h
dtkWidgetsParameterLongLongSpinBox
dtkWidgetsParameterLongLongSpinBox.h
dtkWidgetsParameterMenuBarGenerator dtkWidgetsParameterMenuBarGenerator
dtkWidgetsParameterMenuBarGenerator.h dtkWidgetsParameterMenuBarGenerator.h
dtkWidgetsParameterScientificSpinBox dtkWidgetsParameterScientificSpinBox
...@@ -99,6 +101,7 @@ set(${PROJECT_NAME}_HEADERS ...@@ -99,6 +101,7 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsSettings dtkWidgetsSettings
dtkWidgetsSettings.h dtkWidgetsSettings.h
dtkWidgetsSpinBoxDouble.h dtkWidgetsSpinBoxDouble.h
dtkWidgetsSpinBoxLong.h
dtkWidgetsWidget dtkWidgetsWidget
dtkWidgetsWidget.h dtkWidgetsWidget.h
dtkWidgetsWorkspace dtkWidgetsWorkspace
...@@ -139,17 +142,19 @@ set(${PROJECT_NAME}_SOURCES ...@@ -139,17 +142,19 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameterBoolPushButton.cpp dtkWidgetsParameterBoolPushButton.cpp
dtkWidgetsParameterDirBrowse.cpp dtkWidgetsParameterDirBrowse.cpp
dtkWidgetsParameterDoubleSpinBox.cpp dtkWidgetsParameterDoubleSpinBox.cpp
dtkWidgetsParameterIntSlider.cpp
dtkWidgetsParameterIntSpinBox.cpp
dtkWidgetsParameterFactory.cpp dtkWidgetsParameterFactory.cpp
dtkWidgetsParameterFileBrowse.cpp dtkWidgetsParameterFileBrowse.cpp
dtkWidgetsParameterFileSave.cpp dtkWidgetsParameterFileSave.cpp
dtkWidgetsParameterIntSlider.cpp
dtkWidgetsParameterIntSpinBox.cpp
dtkWidgetsParameterLongLongSpinBox.cpp
dtkWidgetsParameterMenuBarGenerator.cpp dtkWidgetsParameterMenuBarGenerator.cpp
dtkWidgetsParameterScientificSpinBox.cpp dtkWidgetsParameterScientificSpinBox.cpp
dtkWidgetsParameterStringLineEdit.cpp dtkWidgetsParameterStringLineEdit.cpp
dtkWidgetsParameterStringListComboBox.cpp dtkWidgetsParameterStringListComboBox.cpp
dtkWidgetsSettings.cpp dtkWidgetsSettings.cpp
dtkWidgetsSpinBoxDouble.cpp dtkWidgetsSpinBoxDouble.cpp
dtkWidgetsSpinBoxLong.cpp
dtkWidgetsWidget.cpp dtkWidgetsWidget.cpp
dtkWidgetsWorkspace.cpp dtkWidgetsWorkspace.cpp
dtkWidgetsWorkspaceBar.cpp dtkWidgetsWorkspaceBar.cpp
......
...@@ -22,13 +22,14 @@ ...@@ -22,13 +22,14 @@
#include "dtkWidgetsParameterBoolCheckBox.h" #include "dtkWidgetsParameterBoolCheckBox.h"
#include "dtkWidgetsParameterBoolPushButton.h" #include "dtkWidgetsParameterBoolPushButton.h"
#include "dtkWidgetsParameterDoubleSpinBox.h"
#include "dtkWidgetsParameterScientificSpinBox.h"
#include "dtkWidgetsParameterDirBrowse.h" #include "dtkWidgetsParameterDirBrowse.h"
#include "dtkWidgetsParameterDoubleSpinBox.h"
#include "dtkWidgetsParameterFileBrowse.h" #include "dtkWidgetsParameterFileBrowse.h"
#include "dtkWidgetsParameterFileSave.h" #include "dtkWidgetsParameterFileSave.h"
#include "dtkWidgetsParameterIntSlider.h" #include "dtkWidgetsParameterIntSlider.h"
#include "dtkWidgetsParameterIntSpinBox.h" #include "dtkWidgetsParameterIntSpinBox.h"
#include "dtkWidgetsParameterLongLongSpinBox.h"
#include "dtkWidgetsParameterScientificSpinBox.h"
#include "dtkWidgetsParameterStringLineEdit.h" #include "dtkWidgetsParameterStringLineEdit.h"
#include "dtkWidgetsParameterStringListComboBox.h" #include "dtkWidgetsParameterStringListComboBox.h"
...@@ -75,11 +76,12 @@ namespace dtk { ...@@ -75,11 +76,12 @@ namespace dtk {
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterBoolPushButton", dtkWidgetsParameterBoolPushButtonCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterBoolPushButton", dtkWidgetsParameterBoolPushButtonCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterDirBrowse", dtkWidgetsParameterDirBrowseCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterDirBrowse", dtkWidgetsParameterDirBrowseCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterDoubleSpinBox", dtkWidgetsParameterDoubleSpinBoxCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterDoubleSpinBox", dtkWidgetsParameterDoubleSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterScientificSpinBox", dtkWidgetsParameterScientificSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSlider", dtkWidgetsParameterIntSliderCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSlider", dtkWidgetsParameterIntSliderCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSpinBox", dtkWidgetsParameterIntSpinBoxCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSpinBox", dtkWidgetsParameterIntSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterFileBrowse", dtkWidgetsParameterFileBrowseCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterFileBrowse", dtkWidgetsParameterFileBrowseCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterFileSave", dtkWidgetsParameterFileSaveCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterFileSave", dtkWidgetsParameterFileSaveCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterLongLongSpinBox", dtkWidgetsParameterLongLongSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterScientificSpinBox", dtkWidgetsParameterScientificSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringLineEdit", dtkWidgetsParameterStringLineEditCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringLineEdit", dtkWidgetsParameterStringLineEditCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringListComboBox", dtkWidgetsParameterStringListComboBoxCreator); dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringListComboBox", dtkWidgetsParameterStringListComboBoxCreator);
} }
......
...@@ -56,7 +56,7 @@ bool dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreParameter *p) ...@@ -56,7 +56,7 @@ bool dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreParameter *p)
m_parameter = dynamic_cast<dtk::d_real *>(p); m_parameter = dynamic_cast<dtk::d_real *>(p);
if(!m_parameter) { if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterIntSpinBox."; qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterDoubleSpinBox.";
return false; return false;
} }
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterLongLongSpinBox.h"
#include "dtkWidgetsSpinBoxLong.h"
#include <dtkLog>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterLongLongSpinBoxPrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterLongLongSpinBoxPrivate
{
public:
dtkWidgetsSpinBoxLong *spin_box = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterLongLongSpinBox implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterLongLongSpinBox::dtkWidgetsParameterLongLongSpinBox(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_int>(parent), d(new dtkWidgetsParameterLongLongSpinBoxPrivate)
{
d->spin_box = new dtkWidgetsSpinBoxLong();
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->spin_box);
this->setLayout(layout);
}
dtkWidgetsParameterLongLongSpinBox::~dtkWidgetsParameterLongLongSpinBox(void)
{
delete d;
}
bool dtkWidgetsParameterLongLongSpinBox::connect(dtkCoreParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_int *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterLongLongSpinBox.";
return false;
}
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());
m_parameter->connect([=] (QVariant v)
{
long long 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<long long>::of(&dtkWidgetsSpinBoxLong::valueChanged), [=] (long long v)
{
m_parameter->setValue(v);
});
return true;
}
//
// dtkWidgetsParameterLongLongSpinBoxWidget.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include <QtWidgets>
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
class DTKWIDGETS_EXPORT dtkWidgetsParameterLongLongSpinBox : public dtkWidgetsParameterBase<dtk::d_int>
{
Q_OBJECT
public:
dtkWidgetsParameterLongLongSpinBox(QWidget* parent = 0);
~dtkWidgetsParameterLongLongSpinBox(void);
public:
bool connect(dtkCoreParameter *) override;
private:
using dtkWidgetsParameterBase<dtk::d_int>::m_parameter;
class dtkWidgetsParameterLongLongSpinBoxPrivate *d;
};
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsParameter *dtkWidgetsParameterLongLongSpinBoxCreator(void)
{
return new dtkWidgetsParameterLongLongSpinBox();
}
//
// dtkWidgetsParameterLongLongSpinBox.h ends here
...@@ -198,6 +198,9 @@ void dtkWidgetsSpinBoxDouble::stepDown(void) ...@@ -198,6 +198,9 @@ void dtkWidgetsSpinBoxDouble::stepDown(void)
else else
d->value -= 1.0; d->value -= 1.0;
if(d->value < d->minimum)
d->value = d->minimum;
d->touch(); d->touch();
} }
...@@ -208,6 +211,9 @@ void dtkWidgetsSpinBoxDouble::stepUp(void) ...@@ -208,6 +211,9 @@ void dtkWidgetsSpinBoxDouble::stepUp(void)
else else
d->value += 1.0; d->value += 1.0;
if(d->value > d->maximum)
d->value = d->maximum;
d->touch(); d->touch();
} }
......
...@@ -37,7 +37,7 @@ signals: ...@@ -37,7 +37,7 @@ signals:
void valueChanged(double); void valueChanged(double);
public: public:
void stepBy(int); void stepBy(int) override;
void stepDown(void); void stepDown(void);
void stepUp(void); void stepUp(void);
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
void setDecimals(int); void setDecimals(int);
protected: protected:
QAbstractSpinBox::StepEnabled stepEnabled(void) const; QAbstractSpinBox::StepEnabled stepEnabled(void) const override;
private: private:
class dtkWidgetsSpinBoxDoublePrivate *d; class dtkWidgetsSpinBoxDoublePrivate *d;
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsSpinBoxLong.h"
class dtkWidgetsSpinBoxLongPrivate : public QObject
{
Q_OBJECT
public slots:
void update();
void touch();
public:
long long value;
long long minimum;
long long maximum;
QValidator *validator;
public:
QString textFromValue ( long long ) const;
long long valueFromText ( const QString& ) const;
QValidator::State validate(QString&, int&) const;
public:
dtkWidgetsSpinBoxLong *q;
};
void dtkWidgetsSpinBoxLongPrivate::update(void)
{
this->value = valueFromText( q->text());
this->touch();
}
void dtkWidgetsSpinBoxLongPrivate::touch()
{
q->emit valueChanged(this->value);
}
QString dtkWidgetsSpinBoxLongPrivate::textFromValue ( long long value ) const
{
QString strValue;
if (value < this->minimum)
value = this->minimum;
if (value > this->maximum)
value = this->maximum;
return QString::number(value);
}
long long dtkWidgetsSpinBoxLongPrivate::valueFromText ( const QString & text ) const
{
long long val = text.toLongLong();
if (val < this->minimum)
val = this->minimum;
if (val > this->maximum)
val = this->maximum;
q->setValue(val);
return val;
}
QValidator::State dtkWidgetsSpinBoxLongPrivate::validate(QString &text, int &pos) const
{
// check user input
bool input_check;
text.toLongLong(&input_check);
return (input_check ? QValidator::Acceptable : QValidator::Invalid);
}
///
dtkWidgetsSpinBoxLong::dtkWidgetsSpinBoxLong(QWidget *parent) : QAbstractSpinBox(parent)
{
d = new dtkWidgetsSpinBoxLongPrivate;
d->q = this;
this->setLocale(QLocale::C);
d->value = 0.0;
QRegExp rx("-?\\d{1,18}");
d->validator = new QRegExpValidator(rx, this);
d->maximum = std::numeric_limits<long long>::max();
d->minimum = std::numeric_limits<long long>::lowest();
this->setReadOnly(false);
this->setButtonSymbols(QAbstractSpinBox::PlusMinus);
this->setCorrectionMode(QAbstractSpinBox::CorrectToPreviousValue);
this->setKeyboardTracking(true);
this->lineEdit()->setValidator(d->validator);
this->lineEdit()->setReadOnly(false);
connect(this,
SIGNAL(editingFinished()),
d,
SLOT(update()));
}
dtkWidgetsSpinBoxLong::~dtkWidgetsSpinBoxLong(void)
{
delete d->validator;
delete d;
}
void dtkWidgetsSpinBoxLong::stepBy(int step)
{
if (step == 0 ) {
return;
}
if (step < 0) {
int i = step;
while ( i < 0 ) {
stepDown();
i++;
}
}
else {
int i = step;
while ( i > 0) {
stepUp();
i--;
}
}
}
void dtkWidgetsSpinBoxLong::stepDown(void)
{
if(d->value > d->minimum) {
--d->value;
d->touch();
}
}
void dtkWidgetsSpinBoxLong::stepUp(void)
{
if(d->value < d->maximum) {
++d->value;
d->touch();
}
}
void dtkWidgetsSpinBoxLong::setMinimum(long long min)
{
d->minimum = min;
}
void dtkWidgetsSpinBoxLong::setMaximum(long long max)
{
d->maximum = max;
}
void dtkWidgetsSpinBoxLong::setValue(long long val)
{
d->value = val;
this->lineEdit()->blockSignals(true);
this->lineEdit()->setText(d->textFromValue(val));
this->lineEdit()->blockSignals(false);
}
QAbstractSpinBox::StepEnabled dtkWidgetsSpinBoxLong::stepEnabled(void) const
{
return ( QAbstractSpinBox::StepUpEnabled | QAbstractSpinBox::StepDownEnabled ) ;
}
#include "dtkWidgetsSpinBoxLong.moc"
//
// dtkWidgetsSpinBoxLong.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <QtWidgets>
class dtkWidgetsSpinBoxLong : public QAbstractSpinBox
{
Q_OBJECT
public:
dtkWidgetsSpinBoxLong(QWidget * parent = 0);
~dtkWidgetsSpinBoxLong(void);
signals:
void valueChanged(long long);
public:
void stepBy(int) override;
void stepDown(void);
void stepUp(void);
void setMinimum(long long);
void setMaximum(long long);
void setValue(long long);
protected:
QAbstractSpinBox::StepEnabled stepEnabled(void) const override;
private:
class dtkWidgetsSpinBoxLongPrivate *d;
};
//
// dtkWidgetsSpinBoxLong.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