Correct way to apply restrictions.

This commit is contained in:
Roman Telezhynskyi 2020-10-07 18:09:27 +03:00
parent 1bb0a896f5
commit f072ee5888
2 changed files with 43 additions and 16 deletions

View File

@ -453,31 +453,50 @@ void DialogRestrictDimension::AddCell(int row, int column, int rowValue, int col
int base1 = 0; int base1 = 0;
int base2 = 0; int base2 = 0;
MeasurementDimension_p dimension;
QVector<int> bases;
if (m_oneDimesionRestriction) if (m_oneDimesionRestriction)
{ {
base1 = rowValue; base1 = rowValue;
if (m_dimensions.size() >= 2)
{
dimension = m_dimensions.at(1);
bases = dimension->ValidBases();
}
} }
else else
{ {
base1 = ui->comboBoxDimensionA->currentData().toInt(); base1 = ui->comboBoxDimensionA->currentData().toInt();
base2 = rowValue; base2 = rowValue;
if (m_dimensions.size() >= 3)
{
dimension = m_dimensions.at(2);
bases = dimension->ValidBases();
}
} }
QPair<int, int> restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1, base2), QPair<int, int> restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1, base2),
QPair<int, int>(0, 0)); QPair<int, int>(0, 0));
int min = INT32_MIN;
int max = INT32_MAX;
bool leftRestriction = true; if (not dimension.isNull())
if (restriction.first > 0 && restriction.first <= restriction.second)
{ {
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; const bool leftRestriction = columnValue >= min;
if (restriction.second > 0 && restriction.second >= restriction.first) const bool rightRestriction = columnValue <= max;
{
rightRestriction = columnValue <= restriction.second;
}
if (leftRestriction && rightRestriction) if (leftRestriction && rightRestriction)
{ {

View File

@ -333,8 +333,9 @@ bool TMainWindow::LoadFile(const QString &path)
mUnit = m->MUnit(); mUnit = m->MUnit();
pUnit = mUnit; pUnit = mUnit;
currentDimensionB = m->DimensionABase(); currentDimensionA = m->DimensionABase();
currentDimensionA = m->DimensionBBase(); currentDimensionB = m->DimensionBBase();
currentDimensionC = m->DimensionCBase();
ui->labelToolTip->setVisible(false); ui->labelToolTip->setVisible(false);
ui->tabWidget->setVisible(true); ui->tabWidget->setVisible(true);
@ -3424,8 +3425,9 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
mUnit = m->MUnit(); mUnit = m->MUnit();
pUnit = mUnit; pUnit = mUnit;
currentDimensionA = m->DimensionBBase(); currentDimensionA = m->DimensionABase();
currentDimensionB = m->DimensionABase(); currentDimensionB = m->DimensionBBase();
currentDimensionC = m->DimensionCBase();
ui->labelToolTip->setVisible(false); ui->labelToolTip->setVisible(false);
ui->tabWidget->setVisible(true); ui->tabWidget->setVisible(true);
@ -4021,12 +4023,18 @@ QVector<int> TMainWindow::DimensionRestrictedValues(int index, const Measurement
restriction = m->Restriction(currentDimensionA, currentDimensionB); restriction = m->Restriction(currentDimensionA, currentDimensionB);
} }
if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue()) const QVector<int> bases = dimension->ValidBases();
{ // invalid restriction
return 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());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------