Do not store references to disposed objects

pull/3236/head
Andrei Kortunov 5 months ago
parent 5d3aa62e56
commit 355dd0bccf

@ -130,30 +130,24 @@ QWidget* CSVWorld::NotEditableSubDelegate::createEditor(
/* /*
==============================DialogueDelegateDispatcherProxy========================================== ==============================DialogueDelegateDispatcherProxy==========================================
*/ */
CSVWorld::DialogueDelegateDispatcherProxy::refWrapper::refWrapper(const QModelIndex& index)
: mIndex(index)
{
}
CSVWorld::DialogueDelegateDispatcherProxy::DialogueDelegateDispatcherProxy( CSVWorld::DialogueDelegateDispatcherProxy::DialogueDelegateDispatcherProxy(
QWidget* editor, CSMWorld::ColumnBase::Display display) QWidget* editor, CSMWorld::ColumnBase::Display display)
: mEditor(editor) : mEditor(editor)
, mDisplay(display) , mDisplay(display)
, mIndexWrapper(nullptr)
{ {
} }
void CSVWorld::DialogueDelegateDispatcherProxy::editorDataCommited() void CSVWorld::DialogueDelegateDispatcherProxy::editorDataCommited()
{ {
if (mIndexWrapper.get()) if (mIndex.has_value())
{ {
emit editorDataCommited(mEditor, mIndexWrapper->mIndex, mDisplay); emit editorDataCommited(mEditor, mIndex.value(), mDisplay);
} }
} }
void CSVWorld::DialogueDelegateDispatcherProxy::setIndex(const QModelIndex& index) void CSVWorld::DialogueDelegateDispatcherProxy::setIndex(const QModelIndex& index)
{ {
mIndexWrapper = std::make_unique<refWrapper>(index); mIndex = index;
} }
QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const

@ -74,23 +74,14 @@ namespace CSVWorld
QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override; QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
}; };
// this can't be nested into the DialogueDelegateDispatcher, because it needs to emit signals
class DialogueDelegateDispatcherProxy : public QObject class DialogueDelegateDispatcherProxy : public QObject
{ {
Q_OBJECT Q_OBJECT
class refWrapper
{
public:
refWrapper(const QModelIndex& index);
const QModelIndex& mIndex;
};
QWidget* mEditor; QWidget* mEditor;
CSMWorld::ColumnBase::Display mDisplay; CSMWorld::ColumnBase::Display mDisplay;
std::unique_ptr<refWrapper> mIndexWrapper; std::optional<QModelIndex> mIndex;
public: public:
DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display); DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display);

Loading…
Cancel
Save