diff --git a/src/dialogs/tools/dialogalongline.cpp b/src/dialogs/tools/dialogalongline.cpp index 26e72d9e9..730ad762d 100644 --- a/src/dialogs/tools/dialogalongline.cpp +++ b/src/dialogs/tools/dialogalongline.cpp @@ -85,30 +85,23 @@ void DialogAlongLine::ChoosedObject(quint32 id, const Scene::Scenes &type) { if (type == Scene::Point) { - const VPointF *point = data->GeometricObject(id); if (number == 0) { - qint32 index = ui->comboBoxFirstPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxFirstPoint->setCurrentIndex(index); + if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) + { number++; - emit ToolTip(tr("Select second point of line")); return; } } if (number == 1) { - qint32 index = ui->comboBoxSecondPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxSecondPoint->setCurrentIndex(index); - number = 0; - emit ToolTip(""); - } - if (isInitialized == false) + if (ChoosedPoint(id, ui->comboBoxSecondPoint, "")) { - this->show(); + number = 0; + if (isInitialized == false) + { + this->show(); + } } } } diff --git a/src/dialogs/tools/dialognormal.cpp b/src/dialogs/tools/dialognormal.cpp index 99ea9f05f..401b4aa64 100644 --- a/src/dialogs/tools/dialognormal.cpp +++ b/src/dialogs/tools/dialognormal.cpp @@ -102,30 +102,23 @@ void DialogNormal::ChoosedObject(quint32 id, const Scene::Scenes &type) { if (type == Scene::Point) { - const VPointF *point = data->GeometricObject(id); if (number == 0) { - qint32 index = ui->comboBoxFirstPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxFirstPoint->setCurrentIndex(index); + if (ChoosedPoint(id, ui->comboBoxFirstPoint, tr("Select second point of line"))) + { number++; - emit ToolTip(tr("Select second point of line")); return; } } if (number == 1) { - qint32 index = ui->comboBoxSecondPoint->findText(point->name()); - if ( index != -1 ) - { // -1 for not found - ui->comboBoxSecondPoint->setCurrentIndex(index); - number = 0; - emit ToolTip(""); - } - if (isInitialized == false) + if (ChoosedPoint(id, ui->comboBoxSecondPoint, "")) { - this->show(); + number = 0; + if (isInitialized == false) + { + this->show(); + } } } } diff --git a/src/dialogs/tools/dialogtool.cpp b/src/dialogs/tools/dialogtool.cpp index 03ce0823f..496c52be6 100644 --- a/src/dialogs/tools/dialogtool.cpp +++ b/src/dialogs/tools/dialogtool.cpp @@ -384,6 +384,21 @@ quint32 DialogTool::getCurrentObjectId(QComboBox *box) const } } +bool DialogTool::ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip) +{ + Q_CHECK_PTR(box); + const VPointF *point = data->GeometricObject(id); + Q_CHECK_PTR(point); + const qint32 index = box->findText(point->name()); + if ( index != -1 ) + { // -1 for not found + box->setCurrentIndex(index); + emit ToolTip(toolTip); + return true; + } + return false; +} + void DialogTool::FillList(QComboBox *box, const QMap &list) const { Q_CHECK_PTR(box); diff --git a/src/dialogs/tools/dialogtool.h b/src/dialogs/tools/dialogtool.h index 9b68e07bb..48ee2b043 100644 --- a/src/dialogs/tools/dialogtool.h +++ b/src/dialogs/tools/dialogtool.h @@ -398,6 +398,7 @@ protected: * @return id or -1 if combobox is empty */ quint32 getCurrentObjectId(QComboBox *box) const; + bool ChoosedPoint(const quint32 &id, QComboBox *box, const QString &toolTip); private: /** * @brief FillList fill combobox list