Fixed crash when editing character properties

This commit is contained in:
parax0 2016-03-22 20:22:43 -06:00
parent 0ca82afbfe
commit 77eb2b3dc5
2 changed files with 58 additions and 37 deletions

View File

@ -30,7 +30,6 @@ CPropertyDelegate::CPropertyDelegate(QObject *pParent /*= 0*/)
, mInRelayWidgetEdit(false) , mInRelayWidgetEdit(false)
, mEditInProgress(false) , mEditInProgress(false)
, mRelaysBlocked(false) , mRelaysBlocked(false)
, mUpdatingModel(false)
{ {
} }
@ -199,8 +198,6 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie
void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkIndex) const void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkIndex) const
{ {
if (mUpdatingModel) return;
BlockRelays(true); BlockRelays(true);
mEditInProgress = false; // fixes case where user does undo mid-edit mEditInProgress = false; // fixes case where user does undo mid-edit
@ -227,24 +224,39 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
case eShortProperty: case eShortProperty:
{ {
WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor); WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor);
if (!pSpinBox->hasFocus())
{
TShortProperty *pShort = static_cast<TShortProperty*>(pProp); TShortProperty *pShort = static_cast<TShortProperty*>(pProp);
pSpinBox->setValue(pShort->Get()); pSpinBox->setValue(pShort->Get());
}
break; break;
} }
case eLongProperty: case eLongProperty:
{ {
WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor); WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor);
if (!pSpinBox->hasFocus())
{
TLongProperty *pLong = static_cast<TLongProperty*>(pProp); TLongProperty *pLong = static_cast<TLongProperty*>(pProp);
pSpinBox->setValue(pLong->Get()); pSpinBox->setValue(pLong->Get());
}
break; break;
} }
case eFloatProperty: case eFloatProperty:
{ {
WDraggableSpinBox *pSpinBox = static_cast<WDraggableSpinBox*>(pEditor); WDraggableSpinBox *pSpinBox = static_cast<WDraggableSpinBox*>(pEditor);
if (!pSpinBox->hasFocus())
{
TFloatProperty *pFloat = static_cast<TFloatProperty*>(pProp); TFloatProperty *pFloat = static_cast<TFloatProperty*>(pProp);
pSpinBox->setValue(pFloat->Get()); pSpinBox->setValue(pFloat->Get());
}
break; break;
} }
@ -267,8 +279,13 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
case eStringProperty: case eStringProperty:
{ {
QLineEdit *pLineEdit = static_cast<QLineEdit*>(pEditor); QLineEdit *pLineEdit = static_cast<QLineEdit*>(pEditor);
if (!pLineEdit->hasFocus())
{
TStringProperty *pString = static_cast<TStringProperty*>(pProp); TStringProperty *pString = static_cast<TStringProperty*>(pProp);
pLineEdit->setText(TO_QSTRING(pString->Get())); pLineEdit->setText(TO_QSTRING(pString->Get()));
}
break; break;
} }
@ -292,8 +309,13 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
case eArrayProperty: case eArrayProperty:
{ {
WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor); WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor);
if (!pSpinBox->hasFocus())
{
CArrayProperty *pArray = static_cast<CArrayProperty*>(pProp); CArrayProperty *pArray = static_cast<CArrayProperty*>(pProp);
pSpinBox->setValue(pArray->Count()); pSpinBox->setValue(pArray->Count());
}
break; break;
} }
@ -323,6 +345,8 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
WDraggableSpinBox *pSpinBox = static_cast<WDraggableSpinBox*>(pEditor); WDraggableSpinBox *pSpinBox = static_cast<WDraggableSpinBox*>(pEditor);
float Value; float Value;
if (!pSpinBox->hasFocus())
{
if (pProp->Type() == eVector3Property) if (pProp->Type() == eVector3Property)
{ {
TVector3Property *pVector = static_cast<TVector3Property*>(pProp); TVector3Property *pVector = static_cast<TVector3Property*>(pProp);
@ -348,6 +372,7 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
} }
} }
} }
}
BlockRelays(false); BlockRelays(false);
} }
@ -356,7 +381,6 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
{ {
if (!mpModel) return; if (!mpModel) return;
if (!pEditor) return; if (!pEditor) return;
mUpdatingModel = true;
IProperty *pProp = mpModel->PropertyForIndex(rkIndex, false); IProperty *pProp = mpModel->PropertyForIndex(rkIndex, false);
IPropertyValue *pOldValue = nullptr; IPropertyValue *pOldValue = nullptr;
@ -537,8 +561,6 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
else else
delete pOldValue; delete pOldValue;
} }
mUpdatingModel = false;
} }
bool CPropertyDelegate::eventFilter(QObject *pObject, QEvent *pEvent) bool CPropertyDelegate::eventFilter(QObject *pObject, QEvent *pEvent)
@ -624,7 +646,7 @@ void CPropertyDelegate::SetCharacterEditorData(QWidget *pEditor, const QModelInd
static_cast<QComboBox*>(pEditor)->setCurrentIndex(Params.CharacterIndex()); static_cast<QComboBox*>(pEditor)->setCurrentIndex(Params.CharacterIndex());
} }
else if (Type == eLongProperty) else if (Type == eLongProperty && !pEditor->hasFocus())
{ {
int UnkIndex = (Params.Version() <= eEchoes ? rkIndex.row() - 2 : rkIndex.row() - 1); int UnkIndex = (Params.Version() <= eEchoes ? rkIndex.row() - 2 : rkIndex.row() - 1);
u32 Value = Params.Unknown(UnkIndex); u32 Value = Params.Unknown(UnkIndex);

View File

@ -14,7 +14,6 @@ class CPropertyDelegate : public QStyledItemDelegate
bool mInRelayWidgetEdit; bool mInRelayWidgetEdit;
mutable bool mEditInProgress; mutable bool mEditInProgress;
mutable bool mRelaysBlocked; mutable bool mRelaysBlocked;
mutable bool mUpdatingModel;
public: public:
CPropertyDelegate(QObject *pParent = 0); CPropertyDelegate(QObject *pParent = 0);