-
Notifications
You must be signed in to change notification settings - Fork 1
/
qt4x5.hh
150 lines (127 loc) · 2.59 KB
/
qt4x5.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* 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
{
/*
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
{
// 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 )
{
#if IS_QT_5
QLatin1Char slash( '/' );
if ( path.startsWith( slash ) )
return path;
return slash + path;
#else
return path;
#endif
}
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
return QUrlQuery( url ).queryItemValue( item, QUrl::FullyDecoded );
#else
return url.queryItemValue( item );
#endif
}
inline QByteArray encodedQueryItemValue( QUrl const & url, QString const & item )
{
#if IS_QT_5
return QUrlQuery( url ).queryItemValue( item, QUrl::FullyEncoded ).toLatin1();
#else
return url.encodedQueryItemValue( item.toLatin1() );
#endif
}
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
}
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
}
inline QString path( QUrl const & url )
{
#if IS_QT_5
return url.path( QUrl::FullyDecoded );
#else
return url.path();
#endif
}
}
namespace Dom
{
#if IS_QT_5
typedef int size_type;
#else
typedef uint size_type;
#endif
}
}
#endif // QT4X5_HH