Added separate class for text, vector, checkbox, slider
This commit is contained in:
parent
b4d418ac64
commit
05a9af0928
15 changed files with 258 additions and 19 deletions
|
|
@ -1,10 +1,10 @@
|
|||
@Description("The resolution of the curves. Higher values give smoother curves but may increase the model render time.")
|
||||
@Parameter()
|
||||
@Parameter([10, 20, 30, 50, 100])
|
||||
resolution = 30;
|
||||
|
||||
@Description("The horizontal radius of the outer ellipse of the sign.")
|
||||
@Parameter([60: 200])
|
||||
radius = 100;
|
||||
@Parameter([60 : 200])
|
||||
radius = 80;
|
||||
|
||||
@Parameter([1 : 10])
|
||||
@Description("Total height of the sign")
|
||||
|
|
|
|||
12
openscad.pro
12
openscad.pro
|
|
@ -342,7 +342,11 @@ HEADERS += src/typedefs.h \
|
|||
src/parameterextractor.h \
|
||||
src/parametervirtualwidget.h \
|
||||
src/parameterspinbox.h \
|
||||
src/parametercombobox.h
|
||||
src/parametercombobox.h \
|
||||
src/parameterslider.h \
|
||||
src/parametercheckbox.h \
|
||||
src/parametertext.h \
|
||||
src/parametervector.h
|
||||
|
||||
SOURCES += src/version_check.cc \
|
||||
src/ProgressWidget.cc \
|
||||
|
|
@ -459,7 +463,11 @@ SOURCES += src/version_check.cc \
|
|||
src/parameterextractor.cpp \
|
||||
src/parametervirtualwidget.cpp \
|
||||
src/parameterspinbox.cpp \
|
||||
src/parametercombobox.cpp
|
||||
src/parametercombobox.cpp \
|
||||
src/parameterslider.cpp \
|
||||
src/parametercheckbox.cpp \
|
||||
src/parametertext.cpp \
|
||||
src/parametervector.cpp
|
||||
|
||||
# ClipperLib
|
||||
SOURCES += src/polyclipping/clipper.cpp
|
||||
|
|
|
|||
|
|
@ -26,8 +26,14 @@
|
|||
#include <QWidget>
|
||||
|
||||
#include "ParameterWidget.h"
|
||||
|
||||
#include "parameterspinbox.h"
|
||||
#include "parametercombobox.h"
|
||||
#include "parameterslider.h"
|
||||
#include "parametercheckbox.h"
|
||||
#include "parametertext.h"
|
||||
#include "parametervector.h"
|
||||
|
||||
#include "module.h"
|
||||
#include "modcontext.h"
|
||||
#include "expression.h"
|
||||
|
|
@ -100,17 +106,32 @@ void ParameterWidget::connectWidget()
|
|||
switch (it->second->target) {
|
||||
case 1:{
|
||||
entry = new ParameterComboBox(it->second);
|
||||
connect(entry, SIGNAL(changed()), this, SLOT(onValueChanged()));
|
||||
addEntry(entry);
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
entry = new ParameterSlider(it->second);
|
||||
break;
|
||||
}
|
||||
case 5:{
|
||||
entry = new ParameterSpinBox(it->second);
|
||||
connect(entry, SIGNAL(changed()), this, SLOT(onValueChanged()));
|
||||
addEntry(entry);
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:{
|
||||
entry = new ParameterCheckBox(it->second);
|
||||
break;
|
||||
}
|
||||
case 4:{
|
||||
entry = new ParameterText(it->second);
|
||||
break;
|
||||
}
|
||||
case 5:{
|
||||
entry = new ParameterSpinBox(it->second);
|
||||
break;
|
||||
}
|
||||
case 6:{
|
||||
entry = new ParameterVector(it->second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(it->second->target!=0){
|
||||
connect(entry, SIGNAL(changed()), this, SLOT(onValueChanged()));
|
||||
addEntry(entry);
|
||||
}
|
||||
}
|
||||
end();
|
||||
|
|
|
|||
18
src/parametercheckbox.cpp
Normal file
18
src/parametercheckbox.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include "parametercheckbox.h"
|
||||
|
||||
ParameterCheckBox::ParameterCheckBox(ParameterObject *parameterobject)
|
||||
{
|
||||
object=parameterobject;
|
||||
set();
|
||||
connect(checkBox,SIGNAL(clicked()),this,SLOT(on_Changed()));
|
||||
}
|
||||
|
||||
void ParameterCheckBox::on_Changed(){
|
||||
object->value = ValuePtr(checkBox->isChecked());
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterCheckBox::setValue(){
|
||||
this->stackedWidget->setCurrentWidget(this->pageCheckBox);
|
||||
this->checkBox->setChecked(object->value->toBool());
|
||||
}
|
||||
18
src/parametercheckbox.h
Normal file
18
src/parametercheckbox.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PARAMETERCHECKBOX_H
|
||||
#define PARAMETERCHECKBOX_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
#include "parameterobject.h"
|
||||
|
||||
class ParameterCheckBox : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterCheckBox(ParameterObject *parameterobject);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed();
|
||||
};
|
||||
|
||||
#endif // PARAMETERCHECKBOX_H
|
||||
25
src/parameterslider.cpp
Normal file
25
src/parameterslider.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "parameterslider.h"
|
||||
|
||||
ParameterSlider::ParameterSlider(ParameterObject *parameterobject)
|
||||
{
|
||||
object=parameterobject;
|
||||
set();
|
||||
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(on_Changed(int)));
|
||||
}
|
||||
void ParameterSlider::on_Changed(int)
|
||||
{
|
||||
double v = slider->value();
|
||||
object->value = ValuePtr(v);
|
||||
//to be corrected
|
||||
this->labelSliderValue->setText(QString::number(v, 'f', 0));
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterSlider::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageSlider);
|
||||
this->slider->setMaximum(object->values->toRange().end_value());
|
||||
this->slider->setValue(object->value->toDouble());
|
||||
this->slider->setMinimum(object->values->toRange().begin_value());
|
||||
this->labelSliderValue->setText(QString::number(object->value->toDouble(), 'f', 0));
|
||||
}
|
||||
18
src/parameterslider.h
Normal file
18
src/parameterslider.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PARAMETERSLIDER_H
|
||||
#define PARAMETERSLIDER_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
#include "parameterobject.h"
|
||||
|
||||
class ParameterSlider : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterSlider(ParameterObject *parameterobject);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed(int);
|
||||
};
|
||||
|
||||
#endif // PARAMETERSLIDER_H
|
||||
|
|
@ -3,10 +3,8 @@
|
|||
ParameterSpinBox::ParameterSpinBox(ParameterObject *parameterobject)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
setDescription(QString::fromStdString(object->descritpion));
|
||||
set();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
}
|
||||
|
||||
void ParameterSpinBox::on_Changed(double){
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class ParameterSpinBox :public ParameterVirtualWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterSpinBox(ParameterObject *parameterobject );
|
||||
ParameterSpinBox(ParameterObject *parameterobject);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
|
|
|
|||
28
src/parametertext.cpp
Normal file
28
src/parametertext.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "parametertext.h"
|
||||
|
||||
ParameterText::ParameterText(ParameterObject *parameterobject)
|
||||
{
|
||||
object=parameterobject;
|
||||
set();
|
||||
connect(lineEdit,SIGNAL(editingFinished()),this,SLOT(on_Changed()));
|
||||
}
|
||||
|
||||
void ParameterText::on_Changed()
|
||||
{
|
||||
if (object->dvt == Value::NUMBER) {
|
||||
try {
|
||||
object->value = ValuePtr(boost::lexical_cast<double>(lineEdit->text().toStdString()));
|
||||
} catch (const boost::bad_lexical_cast& e) {
|
||||
lineEdit->setText(QString::fromStdString(object->defaultValue->toString()));
|
||||
}
|
||||
} else {
|
||||
object->value = ValuePtr(lineEdit->text().toStdString());
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterText::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageText);
|
||||
this->lineEdit->setText(QString::fromStdString(object->defaultValue->toString()));
|
||||
}
|
||||
18
src/parametertext.h
Normal file
18
src/parametertext.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PARAMETERTEXT_H
|
||||
#define PARAMETERTEXT_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
#include "parameterobject.h"
|
||||
|
||||
class ParameterText : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterText(ParameterObject *parameterobject);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed();
|
||||
};
|
||||
|
||||
#endif // PARAMETERTEXT_H
|
||||
63
src/parametervector.cpp
Normal file
63
src/parametervector.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#include "parametervector.h"
|
||||
|
||||
ParameterVector::ParameterVector(ParameterObject *parameterobject)
|
||||
{
|
||||
object=parameterobject;
|
||||
set();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
connect(doubleSpinBox2,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
connect(doubleSpinBox3,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
connect(doubleSpinBox4,SIGNAL(valueChanged(double)),this,SLOT(on_Changed(double)));
|
||||
}
|
||||
|
||||
void ParameterVector::on_Changed(double)
|
||||
{
|
||||
if (object->target == 5) {
|
||||
object->value = ValuePtr(doubleSpinBox1->value());
|
||||
} else {
|
||||
Value::VectorType vt;
|
||||
vt.push_back(this->doubleSpinBox1->value());
|
||||
if (!this->doubleSpinBox2->isReadOnly()) {
|
||||
vt.push_back(this->doubleSpinBox2->value());
|
||||
}
|
||||
if (!this->doubleSpinBox3->isReadOnly()) {
|
||||
vt.push_back(this->doubleSpinBox3->value());
|
||||
}
|
||||
if (!this->doubleSpinBox4->isReadOnly()) {
|
||||
vt.push_back(this->doubleSpinBox4->value());
|
||||
}
|
||||
object->value = ValuePtr(vt);
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterVector::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
Value::VectorType vec = object->defaultValue->toVector();
|
||||
if (vec.size() < 4) {
|
||||
this->doubleSpinBox4->hide();
|
||||
this->doubleSpinBox4->setReadOnly(true);
|
||||
}
|
||||
if (vec.size() < 3) {
|
||||
this->doubleSpinBox3->hide();
|
||||
this->doubleSpinBox3->setReadOnly(true);
|
||||
}
|
||||
if (vec.size() < 2) {
|
||||
this->doubleSpinBox2->hide();
|
||||
this->doubleSpinBox2->setReadOnly(true);
|
||||
}
|
||||
this->doubleSpinBox1->setValue(vec.at(0)->toDouble());
|
||||
if (vec.size() > 1) {
|
||||
this->doubleSpinBox2->setValue(vec.at(1)->toDouble());
|
||||
this->doubleSpinBox2->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 2) {
|
||||
this->doubleSpinBox3->setValue(vec.at(2)->toDouble());
|
||||
this->doubleSpinBox3->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 3) {
|
||||
this->doubleSpinBox4->setValue(vec.at(3)->toDouble());
|
||||
this->doubleSpinBox4->setReadOnly(false);
|
||||
}
|
||||
}
|
||||
17
src/parametervector.h
Normal file
17
src/parametervector.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef PARAMETERVECTOR_H
|
||||
#define PARAMETERVECTOR_H
|
||||
|
||||
#include"parametervirtualwidget.h"
|
||||
|
||||
class ParameterVector : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterVector(ParameterObject *parameterobject);
|
||||
void setValue();
|
||||
|
||||
protected slots:
|
||||
void on_Changed(double);
|
||||
};
|
||||
|
||||
#endif // PARAMETERVECTOR_H
|
||||
|
|
@ -33,3 +33,9 @@ void ParameterVirtualWidget::setDescription(const QString& description)
|
|||
this->labelDescription->show();
|
||||
this->labelDescription->setText(description);
|
||||
}
|
||||
|
||||
void ParameterVirtualWidget::set(){
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
setDescription(QString::fromStdString(object->descritpion));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ signals:
|
|||
void changed();
|
||||
|
||||
protected:
|
||||
void set();
|
||||
void setName(const QString& name);
|
||||
virtual void setValue()=0;
|
||||
void setDescription(const QString& description);
|
||||
|
|
|
|||
Loading…
Reference in a new issue