remove IS_QT_5

This commit is contained in:
yifang.xiao 2021-11-26 16:42:21 +08:00 committed by yifang
parent 69db1d4c71
commit f39429f35a
4 changed files with 4 additions and 106 deletions

View file

@ -27,7 +27,7 @@ QHotkeyApplication::QHotkeyApplication( int & argc, char ** argv ):
connect( this, SIGNAL( saveStateRequest( QSessionManager& ) ), connect( this, SIGNAL( saveStateRequest( QSessionManager& ) ),
this, SLOT( hotkeyAppSaveState( QSessionManager& ) ), Qt::DirectConnection ); this, SLOT( hotkeyAppSaveState( QSessionManager& ) ), Qt::DirectConnection );
#if defined( Q_OS_WIN ) && IS_QT_5 #if defined( Q_OS_WIN )
installNativeEventFilter( this ); installNativeEventFilter( this );
#endif #endif
} }
@ -45,7 +45,7 @@ QHotkeyApplication::QHotkeyApplication( QString const & id,
connect( this, SIGNAL( saveStateRequest( QSessionManager& ) ), connect( this, SIGNAL( saveStateRequest( QSessionManager& ) ),
this, SLOT( hotkeyAppSaveState( QSessionManager& ) ), Qt::DirectConnection ); this, SLOT( hotkeyAppSaveState( QSessionManager& ) ), Qt::DirectConnection );
#if defined( Q_OS_WIN ) && IS_QT_5 #if defined( Q_OS_WIN )
installNativeEventFilter( this ); installNativeEventFilter( this );
#endif #endif
} }
@ -478,9 +478,6 @@ void HotkeyWrapper::unregister()
(static_cast<QHotkeyApplication*>(qApp))->unregisterWrapper(this); (static_cast<QHotkeyApplication*>(qApp))->unregisterWrapper(this);
} }
#if IS_QT_5
bool QHotkeyApplication::nativeEventFilter( const QByteArray & /*eventType*/, void * message, long * result ) bool QHotkeyApplication::nativeEventFilter( const QByteArray & /*eventType*/, void * message, long * result )
{ {
MSG * msg = reinterpret_cast< MSG * >( message ); MSG * msg = reinterpret_cast< MSG * >( message );
@ -503,30 +500,6 @@ bool QHotkeyApplication::nativeEventFilter( const QByteArray & /*eventType*/, vo
return false; return false;
} }
#else // IS_QT_5
bool QHotkeyApplication::winEventFilter ( MSG * message, long * result )
{
if (message->message == WM_HOTKEY || message->message == GD_HOTKEY_MESSAGE)
{
for (int i = 0; i < hotkeyWrappers.size(); i++)
{
if ( hotkeyWrappers.at(i)->winEvent( message, result ) )
return true;
}
}
if( mainWindow )
{
if( ( static_cast< MainWindow * >( mainWindow ) )->handleGDMessage( message, result ) )
return true;
}
return QApplication::winEventFilter( message, result );
}
#endif
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
#else #else

View file

@ -215,7 +215,7 @@ public:
// by Qt meta-object compiler // by Qt meta-object compiler
class QIntermediateApplication : public QtSingleApplication class QIntermediateApplication : public QtSingleApplication
#if defined( Q_OS_WIN ) && IS_QT_5 #if defined( Q_OS_WIN )
, public QAbstractNativeEventFilter , public QAbstractNativeEventFilter
#endif #endif
{ {
@ -255,11 +255,7 @@ protected:
void unregisterWrapper(HotkeyWrapper *wrapper); void unregisterWrapper(HotkeyWrapper *wrapper);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
#if IS_QT_5
virtual bool nativeEventFilter( const QByteArray & eventType, void * message, long * result ); virtual bool nativeEventFilter( const QByteArray & eventType, void * message, long * result );
#else // IS_QT_5
virtual bool winEventFilter ( MSG * message, long * result );
#endif // IS_QT_5
QWidget * mainWindow; QWidget * mainWindow;
public: public:

View file

@ -130,11 +130,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
GD_DPRINTF( "request begin\n" ); GD_DPRINTF( "request begin\n" );
QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" ); QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" );
#if IS_QT_5
Qt4x5::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ).replace( '+', "%2B" ) ); Qt4x5::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ).replace( '+', "%2B" ) );
#else
reqUrl.addEncodedQueryItem( "apfrom", QUrl::toPercentEncoding( gd::toQString( str ) ) );
#endif
netReply = mgr.get( QNetworkRequest( reqUrl ) ); netReply = mgr.get( QNetworkRequest( reqUrl ) );
@ -295,11 +291,7 @@ void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr,
QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid&format=xml&redirects" ); QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid&format=xml&redirects" );
#if IS_QT_5
Qt4x5::Url::addQueryItem( reqUrl, "page", gd::toQString( str ).replace( '+', "%2B" ) ); Qt4x5::Url::addQueryItem( reqUrl, "page", gd::toQString( str ).replace( '+', "%2B" ) );
#else
reqUrl.addEncodedQueryItem( "page", QUrl::toPercentEncoding( gd::toQString( str ) ) );
#endif
QNetworkReply * netReply = mgr.get( QNetworkRequest( reqUrl ) ); QNetworkReply * netReply = mgr.get( QNetworkRequest( reqUrl ) );

