GCC warnings.

This commit is contained in:
Roman Telezhynskyi 2021-09-25 08:17:30 +03:00
parent c8c94b7df8
commit fc30957b85
2 changed files with 77 additions and 97 deletions

View File

@ -156,67 +156,48 @@ void DialogMeasurementsCSVColumns::ColumnChanged()
{ {
auto *control = qobject_cast<QComboBox*>(sender()); auto *control = qobject_cast<QComboBox*>(sender());
auto SaveColum = [this, control](int column)
{
m_columnsMap[column] = control->currentData().toInt();
ShowImportPreview();
CheckStatus();
};
if (control == ui->comboBoxName) if (control == ui->comboBoxName)
{ {
if (m_type == MeasurementsType::Individual) m_type == MeasurementsType::Individual ? SaveColum(control, IndividualMeasurementsColumns::Name)
{ : SaveColum(control, MultisizeMeasurementsColumns::Name);
SaveColum(static_cast<int>(IndividualMeasurementsColumns::Name));
}
else
{
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::Name));
}
} }
else if (control == ui->comboBoxValue) else if (control == ui->comboBoxValue)
{ {
if (m_type == MeasurementsType::Individual) m_type == MeasurementsType::Individual ? SaveColum(control, IndividualMeasurementsColumns::Value)
{ : SaveColum(control, MultisizeMeasurementsColumns::BaseValue);
SaveColum(static_cast<int>(IndividualMeasurementsColumns::Value));
}
else
{
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::BaseValue));
}
} }
else if (control == ui->comboBoxShiftA) else if (control == ui->comboBoxShiftA)
{ {
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::ShiftA)); SaveColum(control, MultisizeMeasurementsColumns::ShiftA);
} }
else if (control == ui->comboBoxShiftB) else if (control == ui->comboBoxShiftB)
{ {
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::ShiftB)); SaveColum(control, MultisizeMeasurementsColumns::ShiftB);
} }
else if (control == ui->comboBoxShiftC) else if (control == ui->comboBoxShiftC)
{ {
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::ShiftC)); SaveColum(control, MultisizeMeasurementsColumns::ShiftC);
} }
else if (control == ui->comboBoxFullName) else if (control == ui->comboBoxFullName)
{ {
if (m_type == MeasurementsType::Individual) if (m_type == MeasurementsType::Individual)
{ {
SaveColum(static_cast<int>(IndividualMeasurementsColumns::FullName)); SaveColum(control, IndividualMeasurementsColumns::FullName);
} }
else else
{ {
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::FullName)); SaveColum(control, MultisizeMeasurementsColumns::FullName);
} }
} }
else if (control == ui->comboBoxDescription) else if (control == ui->comboBoxDescription)
{ {
if (m_type == MeasurementsType::Individual) if (m_type == MeasurementsType::Individual)
{ {
SaveColum(static_cast<int>(IndividualMeasurementsColumns::Description)); SaveColum(control, IndividualMeasurementsColumns::Description);
} }
else else
{ {
SaveColum(static_cast<int>(MultisizeMeasurementsColumns::Description)); SaveColum(control, MultisizeMeasurementsColumns::Description);
} }
} }
} }
@ -347,13 +328,13 @@ int DialogMeasurementsCSVColumns::MinimumColumns() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool DialogMeasurementsCSVColumns::ColumnsValid() auto DialogMeasurementsCSVColumns::ColumnsValid() -> bool
{ {
ChangeColor(ui->labelName, OkColor(this)); ChangeColor(ui->labelName, OkColor(this));
ChangeColor(ui->labelValue, OkColor(this)); ChangeColor(ui->labelValue, OkColor(this));
if (m_type == MeasurementsType::Multisize) if (m_type == MeasurementsType::Multisize)
{ {
if (m_dimensions.size() > 0) if (not m_dimensions.empty())
{ {
ChangeColor(ui->labelShiftA, OkColor(this)); ChangeColor(ui->labelShiftA, OkColor(this));
} }
@ -371,31 +352,6 @@ bool DialogMeasurementsCSVColumns::ColumnsValid()
ChangeColor(ui->labelFullName, OkColor(this)); ChangeColor(ui->labelFullName, OkColor(this));
ChangeColor(ui->labelDescription, OkColor(this)); ChangeColor(ui->labelDescription, OkColor(this));
auto ColumnValid = [this](int column)
{
int value = m_columnsMap.at(column);
if (value == -1 && not ColumnMandatory(column))
{
return true;
}
for (int c=0; c < m_columnsMap.size(); ++c)
{
if (c == column)
{
continue;
}
if (value == m_columnsMap.at(c))
{
return false;
}
}
return true;
};
bool columnNameFlag = true; bool columnNameFlag = true;
bool columnValueFlag = true; bool columnValueFlag = true;
bool columnShiftAFlag = true; bool columnShiftAFlag = true;
@ -406,46 +362,26 @@ bool DialogMeasurementsCSVColumns::ColumnsValid()
const QColor errorColor = Qt::red; const QColor errorColor = Qt::red;
if (m_type == MeasurementsType::Multisize ? not ColumnValid(MultisizeMeasurementsColumns::Name)
if (m_type == MeasurementsType::Multisize) : not ColumnValid(IndividualMeasurementsColumns::Name))
{
if (not ColumnValid(static_cast<int>(MultisizeMeasurementsColumns::Name)))
{ {
ChangeColor(ui->labelName, errorColor); ChangeColor(ui->labelName, errorColor);
columnNameFlag = false; columnNameFlag = false;
} }
}
else
{
if (not ColumnValid(static_cast<int>(IndividualMeasurementsColumns::Name)))
{
ChangeColor(ui->labelName, errorColor);
columnNameFlag = false;
}
}
if (m_type == MeasurementsType::Multisize)
{ if (m_type == MeasurementsType::Multisize ? not ColumnValid(MultisizeMeasurementsColumns::BaseValue)
if (not ColumnValid(static_cast<int>(MultisizeMeasurementsColumns::BaseValue))) : not ColumnValid(IndividualMeasurementsColumns::Value))
{ {
ChangeColor(ui->labelValue, errorColor); ChangeColor(ui->labelValue, errorColor);
columnValueFlag = false; columnValueFlag = false;
} }
}
else
{
if (not ColumnValid(static_cast<int>(IndividualMeasurementsColumns::Value)))
{
ChangeColor(ui->labelValue, errorColor);
columnValueFlag = false;
}
}
if (m_type == MeasurementsType::Multisize) if (m_type == MeasurementsType::Multisize)
{ {
if (m_dimensions.size() > 0) if (not m_dimensions.empty())
{ {
if (not ColumnValid(static_cast<int>(MultisizeMeasurementsColumns::ShiftA))) if (not ColumnValid(MultisizeMeasurementsColumns::ShiftA))
{ {
ChangeColor(ui->labelShiftA, errorColor); ChangeColor(ui->labelShiftA, errorColor);
columnShiftAFlag = false; columnShiftAFlag = false;
@ -454,7 +390,7 @@ bool DialogMeasurementsCSVColumns::ColumnsValid()
if (m_dimensions.size() > 1) if (m_dimensions.size() > 1)
{ {
if (not ColumnValid(static_cast<int>(MultisizeMeasurementsColumns::ShiftB))) if (not ColumnValid(MultisizeMeasurementsColumns::ShiftB))
{ {
ChangeColor(ui->labelShiftB, errorColor); ChangeColor(ui->labelShiftB, errorColor);
columnShiftBFlag = false; columnShiftBFlag = false;
@ -463,7 +399,7 @@ bool DialogMeasurementsCSVColumns::ColumnsValid()
if (m_dimensions.size() > 2) if (m_dimensions.size() > 2)
{ {
if (not ColumnValid(static_cast<int>(MultisizeMeasurementsColumns::ShiftC))) if (not ColumnValid(MultisizeMeasurementsColumns::ShiftC))
{ {
ChangeColor(ui->labelShiftC, errorColor); ChangeColor(ui->labelShiftC, errorColor);
columnShiftCFlag = false; columnShiftCFlag = false;
@ -471,17 +407,15 @@ bool DialogMeasurementsCSVColumns::ColumnsValid()
} }
} }
if (not ColumnValid(m_type == MeasurementsType::Multisize if (m_type == MeasurementsType::Multisize ? not ColumnValid(MultisizeMeasurementsColumns::FullName)
? static_cast<int>(MultisizeMeasurementsColumns::FullName) : not ColumnValid(IndividualMeasurementsColumns::FullName))
: static_cast<int>(IndividualMeasurementsColumns::FullName)))
{ {
ChangeColor(ui->labelFullName, errorColor); ChangeColor(ui->labelFullName, errorColor);
columnFullNameFlag = false; columnFullNameFlag = false;
} }
if (not ColumnValid(m_type == MeasurementsType::Multisize if (m_type == MeasurementsType::Multisize ? not ColumnValid(MultisizeMeasurementsColumns::Description)
? static_cast<int>(MultisizeMeasurementsColumns::Description) : not ColumnValid(IndividualMeasurementsColumns::Description))
: static_cast<int>(IndividualMeasurementsColumns::Description)))
{ {
ChangeColor(ui->labelDescription, errorColor); ChangeColor(ui->labelDescription, errorColor);
columnDescriptionFlag = false; columnDescriptionFlag = false;
@ -927,3 +861,43 @@ void DialogMeasurementsCSVColumns::HackWidget(T **widget)
*widget = new T(); *widget = new T();
m_hackedWidgets.append(*widget); m_hackedWidgets.append(*widget);
} }
//---------------------------------------------------------------------------------------------------------------------
template<class T>
auto DialogMeasurementsCSVColumns::ColumnValid(T column) const -> bool
{
const int columnNumber = static_cast<int>(column);
int value = m_columnsMap.at(columnNumber);
if (value == -1 && not ColumnMandatory(columnNumber))
{
return true;
}
for (int c=0; c < m_columnsMap.size(); ++c)
{
if (c == columnNumber)
{
continue;
}
if (value == m_columnsMap.at(c))
{
return false;
}
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
template<class T>
void DialogMeasurementsCSVColumns::SaveColum(QComboBox *control, T column)
{
SCASSERT(control != nullptr)
const int columnNumber = static_cast<int>(column);
m_columnsMap[columnNumber] = control->currentData().toInt();
ShowImportPreview();
CheckStatus();
}

View File

@ -120,6 +120,12 @@ private:
void SetDefaultColumns(); void SetDefaultColumns();
void CheckStatus(); void CheckStatus();
template <class T>
auto ColumnValid(T column) const -> bool;
template <class T>
void SaveColum(QComboBox *control, T column);
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------