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]()
{
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"));

View File

@ -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();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -80,21 +80,13 @@ DialogNewMeasurements::~DialogNewMeasurements()
//---------------------------------------------------------------------------------------------------------------------
MeasurementsType DialogNewMeasurements::Type() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
return static_cast<MeasurementsType>(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt());
#else
return static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt());
#endif
return static_cast<MeasurementsType>(CURRENT_DATA(ui->comboBoxMType).toInt());
}
//---------------------------------------------------------------------------------------------------------------------
Unit DialogNewMeasurements::MUnit() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
return static_cast<Unit>(ui->comboBoxUnit->itemData(ui->comboBoxUnit->currentIndex()).toInt());
#else
return static_cast<Unit>(ui->comboBoxUnit->currentData().toInt());
#endif
return static_cast<Unit>(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<MeasurementsType>(ui->comboBoxMType->itemData(ui->comboBoxMType->currentIndex()).toInt());
#else
const MeasurementsType type = static_cast<MeasurementsType>(ui->comboBoxMType->currentData().toInt());
#endif
InitUnits(type);
InitUnits(static_cast<MeasurementsType>(CURRENT_DATA(ui->comboBoxMType).toInt()));
}
// remember to call base class implementation
@ -192,11 +177,7 @@ void DialogNewMeasurements::InitMTypes()
int val = static_cast<int>(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<int>(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);

View File

@ -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"));

View File

@ -823,12 +823,7 @@ QString DialogLayoutSettings::MakeHelpTemplateList()
QSizeF DialogLayoutSettings::Template()
{
PaperSizeTemplate temp;
#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0)
temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->itemData(ui->comboBoxTemplates->currentIndex())
.toInt());
#else
temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt());
#endif
temp = static_cast<PaperSizeTemplate>(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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -59,6 +59,11 @@ template <class T> 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;

View File

@ -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<quint32>(ui->comboBoxFirstPoint->itemData(ui->comboBoxFirstPoint->currentIndex()));
#else
return qvariant_cast<quint32>(ui->comboBoxFirstPoint->currentData());
#endif
return qvariant_cast<quint32>(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<quint32>(ui->comboBoxSecondPoint->itemData(ui->comboBoxSecondPoint->currentIndex()));
#else
return qvariant_cast<quint32>(ui->comboBoxSecondPoint->currentData());
#endif
return qvariant_cast<quint32>(CURRENT_DATA(ui->comboBoxSecondPoint));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<PieceNodeAngle>(ui->comboBoxAngle->itemData(index).toUInt());
#else
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(ui->comboBoxAngle->currentData().toUInt());
#endif
const PieceNodeAngle angle = static_cast<PieceNodeAngle>(CURRENT_DATA(ui->comboBoxAngle).toUInt());
VPieceNode rowNode = qvariant_cast<VPieceNode>(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<PiecePathType>(ui->comboBoxType->itemData(ui->comboBoxType->currentIndex()).toInt());
#else
const PiecePathType type = static_cast<PiecePathType>(ui->comboBoxType->currentData().toInt());
#endif
return type;
return static_cast<PiecePathType>(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<VPieceNode>(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<VPieceNode>(rowItem->data(Qt::UserRole));