Commit ccbc04be authored by LACROIX Romain's avatar LACROIX Romain

Created a new widget for categorized combo-boxes, as used in Stream Tracer /...

Created a new widget for categorized combo-boxes, as used in Stream Tracer / Integrator type and direction for example.
parent f87b9b27
......@@ -121,7 +121,7 @@ public:
QCheckBox *show_source_actor_cb = nullptr;
public:
QComboBox *cb_seed_type = nullptr;
dtkVisualizationWidgetsComboBox *cb_seed_type = nullptr;
QSpinBox *sp_integrator_max_steps = nullptr;
QSpinBox *sp_resolution = nullptr;
QDoubleSpinBox *sp_integrator_max_lengths = nullptr;
......@@ -206,11 +206,11 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
d->show_actor_cb = new QCheckBox;
d->show_source_actor_cb = new QCheckBox;
auto *cb_integrator_direction = dtkVisualizationWidgetsStreamTracer::createComboBox("Integration Direction", {"Forward", "Backward", "Both"}, 2);
dtkVisualizationWidgetsComboBox *cb_integrator_direction = new dtkVisualizationWidgetsComboBox("Direction", {"Forward", "Backward", "Both"}, 2);
auto *cb_integrator_type = dtkVisualizationWidgetsStreamTracer::createComboBox("Integrator Type", {"RK2", "RK4", "RK45"}, 0);
dtkVisualizationWidgetsComboBox *cb_integrator_type = new dtkVisualizationWidgetsComboBox("Type", {"RK2", "RK4", "RK45"}, 0);
d->cb_seed_type = dtkVisualizationWidgetsStreamTracer::createComboBox("Type", { "Line", "Sphere" }, 1);
d->cb_seed_type = new dtkVisualizationWidgetsComboBox("Type", { "Line", "Sphere" }, 1);
d->sp_resolution = new QSpinBox;
d->sp_resolution->setMaximum(1000);
......@@ -255,19 +255,19 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
this->draw();
});
connect(cb_integrator_direction, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int id)
connect(cb_integrator_direction->combobox(), QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int id)
{
d->streamtracer->SetIntegrationDirection(id);
this->draw();
});
connect(cb_integrator_type, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int id)
connect(cb_integrator_type->combobox(), QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int id)
{
d->streamtracer->SetIntegratorType(id);
this->draw();
});
connect(d->cb_seed_type, &QComboBox::currentTextChanged, [=] (const QString& text)
connect(d->cb_seed_type->combobox(), &QComboBox::currentTextChanged, [=] (const QString& text)
{
if (text == "Sphere") {
d->source_line_widget->SetEnabled(false);
......@@ -317,8 +317,8 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
d->sp_radius->setObjectName("Tube Radius");
d->sp_resolution->setObjectName("Resolution");
auto *integrator_box = dtkVisualizationWidgetsStreamTracer::createCategory("Integrator", {cb_integrator_direction, cb_integrator_type});
auto *seed_box = dtkVisualizationWidgetsStreamTracer::createCategory("Seed", { d->cb_seed_type });
QWidget *integrator_box = dtkVisualizationWidgetsStreamTracer::createCategory("Integrator", {cb_integrator_direction, cb_integrator_type});
QWidget *seed_box = dtkVisualizationWidgetsStreamTracer::createCategory("Seed", { d->cb_seed_type });
d_func()->inspectors << seed_box << integrator_box << d->sp_integrator_max_steps
<< d->sp_integrator_max_lengths << d->sp_radius << d->sp_resolution
......
......@@ -2,6 +2,38 @@
#include <QtWidgets>
dtkVisualizationWidgetsComboBox::dtkVisualizationWidgetsComboBox(const QString& name, const QVector<QString>& labels, const int index, QWidget *parent) : QGroupBox(parent), cbox(new QComboBox)
{
for (const auto& label: labels)
{
cbox->addItem(label);
}
cbox->setCurrentIndex(index);
QLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0,0,0,0);
layout->addWidget(new QLabel(name));
layout->addWidget(cbox);
setLayout(layout);
this->setStyleSheet("QGroupBox { margin: 0px; padding-left: 20px }");
}
dtkVisualizationWidgetsComboBox::~dtkVisualizationWidgetsComboBox()
{
}
QComboBox *dtkVisualizationWidgetsComboBox::combobox()
{
return cbox;
}
QString dtkVisualizationWidgetsComboBox::currentText() const
{
return cbox->currentText();
}
// class dtkVisualizationWidgetsStreamTracerPrivate
// {
// public:
......@@ -20,27 +52,19 @@ dtkVisualizationWidgetsStreamTracer::~dtkVisualizationWidgetsStreamTracer()
// delete d;
}
QComboBox *dtkVisualizationWidgetsStreamTracer::createComboBox(const QString& name, const QVector<QString>& labels, const int index)
{
QComboBox *box = new QComboBox;
for (const auto& label: labels)
{
box->addItem(label);
}
box->setCurrentIndex(index);
box->setObjectName(name);
return box;
}
QGroupBox *dtkVisualizationWidgetsStreamTracer::createCategory(const QString& name, const QVector<QWidget*>& widgets)
// todo : change this static function to class, remove unused class
QGroupBox *dtkVisualizationWidgetsStreamTracer::createCategory(const QString& name, const QVector<QWidget*>& widgets, QWidget* parent)
{
auto *layout = new QVBoxLayout;
QLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0,0,0,0);
QGroupBox *box = new QGroupBox(parent);
for (auto *widget: widgets)
{
layout->addWidget(widget);
widget->setParent(box);
}
auto *box = new QGroupBox;
box->setObjectName(name);
box->setLayout(layout);
box->setStyleSheet("QGroupBox { background-color: transparent; margin: 0px; border: transparent; } ");
return box;
}
......@@ -2,9 +2,23 @@
#include <dtkVisualizationWidgetsExport>
#include <QWidget>
class QGroupBox;
class QComboBox;
#include <QGroupBox>
class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsComboBox : public QGroupBox
{
Q_OBJECT
public:
dtkVisualizationWidgetsComboBox(const QString& name, const QVector<QString>& labels, const int index, QWidget *parent = nullptr);
~dtkVisualizationWidgetsComboBox(void);
QComboBox *combobox();
QString currentText() const;
private:
QComboBox* cbox;
};
class DTKVISUALIZATIONWIDGETS_EXPORT dtkVisualizationWidgetsStreamTracer // : public QWidget
{
......@@ -14,8 +28,7 @@ public:
dtkVisualizationWidgetsStreamTracer(QWidget *parent = nullptr);
~dtkVisualizationWidgetsStreamTracer(void);
static QComboBox *createComboBox(const QString& name, const QVector<QString>& labels, const int index);
static QGroupBox *createCategory(const QString& name, const QVector<QWidget*>& widgets);
static QGroupBox *createCategory(const QString& name, const QVector<QWidget*>& widgets, QWidget* parent = nullptr);
/* public slots: */
/* void setValue(double value); */
......
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