From 8b36669e0236a61cb14a2ecdbf5e0f992558cbbd Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 22 Jan 2020 14:14:56 +0300 Subject: [PATCH] Add "Add pole" button --- src/PartSet/PartSet_BSplineWidget.cpp | 72 +++++++++++++++++++-------- src/PartSet/PartSet_BSplineWidget.h | 8 ++- 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/PartSet/PartSet_BSplineWidget.cpp b/src/PartSet/PartSet_BSplineWidget.cpp index 893306dc1..43632faec 100644 --- a/src/PartSet/PartSet_BSplineWidget.cpp +++ b/src/PartSet/PartSet_BSplineWidget.cpp @@ -34,6 +34,7 @@ #include #include #include +#include PartSet_BSplineWidget::PartSet_BSplineWidget( @@ -64,7 +65,6 @@ PartSet_BSplineWidget::PartSet_BSplineWidget( // layout of GroupBox myPolesWgt = new QWidget(aContainer); QGridLayout* aGroupLayout = new QGridLayout(myPolesWgt); - aGroupLayout->setSpacing(4); aGroupLayout->setColumnStretch(1, 1); ModuleBase_Tools::adjustMargins(aGroupLayout); @@ -154,32 +154,60 @@ bool PartSet_BSplineWidget::restoreValueCustom() void PartSet_BSplineWidget::addPoleWidget() { QGridLayout* aGroupLay = dynamic_cast(myPolesWgt->layout()); - ModuleBase_Tools::adjustMargins(aGroupLay); - int aNbPoles = (int)myPoles.size(); + QString aPoleStr = tr("Pole %1").arg(aNbPoles + 1); - QString aPoleStr = tr("Pole %1"); - aPoleStr = aPoleStr.arg(aNbPoles + 1); + myPoles.push_back(BSplinePoleWidgets()); + BSplinePoleWidgets& aPole = myPoles.back(); + aGroupLay->addWidget(createPoleWidget(aPole, aPoleStr, myPolesWgt), aNbPoles, 1); +} - QGroupBox* aPoleGroupBox = new QGroupBox(aPoleStr, myPolesWgt); - QFormLayout* aPoleLay = new QFormLayout(aPoleGroupBox); - ModuleBase_Tools::adjustMargins(aPoleLay); - aPoleLay->setSpacing(2); +QGroupBox* PartSet_BSplineWidget::createPoleWidget(BSplinePoleWidgets& thePole, + const QString& theName, QWidget* theParent) +{ + QGroupBox* aPoleGroupBox = new QGroupBox(theName, theParent); + QGridLayout* aPoleLay = new QGridLayout(aPoleGroupBox); + aPoleLay->setSpacing(0); + ModuleBase_Tools::zeroMargins(aPoleLay); + + thePole.myX = new ModuleBase_LabelValue(aPoleGroupBox, tr("X")); + aPoleLay->addWidget(thePole.myX, 0, 0, 1, 3); + thePole.myY = new ModuleBase_LabelValue(aPoleGroupBox, tr("Y")); + aPoleLay->addWidget(thePole.myY, 1, 0, 1, 3); + thePole.myWeight = new ModuleBase_ParamSpinBox(aPoleGroupBox); + thePole.myWeight->setMinimum(0.0); + + aPoleLay->addWidget(new QLabel(tr("Weight :"), aPoleGroupBox), 2, 0); + aPoleLay->addWidget(thePole.myWeight, 2, 1); + // we should listen textChanged signal as valueChanged do not send when text is modified + connect(thePole.myWeight, SIGNAL(textChanged(const QString&)), + this, SIGNAL(valuesChanged())); - myPoles.push_back(BSplinePoleWidgets()); - BSplinePoleWidgets& aPoleWidgets = myPoles.back(); + thePole.myAddBtn = new QToolButton(aPoleGroupBox); + thePole.myAddBtn->setIcon(QIcon(":pictures/add.png")); + thePole.myAddBtn->setToolTip(tr("Add a new pole after the current")); + aPoleLay->addWidget(thePole.myAddBtn, 2, 2); + connect(thePole.myAddBtn, SIGNAL(clicked(bool)), SLOT(onAddPole())); - aPoleWidgets.myX = new ModuleBase_LabelValue(aPoleGroupBox, tr("X")); - aPoleLay->addRow(aPoleWidgets.myX); - aPoleWidgets.myY = new ModuleBase_LabelValue(aPoleGroupBox, tr("Y")); - aPoleLay->addRow(aPoleWidgets.myY); - aPoleWidgets.myWeight = new ModuleBase_ParamSpinBox(aPoleGroupBox); - aPoleWidgets.myWeight->setMinimum(0.0); - aPoleLay->addRow(tr("Weight") + " : ", aPoleWidgets.myWeight); + return aPoleGroupBox; +} - aGroupLay->addWidget(aPoleGroupBox, aNbPoles, 1); - // we should listen textChanged signal as valueChanged do not send when text is modified - connect(aPoleWidgets.myWeight, SIGNAL(textChanged(const QString&)), - this, SIGNAL(valuesChanged())); +void PartSet_BSplineWidget::onAddPole() +{ + QObject* aObj = sender(); + std::list::const_iterator aIt; + int aId = 0; + bool aFound = false; + for (aIt = myPoles.cbegin(); aIt != myPoles.cend(); aIt++, aId++) { + if ((*aIt).myAddBtn == aObj) { + aFound = true; + break; + } + } + if (aFound) { + // TODO: add a new pole after found Id + + restoreValueCustom(); + } } diff --git a/src/PartSet/PartSet_BSplineWidget.h b/src/PartSet/PartSet_BSplineWidget.h index ee2030894..7bbd319d0 100644 --- a/src/PartSet/PartSet_BSplineWidget.h +++ b/src/PartSet/PartSet_BSplineWidget.h @@ -31,7 +31,7 @@ class QGroupBox; class QScrollArea; - +class QToolButton; /** \brief Represent a content of the property panel to show/modify parameters of B-spline curve. * \ingroup GUI @@ -76,13 +76,19 @@ protected: /// Update attributes of B-spline feature void storePolesAndWeights() const; +private slots: + void onAddPole(); + private: struct BSplinePoleWidgets { ModuleBase_LabelValue* myX; ModuleBase_LabelValue* myY; ModuleBase_ParamSpinBox* myWeight; + QToolButton* myAddBtn; }; + QGroupBox* createPoleWidget(BSplinePoleWidgets& thePole, const QString& theName, QWidget* theParent); + QWidget* myPolesWgt; ///< widget to show poles and weights of B-spline curve QGroupBox* myPolesGroupBox; QScrollArea* myScrollArea; -- 2.39.2