Refacoring. Use marcos for getting current combobox data.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-02-15 15:23:04 +02:00
parent 6597f68dad
commit a3d27bf9db
9 changed files with 33 additions and 152 deletions

View File

@ -234,18 +234,10 @@ QGroupBox *TapeConfigurationPage::PMSystemGroup()
connect(systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), RECEIVER(this)[this]() connect(systemCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), RECEIVER(this)[this]()
{ {
systemChanged = true; systemChanged = true;
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString());
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString());
#endif
systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setText(text);
systemAuthorValueLabel->setToolTip(text); systemAuthorValueLabel->setToolTip(text);
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString());
text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString());
#endif
systemBookValueLabel->setPlainText(text); systemBookValueLabel->setPlainText(text);
}); });
@ -337,18 +329,10 @@ void TapeConfigurationPage::RetranslateUi()
systemAuthorLabel->setText(tr("Author:")); systemAuthorLabel->setText(tr("Author:"));
systemBookLabel->setText(tr("Book:")); systemBookLabel->setText(tr("Book:"));
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString());
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString());
#endif
systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setText(text);
systemAuthorValueLabel->setToolTip(text); systemAuthorValueLabel->setToolTip(text);
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString());
text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString());
#endif
systemBookValueLabel->setPlainText(text); systemBookValueLabel->setPlainText(text);
gradationGroup->setTitle(tr("Default height and size")); gradationGroup->setTitle(tr("Default height and size"));

View File

@ -81,11 +81,7 @@ bool DialogExportToCSV::WithHeader() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int DialogExportToCSV::SelectedMib() const int DialogExportToCSV::SelectedMib() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return CURRENT_DATA(ui->comboBoxCodec).toInt();
return ui->comboBoxCodec->itemData(ui->comboBoxCodec->currentIndex()).toInt();
#else
return ui->comboBoxCodec->currentData().toInt();
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -80,21 +80,13 @@ DialogNewMeasurements::~DialogNewMeasurements()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MeasurementsType DialogNewMeasurements::Type() const MeasurementsType DialogNewMeasurements::Type() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return static_cast<MeasurementsType>(CURRENT_DATA(ui->comboBoxMType).toInt());
return static_cast<MeasurementsType>(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt());
#else
return static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt());
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Unit DialogNewMeasurements::MUnit() const Unit DialogNewMeasurements::MUnit() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return static_cast<Unit>(CURRENT_DATA(ui->comboBoxUnit).toInt());
return static_cast<Unit>(ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt());
#else
return static_cast<Unit>(ui->comboBoxUnit->currentData().toInt());
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -117,14 +109,7 @@ void DialogNewMeasurements::changeEvent(QEvent *event)
// retranslate designer form (single inheritance approach) // retranslate designer form (single inheritance approach)
ui->retranslateUi(this); ui->retranslateUi(this);
InitMTypes(); InitMTypes();
InitUnits(static_cast<MeasurementsType>(CURRENT_DATA(ui->comboBoxMType).toInt()));
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
const MeasurementsType type =
static_cast<MeasurementsType>(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt());
#else
const MeasurementsType type = static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt());
#endif
InitUnits(type);
} }
// remember to call base class implementation // remember to call base class implementation
@ -192,11 +177,7 @@ void DialogNewMeasurements::InitMTypes()
int val = static_cast<int>(MeasurementsType::Unknown); int val = static_cast<int>(MeasurementsType::Unknown);
if (ui->comboBoxMType->currentIndex() != -1) if (ui->comboBoxMType->currentIndex() != -1)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) val = CURRENT_DATA(ui->comboBoxMType).toInt();
val = ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt();
#else
val = ui->comboBoxMType->currentData().toInt();
#endif
} }
ui->comboBoxMType->blockSignals(true); ui->comboBoxMType->blockSignals(true);
@ -234,11 +215,7 @@ void DialogNewMeasurements::InitUnits(const MeasurementsType &type)
int val = static_cast<int>(Unit::Cm); int val = static_cast<int>(Unit::Cm);
if (ui->comboBoxUnit->currentIndex() != -1) if (ui->comboBoxUnit->currentIndex() != -1)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) val = CURRENT_DATA(ui->comboBoxUnit).toInt();
val = ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt();
#else
val = ui->comboBoxUnit->currentData().toInt();
#endif
} }
ui->comboBoxUnit->blockSignals(true); ui->comboBoxUnit->blockSignals(true);

