From b5b415af874cf86f09d495f034b5d097c4c1d4ac Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Jan 2019 18:04:42 +0100 Subject: [PATCH 1/6] Stop converting wxPoint(-1,-1) to QPoint(0,0) and vice versa QPoint(0,0) is a valid position and there just doesn't seem to be any good reason to make it invalid by mapping it to wxDefaultPosition. Closes https://github.com/wxWidgets/wxWidgets/pull/1202 --- src/qt/converter.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/qt/converter.cpp b/src/qt/converter.cpp index fbc14a34c3..c9135843be 100644 --- a/src/qt/converter.cpp +++ b/src/qt/converter.cpp @@ -30,17 +30,11 @@ wxPoint wxQtConvertPoint( const QPoint &point ) { - if (point.isNull()) - return wxDefaultPosition; - return wxPoint( point.x(), point.y() ); } QPoint wxQtConvertPoint( const wxPoint &point ) { - if (point == wxDefaultPosition) - return QPoint(); - return QPoint( point.x, point.y ); } From 6bd15cd1eedfb0cea23711dec4270c5d08a845cc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Jan 2019 18:06:09 +0100 Subject: [PATCH 2/6] Remove duplicate header inclusion in wxQt No real changes, just remove a redundant line. --- src/qt/converter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qt/converter.cpp b/src/qt/converter.cpp index c9135843be..9e71dffd24 100644 --- a/src/qt/converter.cpp +++ b/src/qt/converter.cpp @@ -25,7 +25,6 @@ #include "wx/kbdstate.h" #include "wx/gdicmn.h" -#include "wx/gdicmn.h" wxPoint wxQtConvertPoint( const QPoint &point ) From b0d88a306dc5d59804d848553f1b61337cc37b3f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Jan 2019 18:07:33 +0100 Subject: [PATCH 3/6] Include wx/qt/private/converter.h from src/qt/converter.cpp Follow standard practice and include the header corresponding to the source file from it explicitly. Also include wx/gdicmn.h from the header itself, this is a pretty common header and there is no real advantage in avoiding it there and including it allows to avoid a bunch of forward declarations. --- include/wx/qt/private/converter.h | 5 +---- src/qt/converter.cpp | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/wx/qt/private/converter.h b/include/wx/qt/private/converter.h index f6406a8009..5f7b406a08 100644 --- a/include/wx/qt/private/converter.h +++ b/include/wx/qt/private/converter.h @@ -15,21 +15,19 @@ #include #include "wx/kbdstate.h" +#include "wx/gdicmn.h" // Rely on overloading and let the compiler pick the correct version, which makes // them easier to use then to write wxQtConvertQtRectToWxRect() or wxQtConvertWxRectToQtRect() -class WXDLLIMPEXP_FWD_CORE wxPoint; class QPoint; wxPoint wxQtConvertPoint( const QPoint &point ); QPoint wxQtConvertPoint( const wxPoint &point ); -class WXDLLIMPEXP_FWD_CORE wxRect; class QRect; wxRect wxQtConvertRect( const QRect &rect ); QRect wxQtConvertRect( const wxRect &rect ); -class WXDLLIMPEXP_FWD_BASE wxString; class QString; wxString wxQtConvertString( const QString &str ); QString wxQtConvertString( const wxString &str ); @@ -44,7 +42,6 @@ QDate wxQtConvertDate(const wxDateTime& date); #endif // wxUSE_DATETIME -class WXDLLIMPEXP_FWD_BASE wxSize; class QSize; wxSize wxQtConvertSize( const QSize &size ); QSize wxQtConvertSize( const wxSize &size ); diff --git a/src/qt/converter.cpp b/src/qt/converter.cpp index 9e71dffd24..86b7724dcc 100644 --- a/src/qt/converter.cpp +++ b/src/qt/converter.cpp @@ -23,8 +23,7 @@ #include #endif // wxUSE_DATETIME -#include "wx/kbdstate.h" -#include "wx/gdicmn.h" +#include "wx/qt/private/converter.h" wxPoint wxQtConvertPoint( const QPoint &point ) From 5154cc711a97b243e54f4dea9f32ac62a6bac44f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Jan 2019 18:11:03 +0100 Subject: [PATCH 4/6] Include QRect, QSize and QString from wx/qt/private/converter.h Similarly to the previous commit, it doesn't seem to be worth it to avoid including these simple and common headers from there and it simplifies code and will allow making the converter functions inline. --- include/wx/qt/private/converter.h | 9 ++++----- src/qt/converter.cpp | 3 --- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/wx/qt/private/converter.h b/include/wx/qt/private/converter.h index 5f7b406a08..d55e9e8110 100644 --- a/include/wx/qt/private/converter.h +++ b/include/wx/qt/private/converter.h @@ -12,23 +12,23 @@ #define _WX_QT_CONVERTER_H_ #include "wx/defs.h" -#include #include "wx/kbdstate.h" #include "wx/gdicmn.h" +#include +#include +#include + // Rely on overloading and let the compiler pick the correct version, which makes // them easier to use then to write wxQtConvertQtRectToWxRect() or wxQtConvertWxRectToQtRect() -class QPoint; wxPoint wxQtConvertPoint( const QPoint &point ); QPoint wxQtConvertPoint( const wxPoint &point ); -class QRect; wxRect wxQtConvertRect( const QRect &rect ); QRect wxQtConvertRect( const wxRect &rect ); -class QString; wxString wxQtConvertString( const QString &str ); QString wxQtConvertString( const wxString &str ); @@ -42,7 +42,6 @@ QDate wxQtConvertDate(const wxDateTime& date); #endif // wxUSE_DATETIME -class QSize; wxSize wxQtConvertSize( const QSize &size ); QSize wxQtConvertSize( const wxSize &size ); diff --git a/src/qt/converter.cpp b/src/qt/converter.cpp index 86b7724dcc..f2941e322d 100644 --- a/src/qt/converter.cpp +++ b/src/qt/converter.cpp @@ -13,10 +13,7 @@ #pragma hdrstop #endif -#include -#include #include -#include #if wxUSE_DATETIME #include "wx/datetime.h" From 1a9f0f8b8d28d58164eb212ab647ba17665fb557 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Jan 2019 18:14:36 +0100 Subject: [PATCH 5/6] Make trivial Qt <-> wx conversion functions inline No real changes, just make often used and trivial functions inline as this like an obviously better thing to do. --- include/wx/qt/private/converter.h | 50 ++++++++++++++++++++++++----- src/qt/converter.cpp | 52 ------------------------------- 2 files changed, 42 insertions(+), 60 deletions(-) diff --git a/include/wx/qt/private/converter.h b/include/wx/qt/private/converter.h index d55e9e8110..e008471216 100644 --- a/include/wx/qt/private/converter.h +++ b/include/wx/qt/private/converter.h @@ -23,14 +23,36 @@ // Rely on overloading and let the compiler pick the correct version, which makes // them easier to use then to write wxQtConvertQtRectToWxRect() or wxQtConvertWxRectToQtRect() -wxPoint wxQtConvertPoint( const QPoint &point ); -QPoint wxQtConvertPoint( const wxPoint &point ); +inline wxPoint wxQtConvertPoint( const QPoint &point ) +{ + return wxPoint( point.x(), point.y() ); +} +inline QPoint wxQtConvertPoint( const wxPoint &point ) +{ + return QPoint( point.x, point.y ); +} -wxRect wxQtConvertRect( const QRect &rect ); -QRect wxQtConvertRect( const wxRect &rect ); +inline wxRect wxQtConvertRect( const QRect &rect ) +{ + return wxRect( rect.x(), rect.y(), rect.width(), rect.height() ); +} -wxString wxQtConvertString( const QString &str ); -QString wxQtConvertString( const wxString &str ); +inline QRect wxQtConvertRect( const wxRect &rect ) +{ + return QRect( rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight() ); +} + +// TODO: Check whether QString::toStdString/QString::toStdWString might be faster + +inline wxString wxQtConvertString( const QString &str ) +{ + return wxString( str.toUtf8().data(), wxConvUTF8 ); +} + +inline QString wxQtConvertString( const wxString &str ) +{ + return QString( str.utf8_str() ); +} #if wxUSE_DATETIME @@ -42,8 +64,20 @@ QDate wxQtConvertDate(const wxDateTime& date); #endif // wxUSE_DATETIME -wxSize wxQtConvertSize( const QSize &size ); -QSize wxQtConvertSize( const wxSize &size ); +inline wxSize wxQtConvertSize( const QSize &size ) +{ + if (size.isNull()) + return wxDefaultSize; + + return wxSize(size.width(), size.height()); +} +inline QSize wxQtConvertSize( const wxSize &size ) +{ + if (size == wxDefaultSize) + return QSize(); + + return QSize(size.GetWidth(), size.GetHeight()); +} Qt::Orientation wxQtConvertOrientation( long style, wxOrientation defaultOrientation ); wxOrientation wxQtConvertOrientation( Qt::Orientation ); diff --git a/src/qt/converter.cpp b/src/qt/converter.cpp index f2941e322d..df4d69c99c 100644 --- a/src/qt/converter.cpp +++ b/src/qt/converter.cpp @@ -23,42 +23,6 @@ #include "wx/qt/private/converter.h" -wxPoint wxQtConvertPoint( const QPoint &point ) -{ - return wxPoint( point.x(), point.y() ); -} - -QPoint wxQtConvertPoint( const wxPoint &point ) -{ - return QPoint( point.x, point.y ); -} - - -QRect wxQtConvertRect( const wxRect &rect ) -{ - return QRect( rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight() ); -} - -wxRect wxQtConvertRect( const QRect &rect ) -{ - return wxRect( rect.x(), rect.y(), rect.width(), rect.height() ); -} - -// TODO: Check whether QString::toStdString/QString::toStdWString might be faster - -wxString wxQtConvertString( const QString &str ) -{ - return wxString( str.toUtf8().data(), wxConvUTF8 ); -} - -QString wxQtConvertString( const wxString &str ) -{ - return QString( str.utf8_str() ); -} - - - - #if wxUSE_DATETIME wxDateTime wxQtConvertDate(const QDate& date) @@ -81,22 +45,6 @@ QDate wxQtConvertDate(const wxDateTime& date) #endif // wxUSE_DATETIME -wxSize wxQtConvertSize( const QSize &size ) -{ - if (size.isNull()) - return wxDefaultSize; - - return wxSize(size.width(), size.height()); -} - -QSize wxQtConvertSize( const wxSize &size ) -{ - if (size == wxDefaultSize) - return QSize(); - - return QSize(size.GetWidth(), size.GetHeight()); -} - Qt::Orientation wxQtConvertOrientation( long style, wxOrientation defaultOrientation ) { if (( style & ( wxHORIZONTAL | wxVERTICAL )) == 0 ) From 481b29e6cefe7a253bc91eeb1c34c80844a49da7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 30 Jan 2019 18:15:20 +0100 Subject: [PATCH 6/6] Stop mapping QSize(0,0) to wxSize(-1,-1) as well Do this for consistency with a similar recent change to wxPoint. --- include/wx/qt/private/converter.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/wx/qt/private/converter.h b/include/wx/qt/private/converter.h index e008471216..7cdce58fad 100644 --- a/include/wx/qt/private/converter.h +++ b/include/wx/qt/private/converter.h @@ -66,16 +66,10 @@ QDate wxQtConvertDate(const wxDateTime& date); inline wxSize wxQtConvertSize( const QSize &size ) { - if (size.isNull()) - return wxDefaultSize; - return wxSize(size.width(), size.height()); } inline QSize wxQtConvertSize( const wxSize &size ) { - if (size == wxDefaultSize) - return QSize(); - return QSize(size.GetWidth(), size.GetHeight()); }