CPropertyDelegate: Make use of Qt 5 signals and slots
This commit is contained in:
parent
f798517416
commit
8f56333249
|
@ -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.
|
// 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) \
|
#define CONNECT_RELAY(Widget, Index, Signal) \
|
||||||
{ \
|
do { \
|
||||||
CPropertyRelay *pRelay = new CPropertyRelay(Widget, Index); \
|
CPropertyRelay *pRelay = new CPropertyRelay(Widget, Index); \
|
||||||
connect(Widget, SIGNAL(Signal), pRelay, SLOT(OnWidgetEdited())); \
|
connect(Widget, Signal, pRelay, &CPropertyRelay::OnWidgetEdited); \
|
||||||
connect(pRelay, SIGNAL(WidgetEdited(QWidget*, const QModelIndex&)), this, SLOT(WidgetEdited(QWidget*, const QModelIndex&))); \
|
connect(pRelay, &CPropertyRelay::WidgetEdited, this, &CPropertyDelegate::WidgetEdited); \
|
||||||
}
|
} while (false)
|
||||||
|
|
||||||
CPropertyDelegate::CPropertyDelegate(QObject* pParent)
|
CPropertyDelegate::CPropertyDelegate(QObject* pParent)
|
||||||
: QStyledItemDelegate(pParent)
|
: QStyledItemDelegate(pParent)
|
||||||
|
@ -58,7 +58,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
case EPropertyType::Bool:
|
case EPropertyType::Bool:
|
||||||
{
|
{
|
||||||
QCheckBox *pCheckBox = new QCheckBox(pParent);
|
QCheckBox *pCheckBox = new QCheckBox(pParent);
|
||||||
CONNECT_RELAY(pCheckBox, rkIndex, toggled(bool))
|
CONNECT_RELAY(pCheckBox, rkIndex, &QCheckBox::toggled);
|
||||||
pOut = pCheckBox;
|
pOut = pCheckBox;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
pSpinBox->setMinimum(INT16_MIN);
|
pSpinBox->setMinimum(INT16_MIN);
|
||||||
pSpinBox->setMaximum(INT16_MAX);
|
pSpinBox->setMaximum(INT16_MAX);
|
||||||
pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix()));
|
pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix()));
|
||||||
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int))
|
CONNECT_RELAY(pSpinBox, rkIndex, qOverload<int>(&WIntegralSpinBox::valueChanged));
|
||||||
pOut = pSpinBox;
|
pOut = pSpinBox;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
pSpinBox->setMinimum(INT32_MIN);
|
pSpinBox->setMinimum(INT32_MIN);
|
||||||
pSpinBox->setMaximum(INT32_MAX);
|
pSpinBox->setMaximum(INT32_MAX);
|
||||||
pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix()));
|
pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix()));
|
||||||
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int))
|
CONNECT_RELAY(pSpinBox, rkIndex, qOverload<int>(&WIntegralSpinBox::valueChanged));
|
||||||
pOut = pSpinBox;
|
pOut = pSpinBox;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
WDraggableSpinBox *pSpinBox = new WDraggableSpinBox(pParent);
|
WDraggableSpinBox *pSpinBox = new WDraggableSpinBox(pParent);
|
||||||
pSpinBox->setSingleStep(0.1);
|
pSpinBox->setSingleStep(0.1);
|
||||||
pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix()));
|
pSpinBox->setSuffix(TO_QSTRING(pProp->Suffix()));
|
||||||
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(double))
|
CONNECT_RELAY(pSpinBox, rkIndex, qOverload<double>(&WDraggableSpinBox::valueChanged));
|
||||||
pOut = pSpinBox;
|
pOut = pSpinBox;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
case EPropertyType::Color:
|
case EPropertyType::Color:
|
||||||
{
|
{
|
||||||
WColorPicker *pColorPicker = new WColorPicker(pParent);
|
WColorPicker *pColorPicker = new WColorPicker(pParent);
|
||||||
CONNECT_RELAY(pColorPicker, rkIndex, ColorChanged(QColor))
|
CONNECT_RELAY(pColorPicker, rkIndex, &WColorPicker::ColorChanged);
|
||||||
pOut = pColorPicker;
|
pOut = pColorPicker;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
|
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
|
||||||
pSpinBox->setMinimum(-1);
|
pSpinBox->setMinimum(-1);
|
||||||
pSpinBox->setMaximum(0xFFFF);
|
pSpinBox->setMaximum(0xFFFF);
|
||||||
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int))
|
CONNECT_RELAY(pSpinBox, rkIndex, qOverload<int>(&WIntegralSpinBox::valueChanged));
|
||||||
pOut = pSpinBox;
|
pOut = pSpinBox;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
case EPropertyType::String:
|
case EPropertyType::String:
|
||||||
{
|
{
|
||||||
QLineEdit *pLineEdit = new QLineEdit(pParent);
|
QLineEdit *pLineEdit = new QLineEdit(pParent);
|
||||||
CONNECT_RELAY(pLineEdit, rkIndex, textEdited(QString))
|
CONNECT_RELAY(pLineEdit, rkIndex, &QLineEdit::textEdited);
|
||||||
pOut = pLineEdit;
|
pOut = pLineEdit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
for (size_t ValueIdx = 0; ValueIdx < pEnum->NumPossibleValues(); ValueIdx++)
|
for (size_t ValueIdx = 0; ValueIdx < pEnum->NumPossibleValues(); ValueIdx++)
|
||||||
pComboBox->addItem(TO_QSTRING(pEnum->ValueName(ValueIdx)));
|
pComboBox->addItem(TO_QSTRING(pEnum->ValueName(ValueIdx)));
|
||||||
|
|
||||||
CONNECT_RELAY(pComboBox, rkIndex, currentIndexChanged(int))
|
CONNECT_RELAY(pComboBox, rkIndex, qOverload<int>(&QComboBox::currentIndexChanged));
|
||||||
pOut = pComboBox;
|
pOut = pComboBox;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
CAssetProperty *pAsset = TPropCast<CAssetProperty>(pProp);
|
CAssetProperty *pAsset = TPropCast<CAssetProperty>(pProp);
|
||||||
pSelector->SetTypeFilter(pAsset->GetTypeFilter());
|
pSelector->SetTypeFilter(pAsset->GetTypeFilter());
|
||||||
|
|
||||||
CONNECT_RELAY(pSelector, rkIndex, ResourceChanged(CResourceEntry*))
|
CONNECT_RELAY(pSelector, rkIndex, &CResourceSelector::ResourceChanged);
|
||||||
pOut = pSelector;
|
pOut = pSelector;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ QWidget* CPropertyDelegate::createEditor(QWidget* pParent, const QStyleOptionVie
|
||||||
else if (Type == EPropertyType::Flags)
|
else if (Type == EPropertyType::Flags)
|
||||||
{
|
{
|
||||||
QCheckBox *pCheckBox = new QCheckBox(pParent);
|
QCheckBox *pCheckBox = new QCheckBox(pParent);
|
||||||
CONNECT_RELAY(pCheckBox, rkIndex, toggled(bool))
|
CONNECT_RELAY(pCheckBox, rkIndex, &QCheckBox::toggled);
|
||||||
pOut = pCheckBox;
|
pOut = pCheckBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -576,11 +576,11 @@ QWidget* CPropertyDelegate::CreateCharacterEditor(QWidget *pParent, const QModel
|
||||||
else
|
else
|
||||||
pSelector->SetTypeFilter(gpEdApp->CurrentGame(), "CHAR");
|
pSelector->SetTypeFilter(gpEdApp->CurrentGame(), "CHAR");
|
||||||
|
|
||||||
CONNECT_RELAY(pSelector, rkIndex, ResourceChanged(CResourceEntry*));
|
CONNECT_RELAY(pSelector, rkIndex, &CResourceSelector::ResourceChanged);
|
||||||
return pSelector;
|
return pSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Type == EPropertyType::Enum || Type == EPropertyType::Choice)
|
if (Type == EPropertyType::Enum || Type == EPropertyType::Choice)
|
||||||
{
|
{
|
||||||
QComboBox* pComboBox = new QComboBox(pParent);
|
QComboBox* pComboBox = new QComboBox(pParent);
|
||||||
CAnimSet* pAnimSet = Params.AnimSet();
|
CAnimSet* pAnimSet = Params.AnimSet();
|
||||||
|
@ -591,14 +591,14 @@ QWidget* CPropertyDelegate::CreateCharacterEditor(QWidget *pParent, const QModel
|
||||||
pComboBox->addItem(TO_QSTRING(pAnimSet->Character(CharIdx)->Name));
|
pComboBox->addItem(TO_QSTRING(pAnimSet->Character(CharIdx)->Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
CONNECT_RELAY(pComboBox, rkIndex, currentIndexChanged(int));
|
CONNECT_RELAY(pComboBox, rkIndex, qOverload<int>(&QComboBox::currentIndexChanged));
|
||||||
return pComboBox;
|
return pComboBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Type == EPropertyType::Int)
|
if (Type == EPropertyType::Int)
|
||||||
{
|
{
|
||||||
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
|
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
|
||||||
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int));
|
CONNECT_RELAY(pSpinBox, rkIndex, qOverload<int>(&WIntegralSpinBox::valueChanged));
|
||||||
return pSpinBox;
|
return pSpinBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue