Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Port QProcess::splitCommand for older qt
  • Loading branch information
nyalldawson committed Dec 7, 2021
1 parent 4dc3a5e commit 9d29eb3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/crashhandler/qgscrashdialog.cpp
Expand Up @@ -65,6 +65,59 @@ void QgsCrashDialog::on_mUserFeedbackText_textChanged()
mCopyReportButton->setEnabled( !mUserFeedbackText->toPlainText().isEmpty() );
}

QStringList QgsCrashDialog::splitCommand( const QString &command )
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
return QProcess::splitCommand( command );
#else
// taken from Qt 5.15's implementation
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
}

void QgsCrashDialog::createBugReport()
{
QClipboard *clipboard = QApplication::clipboard();
Expand All @@ -77,7 +130,7 @@ void QgsCrashDialog::createBugReport()

void QgsCrashDialog::reloadQGIS()
{
const QStringList command = QProcess::splitCommand( mReloadArgs );
const QStringList command = splitCommand( mReloadArgs );
if ( command.isEmpty() )
return;

Expand Down
2 changes: 2 additions & 0 deletions src/crashhandler/qgscrashdialog.h
Expand Up @@ -47,6 +47,8 @@ class QgsCrashDialog : public QDialog, private Ui::QgsCrashDialog
void on_mUserFeedbackText_textChanged();

private:
static QStringList splitCommand( const QString &command );

QString mReportData;
QString mReloadArgs;
};
Expand Down

0 comments on commit 9d29eb3

Please sign in to comment.