From 355dd0bccfb10b7d01006a317f5f10ba8cdd6ec1 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 23 Jul 2024 10:27:23 +0400 Subject: [PATCH] Do not store references to disposed objects --- apps/opencs/view/world/dialoguesubview.cpp | 12 +++--------- apps/opencs/view/world/dialoguesubview.hpp | 11 +---------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 3a87e6cf31..168e555eae 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -130,30 +130,24 @@ QWidget* CSVWorld::NotEditableSubDelegate::createEditor( /* ==============================DialogueDelegateDispatcherProxy========================================== */ -CSVWorld::DialogueDelegateDispatcherProxy::refWrapper::refWrapper(const QModelIndex& index) - : mIndex(index) -{ -} - CSVWorld::DialogueDelegateDispatcherProxy::DialogueDelegateDispatcherProxy( QWidget* editor, CSMWorld::ColumnBase::Display display) : mEditor(editor) , mDisplay(display) - , mIndexWrapper(nullptr) { } 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) { - mIndexWrapper = std::make_unique(index); + mIndex = index; } QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index b5108f3b0e..eb1c8d96d5 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -74,23 +74,14 @@ namespace CSVWorld 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 { Q_OBJECT - class refWrapper - { - public: - refWrapper(const QModelIndex& index); - - const QModelIndex& mIndex; - }; - QWidget* mEditor; CSMWorld::ColumnBase::Display mDisplay; - std::unique_ptr mIndexWrapper; + std::optional mIndex; public: DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display);