Skip to content

Commit 8f4d3ba

Browse files
authored
Merge pull request #8041 from 3nids/user_doc_auto_screenshots
Automatic creation of screenshots for user documentation
2 parents 618ed2e + 77bfec6 commit 8f4d3ba

15 files changed

+544
-8
lines changed

python/gui/auto_generated/qgisinterface.sip.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,15 @@ used for interacting and adding widgets and messages to the app's
598598
status bar (do not use the native Qt statusBar() method).
599599

600600
.. versionadded:: 3.0
601+
%End
602+
603+
virtual void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 );
604+
%Docstring
605+
Take screenshots for user documentation
606+
@param saveDirectory path where the screenshots will be saved
607+
@param categories an int as a flag value of QgsAppScreenShots.Categories
608+
609+
.. versionadded:: 3.4
601610
%End
602611

603612
public slots: // TODO: do these functions really need to be slots?

src/app/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SET(QGIS_APP_SRCS
1313
qgsappwindowmanager.cpp
1414
qgsaddattrdialog.cpp
1515
qgsaddtaborgroup.cpp
16+
qgsappscreenshots.cpp
1617
qgsjoindialog.cpp
1718
qgsannotationwidget.cpp
1819
qgsattributeactiondialog.cpp
@@ -236,6 +237,7 @@ SET (QGIS_APP_MOC_HDRS
236237
qgsaddattrdialog.h
237238
qgsalignrasterdialog.h
238239
qgsappbrowserproviders.h
240+
qgsappscreenshots.h
239241
qgsjoindialog.h
240242
qgsaddtaborgroup.h
241243
qgsannotationwidget.h
@@ -541,6 +543,10 @@ IF (PROJ_HAS_INFO)
541543
ADD_DEFINITIONS(-DPROJ_HAS_INFO)
542544
ENDIF (PROJ_HAS_INFO)
543545

546+
# Test data dir for QgsAppScreenShots
547+
ADD_DEFINITIONS(-DTEST_DATA_DIR="${TEST_DATA_DIR}")
548+
549+
544550
SET(IMAGE_RCCS ../../images/images.qrc)
545551

546552
QT5_ADD_RESOURCES(IMAGE_RCC_SRCS ${IMAGE_RCCS})

src/app/main.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ void usage( const QString &appName )
142142
<< QStringLiteral( "\t[--dxf-scale-denom scale]\tscale for dxf output\n" )
143143
<< QStringLiteral( "\t[--dxf-encoding encoding]\tencoding to use for dxf output\n" )
144144
<< QStringLiteral( "\t[--dxf-map-theme maptheme]\tmap theme to use for dxf output\n" )
145+
<< QStringLiteral( "\t[--take-screenshots output_path]\ttake screen shots for the user documentation\n" )
146+
<< QStringLiteral( "\t[--screenshots-categories categories]\tspecify the categories of screenshot to be used (see QgsAppScreenShots::Categories).\n" )
145147
<< QStringLiteral( "\t[--profile name]\tload a named profile from the users profiles folder.\n" )
146148
<< QStringLiteral( "\t[--profiles-path path]\tpath to store user profile folders. Will create profiles inside a {path}\\profiles folder \n" )
147149
<< QStringLiteral( "\t[--version-migration]\tforce the settings migration from older version if found\n" )
@@ -529,6 +531,10 @@ int main( int argc, char *argv[] )
529531
QString dxfMapTheme;
530532
QgsRectangle dxfExtent;
531533

534+
bool takeScreenShots = false;
535+
QString screenShotsPath;
536+
int screenShotsCategories = 0;
537+
532538
// This behavior will set initial extent of map canvas, but only if
533539
// there are no command line arguments. This gives a usable map
534540
// extent when qgis starts with no layers loaded. When layers are
@@ -745,6 +751,15 @@ int main( int argc, char *argv[] )
745751
{
746752
dxfMapTheme = args[++i];
747753
}
754+
else if ( arg == QLatin1String( "--take-screenshots" ) )
755+
{
756+
takeScreenShots = true;
757+
screenShotsPath = args[++i];
758+
}
759+
else if ( arg == QLatin1String( "--screenshots-categories" ) )
760+
{
761+
screenShotsCategories = args[++i].toInt();
762+
}
748763
#ifdef HAVE_OPENCL
749764
else if ( arg == QLatin1String( "--openclprogramfolder" ) )
750765
{
@@ -1233,7 +1248,7 @@ int main( int argc, char *argv[] )
12331248
int h = 300 * qApp->desktop()->logicalDpiY() / 96;
12341249

12351250
QSplashScreen *mypSplash = new QSplashScreen( myPixmap.scaled( w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
1236-
if ( !myHideSplash && !settings.value( QStringLiteral( "qgis/hideSplash" ) ).toBool() )
1251+
if ( !takeScreenShots && !myHideSplash && !settings.value( QStringLiteral( "qgis/hideSplash" ) ).toBool() )
12371252
{
12381253
//for win and linux we can just automask and png transparency areas will be used
12391254
mypSplash->setMask( myPixmap.mask() );
@@ -1457,6 +1472,11 @@ int main( int argc, char *argv[] )
14571472

14581473
#endif
14591474

1475+
if ( takeScreenShots )
1476+
{
1477+
qgis->takeAppScreenShots( screenShotsPath, screenShotsCategories );
1478+
}
1479+
14601480
/////////////////////////////////////////////////////////////////////
14611481
// Continue on to interactive gui...
14621482
/////////////////////////////////////////////////////////////////////

src/app/qgisapp.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
149149
#include "qgsauthcertutils.h"
150150
#include "qgsauthsslerrorsdialog.h"
151151
#endif
152+
#include "qgsappscreenshots.h"
152153
#include "qgsbookmarks.h"
153154
#include "qgsbrowserdockwidget.h"
154155
#include "qgsadvanceddigitizingdockwidget.h"
@@ -10281,19 +10282,25 @@ QMap< QString, QString > QgisApp::optionsPagesMap()
1028110282
return mOptionsPagesMap;
1028210283
}
1028310284

10284-
void QgisApp::showOptionsDialog( QWidget *parent, const QString &currentPage )
10285+
QgsOptions *QgisApp::createOptionsDialog( QWidget *parent )
1028510286
{
10286-
QgsSettings mySettings;
10287-
QString oldScales = mySettings.value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString();
10288-
1028910287
QList< QgsOptionsWidgetFactory * > factories;
1029010288
Q_FOREACH ( const QPointer< QgsOptionsWidgetFactory > &f, mOptionsWidgetFactories )
1029110289
{
1029210290
// remove any deleted factories
1029310291
if ( f )
1029410292
factories << f;
1029510293
}
10296-
std::unique_ptr< QgsOptions > optionsDialog( new QgsOptions( parent, QgsGuiUtils::ModalDialogFlags, factories ) );
10294+
return new QgsOptions( parent, QgsGuiUtils::ModalDialogFlags, factories );
10295+
}
10296+
10297+
void QgisApp::showOptionsDialog( QWidget *parent, const QString &currentPage )
10298+
{
10299+
std::unique_ptr< QgsOptions > optionsDialog( createOptionsDialog( parent ) );
10300+
10301+
QgsSettings mySettings;
10302+
QString oldScales = mySettings.value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString();
10303+
1029710304
if ( !currentPage.isEmpty() )
1029810305
{
1029910306
optionsDialog->setCurrentPage( currentPage );
@@ -13062,6 +13069,12 @@ void QgisApp::zoomToBookmarkIndex( const QModelIndex &index )
1306213069
mBookMarksDockWidget->zoomToBookmarkIndex( index );
1306313070
}
1306413071

13072+
void QgisApp::takeAppScreenShots( const QString &saveDirectory, const int categories )
13073+
{
13074+
QgsAppScreenShots ass( saveDirectory );
13075+
ass.takePicturesOf( QgsAppScreenShots::Categories( categories ) );
13076+
}
13077+
1306513078
// Slot that gets called when the project file was saved with an older
1306613079
// version of QGIS
1306713080

src/app/qgisapp.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class QgsMapToolDigitizeFeature;
7676
class QgsMapToolAdvancedDigitizing;
7777
class QgsMapToolIdentifyAction;
7878
class QgsMapToolSelect;
79+
class QgsOptions;
7980
class QgsPluginLayer;
8081
class QgsPluginLayer;
8182
class QgsPluginManager;
@@ -696,6 +697,13 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
696697
//! Returns pointer to the identify map tool - used by identify tool in 3D view
697698
QgsMapToolIdentifyAction *identifyMapTool() const { return mMapTools.mIdentify; }
698699

700+
/**
701+
* Take screenshots for user documentation
702+
* @param saveDirectory path were the screenshots will be saved
703+
* @param categories an int as a flag value of QgsAppScreenShots::Categories
704+
*/
705+
void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 );
706+
699707
public slots:
700708
//! save current vector layer
701709
void saveAsFile( QgsMapLayer *layer = nullptr, bool onlySelected = false );
@@ -1955,6 +1963,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
19551963
//! Populates project "load from" / "save to" menu based on project storages (when the menu is about to be shown)
19561964
void populateProjectStorageMenu( QMenu *menu, bool saving );
19571965

1966+
//! Create the option dialog
1967+
QgsOptions *createOptionsDialog( QWidget *parent = nullptr );
1968+
19581969
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
19591970

19601971
// actions for menus and toolbars -----------------
@@ -2127,7 +2138,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
21272138

21282139
//! interface to QgisApp for plugins
21292140
QgisAppInterface *mQgisInterface = nullptr;
2130-
friend class QgisAppInterface;
21312141

21322142
QSplashScreen *mSplash = nullptr;
21332143
//! list of recently opened/saved project files
@@ -2294,6 +2304,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
22942304
bool mBlockActiveLayerChanged = false;
22952305

22962306
friend class TestQgisAppPython;
2307+
friend class QgisAppInterface;
2308+
friend class QgsAppScreenShots;
22972309
};
22982310

22992311
#ifdef ANDROID

src/app/qgisappinterface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,8 @@ bool QgisAppInterface::askForDatumTransform( QgsCoordinateReferenceSystem source
789789
{
790790
return qgis->askUserForDatumTransform( sourceCrs, destinationCrs );
791791
}
792+
793+
void QgisAppInterface::takeAppScreenShots( const QString &saveDirectory, const int categories )
794+
{
795+
return qgis->takeAppScreenShots( saveDirectory, categories );
796+
}

src/app/qgisappinterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
551551

552552
bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs ) override;
553553

554+
void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 ) override;
555+
554556

555557
private slots:
556558

0 commit comments

Comments
 (0)