1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 12:09:53 +00:00

Do not store references to disposed objects

This commit is contained in:
Andrei Kortunov 2024-07-23 10:27:23 +04:00
parent 5d3aa62e56
commit 355dd0bccf
2 changed files with 4 additions and 19 deletions

View file

@ -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<refWrapper>(index);
mIndex = index;
}
QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const

View file

@ -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<refWrapper> mIndexWrapper;
std::optional<QModelIndex> mIndex;
public:
DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display);