View file

@ -3,32 +3,19 @@
#ifndef QT4X5_HH #ifndef QT4X5_HH
#define 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 <QString>
#include <QAtomicInt> #include <QAtomicInt>
#include <QTextDocument> #include <QTextDocument>
#include <QUrl> #include <QUrl>
#if IS_QT_5
#include <QUrlQuery> #include <QUrlQuery>
#endif
namespace Qt4x5 namespace Qt4x5
{ {
inline QString escape( QString const & plain ) inline QString escape( QString const & plain )
{ {
#if IS_QT_5
return plain.toHtmlEscaped(); return plain.toHtmlEscaped();
#else
return Qt::escape( plain );
#endif
} }
namespace AtomicInt namespace AtomicInt
@ -36,11 +23,7 @@ namespace AtomicInt
inline int loadAcquire( QAtomicInt const & ref ) inline int loadAcquire( QAtomicInt const & ref )
{ {
#if IS_QT_5
return ref.loadAcquire(); return ref.loadAcquire();
#else
return ( int )ref;
#endif
} }
} }
@ -53,114 +36,68 @@ namespace Url
// https://codereview.qt-project.org/#change,38257 // https://codereview.qt-project.org/#change,38257
inline QString ensureLeadingSlash( const QString & path ) inline QString ensureLeadingSlash( const QString & path )
{ {
#if IS_QT_5
QLatin1Char slash( '/' ); QLatin1Char slash( '/' );
if ( path.startsWith( slash ) ) if ( path.startsWith( slash ) )
return path; return path;
return slash + path; return slash + path;
#else
return path;
#endif
} }
inline bool hasQueryItem( QUrl const & url, QString const & key ) inline bool hasQueryItem( QUrl const & url, QString const & key )
{ {
#if IS_QT_5
return QUrlQuery( url ).hasQueryItem( key ); return QUrlQuery( url ).hasQueryItem( key );
#else
return url.hasQueryItem( key );
#endif
} }
inline QString queryItemValue( QUrl const & url, QString const & item ) inline QString queryItemValue( QUrl const & url, QString const & item )
{ {
#if IS_QT_5
return QUrlQuery( url ).queryItemValue( item, QUrl::FullyDecoded ); return QUrlQuery( url ).queryItemValue( item, QUrl::FullyDecoded );
#else
return url.queryItemValue( item );
#endif
} }
inline QByteArray encodedQueryItemValue( QUrl const & url, QString const & item ) inline QByteArray encodedQueryItemValue( QUrl const & url, QString const & item )
{ {
#if IS_QT_5
return QUrlQuery( url ).queryItemValue( item, QUrl::FullyEncoded ).toLatin1(); 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 ) inline void addQueryItem( QUrl & url, QString const & key, QString const & value )
{ {
#if IS_QT_5
QUrlQuery urlQuery( url ); QUrlQuery urlQuery( url );
urlQuery.addQueryItem( key, value ); urlQuery.addQueryItem( key, value );
url.setQuery( urlQuery ); url.setQuery( urlQuery );
#else
url.addQueryItem( key, value );
#endif
} }
inline void removeQueryItem( QUrl & url, QString const & key ) inline void removeQueryItem( QUrl & url, QString const & key )
{ {
#if IS_QT_5
QUrlQuery urlQuery( url ); QUrlQuery urlQuery( url );
urlQuery.removeQueryItem( key ); urlQuery.removeQueryItem( key );
url.setQuery( urlQuery ); url.setQuery( urlQuery );
#else
url.removeQueryItem( key );
#endif
} }
inline void setQueryItems( QUrl & url, QList< QPair< QString, QString > > const & query ) inline void setQueryItems( QUrl & url, QList< QPair< QString, QString > > const & query )
{ {
#if IS_QT_5
QUrlQuery urlQuery( url ); QUrlQuery urlQuery( url );
urlQuery.setQueryItems( query ); urlQuery.setQueryItems( query );
url.setQuery( urlQuery ); url.setQuery( urlQuery );
#else
url.setQueryItems( query );
#endif
} }
inline QString path( QUrl const & url ) inline QString path( QUrl const & url )
{ {
#if IS_QT_5
return url.path( QUrl::FullyDecoded ); return url.path( QUrl::FullyDecoded );
#else
return url.path();
#endif
} }
inline void setFragment( QUrl & url, const QString & fragment ) inline void setFragment( QUrl & url, const QString & fragment )
{ {
#if IS_QT_5
url.setFragment( fragment, QUrl::DecodedMode ); url.setFragment( fragment, QUrl::DecodedMode );
#else
url.setFragment( fragment );
#endif
} }
inline QString fragment( const QUrl & url ) inline QString fragment( const QUrl & url )
{ {
#if IS_QT_5
return url.fragment( QUrl::FullyDecoded ); return url.fragment( QUrl::FullyDecoded );
#else
return url.fragment();
#endif
} }
} }
namespace Dom namespace Dom
{ {
typedef int size_type;
#if IS_QT_5
typedef int size_type;
#else
typedef uint size_type;
#endif
} }
} }