From 318517d3d76289bc92138f398aa2f849a86af70f Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 9 Aug 2014 11:43:01 +0300 Subject: [PATCH] Use QObject::blockSignals if need block signal instead disconnect() each time. --HG-- branch : develop --- src/app/dialogs/app/dialoghistory.cpp | 4 +-- src/app/dialogs/app/dialogincrements.cpp | 21 ++++++--------- src/app/dialogs/tools/dialogarc.cpp | 4 +-- src/app/dialogs/tools/dialogdetail.cpp | 12 +++------ src/app/dialogs/tools/dialogsplinepath.cpp | 30 +++++++-------------- src/app/dialogs/tools/dialogtool.cpp | 16 +++++------ src/app/mainwindow.cpp | 12 +++------ src/app/tools/drawTools/vtoolpoint.cpp | 4 +-- src/app/tools/drawTools/vtoolspline.cpp | 28 +++++++++---------- src/app/tools/drawTools/vtoolsplinepath.cpp | 30 ++++++++++----------- src/app/tools/nodeDetails/vnodepoint.cpp | 7 +++-- 11 files changed, 67 insertions(+), 101 deletions(-) diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 07e89cdd1..2ee26aa2d 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -96,9 +96,9 @@ void DialogHistory::cellClicked(int row, int column) cursorRow = row; item->setIcon(QIcon("://icon/32x32/put_after.png")); quint32 id = qvariant_cast(item->data(Qt::UserRole)); - disconnect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor); + doc->blockSignals(true); doc->setCursor(id); - connect(doc, &VPattern::ChangedCursor, this, &DialogHistory::ChangedCursor); + doc->blockSignals(false); } else { diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index 4a366822f..3c6317510 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -350,22 +350,21 @@ void DialogIncrements::FullUpdateFromFile() { if (qApp->patternType() == MeasurementsType::Individual) { - disconnect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, - &DialogIncrements::MeasurementChanged); + ui->tableWidgetMeasurements->blockSignals(true); } ui->tableWidgetMeasurements->clearContents(); FillMeasurements(); ui->tableWidgetMeasurements->horizontalHeader()->setStretchLastSection(true); if (qApp->patternType() == MeasurementsType::Individual) { - connect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged); + ui->tableWidgetMeasurements->blockSignals(false); } - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->blockSignals(true); ui->tableWidgetIncrement->clearContents(); FillIncrements(); ui->tableWidgetIncrement->horizontalHeader()->setStretchLastSection(true); - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->blockSignals(false); ui->tableWidgetLines->clearContents(); FillLengthLines(); @@ -527,8 +526,7 @@ void DialogIncrements::OpenTable() void DialogIncrements::clickedToolButtonAdd() { ui->tableWidgetIncrement->setFocus(Qt::OtherFocusReason); - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->blockSignals(true); qint32 currentRow = ui->tableWidgetIncrement->rowCount(); ui->tableWidgetIncrement->insertRow( currentRow ); @@ -579,8 +577,7 @@ void DialogIncrements::clickedToolButtonAdd() ui->tableWidgetIncrement->setItem(currentRow, 5, item); ui->toolButtonRemove->setEnabled(true); - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->blockSignals(false); emit haveLiteChange(); } @@ -590,8 +587,7 @@ void DialogIncrements::clickedToolButtonAdd() */ void DialogIncrements::clickedToolButtonRemove() { - disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->blockSignals(true); QTableWidgetItem *item = ui->tableWidgetIncrement->currentItem(); qint32 row = item->row(); @@ -613,8 +609,7 @@ void DialogIncrements::clickedToolButtonRemove() ui->toolButtonRemove->setEnabled(false); } - connect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, - &DialogIncrements::IncrementChanged); + ui->tableWidgetIncrement->blockSignals(false); emit haveLiteChange(); } diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 000663474..bd860e2a9 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -354,9 +354,9 @@ void DialogArc::EvalF2() */ void DialogArc::ShowLineAngles() { - disconnect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); + ui->listWidget->blockSignals(true); ui->listWidget->clear(); - connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogArc::ValChenged); + ui->listWidget->blockSignals(false); const QMap lineAnglesTable = data->DataLineAngles(); QMapIterator i(lineAnglesTable); while (i.hasNext()) diff --git a/src/app/dialogs/tools/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 70ee365ec..c7fbbacef 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -179,16 +179,12 @@ void DialogDetail::NewItem(quint32 id, const Tool &typeTool, const NodeDetail &t item->setData(Qt::UserRole, QVariant::fromValue(node)); ui.listWidget->addItem(item); ui.listWidget->setCurrentRow(ui.listWidget->count()-1); - disconnect(ui.doubleSpinBoxBiasX, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogDetail::BiasXChanged); - disconnect(ui.doubleSpinBoxBiasY, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogDetail::BiasYChanged); + ui.doubleSpinBoxBiasX->blockSignals(true); + ui.doubleSpinBoxBiasY->blockSignals(true); ui.doubleSpinBoxBiasX->setValue(qApp->fromPixel(node.getMx())); ui.doubleSpinBoxBiasY->setValue(qApp->fromPixel(node.getMy())); - connect(ui.doubleSpinBoxBiasX, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogDetail::BiasXChanged); - connect(ui.doubleSpinBoxBiasY, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogDetail::BiasYChanged); + ui.doubleSpinBoxBiasX->blockSignals(false); + ui.doubleSpinBoxBiasY->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index e307f60db..3888c3cdb 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -257,16 +257,11 @@ void DialogSplinePath::NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm */ void DialogSplinePath::DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2) { - disconnect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), - this, &DialogSplinePath::currentPointChanged); - disconnect(ui->doubleSpinBoxAngle1, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::Angle1Changed); - disconnect(ui->doubleSpinBoxAngle2, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::Angle2Changed); - disconnect(ui->doubleSpinBoxKasm1, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::KAsm1Changed); - disconnect(ui->doubleSpinBoxKasm2, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::KAsm2Changed); + ui->comboBoxPoint->blockSignals(true); + ui->doubleSpinBoxAngle1->blockSignals(true); + ui->doubleSpinBoxAngle2->blockSignals(true); + ui->doubleSpinBoxKasm1->blockSignals(true); + ui->doubleSpinBoxKasm2->blockSignals(true); ChangeCurrentData(ui->comboBoxPoint, id); ui->doubleSpinBoxKasm1->setValue(kAsm1); @@ -274,16 +269,11 @@ void DialogSplinePath::DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kA ui->doubleSpinBoxAngle2->setValue(angle2); ui->doubleSpinBoxAngle1->setValue(angle1); - connect(ui->comboBoxPoint, static_cast(&QComboBox::currentIndexChanged), - this, &DialogSplinePath::currentPointChanged); - connect(ui->doubleSpinBoxAngle1, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::Angle1Changed); - connect(ui->doubleSpinBoxAngle2, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::Angle2Changed); - connect(ui->doubleSpinBoxKasm1, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::KAsm1Changed); - connect(ui->doubleSpinBoxKasm2, static_cast(&QDoubleSpinBox::valueChanged), - this, &DialogSplinePath::KAsm2Changed); + ui->comboBoxPoint->blockSignals(false); + ui->doubleSpinBoxAngle1->blockSignals(false); + ui->doubleSpinBoxAngle2->blockSignals(false); + ui->doubleSpinBoxKasm1->blockSignals(false); + ui->doubleSpinBoxKasm2->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 4a38ef5ea..f8a613c4f 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -688,13 +688,9 @@ void DialogTool::ChangeColor(QWidget *widget, const QColor &color) void DialogTool::setPointId(QComboBox *box, quint32 &pointId, const quint32 &value) { SCASSERT(box != nullptr); - disconnect(box, static_cast(&QComboBox::currentIndexChanged), this, - &DialogTool::PointNameChanged); - + box->blockSignals(true); setCurrentPointId(box, pointId, value); - - connect(box, static_cast(&QComboBox::currentIndexChanged), this, - &DialogTool::PointNameChanged); + box->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -835,7 +831,7 @@ void DialogTool::EvalFormula() void DialogTool::SizeHeight() { SCASSERT(listWidget != nullptr); - disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->blockSignals(true); listWidget->clear(); { @@ -848,7 +844,7 @@ void DialogTool::SizeHeight() item->setFont(QFont("Times", 12, QFont::Bold)); listWidget->addItem(item); - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->blockSignals(false); listWidget->setCurrentRow (0); } @@ -1057,7 +1053,7 @@ template void DialogTool::ShowVariable(const QMap var) { SCASSERT(listWidget != nullptr); - disconnect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->blockSignals(true); listWidget->clear(); QMapIterator iMap(var); @@ -1071,7 +1067,7 @@ void DialogTool::ShowVariable(const QMap var) listWidget->addItem(item); } } - connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); + listWidget->blockSignals(false); listWidget->setCurrentRow (0); } diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 38ca9d758..cfd0ba960 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -191,8 +191,7 @@ void MainWindow::ActionNewPP() qDebug()<<"Error creating pattern piece with the name "<(&QComboBox::currentIndexChanged), - this, &MainWindow::currentPPChanged); + comboBoxDraws->blockSignals(true); comboBoxDraws->addItem(patternPieceName); pattern->ClearGObjects(); @@ -218,8 +217,7 @@ void MainWindow::ActionNewPP() { comboBoxDraws->setCurrentIndex(0); } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, - &MainWindow::currentPPChanged); + comboBoxDraws->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -1386,12 +1384,10 @@ void MainWindow::FullParseFile() { patternPiece = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); } - disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentPPChanged); + comboBoxDraws->blockSignals(true); comboBoxDraws->clear(); comboBoxDraws->addItems(doc->getPatternPieces()); - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentPPChanged); + comboBoxDraws->blockSignals(false); ui->actionPattern_properties->setEnabled(true); qint32 index = comboBoxDraws->findText(patternPiece); diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 24316191c..15de541d0 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -223,13 +223,13 @@ void VToolPoint::RefreshPointGeometry(const VPointF &point) this->setRect(rec); this->setPos(point.toQPointF()); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); + namePoint->blockSignals(true); QFont font = namePoint->font(); font.setPointSize(static_cast(namePoint->FontSize()/factor)); namePoint->setFont(font); namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); + namePoint->blockSignals(false); RefreshLine(); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index c9157611a..30297d9c0 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -298,16 +298,14 @@ void VToolSpline::SaveDialog(QDomElement &domElement) VSpline spl = VSpline (point1, point4, dialogTool->getAngle1(), dialogTool->getAngle2(), dialogTool->getKAsm1(), dialogTool->getKAsm2(), dialogTool->getKCurve()); - disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); - disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); + controlPoints[0]->blockSignals(true); + controlPoints[1]->blockSignals(true); + controlPoints[0]->setPos(spl.GetP2()); controlPoints[1]->setPos(spl.GetP3()); - connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); - connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); + + controlPoints[0]->blockSignals(false); + controlPoints[1]->blockSignals(false); spl = VSpline (point1, controlPoints[0]->pos(), controlPoints[1]->pos(), point4, dialogTool->getKCurve()); @@ -339,14 +337,12 @@ void VToolSpline::RefreshGeometry() controlPoint = spl->GetP3(); emit RefreshLine(1, SplinePointPosition::LastPoint, controlPoint, splinePoint); - disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); - disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); + controlPoints[0]->blockSignals(true); + controlPoints[1]->blockSignals(true); + controlPoints[0]->setPos(spl->GetP2()); controlPoints[1]->setPos(spl->GetP3()); - connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); - connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSpline::ControlPointChangePosition); + + controlPoints[0]->blockSignals(false); + controlPoints[1]->blockSignals(false); } diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 9a2f19803..99ea10774 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -215,16 +215,15 @@ void VToolSplinePath::RefreshSplinePath(VSplinePath &splPath) { VSpline spl = splPath.GetSpline(i); qint32 j = i*2; - disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); + + controlPoints[j-2]->blockSignals(true); + controlPoints[j-1]->blockSignals(true); + controlPoints[j-2]->setPos(spl.GetP2()); controlPoints[j-1]->setPos(spl.GetP3()); - connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); + + controlPoints[j-2]->blockSignals(false); + controlPoints[j-1]->blockSignals(false); spl = VSpline (spl.GetP1(), controlPoints[j-2]->pos(), controlPoints[j-1]->pos(), spl.GetP4(), splPath.getKCurve()); @@ -391,15 +390,14 @@ void VToolSplinePath::RefreshGeometry() emit RefreshLine(i, SplinePointPosition::LastPoint, controlPoint, splinePoint); qint32 j = i*2; - disconnect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - disconnect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); + + controlPoints[j-2]->blockSignals(true); + controlPoints[j-1]->blockSignals(true); + controlPoints[j-2]->setPos(spl.GetP2()); controlPoints[j-1]->setPos(spl.GetP3()); - connect(controlPoints[j-2], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); - connect(controlPoints[j-1], &VControlPointSpline::ControlPointChangePosition, this, - &VToolSplinePath::ControlPointChangePosition); + + controlPoints[j-2]->blockSignals(false); + controlPoints[j-1]->blockSignals(false); } } diff --git a/src/app/tools/nodeDetails/vnodepoint.cpp b/src/app/tools/nodeDetails/vnodepoint.cpp index ffca41569..9b27d5b5e 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -267,12 +267,11 @@ void VNodePoint::RefreshPointGeometry(const VPointF &point) rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); this->setPos(point.toQPointF()); - disconnect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VNodePoint::NameChangePosition); + + namePoint->blockSignals(true); namePoint->setText(point.name()); namePoint->setPos(QPointF(point.mx(), point.my())); - connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, - &VNodePoint::NameChangePosition); + namePoint->blockSignals(false); RefreshLine(); }