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==========================================
*/
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

@ -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);

Loading…
Cancel
Save