From c028f61d0f95334f333585b46a0b1a1ecbcb35bf Mon Sep 17 00:00:00 2001 From: ali kettab Date: Sat, 9 Sep 2023 22:27:47 +0100 Subject: [PATCH] Default ctor should create uninitialised wxPen too in wxQt as documented --- src/qt/dc.cpp | 2 ++ src/qt/pen.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index 520cc64797..393548fcfd 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -178,6 +178,8 @@ void wxQtDCImpl::SetPen(const wxPen& pen) { m_pen = pen; + if ( !m_pen.IsOk() ) return; + m_qtPainter->setPen(pen.GetHandle()); ApplyRasterColourOp(); diff --git a/src/qt/pen.cpp b/src/qt/pen.cpp index 8e9052fce8..a2f930bae6 100644 --- a/src/qt/pen.cpp +++ b/src/qt/pen.cpp @@ -241,7 +241,6 @@ class wxPenRefData: public wxGDIRefData wxPen::wxPen() { - m_refData = new wxPenRefData(); } wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style) @@ -334,6 +333,8 @@ void wxPen::SetCap(wxPenCap cap) wxColour wxPen::GetColour() const { + wxCHECK_MSG( IsOk(), wxNullColour, "invalid pen" ); + wxColour c(M_PENDATA.color()); return c; } @@ -345,33 +346,43 @@ wxBitmap *wxPen::GetStipple() const wxPenStyle wxPen::GetStyle() const { + wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, "invalid pen" ); + return ConvertPenStyle(M_PENDATA.style()); } wxPenJoin wxPen::GetJoin() const { + wxCHECK_MSG( IsOk(), wxJOIN_INVALID, "invalid pen" ); + return ConvertPenJoinStyle(M_PENDATA.joinStyle()); } wxPenCap wxPen::GetCap() const { + wxCHECK_MSG( IsOk(), wxCAP_INVALID, "invalid pen" ); + return ConvertPenCapStyle(M_PENDATA.capStyle()); } int wxPen::GetWidth() const { + wxCHECK_MSG( IsOk(), -1, "invalid pen" ); + return M_PENDATA.width(); } int wxPen::GetDashes(wxDash **ptr) const { + wxCHECK_MSG( IsOk(), -1, "invalid pen" ); + *ptr = (wxDash *)((wxPenRefData *)m_refData)->m_dashes; return ((wxPenRefData *)m_refData)->m_dashesSize; } QPen wxPen::GetHandle() const { - return M_PENDATA; + return IsOk() ? M_PENDATA : QPen(); } wxGDIRefData *wxPen::CreateGDIRefData() const