Add View::isNull()
ViewWrappers don't have ownership of the gui element. The gui element might have been deleted, leaving us with a stale wrapper For impl simply use a QPointer in the QtWidgets and QtQuick backends
This commit is contained in:
@@ -258,3 +258,8 @@ bool View::equals(const std::shared_ptr<ViewWrapper> &other) const
|
||||
{
|
||||
return other && handle() == other->handle();
|
||||
}
|
||||
|
||||
bool View::isNull() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,12 @@ public:
|
||||
/// as long as it uniquely identifies the GUI element. KDDW backend only uses it for comparison purposes
|
||||
virtual HANDLE handle() const = 0;
|
||||
|
||||
/// @brief Returns whether the gui item represented by this view was already deleted
|
||||
/// Usually false, as KDDW internal gui elements inherit View, and nobody will access them after destruction.
|
||||
/// However, ViewWrapper derived classes, wrap an existing gui element, which might get deleted.
|
||||
/// Override isNull() in our ViewWrapper subclasses and return true if the wrapped gui element was already deleted
|
||||
virtual bool isNull() const;
|
||||
|
||||
/// @brief Called by the layouting engine
|
||||
/// Override it in case your widget needs to know where it is in the layout. Usually only needed by Frame.s
|
||||
virtual void setLayoutItem(Layouting::Item *) {};
|
||||
|
||||
@@ -168,7 +168,7 @@ std::shared_ptr<ViewWrapper> ViewWrapper_qtquick::parentView() const
|
||||
|
||||
HANDLE ViewWrapper_qtquick::handle() const
|
||||
{
|
||||
return reinterpret_cast<HANDLE>(m_item);
|
||||
return reinterpret_cast<HANDLE>(m_item.data());
|
||||
}
|
||||
|
||||
void ViewWrapper_qtquick::grabMouse()
|
||||
@@ -192,3 +192,8 @@ QString ViewWrapper_qtquick::objectName() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ViewWrapper_qtquick::isNull() const
|
||||
{
|
||||
return m_item.data() == nullptr;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "ViewWrapper.h"
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QPointer>
|
||||
|
||||
namespace KDDockWidgets::Views {
|
||||
|
||||
@@ -50,9 +51,10 @@ public:
|
||||
QScreen *screen() const override;
|
||||
void setFocus(Qt::FocusReason) override;
|
||||
QString objectName() const override;
|
||||
bool isNull() const override;
|
||||
|
||||
private:
|
||||
QQuickItem *const m_item;
|
||||
QPointer<QQuickItem> m_item;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ std::shared_ptr<ViewWrapper> ViewWrapper_qtwidgets::parentView() const
|
||||
|
||||
HANDLE ViewWrapper_qtwidgets::handle() const
|
||||
{
|
||||
return reinterpret_cast<HANDLE>(m_widget);
|
||||
return reinterpret_cast<HANDLE>(m_widget.data());
|
||||
}
|
||||
|
||||
void ViewWrapper_qtwidgets::grabMouse()
|
||||
@@ -270,3 +270,8 @@ QString ViewWrapper_qtwidgets::objectName() const
|
||||
{
|
||||
return m_widget->QWidget::objectName();
|
||||
}
|
||||
|
||||
bool ViewWrapper_qtwidgets::isNull() const
|
||||
{
|
||||
return m_widget.data() == nullptr;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "ViewWrapper.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
namespace KDDockWidgets::Views {
|
||||
|
||||
@@ -50,9 +51,10 @@ public:
|
||||
QScreen *screen() const override;
|
||||
void setFocus(Qt::FocusReason) override;
|
||||
QString objectName() const override;
|
||||
bool isNull() const override;
|
||||
|
||||
private:
|
||||
QWidget *const m_widget;
|
||||
QPointer<QWidget> m_widget;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user