coding style
This commit is contained in:
parent
fa2d711244
commit
498a5c3186
17 changed files with 406 additions and 416 deletions
|
|
@ -2,74 +2,76 @@
|
|||
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
GroupWidget::GroupWidget(bool &show, const QString & title, const int animationDuration, QWidget *parent) : QWidget(parent), animationDuration(animationDuration) {
|
||||
toggleButton.setStyleSheet("QToolButton { border: none; }");
|
||||
toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
toggleButton.setText(title);
|
||||
toggleButton.setCheckable(true);
|
||||
|
||||
headerLine.setFrameShape(QFrame::HLine);
|
||||
headerLine.setFrameShadow(QFrame::Sunken);
|
||||
headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
|
||||
contentArea.setStyleSheet("QScrollArea { background-color: white; border: none; }");
|
||||
contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
// start out collapsed
|
||||
contentArea.setMaximumHeight(0);
|
||||
contentArea.setMinimumHeight(0);
|
||||
// let the entire widget grow and shrink with its content
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight"));
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(this, "maximumHeight"));
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(&contentArea, "maximumHeight"));
|
||||
|
||||
this->show=&show;
|
||||
toggleButton.setChecked(show);
|
||||
|
||||
// don't waste space
|
||||
mainLayout.setVerticalSpacing(0);
|
||||
mainLayout.setContentsMargins(0, 0, 0, 0);
|
||||
int row = 0;
|
||||
mainLayout.addWidget(&toggleButton, row, 0, 1, 1, Qt::AlignLeft);
|
||||
mainLayout.addWidget(&headerLine, row++, 2, 1, 1);
|
||||
mainLayout.addWidget(&contentArea, row, 0, 1, 3);
|
||||
setLayout(&mainLayout);
|
||||
QObject::connect(&toggleButton, SIGNAL(toggled(bool)),this, SLOT(onclicked(bool)));
|
||||
GroupWidget::GroupWidget(bool &show, const QString & title, const int animationDuration, QWidget *parent) : QWidget(parent), animationDuration(animationDuration)
|
||||
{
|
||||
toggleButton.setStyleSheet("QToolButton { border: none; }");
|
||||
toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
toggleButton.setText(title);
|
||||
toggleButton.setCheckable(true);
|
||||
|
||||
headerLine.setFrameShape(QFrame::HLine);
|
||||
headerLine.setFrameShadow(QFrame::Sunken);
|
||||
headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
|
||||
contentArea.setStyleSheet("QScrollArea { background-color: white; border: none; }");
|
||||
contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
// start out collapsed
|
||||
contentArea.setMaximumHeight(0);
|
||||
contentArea.setMinimumHeight(0);
|
||||
// let the entire widget grow and shrink with its content
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight"));
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(this, "maximumHeight"));
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(&contentArea, "maximumHeight"));
|
||||
|
||||
this->show = &show;
|
||||
toggleButton.setChecked(show);
|
||||
|
||||
// don't waste space
|
||||
mainLayout.setVerticalSpacing(0);
|
||||
mainLayout.setContentsMargins(0, 0, 0, 0);
|
||||
int row = 0;
|
||||
mainLayout.addWidget(&toggleButton, row, 0, 1, 1, Qt::AlignLeft);
|
||||
mainLayout.addWidget(&headerLine, row++, 2, 1, 1);
|
||||
mainLayout.addWidget(&contentArea, row, 0, 1, 3);
|
||||
setLayout(&mainLayout);
|
||||
QObject::connect(&toggleButton, SIGNAL(toggled(bool)),this, SLOT(onclicked(bool)));
|
||||
}
|
||||
|
||||
|
||||
void GroupWidget::onclicked(const bool checked){
|
||||
toggleButton.setArrowType(toggleButton.isChecked() ? Qt::DownArrow : Qt::RightArrow);
|
||||
toggleAnimation.setDirection(toggleButton.isChecked() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
|
||||
toggleAnimation.start();
|
||||
if(toggleButton.isChecked()){
|
||||
*(this->show)=true;
|
||||
}else{
|
||||
*(this->show)=false;
|
||||
}
|
||||
this->animationDuration=300;
|
||||
}
|
||||
|
||||
void GroupWidget::setContentLayout(QLayout & contentLayout) {
|
||||
delete contentArea.layout();
|
||||
contentArea.setLayout(&contentLayout);
|
||||
const int collapsedHeight = sizeHint().height() - contentArea.maximumHeight();
|
||||
int contentHeight = contentLayout.sizeHint().height();
|
||||
for (int i = 0; i < toggleAnimation.animationCount() - 1; ++i) {
|
||||
QPropertyAnimation * GroupWidgetAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(i));
|
||||
GroupWidgetAnimation->setDuration(animationDuration);
|
||||
GroupWidgetAnimation->setStartValue(collapsedHeight);
|
||||
GroupWidgetAnimation->setEndValue(collapsedHeight + contentHeight);
|
||||
}
|
||||
QPropertyAnimation * contentAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(toggleAnimation.animationCount() - 1));
|
||||
contentAnimation->setDuration(animationDuration);
|
||||
contentAnimation->setStartValue(0);
|
||||
contentAnimation->setEndValue(contentHeight);
|
||||
|
||||
if(*(this->show)){
|
||||
toggleButton.setArrowType(Qt::DownArrow);
|
||||
toggleAnimation.start();
|
||||
}else{
|
||||
toggleButton.setArrowType(Qt::RightArrow);
|
||||
}
|
||||
|
||||
void GroupWidget::onclicked(const bool checked)
|
||||
{
|
||||
toggleButton.setArrowType(toggleButton.isChecked() ? Qt::DownArrow : Qt::RightArrow);
|
||||
toggleAnimation.setDirection(toggleButton.isChecked() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
|
||||
toggleAnimation.start();
|
||||
if (toggleButton.isChecked()) {
|
||||
*(this->show) = true;
|
||||
} else {
|
||||
*(this->show) = false;
|
||||
}
|
||||
this->animationDuration = 300;
|
||||
}
|
||||
|
||||
void GroupWidget::setContentLayout(QLayout & contentLayout)
|
||||
{
|
||||
delete contentArea.layout();
|
||||
contentArea.setLayout(&contentLayout);
|
||||
const int collapsedHeight = sizeHint().height() - contentArea.maximumHeight();
|
||||
int contentHeight = contentLayout.sizeHint().height();
|
||||
for (int i = 0; i < toggleAnimation.animationCount() - 1; ++i) {
|
||||
QPropertyAnimation * GroupWidgetAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(i));
|
||||
GroupWidgetAnimation->setDuration(animationDuration);
|
||||
GroupWidgetAnimation->setStartValue(collapsedHeight);
|
||||
GroupWidgetAnimation->setEndValue(collapsedHeight + contentHeight);
|
||||
}
|
||||
QPropertyAnimation * contentAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(toggleAnimation.animationCount() - 1));
|
||||
contentAnimation->setDuration(animationDuration);
|
||||
contentAnimation->setStartValue(0);
|
||||
contentAnimation->setEndValue(contentHeight);
|
||||
|
||||
if (*(this->show)) {
|
||||
toggleButton.setArrowType(Qt::DownArrow);
|
||||
toggleAnimation.start();
|
||||
} else {
|
||||
toggleButton.setArrowType(Qt::RightArrow);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,26 +8,26 @@
|
|||
#include <QWidget>
|
||||
#include <vector>
|
||||
|
||||
struct groupInst{
|
||||
std::vector<std::string> parameterVector;
|
||||
bool show;
|
||||
struct groupInst {
|
||||
std::vector<std::string> parameterVector;
|
||||
bool show;
|
||||
};
|
||||
|
||||
class GroupWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
QGridLayout mainLayout;
|
||||
QToolButton toggleButton;
|
||||
QFrame headerLine;
|
||||
QParallelAnimationGroup toggleAnimation;
|
||||
QScrollArea contentArea;
|
||||
int animationDuration;
|
||||
bool *show;
|
||||
QGridLayout mainLayout;
|
||||
QToolButton toggleButton;
|
||||
QFrame headerLine;
|
||||
QParallelAnimationGroup toggleAnimation;
|
||||
QScrollArea contentArea;
|
||||
int animationDuration;
|
||||
bool *show;
|
||||
public:
|
||||
groupInst groupinst;
|
||||
explicit GroupWidget(bool &show,const QString & title = "", const int animationDuration = 0, QWidget *parent = 0);
|
||||
void setContentLayout(QLayout & contentLayout);
|
||||
|
||||
groupInst groupinst;
|
||||
explicit GroupWidget(bool &show,const QString & title = "", const int animationDuration = 0, QWidget *parent = 0);
|
||||
void setContentLayout(QLayout & contentLayout);
|
||||
|
||||
private slots:
|
||||
void onclicked(bool);
|
||||
void onclicked(bool);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,32 +2,32 @@
|
|||
|
||||
ParameterCheckBox::ParameterCheckBox(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(checkBox,SIGNAL(clicked()),this,SLOT(onChanged()));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
checkBox->setToolTip(object->description);
|
||||
}
|
||||
|
||||
object = parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(checkBox, SIGNAL(clicked()), this, SLOT(onChanged()));
|
||||
if (showDescription == true) {
|
||||
setDescription(object->description);
|
||||
}
|
||||
else {
|
||||
checkBox->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterCheckBox::onChanged(){
|
||||
object->focus=true;
|
||||
object->value = ValuePtr(checkBox->isChecked());
|
||||
emit changed();
|
||||
void ParameterCheckBox::onChanged()
|
||||
{
|
||||
object->focus = true;
|
||||
object->value = ValuePtr(checkBox->isChecked());
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterCheckBox::setParameterFocus()
|
||||
{
|
||||
this->checkBox->setFocus();
|
||||
object->focus=false;
|
||||
this->checkBox->setFocus();
|
||||
object->focus = false;
|
||||
}
|
||||
|
||||
void ParameterCheckBox::setValue(){
|
||||
this->stackedWidget->setCurrentWidget(this->pageCheckBox);
|
||||
this->checkBox->setChecked(object->value->toBool());
|
||||
void ParameterCheckBox::setValue() {
|
||||
this->stackedWidget->setCurrentWidget(this->pageCheckBox);
|
||||
this->checkBox->setChecked(object->value->toBool());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
class ParameterCheckBox : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterCheckBox(ParameterObject *parameterobject,bool);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
ParameterCheckBox(ParameterObject *parameterobject,bool);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
protected slots:
|
||||
void onChanged();
|
||||
void onChanged();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,62 +1,57 @@
|
|||
#include "parametercombobox.h"
|
||||
|
||||
ParameterComboBox::ParameterComboBox(ParameterObject *parameterobject, bool showDescription){
|
||||
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(comboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(onChanged(int)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
comboBox->setToolTip(object->description);
|
||||
}
|
||||
|
||||
ParameterComboBox::ParameterComboBox(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object = parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onChanged(int)));
|
||||
if (showDescription == true) {
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
comboBox->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterComboBox::onChanged(int idx){
|
||||
|
||||
if(object->dvt == Value::STRING){
|
||||
const std::string v = comboBox->itemData(idx).toString().toStdString();
|
||||
object->value = ValuePtr(v);
|
||||
}else{
|
||||
const double v = comboBox->itemData(idx).toDouble();
|
||||
object->value = ValuePtr(v);
|
||||
}
|
||||
object->focus=true;
|
||||
emit changed();
|
||||
void ParameterComboBox::onChanged(int idx)
|
||||
{
|
||||
if (object->dvt == Value::STRING) {
|
||||
const std::string v = comboBox->itemData(idx).toString().toStdString();
|
||||
object->value = ValuePtr(v);
|
||||
} else {
|
||||
const double v = comboBox->itemData(idx).toDouble();
|
||||
object->value = ValuePtr(v);
|
||||
}
|
||||
object->focus = true;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterComboBox::setParameterFocus()
|
||||
{
|
||||
this->comboBox->setFocus();
|
||||
object->focus=false;
|
||||
this->comboBox->setFocus();
|
||||
object->focus = false;
|
||||
}
|
||||
|
||||
void ParameterComboBox::setValue(){
|
||||
|
||||
this->stackedWidget->setCurrentWidget(this->pageComboBox);
|
||||
comboBox->clear();
|
||||
const Value::VectorType& vec = object->values->toVector();
|
||||
for (Value::VectorType::const_iterator it = vec.begin(); it != vec.end(); it++) {
|
||||
|
||||
if((*it)->toVector().size()>1){
|
||||
comboBox->addItem(QString::fromStdString((*it)->toVector()[1]->toString()),
|
||||
QVariant(QString::fromStdString((*it)->toVector()[0]->toString())));
|
||||
}
|
||||
else
|
||||
{
|
||||
comboBox->addItem(QString::fromStdString((*it)->toString()),
|
||||
QVariant(QString::fromStdString((*it)->toString())));
|
||||
|
||||
}
|
||||
}
|
||||
QString defaultText = QString::fromStdString(object->value->toString());
|
||||
int idx = comboBox->findData(QVariant(defaultText));
|
||||
if (idx >= 0) {
|
||||
comboBox->setCurrentIndex(idx);
|
||||
}
|
||||
void ParameterComboBox::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageComboBox);
|
||||
comboBox->clear();
|
||||
const Value::VectorType& vec = object->values->toVector();
|
||||
for (Value::VectorType::const_iterator it = vec.begin(); it != vec.end(); it++) {
|
||||
if ((*it)->toVector().size() > 1) {
|
||||
comboBox->addItem(QString::fromStdString((*it)->toVector()[1]->toString()),
|
||||
QVariant(QString::fromStdString((*it)->toVector()[0]->toString())));
|
||||
}
|
||||
else {
|
||||
comboBox->addItem(QString::fromStdString((*it)->toString()),
|
||||
QVariant(QString::fromStdString((*it)->toString())));
|
||||
|
||||
}
|
||||
}
|
||||
QString defaultText = QString::fromStdString(object->value->toString());
|
||||
int idx = comboBox->findData(QVariant(defaultText));
|
||||
if (idx >= 0) {
|
||||
comboBox->setCurrentIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
class ParameterComboBox : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ParameterComboBox(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
ParameterComboBox(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
public slots:
|
||||
void onChanged(int idx);
|
||||
void onChanged(int idx);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,62 +2,62 @@
|
|||
|
||||
ParameterSlider::ParameterSlider(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
this->pressed=true;
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(slider,SIGNAL(sliderPressed()),this,SLOT(onPressed()));
|
||||
connect(slider,SIGNAL(sliderReleased()),this,SLOT(onReleased()));
|
||||
connect(slider,SIGNAL(valueChanged(int)),this,SLOT(onChanged(int)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
slider->setToolTip(object->description);
|
||||
}
|
||||
this->pressed = true;
|
||||
object = parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(slider, SIGNAL(sliderPressed()), this, SLOT(onPressed()));
|
||||
connect(slider, SIGNAL(sliderReleased()), this, SLOT(onReleased()));
|
||||
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(onChanged(int)));
|
||||
if (showDescription == true) {
|
||||
setDescription(object->description);
|
||||
}
|
||||
else {
|
||||
slider->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSlider::onChanged(int)
|
||||
{
|
||||
double v = slider->value()*step;
|
||||
this->labelSliderValue->setText(QString::number(v, 'f', decimalPrecision));
|
||||
if(this->pressed){
|
||||
object->focus=true;
|
||||
object->value = ValuePtr(v);
|
||||
emit changed();
|
||||
}
|
||||
double v = slider->value()*step;
|
||||
this->labelSliderValue->setText(QString::number(v, 'f', decimalPrecision));
|
||||
if (this->pressed) {
|
||||
object->focus = true;
|
||||
object->value = ValuePtr(v);
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSlider::setParameterFocus()
|
||||
{
|
||||
slider->setFocus();
|
||||
object->focus=false;
|
||||
slider->setFocus();
|
||||
object->focus = false;
|
||||
}
|
||||
|
||||
void ParameterSlider::onPressed(){
|
||||
this->pressed=false;
|
||||
void ParameterSlider::onPressed()
|
||||
{
|
||||
this->pressed = false;
|
||||
}
|
||||
|
||||
void ParameterSlider::onReleased(){
|
||||
this->pressed=true;
|
||||
onChanged(0);
|
||||
this->pressed = true;
|
||||
onChanged(0);
|
||||
}
|
||||
|
||||
void ParameterSlider::setValue()
|
||||
{
|
||||
if(object->values->toRange().step_value()>0){
|
||||
setPrecision(object->values->toRange().step_value());
|
||||
step=object->values->toRange().step_value();
|
||||
}else{
|
||||
decimalPrecision=1;
|
||||
step=1;
|
||||
}
|
||||
int min = object->values->toRange().begin_value()/step;
|
||||
int max=object->values->toRange().end_value()/step;
|
||||
int current=object->value->toDouble()/step;
|
||||
this->stackedWidget->setCurrentWidget(this->pageSlider);
|
||||
this->slider->setRange(min,max);
|
||||
this->slider->setValue(current);
|
||||
this->labelSliderValue->setText(QString::number(current*step, 'f',decimalPrecision));
|
||||
if (object->values->toRange().step_value() > 0) {
|
||||
setPrecision(object->values->toRange().step_value());
|
||||
step = object->values->toRange().step_value();
|
||||
} else {
|
||||
decimalPrecision = 1;
|
||||
step = 1;
|
||||
}
|
||||
int min = object->values->toRange().begin_value()/step;
|
||||
int max=object->values->toRange().end_value()/step;
|
||||
int current=object->value->toDouble()/step;
|
||||
this->stackedWidget->setCurrentWidget(this->pageSlider);
|
||||
this->slider->setRange(min,max);
|
||||
this->slider->setValue(current);
|
||||
this->labelSliderValue->setText(QString::number(current*step, 'f',decimalPrecision));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
class ParameterSlider : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterSlider(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
ParameterSlider(ParameterObject *parameterobject, bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
private:
|
||||
double step;
|
||||
bool pressed;
|
||||
double step;
|
||||
bool pressed;
|
||||
protected slots:
|
||||
void onChanged(int);
|
||||
void onReleased();
|
||||
void onPressed();
|
||||
void onChanged(int);
|
||||
void onReleased();
|
||||
void onPressed();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,47 +2,47 @@
|
|||
|
||||
ParameterSpinBox::ParameterSpinBox(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
doubleSpinBox1->setToolTip(object->description);
|
||||
}
|
||||
object = parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1, SIGNAL(valueChanged(double)), this, SLOT(onChanged(double)));
|
||||
if (showDescription == true) {
|
||||
setDescription(object->description);
|
||||
}
|
||||
else {
|
||||
doubleSpinBox1->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterSpinBox::onChanged(double){
|
||||
|
||||
object->focus=true;
|
||||
object->value = ValuePtr(doubleSpinBox1->value());
|
||||
emit changed();
|
||||
void ParameterSpinBox::onChanged(double)
|
||||
{
|
||||
object->focus = true;
|
||||
object->value = ValuePtr(doubleSpinBox1->value());
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterSpinBox::setParameterFocus()
|
||||
{
|
||||
this->doubleSpinBox1->setFocus();
|
||||
object->focus=false;
|
||||
this->doubleSpinBox1->setFocus();
|
||||
object->focus = false;
|
||||
}
|
||||
|
||||
void ParameterSpinBox::setValue(){
|
||||
|
||||
if(object->values->toDouble()>0){
|
||||
setPrecision(object->values->toDouble());
|
||||
this->doubleSpinBox1->setSingleStep(object->values->toDouble());
|
||||
}
|
||||
else{
|
||||
setPrecision(object->defaultValue->toDouble());
|
||||
this->doubleSpinBox1->setSingleStep(1/pow(10,decimalPrecision));
|
||||
}
|
||||
this->doubleSpinBox1->setDecimals(decimalPrecision);
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
this->doubleSpinBox1->setRange(object->value->toDouble()-1000,object->value->toDouble()+1000);
|
||||
this->doubleSpinBox1->setValue(object->value->toDouble());
|
||||
|
||||
this->doubleSpinBox2->hide();
|
||||
this->doubleSpinBox3->hide();
|
||||
this->doubleSpinBox4->hide();
|
||||
void ParameterSpinBox::setValue()
|
||||
{
|
||||
if (object->values->toDouble() > 0) {
|
||||
setPrecision(object->values->toDouble());
|
||||
this->doubleSpinBox1->setSingleStep(object->values->toDouble());
|
||||
}
|
||||
else {
|
||||
setPrecision(object->defaultValue->toDouble());
|
||||
this->doubleSpinBox1->setSingleStep(1/pow(10,decimalPrecision));
|
||||
}
|
||||
this->doubleSpinBox1->setDecimals(decimalPrecision);
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
this->doubleSpinBox1->setRange(object->value->toDouble()-1000, object->value->toDouble()+1000);
|
||||
this->doubleSpinBox1->setValue(object->value->toDouble());
|
||||
|
||||
this->doubleSpinBox2->hide();
|
||||
this->doubleSpinBox3->hide();
|
||||
this->doubleSpinBox4->hide();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
class ParameterSpinBox :public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterSpinBox(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
ParameterSpinBox(ParameterObject *parameterobject, bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
protected slots:
|
||||
void onChanged(double);
|
||||
void onChanged(double);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,49 +4,47 @@
|
|||
|
||||
ParameterText::ParameterText(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(onChanged(QString)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
lineEdit->setToolTip(object->description);
|
||||
}
|
||||
object = parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(onChanged(QString)));
|
||||
if (showDescription == true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
lineEdit->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterText::onChanged(QString)
|
||||
{
|
||||
|
||||
if(object->dvt == Value::STRING){
|
||||
object->value = ValuePtr(lineEdit->text().toStdString());
|
||||
}
|
||||
else{
|
||||
ModuleContext ctx;
|
||||
shared_ptr<Expression> params = CommentParser::parser(lineEdit->text().toStdString().c_str());
|
||||
if (!params) return;
|
||||
ValuePtr newValue = params->evaluate(&ctx);
|
||||
if (object->dvt == newValue->type()) {
|
||||
object->value = newValue;
|
||||
}
|
||||
}
|
||||
object->focus=true;
|
||||
emit changed();
|
||||
if (object->dvt == Value::STRING) {
|
||||
object->value = ValuePtr(lineEdit->text().toStdString());
|
||||
}
|
||||
else {
|
||||
ModuleContext ctx;
|
||||
shared_ptr<Expression> params = CommentParser::parser(lineEdit->text().toStdString().c_str());
|
||||
if (!params) return;
|
||||
ValuePtr newValue = params->evaluate(&ctx);
|
||||
if (object->dvt == newValue->type()) {
|
||||
object->value = newValue;
|
||||
}
|
||||
}
|
||||
object->focus = true;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void ParameterText::setParameterFocus()
|
||||
{
|
||||
this->lineEdit->setFocus();
|
||||
object->focus=false;
|
||||
|
||||
this->lineEdit->setFocus();
|
||||
object->focus = false;
|
||||
}
|
||||
|
||||
void ParameterText::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageText);
|
||||
this->lineEdit->setText(QString::fromStdString(object->value->toString()));
|
||||
if(object->values->toDouble()>0){
|
||||
this->lineEdit->setMaxLength(object->values->toDouble());
|
||||
}
|
||||
this->stackedWidget->setCurrentWidget(this->pageText);
|
||||
this->lineEdit->setText(QString::fromStdString(object->value->toString()));
|
||||
if (object->values->toDouble() > 0) {
|
||||
this->lineEdit->setMaxLength(object->values->toDouble());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
class ParameterText : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterText(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
ParameterText(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
protected slots:
|
||||
void onChanged(QString);
|
||||
void onChanged(QString);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,88 +2,88 @@
|
|||
|
||||
ParameterVector::ParameterVector(ParameterObject *parameterobject, bool showDescription)
|
||||
{
|
||||
object=parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
connect(doubleSpinBox2,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
connect(doubleSpinBox3,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
connect(doubleSpinBox4,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
if(showDescription==true){
|
||||
setDescription(object->description);
|
||||
}
|
||||
else{
|
||||
frame->setToolTip(object->description);
|
||||
}
|
||||
object = parameterobject;
|
||||
setName(QString::fromStdString(object->name));
|
||||
setValue();
|
||||
connect(doubleSpinBox1,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
connect(doubleSpinBox2,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
connect(doubleSpinBox3,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
connect(doubleSpinBox4,SIGNAL(valueChanged(double)),this,SLOT(onChanged(double)));
|
||||
if (showDescription == true) {
|
||||
setDescription(object->description);
|
||||
}
|
||||
else {
|
||||
frame->setToolTip(object->description);
|
||||
}
|
||||
}
|
||||
|
||||
void ParameterVector::onChanged(double)
|
||||
{
|
||||
object->focus=true;
|
||||
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();
|
||||
object->focus = true;
|
||||
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::setParameterFocus()
|
||||
{
|
||||
this->doubleSpinBox1->setFocus();
|
||||
object->focus=false;
|
||||
this->doubleSpinBox1->setFocus();
|
||||
object->focus = false;
|
||||
}
|
||||
|
||||
void ParameterVector::setValue()
|
||||
{
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
Value::VectorType vec = object->value->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);
|
||||
}
|
||||
setPrecision(vec.at(0)->toDouble());
|
||||
this->doubleSpinBox1->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox1->setRange(vec.at(0)->toDouble()-1000,vec.at(0)->toDouble()+1000);
|
||||
this->doubleSpinBox1->setValue(vec.at(0)->toDouble());
|
||||
if (vec.size() > 1) {
|
||||
setPrecision(vec.at(1)->toDouble());
|
||||
this->doubleSpinBox2->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox2->setRange(vec.at(1)->toDouble()-1000,vec.at(1)->toDouble()+1000);
|
||||
this->doubleSpinBox2->setValue(vec.at(1)->toDouble());
|
||||
this->doubleSpinBox2->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 2) {
|
||||
setPrecision(vec.at(2)->toDouble());
|
||||
this->doubleSpinBox3->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox3->setRange(vec.at(2)->toDouble()-1000,vec.at(2)->toDouble()+1000);
|
||||
this->doubleSpinBox3->setValue(vec.at(2)->toDouble());
|
||||
this->doubleSpinBox3->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 3) {
|
||||
setPrecision(vec.at(3)->toDouble());
|
||||
this->doubleSpinBox4->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox4->setRange(vec.at(3)->toDouble()-1000,vec.at(3)->toDouble()+1000);
|
||||
this->doubleSpinBox4->setValue(vec.at(3)->toDouble());
|
||||
this->doubleSpinBox4->setReadOnly(false);
|
||||
}
|
||||
this->stackedWidget->setCurrentWidget(this->pageVector);
|
||||
Value::VectorType vec = object->value->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);
|
||||
}
|
||||
setPrecision(vec.at(0)->toDouble());
|
||||
this->doubleSpinBox1->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox1->setRange(vec.at(0)->toDouble()-1000,vec.at(0)->toDouble()+1000);
|
||||
this->doubleSpinBox1->setValue(vec.at(0)->toDouble());
|
||||
if (vec.size() > 1) {
|
||||
setPrecision(vec.at(1)->toDouble());
|
||||
this->doubleSpinBox2->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox2->setRange(vec.at(1)->toDouble()-1000,vec.at(1)->toDouble()+1000);
|
||||
this->doubleSpinBox2->setValue(vec.at(1)->toDouble());
|
||||
this->doubleSpinBox2->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 2) {
|
||||
setPrecision(vec.at(2)->toDouble());
|
||||
this->doubleSpinBox3->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox3->setRange(vec.at(2)->toDouble()-1000,vec.at(2)->toDouble()+1000);
|
||||
this->doubleSpinBox3->setValue(vec.at(2)->toDouble());
|
||||
this->doubleSpinBox3->setReadOnly(false);
|
||||
}
|
||||
if (vec.size() > 3) {
|
||||
setPrecision(vec.at(3)->toDouble());
|
||||
this->doubleSpinBox4->setDecimals(decimalPrecision);
|
||||
this->doubleSpinBox4->setRange(vec.at(3)->toDouble()-1000,vec.at(3)->toDouble()+1000);
|
||||
this->doubleSpinBox4->setValue(vec.at(3)->toDouble());
|
||||
this->doubleSpinBox4->setReadOnly(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
class ParameterVector : public ParameterVirtualWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParameterVector(ParameterObject *parameterobject,bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
ParameterVector(ParameterObject *parameterobject, bool showDescription);
|
||||
void setValue();
|
||||
void setParameterFocus();
|
||||
|
||||
protected slots:
|
||||
void onChanged(double);
|
||||
void onChanged(double);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,30 +3,28 @@
|
|||
|
||||
ParameterVirtualWidget::ParameterVirtualWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
ParameterVirtualWidget::~ParameterVirtualWidget(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ParameterVirtualWidget::setPrecision(double number){
|
||||
|
||||
decimalPrecision =0;
|
||||
int beforeDecimal=0;
|
||||
long double diff, rn; //rn stands for real number
|
||||
unsigned long long intNumber, multi = 1;
|
||||
number=abs(number);
|
||||
while(1)
|
||||
{
|
||||
rn = (number * multi);
|
||||
intNumber = rn; //the fractional part will be truncated here
|
||||
diff = rn - intNumber;
|
||||
if(diff <=0.0 || decimalPrecision>6){
|
||||
break;
|
||||
}
|
||||
multi = multi * 10;
|
||||
decimalPrecision++;
|
||||
}
|
||||
|
||||
|
||||
decimalPrecision = 0;
|
||||
int beforeDecimal = 0;
|
||||
long double diff, rn; //rn stands for real number
|
||||
unsigned long long intNumber, multi = 1;
|
||||
number = abs(number);
|
||||
while(1) {
|
||||
rn = (number * multi);
|
||||
intNumber = rn; //the fractional part will be truncated here
|
||||
diff = rn - intNumber;
|
||||
if (diff <= 0.0 || decimalPrecision > 6) {
|
||||
break;
|
||||
}
|
||||
multi = multi * 10;
|
||||
decimalPrecision++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,33 +7,30 @@
|
|||
|
||||
class ParameterVirtualWidget : public QWidget, public Ui::ParameterEntryWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
ParameterObject *object;
|
||||
|
||||
ParameterObject *object;
|
||||
|
||||
public:
|
||||
ParameterVirtualWidget(QWidget *parent=0);
|
||||
virtual ~ParameterVirtualWidget();
|
||||
virtual void setParameterFocus()=0;
|
||||
|
||||
ParameterVirtualWidget(QWidget *parent = 0);
|
||||
virtual ~ParameterVirtualWidget();
|
||||
virtual void setParameterFocus() = 0;
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
void changed();
|
||||
|
||||
protected:
|
||||
int decimalPrecision;
|
||||
virtual void setPrecision(double number);
|
||||
virtual void setValue()=0;
|
||||
void setName(const QString& name){
|
||||
|
||||
this->labelDescription->hide();
|
||||
this->labelParameter->setText(name);
|
||||
}
|
||||
|
||||
void setDescription(const QString& description){
|
||||
|
||||
this->labelDescription->show();
|
||||
this->labelDescription->setText(description);
|
||||
}
|
||||
|
||||
int decimalPrecision;
|
||||
virtual void setPrecision(double number);
|
||||
virtual void setValue() = 0;
|
||||
void setName(const QString& name) {
|
||||
this->labelDescription->hide();
|
||||
this->labelParameter->setText(name);
|
||||
}
|
||||
|
||||
void setDescription(const QString& description) {
|
||||
this->labelDescription->show();
|
||||
this->labelDescription->setText(description);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@
|
|||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "testdata/scad/misc/allmodules.scad"
|
||||
isEnabled = "YES">
|
||||
isEnabled = "NO">
|
||||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "non-manifold2.scad -o non-manifold2.stl --debug=GeometryUtils"
|
||||
|
|
|
|||
Loading…
Reference in a new issue