From 8f563332499ffcbe007c6d31a417562f79570a19 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 3 Jul 2020 08:27:53 -0400 Subject: [PATCH] CPropertyDelegate: Make use of Qt 5 signals and slots --- src/Editor/PropertyEdit/CPropertyDelegate.cpp | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Editor/PropertyEdit/CPropertyDelegate.cpp b/src/Editor/PropertyEdit/CPropertyDelegate.cpp index 7ce8786e..c939a453 100644 --- a/src/Editor/PropertyEdit/CPropertyDelegate.cpp +++ b/src/Editor/PropertyEdit/CPropertyDelegate.cpp @@ -20,11 +20,11 @@ // This macro should be used on every widget where changes should be reflected in realtime and not just when the edit is finished. #define CONNECT_RELAY(Widget, Index, Signal) \ - { \ - CPropertyRelay *pRelay = new CPropertyRelay(Widget, Index); \ - connect(Widget, SIGNAL(Signal), pRelay, SLOT(OnWidgetEdited())); \ - connect(pRelay, SIGNAL(WidgetEdited(QWidget*, const QModelIndex&)), this, SLOT(WidgetEdited(QWidget*, const QModelIndex&))); \ - } + do { \ + CPropertyRelay *pRelay = new CPropertyRelay(Widget, Index); \ + connect(Widget, Signal, pRelay, &CPropertyRelay::OnWidgetEdited); \ + connect(pRelay, &CPropertyRelay::WidgetEdited, this, &CPropertyDelegate::WidgetEdited); \ + } while (false) CPropertyDelegate::CPropertyDelegate(QObject* pParent) : QStyledItemDelegate(pParent) @@ -58,7 +58,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie case EPropertyType::Bool: { QCheckBox *pCheckBox = new QCheckBox(pParent); - CONNECT_RELAY(pCheckBox, rkIndex, toggled(bool)) + CONNECT_RELAY(pCheckBox, rkIndex, &QCheckBox::toggled); pOut = pCheckBox; break; } @@ -69,7 +69,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie pSpinBox->setMinimum(INT16_MIN); pSpinBox->setMaximum(INT16_MAX); pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix())); - CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int)) + CONNECT_RELAY(pSpinBox, rkIndex, qOverload(&WIntegralSpinBox::valueChanged)); pOut = pSpinBox; break; } @@ -80,7 +80,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie pSpinBox->setMinimum(INT32_MIN); pSpinBox->setMaximum(INT32_MAX); pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix())); - CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int)) + CONNECT_RELAY(pSpinBox, rkIndex, qOverload(&WIntegralSpinBox::valueChanged)); pOut = pSpinBox; break; } @@ -90,7 +90,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie WDraggableSpinBox *pSpinBox = new WDraggableSpinBox(pParent); pSpinBox->setSingleStep(0.1); pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix())); - CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(double)) + CONNECT_RELAY(pSpinBox, rkIndex, qOverload(&WDraggableSpinBox::valueChanged)); pOut = pSpinBox; break; } @@ -98,7 +98,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie case EPropertyType::Color: { WColorPicker *pColorPicker = new WColorPicker(pParent); - CONNECT_RELAY(pColorPicker, rkIndex, ColorChanged(QColor)) + CONNECT_RELAY(pColorPicker, rkIndex, &WColorPicker::ColorChanged); pOut = pColorPicker; break; } @@ -108,7 +108,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent); pSpinBox->setMinimum(-1); pSpinBox->setMaximum(0xFFFF); - CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int)) + CONNECT_RELAY(pSpinBox, rkIndex, qOverload(&WIntegralSpinBox::valueChanged)); pOut = pSpinBox; break; } @@ -116,7 +116,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie case EPropertyType::String: { QLineEdit *pLineEdit = new QLineEdit(pParent); - CONNECT_RELAY(pLineEdit, rkIndex, textEdited(QString)) + CONNECT_RELAY(pLineEdit, rkIndex, &QLineEdit::textEdited); pOut = pLineEdit; break; } @@ -130,7 +130,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie for (size_t ValueIdx = 0; ValueIdx < pEnum->NumPossibleValues(); ValueIdx++) pComboBox->addItem(TO_QSTRING(pEnum->ValueName(ValueIdx))); - CONNECT_RELAY(pComboBox, rkIndex, currentIndexChanged(int)) + CONNECT_RELAY(pComboBox, rkIndex, qOverload(&QComboBox::currentIndexChanged)); pOut = pComboBox; break; } @@ -143,7 +143,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie CAssetProperty *pAsset = TPropCast(pProp); pSelector->SetTypeFilter(pAsset->GetTypeFilter()); - CONNECT_RELAY(pSelector, rkIndex, ResourceChanged(CResourceEntry*)) + CONNECT_RELAY(pSelector, rkIndex, &CResourceSelector::ResourceChanged); pOut = pSelector; break; } @@ -176,7 +176,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie else if (Type == EPropertyType::Flags) { QCheckBox *pCheckBox = new QCheckBox(pParent); - CONNECT_RELAY(pCheckBox, rkIndex, toggled(bool)) + CONNECT_RELAY(pCheckBox, rkIndex, &QCheckBox::toggled); pOut = pCheckBox; } } @@ -576,11 +576,11 @@ QWidget* CPropertyDelegate::CreateCharacterEditor(QWidget *pParent, const QModel else pSelector->SetTypeFilter(gpEdApp->CurrentGame(), "CHAR"); - CONNECT_RELAY(pSelector, rkIndex, ResourceChanged(CResourceEntry*)); + CONNECT_RELAY(pSelector, rkIndex, &CResourceSelector::ResourceChanged); return pSelector; } - else if (Type == EPropertyType::Enum || Type == EPropertyType::Choice) + if (Type == EPropertyType::Enum || Type == EPropertyType::Choice) { QComboBox* pComboBox = new QComboBox(pParent); CAnimSet* pAnimSet = Params.AnimSet(); @@ -591,14 +591,14 @@ QWidget* CPropertyDelegate::CreateCharacterEditor(QWidget *pParent, const QModel pComboBox->addItem(TO_QSTRING(pAnimSet->Character(CharIdx)->Name)); } - CONNECT_RELAY(pComboBox, rkIndex, currentIndexChanged(int)); + CONNECT_RELAY(pComboBox, rkIndex, qOverload(&QComboBox::currentIndexChanged)); return pComboBox; } - else if (Type == EPropertyType::Int) + if (Type == EPropertyType::Int) { WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent); - CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int)); + CONNECT_RELAY(pSpinBox, rkIndex, qOverload(&WIntegralSpinBox::valueChanged)); return pSpinBox; }