From 220028d37c38835987b817193ecaf0e2a1ad066b Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 5 Mar 2019 22:39:27 +0100 Subject: [PATCH] QtBase: introduce QT_DEPRECATED_VERSION/QT_DEPRECATED_VERSION_X QT_DEPRECATED_VERSION(major, minor) and QT_DEPRECATED_VERSION_X(major, minor, text) outputs a deprecation warning if QT_DEPRECATED_WARNINGS_SINCE is equal or greater than the version specified as major, minor. This allows the user to hide deprecation warnings which can't yet be fixed for their codebase because the minimum required Qt version does not provide the replacement function. If QT_DEPRECATED_WARNINGS_SINCE is not set by the user, it's set to QT_DISABLE_DEPRECATED_BEFORE if available, otherwise to QT_VERSION. [ChangeLog][QtCore][QtGlobal] Add new macros QT_DEPRECATED_VERSION and QT_DEPRECATED_VERSION_X to conditionally display deprecation warnings Change-Id: I61b1a7624c9b870695c9e3274313de636f804b5d Reviewed-by: Konstantin Shegunov Reviewed-by: Edward Welbourne Reviewed-by: hjk --- mkspecs/features/qt_module.prf | 1 + src/corelib/global/qglobal.h | 53 +++++++++++++++++++++++++++++++++ src/widgets/widgets/qcombobox.h | 6 ++-- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/mkspecs/features/qt_module.prf b/mkspecs/features/qt_module.prf index 51b5bde67a..8bd2d92421 100644 --- a/mkspecs/features/qt_module.prf +++ b/mkspecs/features/qt_module.prf @@ -317,5 +317,6 @@ win32 { # On other platforms, Qt's own compilation goes needs to compile the Qt 5.0 API DEFINES *= QT_DISABLE_DEPRECATED_BEFORE=0x050000 } +DEFINES *= QT_DEPRECATED_WARNINGS_SINCE=0x060000 TARGET = $$qt5LibraryTarget($$TARGET$$QT_LIBINFIX) # Do this towards the end diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index a0207b483d..3c17bbb2d4 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -307,6 +307,14 @@ typedef double qreal; # define QT_DEPRECATED_CONSTRUCTOR #endif +#ifndef QT_DEPRECATED_WARNINGS_SINCE +# ifdef QT_DISABLE_DEPRECATED_BEFORE +# define QT_DEPRECATED_WARNINGS_SINCE QT_DISABLE_DEPRECATED_BEFORE +# else +# define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION +# endif +#endif + #ifndef QT_DISABLE_DEPRECATED_BEFORE #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(5, 0, 0) #endif @@ -329,6 +337,51 @@ typedef double qreal; #define QT_DEPRECATED_SINCE(major, minor) 0 #endif +/* + QT_DEPRECATED_VERSION(major, minor) and QT_DEPRECATED_VERSION_X(major, minor, text) + outputs a deprecation warning if QT_DEPRECATED_WARNINGS_SINCE is equal or greater + than the version specified as major, minor. This makes it possible to deprecate a + function without annoying a user who needs to stick at a specified minimum version + and therefore can't use the new function. +*/ +#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 12, 0) +# define QT_DEPRECATED_VERSION_X_5_12(text) QT_DEPRECATED_X(text) +# define QT_DEPRECATED_VERSION_5_12 QT_DEPRECATED +#else +# define QT_DEPRECATED_VERSION_X_5_12(text) +# define QT_DEPRECATED_VERSION_5_12 +#endif + +#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 13, 0) +# define QT_DEPRECATED_VERSION_X_5_13(text) QT_DEPRECATED_X(text) +# define QT_DEPRECATED_VERSION_5_13 QT_DEPRECATED +#else +# define QT_DEPRECATED_VERSION_X_5_13(text) +# define QT_DEPRECATED_VERSION_5_13 +#endif + +#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 14, 0) +# define QT_DEPRECATED_VERSION_X_5_14(text) QT_DEPRECATED_X(text) +# define QT_DEPRECATED_VERSION_5_14 QT_DEPRECATED +#else +# define QT_DEPRECATED_VERSION_X_5_14(text) +# define QT_DEPRECATED_VERSION_5_14 +#endif + +#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 15, 0) +# define QT_DEPRECATED_VERSION_X_5_15(text) QT_DEPRECATED_X(text) +# define QT_DEPRECATED_VERSION_5_15 QT_DEPRECATED +#else +# define QT_DEPRECATED_VERSION_X_5_15(text) +# define QT_DEPRECATED_VERSION_5_15 +#endif + +#define QT_DEPRECATED_VERSION_X_5(minor, text) QT_DEPRECATED_VERSION_X_5_##minor(text) +#define QT_DEPRECATED_VERSION_X(major, minor, text) QT_DEPRECATED_VERSION_X_##major(minor, text) + +#define QT_DEPRECATED_VERSION_5(minor) QT_DEPRECATED_VERSION_5_##minor() +#define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major(minor) + /* The Qt modules' export macros. The options are: diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h index 6a87a675a4..37b155774d 100644 --- a/src/widgets/widgets/qcombobox.h +++ b/src/widgets/widgets/qcombobox.h @@ -226,13 +226,13 @@ Q_SIGNALS: void currentIndexChanged(int index); void currentTextChanged(const QString &); #if QT_DEPRECATED_SINCE(5, 13) - QT_DEPRECATED_X("Use currentTextChanged() instead") + QT_DEPRECATED_VERSION_X(5, 13, "Use currentTextChanged() instead") void currentIndexChanged(const QString &); #endif #if QT_DEPRECATED_SINCE(5, 15) - QT_DEPRECATED_X("Use textActivated() instead") + QT_DEPRECATED_VERSION_X(5, 15, "Use textActivated() instead") void activated(const QString &); - QT_DEPRECATED_X("Use textHighlighted() instead") + QT_DEPRECATED_VERSION_X(5, 15, "Use textHighlighted() instead") void highlighted(const QString &); #endif