View File

@ -395,19 +395,11 @@ QGroupBox *ConfigurationPage::ToolBarGroup()
void ConfigurationPage::SystemChanged() void ConfigurationPage::SystemChanged()
{ {
systemChanged = true; systemChanged = true;
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString());
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString());
#endif
systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setText(text);
systemAuthorValueLabel->setToolTip(text); systemAuthorValueLabel->setToolTip(text);
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString());
text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString());
#endif
systemBookValueLabel->setPlainText(text); systemBookValueLabel->setPlainText(text);
} }
@ -470,18 +462,11 @@ void ConfigurationPage::RetranslateUi()
systemAuthorLabel->setText(tr("Author:")); systemAuthorLabel->setText(tr("Author:"));
systemBookLabel->setText(tr("Book:")); systemBookLabel->setText(tr("Book:"));
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString());
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString());
#else
QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString());
#endif
systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setText(text);
systemAuthorValueLabel->setToolTip(text); systemAuthorValueLabel->setToolTip(text);
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString());
#else
text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString());
#endif
systemBookValueLabel->setPlainText(text); systemBookValueLabel->setPlainText(text);
sendGroup->setTitle(tr("Send crash reports")); sendGroup->setTitle(tr("Send crash reports"));

View File

@ -823,12 +823,7 @@ QString DialogLayoutSettings::MakeHelpTemplateList()
QSizeF DialogLayoutSettings::Template() QSizeF DialogLayoutSettings::Template()
{ {
PaperSizeTemplate temp; PaperSizeTemplate temp;
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) temp = static_cast<PaperSizeTemplate>(CURRENT_DATA(ui->comboBoxTemplates).toInt());
temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->itemData(ui->comboBoxTemplates->currentIndex())
.toInt());
#else
temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt());
#endif
switch (temp) switch (temp)
{ {
@ -980,23 +975,13 @@ QMarginsF DialogLayoutSettings::GetDefPrinterFields() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Unit DialogLayoutSettings::PaperUnit() const Unit DialogLayoutSettings::PaperUnit() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return VDomDocument::StrToUnits(CURRENT_DATA(ui->comboBoxPaperSizeUnit).toString());
return VDomDocument::StrToUnits(ui->comboBoxPaperSizeUnit->itemData(ui->comboBoxPaperSizeUnit->currentIndex())
.toString());
#else
return VDomDocument::StrToUnits(ui->comboBoxPaperSizeUnit->currentData().toString());
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Unit DialogLayoutSettings::LayoutUnit() const Unit DialogLayoutSettings::LayoutUnit() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return VDomDocument::StrToUnits(CURRENT_DATA(ui->comboBoxLayoutUnit).toString());
return VDomDocument::StrToUnits(ui->comboBoxLayoutUnit->itemData(ui->comboBoxLayoutUnit->currentIndex())
.toString());
#else
return VDomDocument::StrToUnits(ui->comboBoxLayoutUnit->currentData().toString());
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -195,11 +195,7 @@ QString DialogSaveLayout::FileName() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogSaveLayout::Format() const QString DialogSaveLayout::Format() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return CURRENT_DATA(ui->comboBoxFormat).toString();
return ui->comboBoxFormat->itemData(ui->comboBoxFormat->currentIndex()).toString();
#else
return ui->comboBoxFormat->currentData().toString();
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -59,6 +59,11 @@ template <class T> class QSharedPointer;
#define RECEIVER(obj) #define RECEIVER(obj)
#endif #endif
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
#define CURRENT_DATA(box) box->itemData(box->currentIndex())
#else
#define CURRENT_DATA(box) box->currentData()
#endif
class QComboBox; class QComboBox;
class QMarginsF; class QMarginsF;

View File

@ -219,11 +219,7 @@ void DialogLine::ChosenObject(quint32 id, const SceneObject &type)
*/ */
quint32 DialogLine::GetFirstPoint() const quint32 DialogLine::GetFirstPoint() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return qvariant_cast<quint32>(CURRENT_DATA(ui->comboBoxFirstPoint));
return qvariant_cast<quint32>(ui->comboBoxFirstPoint->itemData(ui->comboBoxFirstPoint->currentIndex()));
#else
return qvariant_cast<quint32>(ui->comboBoxFirstPoint->currentData());
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -233,11 +229,7 @@ quint32 DialogLine::GetFirstPoint() const
*/ */
quint32 DialogLine::GetSecondPoint() const quint32 DialogLine::GetSecondPoint() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return qvariant_cast<quint32>(CURRENT_DATA(ui->comboBoxSecondPoint));
return qvariant_cast<quint32>(ui->comboBoxSecondPoint->itemData(ui->comboBoxSecondPoint->currentIndex()));
#else
return qvariant_cast<quint32>(ui->comboBoxSecondPoint->currentData());
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -298,13 +298,8 @@ void DialogPiecePath::NodeChanged(int index)
if (index != -1) if (index != -1)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
const quint32 id = ui->comboBoxNodes->itemData(index).toUInt();
#else
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
#endif
const VPiecePath path = CreatePath(); const VPiecePath path = CreatePath();
const int nodeIndex = path.indexOfNode(id); const int nodeIndex = path.indexOfNode(CURRENT_DATA(ui->comboBoxNodes).toUInt());
if (nodeIndex != -1) if (nodeIndex != -1)
{ {
const VPieceNode &node = path.at(nodeIndex); const VPieceNode &node = path.at(nodeIndex);
@ -598,11 +593,7 @@ void DialogPiecePath::InitPathTypes()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::InitNodesList() void DialogPiecePath::InitNodesList()
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) const quint32 id = CURRENT_DATA(ui->comboBoxNodes).toUInt();
const quint32 id = ui->comboBoxNodes->itemData(ui->comboBoxNodes->currentIndex()).toUInt();
#else
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
#endif
ui->comboBoxNodes->blockSignals(true); ui->comboBoxNodes->blockSignals(true);
ui->comboBoxNodes->clear(); ui->comboBoxNodes->clear();
@ -639,21 +630,10 @@ void DialogPiecePath::NodeAngleChanged(int index)
const int i = ui->comboBoxNodes->currentIndex(); const int i = ui->comboBoxNodes->currentIndex();
if (i != -1 && index != -1) if (i != -1 && index != -1)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt());
const quint32 id = ui->comboBoxNodes->itemData(i).toUInt();
#else
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
#endif
QListWidgetItem *rowItem = GetItemById(id);
if (rowItem) if (rowItem)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) const PieceNodeAngle angle = static_cast<PieceNodeAngle>(CURRENT_DATA(ui->comboBoxAngle).toUInt());
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->itemData(index).toUInt());
#else
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->currentData().toUInt());
#endif
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole)); VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
rowNode.SetAngleType(angle); rowNode.SetAngleType(angle);
rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode));
@ -694,14 +674,7 @@ void DialogPiecePath::SetPiecePath(const VPiecePath &path)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PiecePathType DialogPiecePath::GetType() const PiecePathType DialogPiecePath::GetType() const
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return static_cast<PiecePathType>(CURRENT_DATA(ui->comboBoxType).toInt());
const PiecePathType type =
static_cast<PiecePathType>(ui->comboBoxType->itemData(ui->comboBoxType->currentIndex()).toInt());
#else
const PiecePathType type = static_cast<PiecePathType>(ui->comboBoxType->currentData().toInt());
#endif
return type;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -781,13 +754,7 @@ void DialogPiecePath::UpdateNodeSABefore(const QString &formula)
const int index = ui->comboBoxNodes->currentIndex(); const int index = ui->comboBoxNodes->currentIndex();
if (index != -1) if (index != -1)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt());
const quint32 id = ui->comboBoxNodes->itemData(index).toUInt();
#else
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
#endif
QListWidgetItem *rowItem = GetItemById(id);
if (rowItem) if (rowItem)
{ {
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole)); VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
@ -803,13 +770,7 @@ void DialogPiecePath::UpdateNodeSAAfter(const QString &formula)
const int index = ui->comboBoxNodes->currentIndex(); const int index = ui->comboBoxNodes->currentIndex();
if (index != -1) if (index != -1)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt());
const quint32 id = ui->comboBoxNodes->itemData(index).toUInt();
#else
const quint32 id = ui->comboBoxNodes->currentData().toUInt();
#endif
QListWidgetItem *rowItem = GetItemById(id);
if (rowItem) if (rowItem)
{ {
VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole)); VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));