Improve restrict dimension dialog. Disable not available combinations.

This commit is contained in:
Roman Telezhynskyi 2021-01-19 12:24:56 +02:00
parent 2b7769c80e
commit 4c0edca64a
4 changed files with 90 additions and 12 deletions

View File

@ -7,6 +7,7 @@
- New option "Don't use the native file dialog". - New option "Don't use the native file dialog".
- Improve the layout option "Auto crop unused width". - Improve the layout option "Auto crop unused width".
- Improve multisize measurements format. Allow decimal step 0.5. - Improve multisize measurements format. Allow decimal step 0.5.
- Improve restrict dimension dialog. Disable not available combinations.
# Version 0.7.41 Dec 4, 2020 # Version 0.7.41 Dec 4, 2020
- Bug fixes. - Bug fixes.

View File

@ -387,7 +387,7 @@ void DialogRestrictDimension::InitTable()
ui->tableWidget->blockSignals(false); ui->tableWidget->blockSignals(false);
RefreshTable(); RefreshTable();
ui->tableWidget->selectRow(0); ui->tableWidget->selectRow(StartRow());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -415,11 +415,11 @@ void DialogRestrictDimension::RefreshTable()
{ {
if (m_dimensions.size() >= 3) if (m_dimensions.size() >= 3)
{ {
MeasurementDimension_p dimensionA = m_dimensions.at(1); MeasurementDimension_p dimensionB = m_dimensions.at(1);
basesRow = dimensionA->ValidBases(); basesRow = dimensionB->ValidBases();
MeasurementDimension_p dimensionB = m_dimensions.at(2); MeasurementDimension_p dimensionC = m_dimensions.at(2);
basesColumn = dimensionB->ValidBases(); basesColumn = dimensionC->ValidBases();
} }
else else
{ {
@ -454,6 +454,7 @@ void DialogRestrictDimension::AddCell(int row, int column, qreal rowValue, qreal
qreal base2 = 0; qreal base2 = 0;
MeasurementDimension_p dimension; MeasurementDimension_p dimension;
QVector<qreal> bases; QVector<qreal> bases;
QVector<qreal> validRows;
if (m_oneDimesionRestriction) if (m_oneDimesionRestriction)
{ {
@ -461,6 +462,7 @@ void DialogRestrictDimension::AddCell(int row, int column, qreal rowValue, qreal
if (m_dimensions.size() >= 2) if (m_dimensions.size() >= 2)
{ {
validRows = m_dimensions.at(0)->ValidBases();
dimension = m_dimensions.at(1); dimension = m_dimensions.at(1);
bases = dimension->ValidBases(); bases = dimension->ValidBases();
} }
@ -472,6 +474,7 @@ void DialogRestrictDimension::AddCell(int row, int column, qreal rowValue, qreal
if (m_dimensions.size() >= 3) if (m_dimensions.size() >= 3)
{ {
validRows = DimensionRestrictedValues(m_dimensions.at(1));
dimension = m_dimensions.at(2); dimension = m_dimensions.at(2);
bases = dimension->ValidBases(); bases = dimension->ValidBases();
} }
@ -494,16 +497,27 @@ void DialogRestrictDimension::AddCell(int row, int column, qreal rowValue, qreal
} }
} }
const bool leftRestriction = columnValue >= min; if (validRows.contains(rowValue))
const bool rightRestriction = columnValue <= max;
if (leftRestriction && rightRestriction)
{ {
item->setIcon(QIcon(QStringLiteral("://icon/24x24/star.png"))); const bool leftRestriction = columnValue >= min;
const bool rightRestriction = columnValue <= max;
if (leftRestriction && rightRestriction)
{
item->setIcon(QIcon(QStringLiteral("://icon/24x24/star.png")));
}
else
{
item->setIcon(QIcon(QStringLiteral("://icon/24x24/close.png")));
}
} }
else else
{ {
item->setIcon(QIcon(QStringLiteral("://icon/24x24/close.png"))); item->setIcon(QIcon(QStringLiteral("://icon/24x24/close.png")));
Qt::ItemFlags flags = item->flags();
flags &= ~(Qt::ItemIsEnabled);
item->setFlags(flags);
} }
// set the item non-editable (view only), and non-selectable // set the item non-editable (view only), and non-selectable
@ -653,3 +667,57 @@ auto DialogRestrictDimension::DimensionLabels(const QVector<qreal> &bases,
return labels; return labels;
} }
//---------------------------------------------------------------------------------------------------------------------
auto DialogRestrictDimension::DimensionRestrictedValues(const MeasurementDimension_p &dimension) const -> QVector<qreal>
{
QPair<qreal, qreal> restriction;
if (not m_oneDimesionRestriction)
{
qreal base1 = ui->comboBoxDimensionA->currentData().toDouble();
restriction = m_restrictions.value(VMeasurement::CorrectionHash(base1), QPair<qreal, qreal>(0, 0));
}
const QVector<qreal> bases = dimension->ValidBases();
qreal min = bases.indexOf(restriction.first) != -1 ? restriction.first : dimension->MinValue();
qreal max = bases.indexOf(restriction.second) != -1 ? restriction.second : dimension->MaxValue();
if (min > max)
{
min = dimension->MinValue();
max = dimension->MaxValue();
}
return VAbstartMeasurementDimension::ValidBases(min, max, dimension->Step());
}
//---------------------------------------------------------------------------------------------------------------------
auto DialogRestrictDimension::StartRow() const -> int
{
if (m_oneDimesionRestriction)
{
return 0;
}
QVector<qreal> basesRow;
if (m_dimensions.size() >= 3)
{
MeasurementDimension_p dimensionB = m_dimensions.at(1);
basesRow = dimensionB->ValidBases();
QVector<qreal> validRows = DimensionRestrictedValues(dimensionB);
for(int i=0; i < basesRow.size(); ++i)
{
if (validRows.contains(basesRow.at(i)))
{
return i;
}
}
}
return 0;
}

View File

@ -84,6 +84,8 @@ private:
void FillBases(const QVector<qreal> &bases, const MeasurementDimension_p &dimension, QComboBox *control) const; void FillBases(const QVector<qreal> &bases, const MeasurementDimension_p &dimension, QComboBox *control) const;
auto DimensionLabels(const QVector<qreal> &bases, const MeasurementDimension_p &dimension) const -> QStringList; auto DimensionLabels(const QVector<qreal> &bases, const MeasurementDimension_p &dimension) const -> QStringList;
auto DimensionRestrictedValues(const MeasurementDimension_p &dimension) const -> QVector<qreal>;
auto StartRow() const -> int;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -39,10 +39,17 @@ void VDecorationAligningDelegate::paint(QPainter *painter, const QStyleOptionVie
{ {
QIcon icon = QIcon(qvariant_cast<QIcon>(index.data(Qt::DecorationRole))); QIcon icon = QIcon(qvariant_cast<QIcon>(index.data(Qt::DecorationRole)));
if (option.state & QStyle::State_Selected) if ((option.state & QStyle::State_Selected) != 0U)
{ {
painter->fillRect(option.rect, option.palette.highlight()); painter->fillRect(option.rect, option.palette.highlight());
} }
icon.paint(painter, option.rect, m_alignment); if ((index.flags() & Qt::ItemIsEnabled) != 0U)
{
icon.paint(painter, option.rect, m_alignment);
}
else
{
icon.paint(painter, option.rect, m_alignment, QIcon::Disabled);
}
} }