Skip to content

Commit

Permalink
support platforms that does not have QProcess support (iOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Nov 13, 2018
1 parent bfdb3ec commit 1559013
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
6 changes: 5 additions & 1 deletion python/core/auto_generated/qgsmaprenderertask.sip.in
Expand Up @@ -26,8 +26,12 @@ task. This can be used to draw maps without blocking the QGIS interface.

enum ErrorType
{
//! Image allocation failure
ImageAllocationFail,
ImageSaveFail
//! Image save failure
ImageSaveFail,

ImageUnsupportedFormat
};

QgsMapRendererTask( const QgsMapSettings &ms,
Expand Down
10 changes: 6 additions & 4 deletions python/core/auto_generated/qgsrunprocess.sip.in
Expand Up @@ -17,6 +17,9 @@ class QgsRunProcess: QObject /NoDefaultCtors/
A class that executes an external program/script.
It can optionally capture the standard output and error from the
process and displays them in a dialog box.

On some platforms (e.g. iOS) , the process execution is skipped
https://lists.qt-project.org/pipermail/development/2015-July/022205.html
%End

%TypeHeaderCode
Expand All @@ -26,16 +29,15 @@ process and displays them in a dialog box.

static QgsRunProcess *create( const QString &action, bool capture ) /Factory/;

private:
QgsRunProcess( const QString &action, bool capture );
~QgsRunProcess();
public slots:
void stdoutAvailable();
void stderrAvailable();
void processError( QProcess::ProcessError );
void processExit( int, QProcess::ExitStatus );
void dialogGone();

private:
QgsRunProcess( const QString &action, bool capture );
~QgsRunProcess();
};

/************************************************************************
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsapplication.cpp
Expand Up @@ -61,6 +61,7 @@
#include <QMessageBox>
#include <QPalette>
#include <QProcess>
#include <QProcessEnvironment>
#include <QIcon>
#include <QPixmap>
#include <QThreadPool>
Expand Down Expand Up @@ -270,7 +271,9 @@ void QgsApplication::init( QString profileFolder )
// store system environment variables passed to application, before they are adjusted
QMap<QString, QString> systemEnvVarMap;
QString passfile( QStringLiteral( "QGIS_AUTH_PASSWORD_FILE" ) ); // QString, for comparison
Q_FOREACH ( const QString &varStr, QProcess::systemEnvironment() )

const auto systemEnvironment = QProcessEnvironment::systemEnvironment().toStringList();
for ( const QString &varStr : systemEnvironment )
{
int pos = varStr.indexOf( QLatin1Char( '=' ) );
if ( pos == -1 )
Expand Down Expand Up @@ -947,7 +950,7 @@ QString QgsApplication::userLoginName()
sUserName = QString( name );
}

#else
#elseif QT_CONFIG(process)
QProcess process;

process.start( QStringLiteral( "whoami" ) );
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsrunprocess.cpp
Expand Up @@ -26,6 +26,7 @@
#include <QTextCodec>
#include <QMessageBox>

#if QT_CONFIG(process)
QgsRunProcess::QgsRunProcess( const QString &action, bool capture )

{
Expand Down Expand Up @@ -162,3 +163,13 @@ void QgsRunProcess::processError( QProcess::ProcessError err )
QgsDebugMsg( "Got error: " + QString( "%d" ).arg( err ) );
}
}
#else
QgsRunProcess::QgsRunProcess( const QString &action, bool )
{
QgsDebugMsg( "Skipping command: " + action );
}

QgsRunProcess::~QgsRunProcess()
{
}
#endif
20 changes: 12 additions & 8 deletions src/core/qgsrunprocess.h
Expand Up @@ -28,12 +28,14 @@
#include "qgis_sip.h"

class QgsMessageOutput;

/**
* \ingroup core
* A class that executes an external program/script.
* It can optionally capture the standard output and error from the
* process and displays them in a dialog box.
*
* On some platforms (e.g. iOS) , the process execution is skipped
* https://lists.qt-project.org/pipermail/development/2015-July/022205.html
*/
class CORE_EXPORT QgsRunProcess: public QObject SIP_NODEFAULTCTORS
{
Expand All @@ -50,23 +52,25 @@ class CORE_EXPORT QgsRunProcess: public QObject SIP_NODEFAULTCTORS
static QgsRunProcess *create( const QString &action, bool capture ) SIP_FACTORY
{ return new QgsRunProcess( action, capture ); }

public slots:
void stdoutAvailable();
void stderrAvailable();
void processError( QProcess::ProcessError );
void processExit( int, QProcess::ExitStatus );
void dialogGone();

private:
QgsRunProcess( const QString &action, bool capture ) SIP_FORCE;
~QgsRunProcess() override SIP_FORCE;

#if QT_CONFIG(process)
// Deletes the instance of the class
void die();

QProcess *mProcess = nullptr;
QgsMessageOutput *mOutput = nullptr;
QString mCommand;

public slots:
void stdoutAvailable();
void stderrAvailable();
void processError( QProcess::ProcessError );
void processExit( int, QProcess::ExitStatus );
void dialogGone();
#endif // !(QT_CONFIG(process)
};

#endif
6 changes: 5 additions & 1 deletion src/core/qgsuserprofilemanager.cpp
Expand Up @@ -196,17 +196,21 @@ QgsUserProfile *QgsUserProfileManager::userProfile()

void QgsUserProfileManager::loadUserProfile( const QString &name )
{
#if QT_CONFIG(process)
QString path = QDir::toNativeSeparators( QCoreApplication::applicationFilePath() );
QStringList arguments;
arguments << QCoreApplication::arguments();
// The first is the path to the application
// on Windows this might not be case so we need to handle that
// http://doc.qt.io/qt-5/qcoreapplication.html#arguments
arguments.removeFirst();

arguments << QStringLiteral( "--profile" ) << name;
QgsDebugMsg( QStringLiteral( "Starting instance from %1 with %2" ).arg( path ).arg( arguments.join( " " ) ) );
QProcess::startDetached( path, arguments, QDir::toNativeSeparators( QCoreApplication::applicationDirPath() ) );
#else
Q_UNUSED( name )
Q_ASSERT( "Starting the user profile is not supported on the platform" );
#endif //QT_CONFIG(process)
}

void QgsUserProfileManager::setActiveUserProfile( const QString &profile )
Expand Down

0 comments on commit 1559013

Please sign in to comment.