port C++ code to Qt5

This commit is contained in:
wmayer 2016-12-13 14:22:59 +01:00
parent c678144272
commit 57e71e5d55
22 changed files with 176 additions and 13 deletions

View File

@ -34,6 +34,9 @@
# include <QFileInfo>
# include <QLocale>
# include <QMessageBox>
#if QT_VERSION >= 0x050000
# include <QMessageLogContext>
#endif
# include <QPointer>
# include <QGLFormat>
# include <QGLPixelBuffer>
@ -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 (...) {

View File

@ -37,7 +37,7 @@
# include <sstream>
#endif
#ifdef FC_OS_WIN32
#if defined (FC_OS_WIN32) && QT_VERSION < 0x050000
#define QTWEBKIT
#endif

View File

@ -73,17 +73,21 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent )
d = QDir(systemMacroDirStr, QLatin1String("*.FCMacro *.py"));
if(d.exists()) {
for (unsigned int i=0; i<d.count(); i++ ) {
actionMacros->insertItem(0,d[i],QVariant(true));
}
if (d.exists()) {
for (unsigned int i=0; i<d.count(); i++ ) {
actionMacros->insertItem(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();
}

View File

@ -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));
}

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -173,7 +173,11 @@ DocumentRecovery::DocumentRecovery(const QList<QFileInfo>& 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;

View File

@ -39,6 +39,9 @@
#include <QHeaderView>
#include <QDebug>
#include <QKeyEvent>
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#endif
#include <QTextDocument>
#include <App/Document.h>
@ -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("<qt>Enter username and password for \"%1\" at %2</qt>");
#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("<qt>Connect to proxy \"%1\" using:</qt>");
#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<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
->GetGroup("Preferences")->GetGroup("General");

View File

@ -33,7 +33,12 @@
#include <QMetaEnum>
#include <QSettings>
#include <QFileIconProvider>
#if QT_VERSION < 0x050000
#include <QWebSettings>
#endif
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
#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<QString, QString> > query = urlQuery.queryItems();
for (QList< QPair<QString, QString> >::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<QString, QString> > query = url.queryItems();
for (QList< QPair<QString, QString> >::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) {

View File

@ -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");

View File

@ -26,6 +26,9 @@
#define GUIAPPLICATIONNATIVEEVENTAWARE_H
#include <QApplication>
#if QT_VERSION >= 0x050000
#include <QAbstractNativeEventFilter>
#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

View File

@ -45,6 +45,9 @@
# include <QStatusBar>
# include <QTimer>
# include <QToolBar>
#if QT_VERSION >= 0x050000
# include <QUrlQuery>
#endif
# include <QWhatsThis>
#endif
@ -1476,8 +1479,15 @@ void MainWindow::loadUrls(App::Document* doc, const QList<QUrl>& 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();

View File

@ -48,6 +48,9 @@
#include <qtimer.h>
#include <qtranslator.h>
#include <QUrl>
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
#endif
#include <qvariant.h>
#include <QWaitCondition>
// QtGui
@ -98,6 +101,9 @@
#include <QMainWindow>
#include <qmenubar.h>
#include <qmessagebox.h>
#if QT_VERSION >= 0x050000
#include <QMessageLogContext>
#endif
#include <QMimeData>
#include <qmovie.h>
#include <qpainter.h>

View File

@ -54,6 +54,10 @@
#include <assert.h>
#include <Quarter/QuarterWidget.h>
#include <Quarter/eventhandlers/EventFilter.h>
#include <Quarter/eventhandlers/DragDropHandler.h>
#include <QtCore/QEvent>
#include <QtCore/QDebug>
#include <QtCore/QFile>
@ -79,10 +83,6 @@
#include <Inventor/scxml/ScXML.h>
#include <Inventor/scxml/SoScXMLStateMachine.h>
#include <Quarter/QuarterWidget.h>
#include <Quarter/eventhandlers/EventFilter.h>
#include <Quarter/eventhandlers/DragDropHandler.h>
#include <ctime>
#include "InteractionMode.h"

View File

@ -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)

View File

@ -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

View File

@ -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();
}

View File

@ -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();

View File

@ -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);
}

View File

@ -28,7 +28,7 @@
#include <Gui/MDIView.h>
#include <Gui/Window.h>
# if QT_VERSION >= 0x040400
#if QT_VERSION >= 0x040400
#include <QWebView>
#endif