2013-05-30 13:24:21 +00:00
|
|
|
/* Thin wrappers for retaining compatibility for both Qt4.x and Qt5.x */
|
|
|
|
|
|
|
|
#ifndef QT4X5_HH
|
|
|
|
#define QT4X5_HH
|
|
|
|
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
# define IS_QT_5 0
|
|
|
|
#else
|
|
|
|
# define IS_QT_5 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QAtomicInt>
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
|
|
|
#include <QUrl>
|
|
|
|
#if IS_QT_5
|
|
|
|
#include <QUrlQuery>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Qt4x5
|
|
|
|
{
|
|
|
|
|
Qt 5.14+: don't use deprecated QString::SkipEmptyParts
This change fixes the following GCC warnings:
warning: ‘QString::SkipEmptyParts’ is deprecated [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(const QString&, SplitBehavior, Qt::CaseSensitivity) const’ is deprecated: Use split(const QString &sep, Qt::SplitBehavior ...) variant instead [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(QChar, SplitBehavior, Qt::CaseSensitivity) const’ is deprecated: Use split(QChar sep, Qt::SplitBehavior ...) variant instead [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(const QRegExp&, SplitBehavior) const’ is deprecated: Use split(const QRegularExpression &, Qt::SplitBehavior) variant instead [-Wdeprecated-declarations]
warning: ‘QStringList QString::split(const QRegularExpression&, SplitBehavior) const’ is deprecated: Use split(const QRegularExpression &, Qt::SplitBehavior) variant instead [-Wdeprecated-declarations]
2022-11-26 16:06:48 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 14, 0 )
|
|
|
|
inline Qt::SplitBehaviorFlags skipEmptyParts()
|
|
|
|
{ return Qt::SkipEmptyParts; }
|
|
|
|
#else
|
|
|
|
inline QString::SplitBehavior skipEmptyParts()
|
|
|
|
{ return QString::SkipEmptyParts; }
|
|
|
|
#endif
|
|
|
|
|
2013-05-30 13:24:21 +00:00
|
|
|
inline QString escape( QString const & plain )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return plain.toHtmlEscaped();
|
|
|
|
#else
|
|
|
|
return Qt::escape( plain );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace AtomicInt
|
|
|
|
{
|
|
|
|
|
|
|
|
inline int loadAcquire( QAtomicInt const & ref )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return ref.loadAcquire();
|
|
|
|
#else
|
|
|
|
return ( int )ref;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Url
|
|
|
|
{
|
|
|
|
|
2013-05-31 04:20:25 +00:00
|
|
|
// This wrapper is created due to behavior change of the setPath() method
|
|
|
|
// See: https://bugreports.qt-project.org/browse/QTBUG-27728
|
|
|
|
// https://codereview.qt-project.org/#change,38257
|
|
|
|
inline QString ensureLeadingSlash( const QString & path )
|
|
|
|
{
|
2016-05-21 13:45:08 +00:00
|
|
|
#if IS_QT_5
|
2013-05-31 04:20:25 +00:00
|
|
|
QLatin1Char slash( '/' );
|
|
|
|
if ( path.startsWith( slash ) )
|
|
|
|
return path;
|
|
|
|
return slash + path;
|
2016-05-21 13:45:08 +00:00
|
|
|
#else
|
|
|
|
return path;
|
|
|
|
#endif
|
2013-05-31 04:20:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 13:24:21 +00:00
|
|
|
inline bool hasQueryItem( QUrl const & url, QString const & key )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return QUrlQuery( url ).hasQueryItem( key );
|
|
|
|
#else
|
|
|
|
return url.hasQueryItem( key );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QString queryItemValue( QUrl const & url, QString const & item )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
2017-01-14 13:52:44 +00:00
|
|
|
return QUrlQuery( url ).queryItemValue( item, QUrl::FullyDecoded );
|
2013-05-30 13:24:21 +00:00
|
|
|
#else
|
|
|
|
return url.queryItemValue( item );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-30 13:35:00 +00:00
|
|
|
inline QByteArray encodedQueryItemValue( QUrl const & url, QString const & item )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return QUrlQuery( url ).queryItemValue( item, QUrl::FullyEncoded ).toLatin1();
|
|
|
|
#else
|
2015-11-11 18:29:10 +00:00
|
|
|
return url.encodedQueryItemValue( item.toLatin1() );
|
2015-10-30 13:35:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-30 13:24:21 +00:00
|
|
|
inline void addQueryItem( QUrl & url, QString const & key, QString const & value )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
QUrlQuery urlQuery( url );
|
|
|
|
urlQuery.addQueryItem( key, value );
|
|
|
|
url.setQuery( urlQuery );
|
|
|
|
#else
|
|
|
|
url.addQueryItem( key, value );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void removeQueryItem( QUrl & url, QString const & key )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
QUrlQuery urlQuery( url );
|
|
|
|
urlQuery.removeQueryItem( key );
|
|
|
|
url.setQuery( urlQuery );
|
|
|
|
#else
|
|
|
|
url.removeQueryItem( key );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-12-22 18:40:18 +00:00
|
|
|
inline QString fullPath( QUrl const & url )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return url.toString( QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemovePort | QUrl::FullyDecoded );
|
|
|
|
#else
|
|
|
|
return url.toString( QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemovePort );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-30 13:24:21 +00:00
|
|
|
inline void setQueryItems( QUrl & url, QList< QPair< QString, QString > > const & query )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
QUrlQuery urlQuery( url );
|
|
|
|
urlQuery.setQueryItems( query );
|
|
|
|
url.setQuery( urlQuery );
|
|
|
|
#else
|
|
|
|
url.setQueryItems( query );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-27 13:04:25 +00:00
|
|
|
inline QString path( QUrl const & url )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return url.path( QUrl::FullyDecoded );
|
|
|
|
#else
|
|
|
|
return url.path();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-09 17:15:35 +00:00
|
|
|
inline void setFragment( QUrl & url, const QString & fragment )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
url.setFragment( fragment, QUrl::DecodedMode );
|
|
|
|
#else
|
|
|
|
url.setFragment( fragment );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline QString fragment( const QUrl & url )
|
|
|
|
{
|
|
|
|
#if IS_QT_5
|
|
|
|
return url.fragment( QUrl::FullyDecoded );
|
|
|
|
#else
|
|
|
|
return url.fragment();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-30 13:24:21 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 15:05:41 +00:00
|
|
|
namespace Dom
|
|
|
|
{
|
|
|
|
|
|
|
|
#if IS_QT_5
|
|
|
|
typedef int size_type;
|
|
|
|
#else
|
|
|
|
typedef uint size_type;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-30 13:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // QT4X5_HH
|