From 87f2866884f199c97b017412a8d4dafece2bd2b6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 13 Dec 2016 19:47:32 +0100 Subject: [PATCH] Linux specific Qt5 port --- src/Gui/Application.cpp | 34 +++++++++++++++++++++++++++++----- src/Gui/FileDialog.cpp | 30 ++++++++++++++++++++++++++++++ src/Gui/WidgetFactory.cpp | 2 ++ src/Main/MainGui.cpp | 2 ++ 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 7c9f79d15..3b69c9cf6 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1387,11 +1387,38 @@ _qt_msg_handler_old old_qtmsg_handler = 0; #if QT_VERSION >= 0x050000 void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &qmsg) { + Q_UNUSED(context); const QChar *msg = qmsg.unicode(); +#ifdef FC_DEBUG + switch (type) + { + case QtInfoMsg: + case QtDebugMsg: + Base::Console().Message("%s\n", msg); + break; + case QtWarningMsg: + Base::Console().Warning("%s\n", msg); + break; + case QtCriticalMsg: + Base::Console().Error("%s\n", msg); + break; + case QtFatalMsg: + Base::Console().Error("%s\n", msg); + abort(); // deliberately core dump + } +#ifdef FC_OS_WIN32 + if (old_qtmsg_handler) + (*old_qtmsg_handler)(type, context, qmsg); +#endif +#else + // do not stress user with Qt internals but write to log file if enabled + Q_UNUSED(type); + Base::Console().Log("%s\n", msg); +#endif +} #else void messageHandler(QtMsgType type, const char *msg) { -#endif #ifdef FC_DEBUG switch (type) { @@ -1410,18 +1437,15 @@ 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); Base::Console().Log("%s\n", msg); #endif } +#endif #ifdef FC_DEBUG // redirect Coin messages to FreeCAD void messageHandlerCoin(const SoError * error, void * /*userdata*/) diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp index c748fa149..023d6539c 100644 --- a/src/Gui/FileDialog.cpp +++ b/src/Gui/FileDialog.cpp @@ -151,12 +151,22 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption, // before showing the file dialog. #if defined(FC_OS_LINUX) QList urls; + +#if QT_VERSION >= 0x050000 + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); +#else urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation)); +#endif urls << QUrl::fromLocalFile(getWorkingDirectory()); urls << QUrl::fromLocalFile(restoreLocation()); urls << QUrl::fromLocalFile(QDir::currentPath()); @@ -232,12 +242,22 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c #if defined(FC_OS_LINUX) QList urls; + +#if QT_VERSION >= 0x050000 + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); +#else urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation)); +#endif urls << QUrl::fromLocalFile(getWorkingDirectory()); urls << QUrl::fromLocalFile(restoreLocation()); urls << QUrl::fromLocalFile(QDir::currentPath()); @@ -292,12 +312,22 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt #if defined(FC_OS_LINUX) QList urls; + +#if QT_VERSION >= 0x050000 + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); + urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); +#else urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation)); urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation)); +#endif urls << QUrl::fromLocalFile(getWorkingDirectory()); urls << QUrl::fromLocalFile(restoreLocation()); urls << QUrl::fromLocalFile(QDir::currentPath()); diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp index b7076e97e..3aacaed45 100644 --- a/src/Gui/WidgetFactory.cpp +++ b/src/Gui/WidgetFactory.cpp @@ -206,6 +206,8 @@ Py::Object PythonWrapper::fromQIcon(const QIcon* icon) PyObject* pyobj = Shiboken::createWrapper(icon, true); if (pyobj) return Py::asObject(pyobj); +#else + Q_UNUSED(icon); #endif throw Py::RuntimeError("Failed to wrap icon"); } diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index 5bfc6ab67..edc4469b3 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -91,11 +91,13 @@ int main( int argc, char ** argv ) // Make sure to setup the Qt locale system before setting LANG and LC_ALL to C. // which is needed to use the system locale settings. (void)QLocale::system(); +#if QT_VERSION < 0x050000 // http://www.freecadweb.org/tracker/view.php?id=399 // Because of setting LANG=C the Qt automagic to use the correct encoding // for file names is broken. This is a workaround to force the use of UTF-8 encoding QFile::setEncodingFunction(myEncoderFunc); QFile::setDecodingFunction(myDecoderFunc); +#endif // Make sure that we use '.' as decimal point. See also // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559846 putenv("LC_NUMERIC=C");