diff --git a/src/app/main.cpp b/src/app/main.cpp index afaaa23eedf8..8a0656a9b9b9 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -142,6 +142,7 @@ void usage( const QString &appName ) << QStringLiteral( "\t[-n, --nologo]\thide splash screen\n" ) << QStringLiteral( "\t[-V, --noversioncheck]\tdon't check for new version of QGIS at startup\n" ) << QStringLiteral( "\t[-P, --noplugins]\tdon't restore plugins on startup\n" ) + << QStringLiteral( "\t[--nopython]\tdisable Python support\n" ) << QStringLiteral( "\t[-B, --skipbadlayers]\tdon't prompt for missing layers\n" ) << QStringLiteral( "\t[-C, --nocustomization]\tdon't apply GUI customization\n" ) << QStringLiteral( "\t[-z, --customizationfile path]\tuse the given ini file as GUI customization\n" ) @@ -570,7 +571,6 @@ int main( int argc, char *argv[] ) bool myHideSplash = false; bool settingsMigrationForce = false; - bool mySkipVersionCheck = false; bool hideBrowser = false; #if defined( ANDROID ) QgsDebugMsgLevel( QStringLiteral( "Android: Splash hidden" ), 2 ); @@ -578,8 +578,6 @@ int main( int argc, char *argv[] ) #endif bool myRestoreDefaultWindowState = false; - bool myRestorePlugins = true; - bool mySkipBadLayers = false; bool myCustomization = true; QString dxfOutputFile; @@ -628,6 +626,7 @@ int main( int argc, char *argv[] ) #endif QStringList args; + QgisApp::AppOptions qgisAppOptions = QgisApp::RestorePlugins | QgisApp::EnablePython; { QCoreApplication coreApp( argc, argv ); @@ -663,16 +662,20 @@ int main( int argc, char *argv[] ) } else if ( arg == QLatin1String( "--noversioncheck" ) || arg == QLatin1String( "-V" ) ) { - mySkipVersionCheck = true; + qgisAppOptions |= QgisApp::SkipVersionCheck; } else if ( arg == QLatin1String( "--noplugins" ) || arg == QLatin1String( "-P" ) ) { - myRestorePlugins = false; + qgisAppOptions &= ~QgisApp::RestorePlugins; + } + else if ( arg == QLatin1String( "--nopython" ) ) + { + qgisAppOptions &= ~QgisApp::EnablePython; } else if ( arg == QLatin1String( "--skipbadlayers" ) || arg == QLatin1String( "-B" ) ) { QgsDebugMsgLevel( QStringLiteral( "Skipping bad layers" ), 2 ); - mySkipBadLayers = true; + qgisAppOptions |= QgisApp::SkipBadLayers; } else if ( arg == QLatin1String( "--nocustomization" ) || arg == QLatin1String( "-C" ) ) { @@ -1540,7 +1543,7 @@ int main( int argc, char *argv[] ) // this should be done in QgsApplication::init() but it doesn't know the settings dir. QgsApplication::setMaxThreads( settings.value( QStringLiteral( "qgis/max_threads" ), -1 ).toInt() ); - QgisApp *qgis = new QgisApp( mypSplash, myRestorePlugins, mySkipBadLayers, mySkipVersionCheck, rootProfileFolder, profileName ); // "QgisApp" used to find canonical instance + QgisApp *qgis = new QgisApp( mypSplash, qgisAppOptions, rootProfileFolder, profileName ); // "QgisApp" used to find canonical instance qgis->setObjectName( QStringLiteral( "QgisApp" ) ); QgsApplication::connect( diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index e1cb02dcce70..75dab49083b4 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -971,7 +971,7 @@ static bool cmpByText_( QAction *a, QAction *b ) QgisApp *QgisApp::sInstance = nullptr; // constructor starts here -QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers, bool skipVersionCheck, const QString &rootProfileLocation, const QString &activeProfile, QWidget *parent, Qt::WindowFlags fl ) +QgisApp::QgisApp( QSplashScreen *splash, AppOptions options, const QString &rootProfileLocation, const QString &activeProfile, QWidget *parent, Qt::WindowFlags fl ) : QMainWindow( parent, fl ) , mSplash( splash ) { @@ -1108,7 +1108,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers endProfile(); startProfile( tr( "Welcome page" ) ); - mWelcomePage = new QgsWelcomePage( skipVersionCheck ); + mWelcomePage = new QgsWelcomePage( options.testFlag( SkipVersionCheck ) ); connect( mWelcomePage, &QgsWelcomePage::projectRemoved, this, [this]( int row ) { mRecentProjects.removeAt( row ); saveRecentProjects(); @@ -1318,7 +1318,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers // initialize the plugin manager startProfile( tr( "Plugin manager" ) ); - mPluginManager = new QgsPluginManager( this, restorePlugins ); + mPluginManager = new QgsPluginManager( this, options.testFlag( RestorePlugins ) ); endProfile(); addDockWidget( Qt::LeftDockWidgetArea, mUndoDock ); @@ -1626,21 +1626,24 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers QgsApplication::dataItemProviderRegistry()->addProvider( new QgsHtmlDataItemProvider() ); // set handler for missing layers (will be owned by QgsProject) - if ( !skipBadLayers ) + if ( !options.testFlag( SkipBadLayers ) ) { QgsDebugMsgLevel( QStringLiteral( "Creating bad layers handler" ), 2 ); mAppBadLayersHandler = new QgsHandleBadLayersHandler(); QgsProject::instance()->setBadLayerHandler( mAppBadLayersHandler ); } - mSplash->showMessage( tr( "Starting Python" ), Qt::AlignHCenter | Qt::AlignBottom, splashTextColor ); - qApp->processEvents(); - loadPythonSupport(); + if ( options.testFlag( EnablePython ) ) + { + mSplash->showMessage( tr( "Starting Python" ), Qt::AlignHCenter | Qt::AlignBottom, splashTextColor ); + qApp->processEvents(); + loadPythonSupport(); #ifdef WITH_BINDINGS - QgsApplication::dataItemProviderRegistry()->addProvider( new QgsPyDataItemProvider() ); - registerCustomDropHandler( new QgsPyDropHandler() ); + QgsApplication::dataItemProviderRegistry()->addProvider( new QgsPyDataItemProvider() ); + registerCustomDropHandler( new QgsPyDropHandler() ); #endif + } QgsApplication::dataItemProviderRegistry()->addProvider( new QgsProjectDataItemProvider() ); QgsApplication::dataItemProviderRegistry()->addProvider( new QgsStacDataItemProvider() ); @@ -1666,7 +1669,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers qApp->processEvents(); QgsPluginRegistry::instance()->setQgisInterface( mQgisInterface ); - if ( restorePlugins ) + if ( options.testFlag( RestorePlugins ) ) { // Restoring of plugins can be disabled with --noplugins command line option // because some plugins may cause QGIS to crash during startup diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index 39dc52ce8942..62884811417b 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -211,8 +211,26 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow { Q_OBJECT public: + /** + * Options to configure the QGIS application behavior at startup. + * + * This enumeration defines flags that control various aspects of QGIS + * initialization. + * + * \since QGIS 3.44 + */ + enum AppOption + { + NoOption = 0x00, //! No Option + RestorePlugins = 0x01, //! Automatically restore and load previously enabled plugins. + SkipBadLayers = 0x02, //! Skip loading layers that are detected as problematic. + SkipVersionCheck = 0x04, //! Bypass the version compatibility check during startup. + EnablePython = 0x08 //! Enable the Python interface for scripting and plugins. + }; + Q_DECLARE_FLAGS( AppOptions, AppOption ) + //! Constructor - QgisApp( QSplashScreen *splash, bool restorePlugins = true, bool skipBadLayers = false, bool skipVersionCheck = false, const QString &rootProfileLocation = QString(), const QString &activeProfile = QString(), QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Window ); + QgisApp( QSplashScreen *splash, AppOptions options = AppOptions( RestorePlugins | EnablePython ), const QString &rootProfileLocation = QString(), const QString &activeProfile = QString(), QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Window ); //! Constructor for unit tests QgisApp(); @@ -2782,6 +2800,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow friend class QgsAppScreenShots; }; +Q_DECLARE_OPERATORS_FOR_FLAGS( QgisApp::AppOptions ) + #ifdef ANDROID #define QGIS_ICON_SIZE 32 #else