From a3d27bf9dbffd10f824b7625b86b0e0872d015ea Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 15 Feb 2017 15:23:04 +0200 Subject: [PATCH] Refacoring. Use marcos for getting current combobox data. --HG-- branch : feature --- .../configpages/tapeconfigurationpage.cpp | 24 ++------- src/app/tape/dialogs/dialogexporttocsv.cpp | 6 +-- .../tape/dialogs/dialognewmeasurements.cpp | 33 ++---------- .../dialogs/configpages/configurationpage.cpp | 25 ++------- .../dialogs/dialoglayoutsettings.cpp | 21 ++------ .../valentina/dialogs/dialogsavelayout.cpp | 6 +-- src/libs/vmisc/def.h | 5 ++ src/libs/vtools/dialogs/tools/dialogline.cpp | 12 +---- .../vtools/dialogs/tools/dialogpiecepath.cpp | 53 +++---------------- 9 files changed, 33 insertions(+), 152 deletions(-) diff --git a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp index 6daefc9b0..0e873df21 100644 --- a/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapeconfigurationpage.cpp @@ -234,18 +234,10 @@ QGroupBox *TapeConfigurationPage::PMSystemGroup() connect(systemCombo, static_cast(&QComboBox::currentIndexChanged), RECEIVER(this)[this]() { systemChanged = true; - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); - #else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); - #endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); - #else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); - #endif + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); }); @@ -337,18 +329,10 @@ void TapeConfigurationPage::RetranslateUi() systemAuthorLabel->setText(tr("Author:")); systemBookLabel->setText(tr("Book:")); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); -#endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); -#endif + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); gradationGroup->setTitle(tr("Default height and size")); diff --git a/src/app/tape/dialogs/dialogexporttocsv.cpp b/src/app/tape/dialogs/dialogexporttocsv.cpp index 8164a437b..81a4b10c3 100644 --- a/src/app/tape/dialogs/dialogexporttocsv.cpp +++ b/src/app/tape/dialogs/dialogexporttocsv.cpp @@ -81,11 +81,7 @@ bool DialogExportToCSV::WithHeader() const //--------------------------------------------------------------------------------------------------------------------- int DialogExportToCSV::SelectedMib() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return ui->comboBoxCodec->itemData(ui->comboBoxCodec->currentIndex()).toInt(); -#else - return ui->comboBoxCodec->currentData().toInt(); -#endif + return CURRENT_DATA(ui->comboBoxCodec).toInt(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tape/dialogs/dialognewmeasurements.cpp b/src/app/tape/dialogs/dialognewmeasurements.cpp index 11dbfa6bf..59eab4922 100644 --- a/src/app/tape/dialogs/dialognewmeasurements.cpp +++ b/src/app/tape/dialogs/dialognewmeasurements.cpp @@ -80,21 +80,13 @@ DialogNewMeasurements::~DialogNewMeasurements() //--------------------------------------------------------------------------------------------------------------------- MeasurementsType DialogNewMeasurements::Type() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return static_cast(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt()); -#else - return static_cast(ui->comboBoxMType->currentData().toInt()); -#endif + return static_cast(CURRENT_DATA(ui->comboBoxMType).toInt()); } //--------------------------------------------------------------------------------------------------------------------- Unit DialogNewMeasurements::MUnit() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return static_cast(ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt()); -#else - return static_cast(ui->comboBoxUnit->currentData().toInt()); -#endif + return static_cast(CURRENT_DATA(ui->comboBoxUnit).toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -117,14 +109,7 @@ void DialogNewMeasurements::changeEvent(QEvent *event) // retranslate designer form (single inheritance approach) ui->retranslateUi(this); InitMTypes(); - - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const MeasurementsType type = - static_cast(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt()); - #else - const MeasurementsType type = static_cast(ui->comboBoxMType->currentData().toInt()); - #endif - InitUnits(type); + InitUnits(static_cast(CURRENT_DATA(ui->comboBoxMType).toInt())); } // remember to call base class implementation @@ -192,11 +177,7 @@ void DialogNewMeasurements::InitMTypes() int val = static_cast(MeasurementsType::Unknown); if (ui->comboBoxMType->currentIndex() != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - val = ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt(); - #else - val = ui->comboBoxMType->currentData().toInt(); - #endif + val = CURRENT_DATA(ui->comboBoxMType).toInt(); } ui->comboBoxMType->blockSignals(true); @@ -234,11 +215,7 @@ void DialogNewMeasurements::InitUnits(const MeasurementsType &type) int val = static_cast(Unit::Cm); if (ui->comboBoxUnit->currentIndex() != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - val = ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt(); - #else - val = ui->comboBoxUnit->currentData().toInt(); - #endif + val = CURRENT_DATA(ui->comboBoxUnit).toInt(); } ui->comboBoxUnit->blockSignals(true); diff --git a/src/app/valentina/dialogs/configpages/configurationpage.cpp b/src/app/valentina/dialogs/configpages/configurationpage.cpp index 3290cf9a0..940ce3353 100644 --- a/src/app/valentina/dialogs/configpages/configurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/configurationpage.cpp @@ -395,19 +395,11 @@ QGroupBox *ConfigurationPage::ToolBarGroup() void ConfigurationPage::SystemChanged() { systemChanged = true; -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); -#endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); -#endif + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); } @@ -470,18 +462,11 @@ void ConfigurationPage::RetranslateUi() systemAuthorLabel->setText(tr("Author:")); systemBookLabel->setText(tr("Book:")); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - QString text = qApp->TrVars()->PMSystemAuthor(systemCombo->currentData().toString()); -#endif + QString text = qApp->TrVars()->PMSystemAuthor(CURRENT_DATA(systemCombo).toString()); systemAuthorValueLabel->setText(text); systemAuthorValueLabel->setToolTip(text); -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - text = qApp->TrVars()->PMSystemBook(systemCombo->itemData(systemCombo->currentIndex()).toString()); -#else - text = qApp->TrVars()->PMSystemBook(systemCombo->currentData().toString()); -#endif + + text = qApp->TrVars()->PMSystemBook(CURRENT_DATA(systemCombo).toString()); systemBookValueLabel->setPlainText(text); sendGroup->setTitle(tr("Send crash reports")); diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index cbe13ec07..51f5ace45 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -823,12 +823,7 @@ QString DialogLayoutSettings::MakeHelpTemplateList() QSizeF DialogLayoutSettings::Template() { PaperSizeTemplate temp; -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - temp = static_cast(ui->comboBoxTemplates->itemData(ui->comboBoxTemplates->currentIndex()) - .toInt()); -#else - temp = static_cast(ui->comboBoxTemplates->currentData().toInt()); -#endif + temp = static_cast(CURRENT_DATA(ui->comboBoxTemplates).toInt()); switch (temp) { @@ -980,23 +975,13 @@ QMarginsF DialogLayoutSettings::GetDefPrinterFields() const //--------------------------------------------------------------------------------------------------------------------- Unit DialogLayoutSettings::PaperUnit() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return VDomDocument::StrToUnits(ui->comboBoxPaperSizeUnit->itemData(ui->comboBoxPaperSizeUnit->currentIndex()) - .toString()); -#else - return VDomDocument::StrToUnits(ui->comboBoxPaperSizeUnit->currentData().toString()); -#endif + return VDomDocument::StrToUnits(CURRENT_DATA(ui->comboBoxPaperSizeUnit).toString()); } //--------------------------------------------------------------------------------------------------------------------- Unit DialogLayoutSettings::LayoutUnit() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return VDomDocument::StrToUnits(ui->comboBoxLayoutUnit->itemData(ui->comboBoxLayoutUnit->currentIndex()) - .toString()); -#else - return VDomDocument::StrToUnits(ui->comboBoxLayoutUnit->currentData().toString()); -#endif + return VDomDocument::StrToUnits(CURRENT_DATA(ui->comboBoxLayoutUnit).toString()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 8044caf97..31fe77bce 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -195,11 +195,7 @@ QString DialogSaveLayout::FileName() const //--------------------------------------------------------------------------------------------------------------------- QString DialogSaveLayout::Format() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return ui->comboBoxFormat->itemData(ui->comboBoxFormat->currentIndex()).toString(); -#else - return ui->comboBoxFormat->currentData().toString(); -#endif + return CURRENT_DATA(ui->comboBoxFormat).toString(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index c0903a1d9..c89d93075 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -59,6 +59,11 @@ template class QSharedPointer; #define RECEIVER(obj) #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 QMarginsF; diff --git a/src/libs/vtools/dialogs/tools/dialogline.cpp b/src/libs/vtools/dialogs/tools/dialogline.cpp index 923091334..121c65ddb 100644 --- a/src/libs/vtools/dialogs/tools/dialogline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogline.cpp @@ -219,11 +219,7 @@ void DialogLine::ChosenObject(quint32 id, const SceneObject &type) */ quint32 DialogLine::GetFirstPoint() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return qvariant_cast(ui->comboBoxFirstPoint->itemData(ui->comboBoxFirstPoint->currentIndex())); -#else - return qvariant_cast(ui->comboBoxFirstPoint->currentData()); -#endif + return qvariant_cast(CURRENT_DATA(ui->comboBoxFirstPoint)); } //--------------------------------------------------------------------------------------------------------------------- @@ -233,11 +229,7 @@ quint32 DialogLine::GetFirstPoint() const */ quint32 DialogLine::GetSecondPoint() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - return qvariant_cast(ui->comboBoxSecondPoint->itemData(ui->comboBoxSecondPoint->currentIndex())); -#else - return qvariant_cast(ui->comboBoxSecondPoint->currentData()); -#endif + return qvariant_cast(CURRENT_DATA(ui->comboBoxSecondPoint)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp index d564d75dd..cd8097aac 100644 --- a/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpiecepath.cpp @@ -298,13 +298,8 @@ void DialogPiecePath::NodeChanged(int index) 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 int nodeIndex = path.indexOfNode(id); + const int nodeIndex = path.indexOfNode(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (nodeIndex != -1) { const VPieceNode &node = path.at(nodeIndex); @@ -598,11 +593,7 @@ void DialogPiecePath::InitPathTypes() //--------------------------------------------------------------------------------------------------------------------- void DialogPiecePath::InitNodesList() { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(ui->comboBoxNodes->currentIndex()).toUInt(); -#else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); -#endif + const quint32 id = CURRENT_DATA(ui->comboBoxNodes).toUInt(); ui->comboBoxNodes->blockSignals(true); ui->comboBoxNodes->clear(); @@ -639,21 +630,10 @@ void DialogPiecePath::NodeAngleChanged(int index) const int i = ui->comboBoxNodes->currentIndex(); if (i != -1 && index != -1) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const quint32 id = ui->comboBoxNodes->itemData(i).toUInt(); - #else - const quint32 id = ui->comboBoxNodes->currentData().toUInt(); - #endif - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { - #if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->itemData(index).toUInt()); - #else - const PieceNodeAngle angle = static_cast(ui->comboBoxAngle->currentData().toUInt()); - #endif - + const PieceNodeAngle angle = static_cast(CURRENT_DATA(ui->comboBoxAngle).toUInt()); VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); rowNode.SetAngleType(angle); rowItem->setData(Qt::UserRole, QVariant::fromValue(rowNode)); @@ -694,14 +674,7 @@ void DialogPiecePath::SetPiecePath(const VPiecePath &path) //--------------------------------------------------------------------------------------------------------------------- PiecePathType DialogPiecePath::GetType() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const PiecePathType type = - static_cast(ui->comboBoxType->itemData(ui->comboBoxType->currentIndex()).toInt()); -#else - const PiecePathType type = static_cast(ui->comboBoxType->currentData().toInt()); -#endif - - return type; + return static_cast(CURRENT_DATA(ui->comboBoxType).toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -781,13 +754,7 @@ void DialogPiecePath::UpdateNodeSABefore(const QString &formula) const int index = ui->comboBoxNodes->currentIndex(); 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 - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole)); @@ -803,13 +770,7 @@ void DialogPiecePath::UpdateNodeSAAfter(const QString &formula) const int index = ui->comboBoxNodes->currentIndex(); 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 - - QListWidgetItem *rowItem = GetItemById(id); + QListWidgetItem *rowItem = GetItemById(CURRENT_DATA(ui->comboBoxNodes).toUInt()); if (rowItem) { VPieceNode rowNode = qvariant_cast(rowItem->data(Qt::UserRole));