From f072ee588810981efbac3e27135b9b878e294613 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 7 Oct 2020 18:09:27 +0300 Subject: [PATCH] Correct way to apply restrictions. --- .../tape/dialogs/dialogrestrictdimension.cpp | 35 ++++++++++++++----- src/app/tape/tmainwindow.cpp | 24 ++++++++----- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/app/tape/dialogs/dialogrestrictdimension.cpp b/src/app/tape/dialogs/dialogrestrictdimension.cpp index 7e66555c7..dde1feca7 100644 --- a/src/app/tape/dialogs/dialogrestrictdimension.cpp +++ b/src/app/tape/dialogs/dialogrestrictdimension.cpp @@ -453,31 +453,50 @@ void DialogRestrictDimension::AddCell(int row, int column, int rowValue, int col int base1 = 0; int base2 = 0; + MeasurementDimension_p dimension; + QVector bases; if (m_oneDimesionRestriction) { base1 = rowValue; + + if (m_dimensions.size() >= 2) + { + dimension = m_dimensions.at(1); + bases = dimension->ValidBases(); + } } else { base1 = ui->comboBoxDimensionA->currentData().toInt(); base2 = rowValue; + + if (m_dimensions.size() >= 3) + { + dimension = m_dimensions.at(2); + bases = dimension->ValidBases(); + } } QPair restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1, base2), QPair(0, 0)); + int min = INT32_MIN; + int max = INT32_MAX; - bool leftRestriction = true; - if (restriction.first > 0 && restriction.first <= restriction.second) + if (not dimension.isNull()) { - leftRestriction = columnValue >= restriction.first; + min = bases.indexOf(restriction.first) != -1 ? restriction.first : dimension->MinValue(); + max = bases.indexOf(restriction.second) != -1 ? restriction.second : dimension->MaxValue(); + + if (max < min) + { + min = dimension->MinValue(); + max = dimension->MaxValue(); + } } - bool rightRestriction = true; - if (restriction.second > 0 && restriction.second >= restriction.first) - { - rightRestriction = columnValue <= restriction.second; - } + const bool leftRestriction = columnValue >= min; + const bool rightRestriction = columnValue <= max; if (leftRestriction && rightRestriction) { diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 49eaad996..248d538f1 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -333,8 +333,9 @@ bool TMainWindow::LoadFile(const QString &path) mUnit = m->MUnit(); pUnit = mUnit; - currentDimensionB = m->DimensionABase(); - currentDimensionA = m->DimensionBBase(); + currentDimensionA = m->DimensionABase(); + currentDimensionB = m->DimensionBBase(); + currentDimensionC = m->DimensionCBase(); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); @@ -3424,8 +3425,9 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) mUnit = m->MUnit(); pUnit = mUnit; - currentDimensionA = m->DimensionBBase(); - currentDimensionB = m->DimensionABase(); + currentDimensionA = m->DimensionABase(); + currentDimensionB = m->DimensionBBase(); + currentDimensionC = m->DimensionCBase(); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); @@ -4021,12 +4023,18 @@ QVector TMainWindow::DimensionRestrictedValues(int index, const Measurement restriction = m->Restriction(currentDimensionA, currentDimensionB); } - if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue()) - { // invalid restriction - return dimension->ValidBases(); + const QVector bases = dimension->ValidBases(); + + int min = bases.indexOf(restriction.first) != -1 ? restriction.first : dimension->MinValue(); + int max = bases.indexOf(restriction.second) != -1 ? restriction.second : dimension->MaxValue(); + + if (min > max) + { + min = dimension->MinValue(); + max = dimension->MaxValue(); } - return VAbstartMeasurementDimension::ValidBases(restriction.first, restriction.second, dimension->Step()); + return VAbstartMeasurementDimension::ValidBases(min, max, dimension->Step()); } //---------------------------------------------------------------------------------------------------------------------