From 4c41e04d49cfefc5a1bfd0ae2bd9b7a7fa01eb46 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 10 Nov 2015 10:07:40 +0200 Subject: [PATCH 1/4] Can not add one point to detail twice --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index a14c08ccb..47158b75b 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -180,31 +180,49 @@ void DialogDetail::NewItem(quint32 id, const Tool &typeTool, const NodeDetail &t return; } - QListWidgetItem *item = new QListWidgetItem(name); - item->setFont(QFont("Times", 12, QFont::Bold)); - VNodeDetail node(id, typeTool, typeNode, mx, my, reverse); - item->setData(Qt::UserRole, QVariant::fromValue(node)); - ui.listWidget->addItem(item); - ui.listWidget->setCurrentRow(ui.listWidget->count()-1); + bool canAddNewPoint = false; - ui.doubleSpinBoxBiasX->blockSignals(true); - ui.doubleSpinBoxBiasY->blockSignals(true); - - ui.doubleSpinBoxBiasX->setValue(qApp->fromPixel(node.getMx())); - ui.doubleSpinBoxBiasY->setValue(qApp->fromPixel(node.getMy())); - if (node.getTypeTool() == Tool::NodePoint) + if(ui.listWidget->count() == 0) { - ui.checkBoxReverse->setChecked(false); - ui.checkBoxReverse->setEnabled(false); + canAddNewPoint = true; } else { - ui.checkBoxReverse->setEnabled(true); - ui.checkBoxReverse->setChecked(node.getReverse()); + QString lastItemName = ui.listWidget->item(ui.listWidget->count()-1)->text(); + if(QString::compare(lastItemName, name) != 0) + { + canAddNewPoint = true; + } } - ui.doubleSpinBoxBiasX->blockSignals(false); - ui.doubleSpinBoxBiasY->blockSignals(false); + if(canAddNewPoint) + { + QListWidgetItem *item = new QListWidgetItem(name); + item->setFont(QFont("Times", 12, QFont::Bold)); + VNodeDetail node(id, typeTool, typeNode, mx, my, reverse); + item->setData(Qt::UserRole, QVariant::fromValue(node)); + ui.listWidget->addItem(item); + ui.listWidget->setCurrentRow(ui.listWidget->count()-1); + + ui.doubleSpinBoxBiasX->blockSignals(true); + ui.doubleSpinBoxBiasY->blockSignals(true); + + ui.doubleSpinBoxBiasX->setValue(qApp->fromPixel(node.getMx())); + ui.doubleSpinBoxBiasY->setValue(qApp->fromPixel(node.getMy())); + if (node.getTypeTool() == Tool::NodePoint) + { + ui.checkBoxReverse->setChecked(false); + ui.checkBoxReverse->setEnabled(false); + } + else + { + ui.checkBoxReverse->setEnabled(true); + ui.checkBoxReverse->setChecked(node.getReverse()); + } + + ui.doubleSpinBoxBiasX->blockSignals(false); + ui.doubleSpinBoxBiasY->blockSignals(false); + } } //--------------------------------------------------------------------------------------------------------------------- From d27a64b819ef2bb950fed15da69f2f1b358a8b81 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Tue, 10 Nov 2015 11:58:33 +0200 Subject: [PATCH 2/4] Delete the last point from detail when the first point equals the last point --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 65 ++++++++++++++++++- src/libs/vtools/dialogs/tools/dialogdetail.h | 3 + 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 47158b75b..083908617 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -78,6 +78,7 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NamePointChanged); connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &DialogDetail::DeleteLastPoint); } //--------------------------------------------------------------------------------------------------------------------- @@ -117,7 +118,7 @@ void DialogDetail::ChosenObject(quint32 id, const SceneObject &type) EnableObjectGUI(true); } - if (CreateDetail().ContourPoints(data).size() < 3) + if (not DetailIsValid()) { ValidObjects(false); } @@ -420,9 +421,67 @@ void DialogDetail::DeleteItem() EnableObjectGUI(false); } - delete ui.listWidget->item( ui.listWidget->currentRow() ); - if (CreateDetail().ContourPoints(data).size() < 3 ) + int rowNumber = ui.listWidget->currentRow(); + + if (rowNumber != 0 && rowNumber != ui.listWidget->count()-1) + { + QString previousRow = ui.listWidget->item(rowNumber-1)->text(); + QString nextRow = ui.listWidget->item(rowNumber+1)->text(); + + if (QString::compare(previousRow, nextRow) == 0) + { + ValidObjects(false); + } + } + + delete ui.listWidget->item(rowNumber); + if (not DetailIsValid()) { ValidObjects(false); } } + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogDetail::DetailIsValid() +{ + if (ui.listWidget->count() < 3) + { + return false; + } + else if (ui.listWidget->count() == 3) + { + if (FirstPointEqualLast()) + { + return false; + } + } + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogDetail::FirstPointEqualLast() +{ + QString firstDetailPoint = ui.listWidget->item(0)->text(); + QString lastDetailPoint = ui.listWidget->item(ui.listWidget->count()-1)->text(); + + if (QString::compare(firstDetailPoint, lastDetailPoint) == 0) + { + return true; + } + else + { + return false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::DeleteLastPoint() +{ + if (ui.listWidget->count() > 3) + { + if (FirstPointEqualLast()) + { + delete ui.listWidget->item(ui.listWidget->count()-1); + } + } +} diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index dbdc6ec94..44ab0da65 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -54,6 +54,7 @@ public slots: void ClickedReverse(bool checked); void ObjectChanged(int row); void DeleteItem(); + void DeleteLastPoint(); protected: /** * @brief SaveData Put dialog data in local variables @@ -74,6 +75,8 @@ private: /** @brief closed keep option about equdistant (closed or not) */ bool closed; bool flagWidth; + bool DetailIsValid(); + bool FirstPointEqualLast(); void NewItem(quint32 id, const Tool &typeTool, const NodeDetail &typeNode, qreal mx = 0, qreal my = 0, bool reverse = false); From e323afc4e61183557c1db9aa070910740f59f207 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 11 Nov 2015 19:38:21 +0200 Subject: [PATCH 3/4] Fixed DetailIsValid() method --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 69 ++++++------------- src/libs/vtools/dialogs/tools/dialogdetail.h | 1 - 2 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 083908617..1930ba216 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -78,7 +78,6 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NamePointChanged); connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem); - connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &DialogDetail::DeleteLastPoint); } //--------------------------------------------------------------------------------------------------------------------- @@ -118,16 +117,7 @@ void DialogDetail::ChosenObject(quint32 id, const SceneObject &type) EnableObjectGUI(true); } - if (not DetailIsValid()) - { - ValidObjects(false); - } - else - { - ValidObjects(true); - - } - + ValidObjects(DetailIsValid()); this->show(); } } @@ -189,8 +179,8 @@ void DialogDetail::NewItem(quint32 id, const Tool &typeTool, const NodeDetail &t } else { - QString lastItemName = ui.listWidget->item(ui.listWidget->count()-1)->text(); - if(QString::compare(lastItemName, name) != 0) + QString previousItemName = ui.listWidget->item(ui.listWidget->count()-1)->text(); + if(QString::compare(previousItemName, name) != 0) { canAddNewPoint = true; } @@ -421,24 +411,8 @@ void DialogDetail::DeleteItem() EnableObjectGUI(false); } - int rowNumber = ui.listWidget->currentRow(); - - if (rowNumber != 0 && rowNumber != ui.listWidget->count()-1) - { - QString previousRow = ui.listWidget->item(rowNumber-1)->text(); - QString nextRow = ui.listWidget->item(rowNumber+1)->text(); - - if (QString::compare(previousRow, nextRow) == 0) - { - ValidObjects(false); - } - } - - delete ui.listWidget->item(rowNumber); - if (not DetailIsValid()) - { - ValidObjects(false); - } + delete ui.listWidget->item(ui.listWidget->currentRow()); + ValidObjects(DetailIsValid()); } //--------------------------------------------------------------------------------------------------------------------- @@ -448,21 +422,34 @@ bool DialogDetail::DetailIsValid() { return false; } - else if (ui.listWidget->count() == 3) + else { if (FirstPointEqualLast()) { return false; } - } + else + { + for (int i=0; icount()-1; i++) + { + QString previousRow = ui.listWidget->item(i)->text(); + QString nextRow = ui.listWidget->item(i+1)->text(); + + if (QString::compare(previousRow, nextRow) == 0) + { + return false; + } + } + } + } return true; } //--------------------------------------------------------------------------------------------------------------------- bool DialogDetail::FirstPointEqualLast() { - QString firstDetailPoint = ui.listWidget->item(0)->text(); - QString lastDetailPoint = ui.listWidget->item(ui.listWidget->count()-1)->text(); + const QString firstDetailPoint = ui.listWidget->item(0)->text(); + const QString lastDetailPoint = ui.listWidget->item(ui.listWidget->count()-1)->text(); if (QString::compare(firstDetailPoint, lastDetailPoint) == 0) { @@ -473,15 +460,3 @@ bool DialogDetail::FirstPointEqualLast() return false; } } - -//--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::DeleteLastPoint() -{ - if (ui.listWidget->count() > 3) - { - if (FirstPointEqualLast()) - { - delete ui.listWidget->item(ui.listWidget->count()-1); - } - } -} diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 44ab0da65..7e3463175 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -54,7 +54,6 @@ public slots: void ClickedReverse(bool checked); void ObjectChanged(int row); void DeleteItem(); - void DeleteLastPoint(); protected: /** * @brief SaveData Put dialog data in local variables From c6577675e7ef4628cf7c8e0741f651d737f7e147 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 11 Nov 2015 21:46:36 +0200 Subject: [PATCH 4/4] Changed some methods to be const --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 34 +++++++++++-------- src/libs/vtools/dialogs/tools/dialogdetail.h | 4 +-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 1930ba216..cbf4d159c 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -179,7 +179,7 @@ void DialogDetail::NewItem(quint32 id, const Tool &typeTool, const NodeDetail &t } else { - QString previousItemName = ui.listWidget->item(ui.listWidget->count()-1)->text(); + const QString previousItemName = ui.listWidget->item(ui.listWidget->count()-1)->text(); if(QString::compare(previousItemName, name) != 0) { canAddNewPoint = true; @@ -416,7 +416,7 @@ void DialogDetail::DeleteItem() } //--------------------------------------------------------------------------------------------------------------------- -bool DialogDetail::DetailIsValid() +bool DialogDetail::DetailIsValid() const { if (ui.listWidget->count() < 3) { @@ -430,10 +430,10 @@ bool DialogDetail::DetailIsValid() } else { - for (int i=0; icount()-1; i++) + for (int i=0, sz = ui.listWidget->count()-1; iitem(i)->text(); - QString nextRow = ui.listWidget->item(i+1)->text(); + const QString previousRow = ui.listWidget->item(i)->text(); + const QString nextRow = ui.listWidget->item(i+1)->text(); if (QString::compare(previousRow, nextRow) == 0) { @@ -446,17 +446,21 @@ bool DialogDetail::DetailIsValid() } //--------------------------------------------------------------------------------------------------------------------- -bool DialogDetail::FirstPointEqualLast() +bool DialogDetail::FirstPointEqualLast() const { - const QString firstDetailPoint = ui.listWidget->item(0)->text(); - const QString lastDetailPoint = ui.listWidget->item(ui.listWidget->count()-1)->text(); + if (ui.listWidget->count() > 1) + { + const QString firstDetailPoint = ui.listWidget->item(0)->text(); + const QString lastDetailPoint = ui.listWidget->item(ui.listWidget->count()-1)->text(); - if (QString::compare(firstDetailPoint, lastDetailPoint) == 0) - { - return true; - } - else - { - return false; + if (QString::compare(firstDetailPoint, lastDetailPoint) == 0) + { + return true; + } + else + { + return false; + } } + return false; } diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 7e3463175..dac43f320 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -74,8 +74,8 @@ private: /** @brief closed keep option about equdistant (closed or not) */ bool closed; bool flagWidth; - bool DetailIsValid(); - bool FirstPointEqualLast(); + bool DetailIsValid() const; + bool FirstPointEqualLast() const; void NewItem(quint32 id, const Tool &typeTool, const NodeDetail &typeNode, qreal mx = 0, qreal my = 0, bool reverse = false);