From 21e989751fd6e3e5c8ff5b61a76d6e87c059f76f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Jan 2019 19:42:56 +0100 Subject: [PATCH] Get rid of m_ownsPainter flag in wxQtGraphicsContext Use wxScopedPtr to ensure that the pointer is destroyed automatically instead of doing it manually. --- src/qt/graphics.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/qt/graphics.cpp b/src/qt/graphics.cpp index f4df9b0af7..be97b85cfe 100644 --- a/src/qt/graphics.cpp +++ b/src/qt/graphics.cpp @@ -31,6 +31,7 @@ #endif #include "wx/graphics.h" +#include "wx/scopedptr.h" #include "wx/tokenzr.h" #include "wx/private/graphics.h" @@ -640,7 +641,6 @@ class WXDLLIMPEXP_CORE wxQtGraphicsContext : public wxGraphicsContext void InitFromDC(const wxDC& dc) { m_qtPainter = static_cast(dc.GetHandle()); - m_ownsPainter = false; const wxSize sz = dc.GetSize(); m_width = sz.x; @@ -653,13 +653,14 @@ protected: void AttachPainter(QPainter* painter) { m_qtPainter = painter; - m_ownsPainter = true; + + // Ensure that it will be destroyed when this object is. + m_ownedPainter.reset(m_qtPainter); } wxQtGraphicsContext(wxGraphicsRenderer* renderer) : wxGraphicsContext(renderer), - m_qtPainter(NULL), - m_ownsPainter(false) + m_qtPainter(NULL) { } @@ -698,19 +699,12 @@ public: : wxGraphicsContext(renderer) { m_qtPainter = static_cast(window->QtGetPainter()); - m_ownsPainter = false; const wxSize sz = window->GetClientSize(); m_width = sz.x; m_height = sz.y; } - virtual ~wxQtGraphicsContext() - { - if ( m_ownsPainter ) - delete m_qtPainter; - } - virtual bool ShouldOffset() const wxOVERRIDE { return false; @@ -1056,7 +1050,8 @@ protected: QPainter* m_qtPainter; private: - bool m_ownsPainter; + // This pointer may be empty if we don't own m_qtPainter. + wxScopedPtr m_ownedPainter; wxDECLARE_NO_COPY_CLASS(wxQtGraphicsContext); };