From 57e71e5d55b57f67c611a86f4a0b14d683d86ea0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 13 Dec 2016 14:22:59 +0100 Subject: [PATCH] port C++ code to Qt5 --- src/Gui/Application.cpp | 27 +++++++++++++++++++++- src/Gui/BitmapFactory.cpp | 2 +- src/Gui/DlgActionsImp.cpp | 12 ++++++---- src/Gui/DlgCommandsImp.cpp | 4 ++++ src/Gui/DlgCustomizeSpaceball.cpp | 4 ++++ src/Gui/DlgKeyboardImp.cpp | 4 ++++ src/Gui/DlgParameterImp.cpp | 6 ++++- src/Gui/DlgToolbarsImp.cpp | 4 ++++ src/Gui/DocumentRecovery.cpp | 4 ++++ src/Gui/DownloadItem.cpp | 19 +++++++++++++++ src/Gui/DownloadManager.cpp | 26 +++++++++++++++++++++ src/Gui/GuiApplicationNativeEventAware.cpp | 4 ++++ src/Gui/GuiApplicationNativeEventAware.h | 22 ++++++++++++++++++ src/Gui/MainWindow.cpp | 10 ++++++++ src/Gui/Qt4All.h | 6 +++++ src/Gui/Quarter/QuarterWidget.cpp | 8 +++---- src/Gui/SceneInspector.cpp | 5 ++++ src/Gui/Tree.cpp | 4 ++++ src/Mod/Part/Gui/DlgFilletEdges.cpp | 6 +++++ src/Mod/Spreadsheet/Gui/SheetTableView.h | 4 ++++ src/Mod/TechDraw/Gui/TemplateTextField.cpp | 6 ++++- src/Mod/Web/Gui/BrowserView.h | 2 +- 22 files changed, 176 insertions(+), 13 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index acee4bb34..7c9f79d15 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -34,6 +34,9 @@ # include # include # include +#if QT_VERSION >= 0x050000 +# include +#endif # include # include # include @@ -1372,13 +1375,23 @@ CommandManager &Application::commandManager(void) } //************************************************************************** -// Init, Destruct and ingleton +// Init, Destruct and singleton +#if QT_VERSION >= 0x050000 +typedef void (*_qt_msg_handler_old)(QtMsgType, const QMessageLogContext &, const QString &); +#else typedef void (*_qt_msg_handler_old)(QtMsgType type, const char *msg); +#endif _qt_msg_handler_old old_qtmsg_handler = 0; +#if QT_VERSION >= 0x050000 +void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &qmsg) +{ + const QChar *msg = qmsg.unicode(); +#else void messageHandler(QtMsgType type, const char *msg) { +#endif #ifdef FC_DEBUG switch (type) { @@ -1397,8 +1410,12 @@ void messageHandler(QtMsgType type, const char *msg) } #ifdef FC_OS_WIN32 if (old_qtmsg_handler) +#if QT_VERSION >=0x050000 + (*old_qtmsg_handler)(type, context, qmsg); +#else (*old_qtmsg_handler)(type, msg); #endif +#endif #else // do not stress user with Qt internals but write to log file if enabled Q_UNUSED(type); @@ -1426,7 +1443,11 @@ void messageHandlerCoin(const SoError * error, void * /*userdata*/) } #ifdef FC_OS_WIN32 if (old_qtmsg_handler) +#if QT_VERSION >=0x050000 + (*old_qtmsg_handler)(QtDebugMsg, QMessageLogContext(), QString::fromLatin1(msg)); +#else (*old_qtmsg_handler)(QtDebugMsg, msg); +#endif #endif } else if (error) { @@ -1457,7 +1478,11 @@ void Application::initApplication(void) initTypes(); new Base::ScriptProducer( "FreeCADGuiInit", FreeCADGuiInit ); init_resources(); +#if QT_VERSION >=0x050000 + old_qtmsg_handler = qInstallMessageHandler(messageHandler); +#else old_qtmsg_handler = qInstallMsgHandler(messageHandler); +#endif init = true; } catch (...) { diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index affb1ae96..cf755c2fb 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -37,7 +37,7 @@ # include #endif -#ifdef FC_OS_WIN32 +#if defined (FC_OS_WIN32) && QT_VERSION < 0x050000 #define QTWEBKIT #endif diff --git a/src/Gui/DlgActionsImp.cpp b/src/Gui/DlgActionsImp.cpp index 372334980..eba886fbc 100644 --- a/src/Gui/DlgActionsImp.cpp +++ b/src/Gui/DlgActionsImp.cpp @@ -73,17 +73,21 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent ) d = QDir(systemMacroDirStr, QLatin1String("*.FCMacro *.py")); - if(d.exists()) { - for (unsigned int i=0; iinsertItem(0,d[i],QVariant(true)); - } + if (d.exists()) { + for (unsigned int i=0; iinsertItem(0,d[i],QVariant(true)); + } } QStringList labels; labels << tr("Icons") << tr("Macros"); actionListWidget->setHeaderLabels(labels); actionListWidget->header()->hide(); actionListWidget->setIconSize(QSize(32, 32)); +#if QT_VERSION >= 0x050000 + actionListWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); +#else actionListWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents); +#endif showActions(); } diff --git a/src/Gui/DlgCommandsImp.cpp b/src/Gui/DlgCommandsImp.cpp index 7c6de872e..7e7246803 100644 --- a/src/Gui/DlgCommandsImp.cpp +++ b/src/Gui/DlgCommandsImp.cpp @@ -116,7 +116,11 @@ DlgCustomCommandsImp::DlgCustomCommandsImp( QWidget* parent ) commandTreeWidget->setHeaderLabels(labels); commandTreeWidget->header()->hide(); commandTreeWidget->setIconSize(QSize(32, 32)); +#if QT_VERSION >= 0x050000 + commandTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); +#else commandTreeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents); +#endif categoryTreeWidget->setCurrentItem(categoryTreeWidget->topLevelItem(0)); } diff --git a/src/Gui/DlgCustomizeSpaceball.cpp b/src/Gui/DlgCustomizeSpaceball.cpp index 46802d41d..43d84473d 100644 --- a/src/Gui/DlgCustomizeSpaceball.cpp +++ b/src/Gui/DlgCustomizeSpaceball.cpp @@ -633,7 +633,11 @@ void DlgCustomizeSpaceball::goPrint() { QTableView *view = new QTableView(this); PrintModel *model = new PrintModel(this, buttonModel, commandModel); +#if QT_VERSION >= 0x050000 + view->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +#else view->horizontalHeader()->setResizeMode(QHeaderView::Fixed); +#endif view->setModel(model); view->horizontalHeader()->resizeSection(0, 150); view->horizontalHeader()->resizeSection(1, 300); diff --git a/src/Gui/DlgKeyboardImp.cpp b/src/Gui/DlgKeyboardImp.cpp index 8e547c295..8b2ead6ed 100644 --- a/src/Gui/DlgKeyboardImp.cpp +++ b/src/Gui/DlgKeyboardImp.cpp @@ -106,7 +106,11 @@ DlgCustomKeyboardImp::DlgCustomKeyboardImp( QWidget* parent ) commandTreeWidget->setHeaderLabels(labels); commandTreeWidget->header()->hide(); commandTreeWidget->setIconSize(QSize(32, 32)); +#if QT_VERSION >= 0x050000 + commandTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); +#else commandTreeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents); +#endif assignedTreeWidget->setHeaderLabels(labels); assignedTreeWidget->header()->hide(); diff --git a/src/Gui/DlgParameterImp.cpp b/src/Gui/DlgParameterImp.cpp index 6ae45c368..eb1307ed8 100644 --- a/src/Gui/DlgParameterImp.cpp +++ b/src/Gui/DlgParameterImp.cpp @@ -73,8 +73,12 @@ DlgParameterImp::DlgParameterImp( QWidget* parent, Qt::WindowFlags fl ) paramValue = new ParameterValue(ui->splitter3); paramValue->setHeaderLabels(valueLabels); paramValue->setRootIsDecorated(false); +#if QT_VERSION >= 0x050000 + paramValue->header()->setSectionResizeMode(0, QHeaderView::Stretch); +#else paramValue->header()->setResizeMode(0, QHeaderView::Stretch); - +#endif + QSizePolicy policy = paramValue->sizePolicy(); policy.setHorizontalStretch(3); paramValue->setSizePolicy(policy); diff --git a/src/Gui/DlgToolbarsImp.cpp b/src/Gui/DlgToolbarsImp.cpp index 8ce87cfd7..062672d4d 100644 --- a/src/Gui/DlgToolbarsImp.cpp +++ b/src/Gui/DlgToolbarsImp.cpp @@ -132,7 +132,11 @@ DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent) commandTreeWidget->setHeaderLabels(labels); commandTreeWidget->header()->hide(); commandTreeWidget->setIconSize(QSize(32, 32)); +#if QT_VERSION >= 0x050000 + commandTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); +#else commandTreeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents); +#endif labels.clear(); labels << tr("Command"); toolbarTreeWidget->setHeaderLabels(labels); diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index a033d8d90..ecf880dc1 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -173,7 +173,11 @@ DocumentRecovery::DocumentRecovery(const QList& dirs, QWidget* parent { d_ptr->ui.setupUi(this); d_ptr->ui.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Start Recovery")); +#if QT_VERSION >= 0x050000 + d_ptr->ui.treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); +#else d_ptr->ui.treeWidget->header()->setResizeMode(QHeaderView::Stretch); +#endif d_ptr->recovered = false; diff --git a/src/Gui/DownloadItem.cpp b/src/Gui/DownloadItem.cpp index 746cf29a3..d7f99cb3e 100644 --- a/src/Gui/DownloadItem.cpp +++ b/src/Gui/DownloadItem.cpp @@ -39,6 +39,9 @@ #include #include #include +#if QT_VERSION >= 0x050000 +#include +#endif #include #include @@ -167,7 +170,11 @@ NetworkAccessManager::NetworkAccessManager(QObject *parent) SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); +#if QT_VERSION >= 0x050000 + QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); +#else QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); +#endif diskCache->setCacheDirectory(location); setCache(diskCache); } @@ -184,7 +191,11 @@ void NetworkAccessManager::authenticationRequired(QNetworkReply *reply, QAuthent dialog.adjustSize(); QString introMessage = tr("Enter username and password for \"%1\" at %2"); +#if QT_VERSION >= 0x050000 + introMessage = introMessage.arg(QString(reply->url().toString()).toHtmlEscaped()).arg(QString(reply->url().toString()).toHtmlEscaped()); +#else introMessage = introMessage.arg(Qt::escape(reply->url().toString())).arg(Qt::escape(reply->url().toString())); +#endif passwordDialog.siteDescription->setText(introMessage); passwordDialog.siteDescription->setWordWrap(true); @@ -206,7 +217,11 @@ void NetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &prox dialog.adjustSize(); QString introMessage = tr("Connect to proxy \"%1\" using:"); +#if QT_VERSION >= 0x050000 + introMessage = introMessage.arg(QString(proxy.hostName()).toHtmlEscaped()); +#else introMessage = introMessage.arg(Qt::escape(proxy.hostName())); +#endif proxyDialog.siteDescription->setText(introMessage); proxyDialog.siteDescription->setWordWrap(true); @@ -272,7 +287,11 @@ void DownloadItem::init() QString DownloadItem::getDownloadDirectory() const { QString exe = QString::fromLatin1(App::GetApplication().getExecutableName()); +#if QT_VERSION >= 0x050000 + QString path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); +#else QString path = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); +#endif QString dirPath = QDir(path).filePath(exe); Base::Reference hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp") ->GetGroup("Preferences")->GetGroup("General"); diff --git a/src/Gui/DownloadManager.cpp b/src/Gui/DownloadManager.cpp index 58187f749..98b767d34 100644 --- a/src/Gui/DownloadManager.cpp +++ b/src/Gui/DownloadManager.cpp @@ -33,7 +33,12 @@ #include #include #include +#if QT_VERSION < 0x050000 #include +#endif +#if QT_VERSION >= 0x050000 +#include +#endif #include "DownloadItem.h" #include "DownloadManager.h" @@ -112,6 +117,24 @@ QUrl DownloadManager::redirectUrl(const QUrl& url) const { QUrl redirectUrl = url; if (url.host() == QLatin1String("www.dropbox.com")) { +#if QT_VERSION >= 0x050000 + QUrlQuery urlQuery(url); + QList< QPair > query = urlQuery.queryItems(); + for (QList< QPair >::iterator it = query.begin(); it != query.end(); ++it) { + if (it->first == QLatin1String("dl")) { + if (it->second == QLatin1String("0\r\n")) { + urlQuery.removeQueryItem(QLatin1String("dl")); + urlQuery.addQueryItem(QLatin1String("dl"), QLatin1String("1\r\n")); + } + else if (it->second == QLatin1String("0")) { + urlQuery.removeQueryItem(QLatin1String("dl")); + urlQuery.addQueryItem(QLatin1String("dl"), QLatin1String("1")); + } + break; + } + } + redirectUrl.setQuery(urlQuery); +#else QList< QPair > query = url.queryItems(); for (QList< QPair >::iterator it = query.begin(); it != query.end(); ++it) { if (it->first == QLatin1String("dl")) { @@ -126,6 +149,7 @@ QUrl DownloadManager::redirectUrl(const QUrl& url) const break; } } +#endif } else { // When the url comes from drag and drop it may end with CR+LF. This may cause problems @@ -193,10 +217,12 @@ void DownloadManager::updateRow() ui->downloadsView->setRowHeight(row, item->minimumSizeHint().height()); bool remove = false; +#if QT_VERSION < 0x050000 QWebSettings *globalSettings = QWebSettings::globalSettings(); if (!item->downloading() && globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) remove = true; +#endif if (item->downloadedSuccessfully() && removePolicy() == DownloadManager::SuccessFullDownload) { diff --git a/src/Gui/GuiApplicationNativeEventAware.cpp b/src/Gui/GuiApplicationNativeEventAware.cpp index 6168d59df..0ed7fa657 100644 --- a/src/Gui/GuiApplicationNativeEventAware.cpp +++ b/src/Gui/GuiApplicationNativeEventAware.cpp @@ -111,7 +111,11 @@ void Gui::GUIApplicationNativeEventAware::initSpaceball(QMainWindow *window) if (InitializeRawInput((HWND)mainWindow->winId())){ gMouseInput = this; +#if QT_VERSION >= 0x050000 + qApp->installNativeEventFilter(new Gui::RawInputEventFilter(Gui::GUIApplicationNativeEventAware::RawInputEventFilter)); +#else qApp->setEventFilter(Gui::GUIApplicationNativeEventAware::RawInputEventFilter); +#endif Base::Console().Log("3Dconnexion device initialized.\n"); } else { Base::Console().Log("3Dconnexion device is attached, but not initialized.\n"); diff --git a/src/Gui/GuiApplicationNativeEventAware.h b/src/Gui/GuiApplicationNativeEventAware.h index d3a5f7108..88791ebc1 100644 --- a/src/Gui/GuiApplicationNativeEventAware.h +++ b/src/Gui/GuiApplicationNativeEventAware.h @@ -26,6 +26,9 @@ #define GUIAPPLICATIONNATIVEEVENTAWARE_H #include +#if QT_VERSION >= 0x050000 +#include +#endif class QMainWindow; @@ -62,6 +65,25 @@ extern void CleanupConnexionHandlers(void) __attribute__((weak_import)); namespace Gui { +#if QT_VERSION >= 0x050000 + class RawInputEventFilter : public QAbstractNativeEventFilter + { + public: + typedef bool (*EventFilter)(void *message, long *result); + RawInputEventFilter(EventFilter) { + } + virtual ~RawInputEventFilter() { + } + + virtual bool nativeEventFilter(const QByteArray & /*eventType*/, void *message, long *result) { + return eventFilter(message, result); + } + + private: + EventFilter eventFilter; + }; +#endif + class GUIApplicationNativeEventAware : public QApplication { Q_OBJECT diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index ba121caea..01002cb27 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -45,6 +45,9 @@ # include # include # include +#if QT_VERSION >= 0x050000 +# include +#endif # include #endif @@ -1476,8 +1479,15 @@ void MainWindow::loadUrls(App::Document* doc, const QList& url) //#ifndef QT_NO_OPENSSL else if (it->scheme().toLower() == QLatin1String("https")) { QUrl url = *it; +#if QT_VERSION >= 0x050000 + QUrlQuery urlq(url); + if (urlq.hasQueryItem(QLatin1String("sid"))) { + urlq.removeAllQueryItems(QLatin1String("sid")); + url.setQuery(urlq); +#else if (it->hasEncodedQueryItem(QByteArray("sid"))) { url.removeEncodedQueryItem(QByteArray("sid")); +#endif url.setScheme(QLatin1String("http")); } Gui::Dialog::DownloadManager* dm = Gui::Dialog::DownloadManager::getInstance(); diff --git a/src/Gui/Qt4All.h b/src/Gui/Qt4All.h index b51b3ac21..a081aae33 100644 --- a/src/Gui/Qt4All.h +++ b/src/Gui/Qt4All.h @@ -48,6 +48,9 @@ #include #include #include +#if QT_VERSION >= 0x050000 +#include +#endif #include #include // QtGui @@ -98,6 +101,9 @@ #include #include #include +#if QT_VERSION >= 0x050000 +#include +#endif #include #include #include diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp index 6e7a36713..37bf36d43 100644 --- a/src/Gui/Quarter/QuarterWidget.cpp +++ b/src/Gui/Quarter/QuarterWidget.cpp @@ -54,6 +54,10 @@ #include +#include +#include +#include + #include #include #include @@ -79,10 +83,6 @@ #include #include -#include -#include -#include - #include #include "InteractionMode.h" diff --git a/src/Gui/SceneInspector.cpp b/src/Gui/SceneInspector.cpp index 64ae97a8c..efa0f3e7a 100644 --- a/src/Gui/SceneInspector.cpp +++ b/src/Gui/SceneInspector.cpp @@ -133,8 +133,13 @@ void DlgInspector::setNode(SoNode* node) model->setNode(node); QHeaderView* header = ui->treeView->header(); +#if QT_VERSION >= 0x050000 + header->setSectionResizeMode(0, QHeaderView::Stretch); + header->setSectionsMovable(false); +#else header->setResizeMode(0, QHeaderView::Stretch); header->setMovable(false); +#endif } void DlgInspector::changeEvent(QEvent *e) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 6e36f08e8..d9b2388c7 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -115,7 +115,11 @@ TreeWidget::TreeWidget(QWidget* parent) labels << tr("Labels & Attributes"); this->setHeaderLabels(labels); // make sure to show a horizontal scrollbar if needed +#if QT_VERSION >= 0x050000 + this->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); +#else this->header()->setResizeMode(0, QHeaderView::ResizeToContents); +#endif this->header()->setStretchLastSection(false); // Add the first main label diff --git a/src/Mod/Part/Gui/DlgFilletEdges.cpp b/src/Mod/Part/Gui/DlgFilletEdges.cpp index f11a61aa9..c1a04411d 100644 --- a/src/Mod/Part/Gui/DlgFilletEdges.cpp +++ b/src/Mod/Part/Gui/DlgFilletEdges.cpp @@ -280,9 +280,15 @@ DlgFilletEdges::DlgFilletEdges(FilletType type, Part::FilletBase* fillet, QWidge ui->treeView->setModel(model); QHeaderView* header = ui->treeView->header(); +#if QT_VERSION >= 0x050000 + header->setSectionResizeMode(0, QHeaderView::Stretch); + header->setDefaultAlignment(Qt::AlignLeft); + header->setSectionsMovable(false); +#else header->setResizeMode(0, QHeaderView::Stretch); header->setDefaultAlignment(Qt::AlignLeft); header->setMovable(false); +#endif on_filletType_activated(0); findShapes(); } diff --git a/src/Mod/Spreadsheet/Gui/SheetTableView.h b/src/Mod/Spreadsheet/Gui/SheetTableView.h index d55210dbe..871c463c5 100644 --- a/src/Mod/Spreadsheet/Gui/SheetTableView.h +++ b/src/Mod/Spreadsheet/Gui/SheetTableView.h @@ -36,7 +36,11 @@ class SheetViewHeader : public QHeaderView { Q_OBJECT public: SheetViewHeader(Qt::Orientation o) : QHeaderView(o) { +#if QT_VERSION >= 0x050000 + setSectionsClickable(true); +#else setClickable(true); +#endif } Q_SIGNALS: void resizeFinished(); diff --git a/src/Mod/TechDraw/Gui/TemplateTextField.cpp b/src/Mod/TechDraw/Gui/TemplateTextField.cpp index c8023cd14..7db9f9c09 100644 --- a/src/Mod/TechDraw/Gui/TemplateTextField.cpp +++ b/src/Mod/TechDraw/Gui/TemplateTextField.cpp @@ -63,7 +63,11 @@ void TemplateTextField::execDialog() if(uiCode == QDialog::Accepted) { if (tmplte) { newContent = ui->getFieldContent(); - QString qsClean = Qt::escape(newContent); //Qt5 note: this becomes qsNewContent.toHtmlEscaped(); +#if QT_VERSION >= 0x050000 + QString qsClean = newContent.toHtmlEscaped(); +#else + QString qsClean = Qt::escape(newContent); +#endif std::string utf8Content = qsClean.toUtf8().constData(); tmplte->EditableTexts.setValue(fieldNameStr, utf8Content); } diff --git a/src/Mod/Web/Gui/BrowserView.h b/src/Mod/Web/Gui/BrowserView.h index e0b9d3d67..f745c8a21 100644 --- a/src/Mod/Web/Gui/BrowserView.h +++ b/src/Mod/Web/Gui/BrowserView.h @@ -28,7 +28,7 @@ #include #include -# if QT_VERSION >= 0x040400 +#if QT_VERSION >= 0x040400 #include #endif