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,34 +4000,13 @@ void TMainWindow::SetCurrentDimensionValues()
//---------------------------------------------------------------------------------------------------------------------
QVector<int> TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension)
{
QPair<int, int> restriction;
if (index == 0)
{
return dimension->ValidBases();
}
if (dimension->Type() == MeasurementDimension::X)
{
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()
|| not restricted.IsValid())
{ // invalid restriction
return dimension->ValidBases();
}
return restricted.ValidBases();
}
else if (dimension->Type() == MeasurementDimension::W)
{
QPair<int, int> restriction;
if (index == 1)
else if (index == 1)
{
restriction = m->Restriction(currentDimensionA);
}
@ -4036,41 +4015,12 @@ QVector<int> TMainWindow::DimensionRestrictedValues(int index, const Measurement
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())
if (restriction.first < dimension->MinValue() || restriction.second > dimension->MaxValue())
{ // 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>();
return VAbstartMeasurementDimension::ValidBases(restriction.first, restriction.second, dimension->Step());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -78,24 +78,7 @@ QVector<int> VAbstartMeasurementDimension::ValidSteps() const
//---------------------------------------------------------------------------------------------------------------------
QVector<int> VAbstartMeasurementDimension::ValidBases() const
{
QVector<int> validBases;
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;
return VAbstartMeasurementDimension::ValidBases(m_minValue, m_maxValue, m_step);
}
//---------------------------------------------------------------------------------------------------------------------
@ -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()
{

View File

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