From 3a04f59cb0824253dba047b02592f6cc311f9d4a Mon Sep 17 00:00:00 2001 From: BigBahss Date: Sun, 13 Dec 2020 04:00:00 -0500 Subject: [PATCH] Fix QProcess::splitCommand() dependency on Qt 5.15. Fix shortcut for Open Map Scripts (Due to merge). --- include/core/parseutil.h | 2 ++ porymap.pro | 2 +- src/core/parseutil.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ src/editor.cpp | 2 +- src/mainwindow.cpp | 8 +++---- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/include/core/parseutil.h b/include/core/parseutil.h index b65dbf76..bd614686 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -63,6 +63,8 @@ public: static QString &removeLineComments(QString &text, const QString &commentSymbol); static QString &removeLineComments(QString &text, const QStringList &commentSymbols); + static QStringList splitShellCommand(QStringView command); + private: QString root; QString text; diff --git a/porymap.pro b/porymap.pro index 56331b25..a741f69a 100644 --- a/porymap.pro +++ b/porymap.pro @@ -165,7 +165,7 @@ FORMS += forms/mainwindow.ui \ forms/aboutporymap.ui \ forms/newtilesetdialog.ui \ forms/mapimageexporter.ui \ - forms/shortcutseditor.ui + forms/shortcutseditor.ui \ forms/preferenceeditor.ui RESOURCES += \ diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index 3b72a9b6..84f924f2 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -487,3 +487,51 @@ QString &ParseUtil::removeLineComments(QString &text, const QStringList &comment removeLineComments(text, commentSymbol); return text; } + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) +#include + +QStringList ParseUtil::splitShellCommand(QStringView command) { + return QProcess::splitCommand(command); +} +#else +// The source for QProcess::splitCommand() as of Qt 5.15.2 +QStringList ParseUtil::splitShellCommand(QStringView command) { + QStringList args; + QString tmp; + int quoteCount = 0; + bool inQuote = false; + + // handle quoting. tokens can be surrounded by double quotes + // "hello world". three consecutive double quotes represent + // the quote character itself. + for (int i = 0; i < command.size(); ++i) { + if (command.at(i) == QLatin1Char('"')) { + ++quoteCount; + if (quoteCount == 3) { + // third consecutive quote + quoteCount = 0; + tmp += command.at(i); + } + continue; + } + if (quoteCount) { + if (quoteCount == 1) + inQuote = !inQuote; + quoteCount = 0; + } + if (!inQuote && command.at(i).isSpace()) { + if (!tmp.isEmpty()) { + args += tmp; + tmp.clear(); + } + } else { + tmp += command.at(i); + } + } + if (!tmp.isEmpty()) + args += tmp; + + return args; +} +#endif diff --git a/src/editor.cpp b/src/editor.cpp index 66c73944..98d3ba19 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -2084,7 +2084,7 @@ bool Editor::startDetachedProcess(const QString &command, const QString &working process.setNativeArguments("/c " + command); process.setWorkingDirectory(workingDirectory); #else - QStringList arguments = QProcess::splitCommand(command); + QStringList arguments = ParseUtil::splitShellCommand(command); process.setProgram(arguments.takeFirst()); process.setArguments(arguments); process.setWorkingDirectory(workingDirectory); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7882b4f3..4c3cb660 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -144,9 +144,9 @@ void MainWindow::initExtraShortcuts() { shortcutCollapse_All->setObjectName("shortcutCollapse_All"); shortcutCollapse_All->setWhatsThis("Map List: Collapse all folders"); - auto *shortcutNew_Event = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_Open_Scripts_clicked())); - shortcutNew_Event->setObjectName("shortcut_Open_Scripts"); - shortcutNew_Event->setWhatsThis("Open Map Scripts"); + auto *shortcut_Open_Scripts = new Shortcut(QKeySequence(), ui->toolButton_Open_Scripts, SLOT(click())); + shortcut_Open_Scripts->setObjectName("shortcut_Open_Scripts"); + shortcut_Open_Scripts->setWhatsThis("Open Map Scripts"); } QObjectList MainWindow::shortcutableObjects() const { @@ -231,7 +231,7 @@ void MainWindow::initEditor() { connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged())); connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged())); connect(this->editor, &Editor::mapRulerStatusChanged, this, &MainWindow::onMapRulerStatusChanged); - connect(ui->toolButton_Open_Scripts, &QToolButton::pressed, this->editor, QOverload<>::of(&Editor::openMapScripts)); + connect(ui->toolButton_Open_Scripts, &QToolButton::pressed, this->editor, &Editor::openMapScripts); connect(ui->actionOpen_Project_in_Text_Editor, &QAction::triggered, this->editor, &Editor::openProjectInTextEditor); this->loadUserSettings();