QT5 -- Enable build on 4.8.4 -OR- 5.2.0

New strategy to enable build on QT5 or QT4.8 is quite
simple to enact as most of the fixes for QT5 can be
applied to earlier releases.

This patch fixes up some of the special cases for QT5 so
they will continue to build on earlier releases.
This commit is contained in:
Mark Liversedge
2013-12-10 16:07:41 +00:00
parent 64c25192ee
commit e6ccd840f2
11 changed files with 108 additions and 24 deletions

View File

@@ -65,8 +65,13 @@ DiaryWindow::DiaryWindow(Context *context) :
monthlyView = new QTableView(this);
monthlyView->setItemDelegate(new GcCalendarDelegate);
monthlyView->setModel(calendarModel);
#if QT_VERSION > 0x050000
monthlyView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
monthlyView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
monthlyView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
monthlyView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
monthlyView->verticalHeader()->hide();
monthlyView->viewport()->installEventFilter(this);
monthlyView->setGridStyle(Qt::DotLine);

View File

@@ -129,7 +129,7 @@ LTMSettings::readChartXML(QDir home, QList<LTMSettings> &charts)
QDataStream &operator<<(QDataStream &out, const LTMSettings &settings)
{
// 4.6 - 4.9 all the same
out.setVersion(QDataStream::Qt_4_9);
out.setVersion(QDataStream::Qt_4_6);
// all the baisc fields first
out<<settings.name;
@@ -180,7 +180,7 @@ QDataStream &operator<<(QDataStream &out, const LTMSettings &settings)
QDataStream &operator>>(QDataStream &in, LTMSettings &settings)
{
// 4.6 - 4.9 all the same
in.setVersion(QDataStream::Qt_4_9);
in.setVersion(QDataStream::Qt_4_6);
RideMetricFactory &factory = RideMetricFactory::instance();
int counter=0;

View File

@@ -79,7 +79,11 @@ OAuthDialog::urlChanged(const QUrl &url)
QString code = url.toString().right(url.toString().length()-url.toString().indexOf("code=")-5);
QByteArray data;
#if QT_VERSION > 0x050000
QUrlQuery params;
#else
QUrl params;
#endif
QString urlstr = "";
if (site == STRAVA) {
@@ -104,7 +108,11 @@ OAuthDialog::urlChanged(const QUrl &url)
}
params.addQueryItem("code", code);
#if QT_VERSION > 0x050000
data.append(params.query(QUrl::FullyEncoded));
#else
data=params.encodedQuery();
#endif
QUrl url = QUrl(urlstr);
QNetworkRequest request = QNetworkRequest(url);

View File

@@ -24,11 +24,16 @@
#include <QtGui>
#include <QWidget>
#include <QStackedLayout>
#include <QUrl>
#include <QtWebKit>
#include <QWebView>
#include <QWebFrame>
#include <QUrl>
// QUrl split into QUrlQuerty in QT5
#if QT_VERSION > 0x050000
#include <QUrlQuery>
#endif
class OAuthDialog : public QDialog
{

View File

@@ -141,15 +141,22 @@ TtbDialog::requestSettings()
QString username = appsettings->cvalue(context->athlete->cyclist, GC_TTBUSER).toString();
QString password = appsettings->cvalue(context->athlete->cyclist, GC_TTBPASS).toString();
#if QT_VERSION > 0x050000
QUrlQuery urlquery( TTB_URL + "/settings/list" );
#else
QUrl urlquery( TTB_URL + "/settings/list" );
#endif
urlquery.addQueryItem( "view", "xml" );
urlquery.addQueryItem( "user", username );
urlquery.addQueryItem( "pass", password );
#if QT_VERSION > 0x050000
QUrl url;
url.setQuery(urlquery);
QNetworkRequest request = QNetworkRequest(url);
#else
QNetworkRequest request = QNetworkRequest(urlquery);
#endif
request.setRawHeader( "Accept-Encoding", "identity" );
request.setRawHeader( "Accept", "application/xml" );
request.setRawHeader( "Accept-Charset", "utf-8" );
@@ -168,15 +175,23 @@ TtbDialog::requestSession()
QString username = appsettings->cvalue(context->athlete->cyclist, GC_TTBUSER).toString();
QString password = appsettings->cvalue(context->athlete->cyclist, GC_TTBPASS).toString();
#if QT_VERSION > 0x050000
QUrlQuery urlquery( TTB_URL + "/login/sso" );
#else
QUrl urlquery( TTB_URL + "/login/sso" );
#endif
urlquery.addQueryItem( "view", "xml" );
urlquery.addQueryItem( "user", username );
urlquery.addQueryItem( "pass", password );
#if QT_VERSION > 0x050000
QUrl url;
url.setQuery(urlquery);
QNetworkRequest request = QNetworkRequest(url);
#else
QNetworkRequest request = QNetworkRequest(urlquery);
#endif
request.setRawHeader( "Accept-Encoding", "identity" );
request.setRawHeader( "Accept", "application/xml" );
request.setRawHeader( "Accept-Charset", "utf-8" );
@@ -234,14 +249,22 @@ TtbDialog::requestUpload()
currentRequest = reqUpload;
#if QT_VERSION > 0x050000
QUrlQuery urlquery( TTB_URL + "/file/upload" );
#else
QUrl urlquery( TTB_URL + "/file/upload" );
#endif
urlquery.addQueryItem( "view", "xml" );
urlquery.addQueryItem( "sso", sessionId );
#if QT_VERSION > 0x050000
QUrl url;
url.setQuery(urlquery);
QNetworkRequest request = QNetworkRequest(url);
#else
QNetworkRequest request = QNetworkRequest(urlquery);
#endif
request.setRawHeader( "Accept-Encoding", "identity" );
request.setRawHeader( "Accept", "application/xml" );
request.setRawHeader( "Accept-Charset", "utf-8" );

View File

@@ -26,13 +26,17 @@
#include <QProgressBar>
#include <QLabel>
#include <QUrl>
#include <QUrlQuery>
#include <QHttpMultiPart>
#include <QXmlInputSource>
#include <QXmlSimpleReader>
#include <QXmlDefaultHandler>
#include <QNetworkReply>
// QUrl split into QUrlQuerty in QT5
#if QT_VERSION > 0x050000
#include <QUrlQuery>
#endif
#include "Context.h"
#include "RideItem.h"

View File

@@ -63,10 +63,15 @@ VideoWindow::VideoWindow(Context *context, const QDir &home) :
/* This is a non working code that show how to hooks into a window,
* if we have a window around */
#ifdef Q_OS_LINUX
#if QT_VERSION > 0x050000
x11Container = new QWidget(this); //XXX PORT TO 5.1 BROKEN CODE XXX
#else
x11Container = new QX11EmbedContainer(this);
#endif
layout->addWidget(x11Container);
libvlc_media_player_set_xwindow (mp, x11Container->winId());
#endif
#ifdef WIN32
container = new QWidget(this);
layout->addWidget(container);
@@ -84,9 +89,9 @@ VideoWindow::VideoWindow(Context *context, const QDir &home) :
VideoWindow::~VideoWindow()
{
#ifdef Q_OS_LINUX
#ifdef Q_OS_LINUX && QT_VERSION < 0x050000 //XXX IN PORT TO QT 5.1 THIS IS BROKEN CODE XXX
// unembed vlc backend first
//x11Container->discardClient(); //XXX PORT TO QT 5.1 BROKEN CODE XXX
x11Container->discardClient();
#endif
stopPlayback();

View File

@@ -39,6 +39,10 @@ extern "C" {
#include "RealtimeData.h"
#include "TrainSidebar.h"
#ifdef Q_OS_LINUX && QT_VERSION < 0x050000
#include <QX11EmbedContainer>
#endif
class MediaHelper
{
public:
@@ -92,8 +96,13 @@ class VideoWindow : public GcWindow
libvlc_media_t *m;
#ifdef Q_OS_LINUX
#if QT_VERSION > 0x050000
QWidget *x11Container;
#else
QX11EmbedContainer *x11Container;
#endif
#endif
#ifdef WIN32
QWidget *container;
#endif

View File

@@ -70,7 +70,11 @@ WorkoutEditorBase::WorkoutEditorBase(QStringList &colms, QWidget *parent) :QFram
table->setColumnCount(colms.count());
table->setHorizontalHeaderLabels(colms);
#if QT_VERSION > 0x050000
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#endif
table->setShowGrid(true);
table->setAlternatingRowColors(true);
table->resizeColumnsToContents();

View File

@@ -19,7 +19,6 @@
#include <QApplication>
#include <QtGui>
#include <QFile>
#include <QStandardPaths>
#include "ChooseCyclistDialog.h"
#include "MainWindow.h"
#include "Settings.h"
@@ -50,6 +49,10 @@ void nostderr(QString dir)
#include <X11/Xlib.h>
#endif
#if QT_VERSION > 0x050000
#include <QStandardPaths>
#endif
QApplication *application;
bool restarting = false;
@@ -161,13 +164,16 @@ main(int argc, char *argv[])
#if defined(Q_OS_MACX)
QString libraryPath="Library/GoldenCheetah";
#elif defined(Q_OS_WIN)
//4.8 etc QString libraryPath=QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/GoldenCheetah";
#if QT_VERSION > 0x050000 // windows and qt5
QStringList paths=QStandardPaths::standardLocations(QStandardPaths::DataLocation);
QString libraryPath = paths.at(0) + "/GoldenCheetah";
#else
QString libraryPath = paths.at(0) + "/GoldenCheetah";
#else // windows not qt5
QString libraryPath=QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/GoldenCheetah";
#endif // qt5
#else // not windows or osx (must be Linux or OpenBSD)
// Q_OS_LINUX et al
QString libraryPath=".goldencheetah";
#endif
#endif //
// or did we override in settings?
QString sh;

View File

@@ -2,21 +2,40 @@
include( gcconfig.pri )
#
# What we are making and core dependencies
#
TEMPLATE = app
TARGET = GoldenCheetah
!isEmpty( APP_NAME ) { TARGET = $${APP_NAME} }
DEPENDPATH += .
## qwt and libz
INCLUDEPATH += ../qwt/src ../qxt/src $${LIBZ_INCLUDE}
QT += core xml sql network webkitwidgets script svg widgets
macx {
QT += macextras
}
LIBS += ../qwt/lib/libqwt.a
LIBS += -lm $${LIBZ_LIBS}
#
# We support 4.8.4 or higher
# 5.2.0 or higher
#
## common modules
QT += xml sql network script svg
lessThan(QT_MAJOR_VERSION, 5) {
## QT4 specific modules
QT += webkit
} else {
## QT5 specific modules
QT += webkitwidgets widgets
macx {
QT += macextras
}
}
# if we are building in debug mode
# then set MACRO -DGC_DEBUG so we can
# add / turnoff code for debugging purposes
@@ -24,10 +43,6 @@ CONFIG(debug, debug|release) {
QMAKE_CXXFLAGS += -DGC_DEBUG
}
!isEmpty( ZLIB_INCLUDE ) {
INCLUDEPATH += $${ZLIB_INCLUDE}
}
!isEmpty( LIBOAUTH_INSTALL ) {
isEmpty( LIBOAUTH_INCLUDE ) { LIBOAUTH_INCLUDE += $${LIBOAUTH_INSTALL}/include }
isEmpty( LIBOAUTH_LIBS ) {