diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index 46c02de81..3a18f7d56 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -157,7 +157,7 @@ void DialogCutArc::closeEvent(QCloseEvent *event) */ void DialogCutArc::setArcId(const quint32 &value) { - setCurrentArcId(ui->comboBoxArc, value, ComboBoxCutArc::CutArc); + setCurrentArcId(ui->comboBoxArc, value, FillComboBox::NoChildren); VisToolCutArc *path = qobject_cast(vis); SCASSERT(path != nullptr); diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 6424936a1..0a2943e1e 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -114,7 +114,7 @@ void DialogCutSpline::SetFormula(const QString &value) */ void DialogCutSpline::setSplineId(const quint32 &value) { - setCurrentSplineId(ui->comboBoxSpline, value, ComboBoxCutSpline::CutSpline); + setCurrentSplineId(ui->comboBoxSpline, value, FillComboBox::NoChildren); VisToolCutSpline *path = qobject_cast(vis); SCASSERT(path != nullptr); diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index f9128f4c7..be67d4cde 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -114,7 +114,7 @@ void DialogCutSplinePath::SetFormula(const QString &value) */ void DialogCutSplinePath::setSplinePathId(const quint32 &value) { - setCurrentSplinePathId(ui->comboBoxSplinePath, value, ComboBoxCutSpline::CutSpline); + setCurrentSplinePathId(ui->comboBoxSplinePath, value, FillComboBox::NoChildren); VisToolCutSplinePath *path = qobject_cast(vis); SCASSERT(path != nullptr); diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 209b3fb43..cea6f4b50 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -115,146 +115,27 @@ void DialogTool::showEvent(QShowEvent *event) * @brief FillComboBoxPoints fill comboBox list of points * @param box comboBox */ -void DialogTool::FillComboBoxPoints(QComboBox *box) const +void DialogTool::FillComboBoxPoints(QComboBox *box, FillComboBox rule) const { - SCASSERT(box != nullptr); - const QHash > *objs = data->DataGObjects(); - QMap list; - QHash >::const_iterator i; - for (i = objs->constBegin(); i != objs->constEnd(); ++i) - { - if (i.key() != toolId) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::Point && obj->getMode() == Draw::Calculation) - { - const QSharedPointer point = data->GeometricObject(i.key()); - list[point->name()] = i.key(); - } - } - } - FillList(box, list); + FillCombo(box, GOType::Point, rule); } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::FillComboBoxArcs(QComboBox *box, ComboBoxCutArc cut) const +void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule) const { - SCASSERT(box != nullptr); - const QHash > *objs = data->DataGObjects(); - QHash >::const_iterator i; - QMap list; - for (i = objs->constBegin(); i != objs->constEnd(); ++i) - { - if (cut == ComboBoxCutArc::CutArc) - { - if (i.key() != toolId + 1 && i.key() != toolId + 2) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::Arc && obj->getMode() == Draw::Calculation) - { - const QSharedPointer arc = data->GeometricObject(i.key()); - list[arc->name()] = i.key(); - } - } - } - else - { - if (i.key() != toolId) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::Arc && obj->getMode() == Draw::Calculation) - { - const QSharedPointer arc = data->GeometricObject(i.key()); - list[arc->name()] = i.key(); - } - } - } - } - FillList(box, list); + FillCombo(box, GOType::Arc, rule); } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief FillComboBoxSplines fill comboBox list of splines - * @param box comboBox - * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 - */ -void DialogTool::FillComboBoxSplines(QComboBox *box, ComboBoxCutSpline cut) const +void DialogTool::FillComboBoxSplines(QComboBox *box, FillComboBox rule) const { - SCASSERT(box != nullptr); - const QHash > *objs = data->DataGObjects(); - QHash >::const_iterator i; - QMap list; - for (i = objs->constBegin(); i != objs->constEnd(); ++i) - { - if (cut == ComboBoxCutSpline::CutSpline) - { - if (i.key() != toolId + 1 && i.key() != toolId + 2) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::Spline && obj->getMode() == Draw::Calculation) - { - const QSharedPointer spl = data->GeometricObject(i.key()); - list[spl->name()] = i.key(); - } - } - } - else - { - if (i.key() != toolId) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::Spline && obj->getMode() == Draw::Calculation) - { - const QSharedPointer spl = data->GeometricObject(i.key()); - list[spl->name()] = i.key(); - } - } - } - } - FillList(box, list); + FillCombo(box, GOType::Spline, rule); } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief FillComboBoxSplinesPath - * @param box comboBox - * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 - */ -void DialogTool::FillComboBoxSplinesPath(QComboBox *box, ComboBoxCutSpline cut) const +void DialogTool::FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule) const { - SCASSERT(box != nullptr); - const QHash > *objs = data->DataGObjects(); - QMap list; - QHash >::const_iterator i; - for (i = objs->constBegin(); i != objs->constEnd(); ++i) - { - if (cut == ComboBoxCutSpline::CutSpline) - { - if (i.key() != toolId + 1 && i.key() != toolId + 2) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::SplinePath && obj->getMode() == Draw::Calculation) - { - const QSharedPointer splPath = data->GeometricObject(i.key()); - list[splPath->name()] = i.key(); - } - } - } - else - { - if (i.key() != toolId) - { - QSharedPointer obj = i.value(); - if (obj->getType() == GOType::SplinePath && obj->getMode() == Draw::Calculation) - { - const QSharedPointer splPath = data->GeometricObject(i.key()); - list[splPath->name()] = i.key(); - } - } - } - } - FillList(box, list); + FillCombo(box, GOType::SplinePath, rule); } //--------------------------------------------------------------------------------------------------------------------- @@ -505,13 +386,13 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt } //--------------------------------------------------------------------------------------------------------------------- -void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value) const +void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value, FillComboBox rule) const { SCASSERT(box != nullptr); box->blockSignals(true); - FillComboBoxPoints(box); + FillComboBoxPoints(box, rule); ChangeCurrentData(box, value); box->blockSignals(false); @@ -520,28 +401,22 @@ void DialogTool::setCurrentPointId(QComboBox *box, const quint32 &value) const //--------------------------------------------------------------------------------------------------------------------- /** * @brief setCurrentSplineId set current spline id in combobox - * @param box combobox - * @param value spline id - * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ -void DialogTool::setCurrentSplineId(QComboBox *box, const quint32 &value, ComboBoxCutSpline cut) const +void DialogTool::setCurrentSplineId(QComboBox *box, const quint32 &value, FillComboBox rule) const { SCASSERT(box != nullptr); - FillComboBoxSplines(box, cut); + FillComboBoxSplines(box, rule); ChangeCurrentData(box, value); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief setCurrentArcId - * @param box combobox - * @param value arc id - * @param cut if set to ComboMode::CutArc don't show id+1 and id+2 */ -void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, ComboBoxCutArc cut) const +void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, FillComboBox rule) const { SCASSERT(box != nullptr); - FillComboBoxArcs(box, cut); + FillComboBoxArcs(box, rule); ChangeCurrentData(box, value); } @@ -552,10 +427,10 @@ void DialogTool::setCurrentArcId(QComboBox *box, const quint32 &value, ComboBoxC * @param value splinePath id * @param cut if set to ComboMode::CutSpline don't show id+1 and id+2 */ -void DialogTool::setCurrentSplinePathId(QComboBox *box, const quint32 &value, ComboBoxCutSpline cut) const +void DialogTool::setCurrentSplinePathId(QComboBox *box, const quint32 &value, FillComboBox rule) const { SCASSERT(box != nullptr); - FillComboBoxSplinesPath(box, cut); + FillComboBoxSplinesPath(box, rule); ChangeCurrentData(box, value); } @@ -922,3 +797,41 @@ void DialogTool::SetAssociatedTool(VAbstractTool *tool) this->associatedTool=tool; SetToolId(tool->getId()); } + +//--------------------------------------------------------------------------------------------------------------------- +template +void DialogTool::FillCombo(QComboBox *box, GOType gType, FillComboBox rule) const +{ + SCASSERT(box != nullptr); + const QHash > *objs = data->DataGObjects(); + QHash >::const_iterator i; + QMap list; + for (i = objs->constBegin(); i != objs->constEnd(); ++i) + { + if (rule == FillComboBox::NoChildren) + { + if (i.key() != toolId + 1 && i.key() != toolId + 2) + { + QSharedPointer obj = i.value(); + if (obj->getType() == gType && obj->getMode() == Draw::Calculation) + { + const QSharedPointer arc = data->GeometricObject(i.key()); + list[arc->name()] = i.key(); + } + } + } + else + { + if (i.key() != toolId) + { + QSharedPointer obj = i.value(); + if (obj->getType() == gType && obj->getMode() == Draw::Calculation) + { + const QSharedPointer arc = data->GeometricObject(i.key()); + list[arc->name()] = i.key(); + } + } + } + } + FillList(box, list); +} diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index 1b9ffd2db..131886543 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -53,8 +53,7 @@ class VContainer; class QPlainTextEdit; class VAbstractTool; -enum class ComboBoxCutSpline : char { CutSpline, NoCutSpline }; -enum class ComboBoxCutArc : char { CutArc, NoCutArc}; +enum class FillComboBox : char { Whole, NoChildren}; /** * @brief The DialogTool class parent for all dialog of tools. @@ -185,11 +184,10 @@ protected: virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); - void FillComboBoxPoints(QComboBox *box)const; - void FillComboBoxArcs(QComboBox *box, ComboBoxCutArc cut = ComboBoxCutArc::NoCutArc)const; - void FillComboBoxSplines(QComboBox *box, ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline)const; - void FillComboBoxSplinesPath(QComboBox *box, - ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline)const; + void FillComboBoxPoints(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; + void FillComboBoxArcs(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; + void FillComboBoxSplines(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; + void FillComboBoxSplinesPath(QComboBox *box, FillComboBox rule = FillComboBox::Whole)const; void FillComboBoxCurves(QComboBox *box)const; void FillComboBoxTypeLine(QComboBox *box, const QMap &stylesPics) const; void FillComboBoxLineColors(QComboBox *box)const; @@ -202,13 +200,15 @@ protected: void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); qreal Eval(const QString &text, bool &flag, QLabel *label, const QString &postfix, bool checkZero = true); - void setCurrentPointId(QComboBox *box, const quint32 &value) const; + + void setCurrentPointId(QComboBox *box, const quint32 &value, + FillComboBox rule = FillComboBox::NoChildren) const; void setCurrentSplineId(QComboBox *box, const quint32 &value, - ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline) const; + FillComboBox rule = FillComboBox::NoChildren) const; void setCurrentArcId(QComboBox *box, const quint32 &value, - ComboBoxCutArc cut = ComboBoxCutArc::NoCutArc) const; + FillComboBox rule = FillComboBox::NoChildren) const; void setCurrentSplinePathId(QComboBox *box, const quint32 &value, - ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline) const; + FillComboBox rule = FillComboBox::NoChildren) const; void setCurrentCurveId(QComboBox *box, const quint32 &value) const; quint32 getCurrentObjectId(QComboBox *box) const; @@ -308,7 +308,10 @@ protected: void MoveCursorToEnd(QPlainTextEdit *plainTextEdit); bool eventFilter(QObject *object, QEvent *event); private: - void FillList(QComboBox *box, const QMap &list)const; + void FillList(QComboBox *box, const QMap &list)const; + + template + void FillCombo(QComboBox *box, GOType gType, FillComboBox rule = FillComboBox::Whole) const; }; //---------------------------------------------------------------------------------------------------------------------