Redesign filtering bases.

This commit is contained in:
Roman Telezhynskyi 2020-10-07 17:12:53 +03:00
parent 4a12c1ca74
commit 506ce6fb5e
3 changed files with 37 additions and 81 deletions

View File

@ -4000,77 +4000,27 @@ void TMainWindow::SetCurrentDimensionValues()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<int> TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension) QVector<int> TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension)
{ {
QPair<int, int> restriction;
if (index == 0) if (index == 0)
{ {
return dimension->ValidBases(); return dimension->ValidBases();
} }
else if (index == 1)
if (dimension->Type() == MeasurementDimension::X)
{ {
restriction = m->Restriction(currentDimensionA);
}
else
{
restriction = m->Restriction(currentDimensionA, currentDimensionB);
}
if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue())
{ // invalid restriction
return dimension->ValidBases(); return dimension->ValidBases();
} }
else if (dimension->Type() == MeasurementDimension::Y)
{
const QPair<int, int> restriction = m->Restriction(currentDimensionA);
VYMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step());
restricted.SetCircumference(dimension->IsCircumference());
if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue() return VAbstartMeasurementDimension::ValidBases(restriction.first, restriction.second, dimension->Step());
|| not restricted.IsValid())
{ // invalid restriction
return dimension->ValidBases();
}
return restricted.ValidBases();
}
else if (dimension->Type() == MeasurementDimension::W)
{
QPair<int, int> restriction;
if (index == 1)
{
restriction = m->Restriction(currentDimensionA);
}
else
{
restriction = m->Restriction(currentDimensionA, currentDimensionB);
}
VWMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step());
if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue()
|| not restricted.IsValid())
{ // invalid restriction
return dimension->ValidBases();
}
return restricted.ValidBases();
}
else if (dimension->Type() == MeasurementDimension::Z)
{
QPair<int, int> restriction;
if (index == 1)
{
restriction = m->Restriction(currentDimensionA);
}
else
{
restriction = m->Restriction(currentDimensionA, currentDimensionB);
}
VZMeasurementDimension restricted(dimension->Units(), restriction.first, restriction.second, dimension->Step());
if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue()
|| not restricted.IsValid())
{ // invalid restriction
return dimension->ValidBases();
}
return restricted.ValidBases();
}
return QVector<int>();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -78,24 +78,7 @@ QVector<int> VAbstartMeasurementDimension::ValidSteps() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<int> VAbstartMeasurementDimension::ValidBases() const QVector<int> VAbstartMeasurementDimension::ValidBases() const
{ {
QVector<int> validBases; return VAbstartMeasurementDimension::ValidBases(m_minValue, m_maxValue, m_step);
int step = Step();
if (step < 0)
{
return validBases;
}
else if (step == 0)
{
step = 1;
}
for (int value = MinValue(); value <= MaxValue(); value += step)
{
validBases.append(value);
}
return validBases;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -111,6 +94,28 @@ QStringList VAbstartMeasurementDimension::ValidBasesList() const
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<int> VAbstartMeasurementDimension::ValidBases(int min, int max, int step)
{
QVector<int> validBases;
if (step < 0)
{
return validBases;
}
else if (step == 0)
{
step = 1;
}
for (int value = min; value <= max; value += step)
{
validBases.append(value);
}
return validBases;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VAbstartMeasurementDimension::IsRangeValid() bool VAbstartMeasurementDimension::IsRangeValid()
{ {

View File

@ -83,6 +83,7 @@ public:
QVector<int> ValidBases() const; QVector<int> ValidBases() const;
QStringList ValidBasesList() const; QStringList ValidBasesList() const;
static QVector<int> ValidBases(int min, int max, int step);
static QString DimensionName(MeasurementDimension type); static QString DimensionName(MeasurementDimension type);
static QString DimensionToolTip(MeasurementDimension type, bool circumference, bool fc); static QString DimensionToolTip(MeasurementDimension type, bool circumference, bool fc);