Skip to content

Commit

Permalink
Merge pull request #8041 from 3nids/user_doc_auto_screenshots
Browse files Browse the repository at this point in the history
Automatic creation of screenshots for user documentation
  • Loading branch information
3nids committed Oct 5, 2018
2 parents 618ed2e + 77bfec6 commit 8f4d3ba
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 8 deletions.
9 changes: 9 additions & 0 deletions python/gui/auto_generated/qgisinterface.sip.in
Expand Up @@ -598,6 +598,15 @@ used for interacting and adding widgets and messages to the app's
status bar (do not use the native Qt statusBar() method).

.. versionadded:: 3.0
%End

virtual void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 );
%Docstring
Take screenshots for user documentation
@param saveDirectory path where the screenshots will be saved
@param categories an int as a flag value of QgsAppScreenShots.Categories

.. versionadded:: 3.4
%End

public slots: // TODO: do these functions really need to be slots?
Expand Down
6 changes: 6 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@ SET(QGIS_APP_SRCS
qgsappwindowmanager.cpp
qgsaddattrdialog.cpp
qgsaddtaborgroup.cpp
qgsappscreenshots.cpp
qgsjoindialog.cpp
qgsannotationwidget.cpp
qgsattributeactiondialog.cpp
Expand Down Expand Up @@ -236,6 +237,7 @@ SET (QGIS_APP_MOC_HDRS
qgsaddattrdialog.h
qgsalignrasterdialog.h
qgsappbrowserproviders.h
qgsappscreenshots.h
qgsjoindialog.h
qgsaddtaborgroup.h
qgsannotationwidget.h
Expand Down Expand Up @@ -541,6 +543,10 @@ IF (PROJ_HAS_INFO)
ADD_DEFINITIONS(-DPROJ_HAS_INFO)
ENDIF (PROJ_HAS_INFO)

# Test data dir for QgsAppScreenShots
ADD_DEFINITIONS(-DTEST_DATA_DIR="${TEST_DATA_DIR}")


SET(IMAGE_RCCS ../../images/images.qrc)

QT5_ADD_RESOURCES(IMAGE_RCC_SRCS ${IMAGE_RCCS})
Expand Down
22 changes: 21 additions & 1 deletion src/app/main.cpp
Expand Up @@ -142,6 +142,8 @@ void usage( const QString &appName )
<< QStringLiteral( "\t[--dxf-scale-denom scale]\tscale for dxf output\n" )
<< QStringLiteral( "\t[--dxf-encoding encoding]\tencoding to use for dxf output\n" )
<< QStringLiteral( "\t[--dxf-map-theme maptheme]\tmap theme to use for dxf output\n" )
<< QStringLiteral( "\t[--take-screenshots output_path]\ttake screen shots for the user documentation\n" )
<< QStringLiteral( "\t[--screenshots-categories categories]\tspecify the categories of screenshot to be used (see QgsAppScreenShots::Categories).\n" )
<< QStringLiteral( "\t[--profile name]\tload a named profile from the users profiles folder.\n" )
<< QStringLiteral( "\t[--profiles-path path]\tpath to store user profile folders. Will create profiles inside a {path}\\profiles folder \n" )
<< QStringLiteral( "\t[--version-migration]\tforce the settings migration from older version if found\n" )
Expand Down Expand Up @@ -529,6 +531,10 @@ int main( int argc, char *argv[] )
QString dxfMapTheme;
QgsRectangle dxfExtent;

bool takeScreenShots = false;
QString screenShotsPath;
int screenShotsCategories = 0;

// This behavior will set initial extent of map canvas, but only if
// there are no command line arguments. This gives a usable map
// extent when qgis starts with no layers loaded. When layers are
Expand Down Expand Up @@ -745,6 +751,15 @@ int main( int argc, char *argv[] )
{
dxfMapTheme = args[++i];
}
else if ( arg == QLatin1String( "--take-screenshots" ) )
{
takeScreenShots = true;
screenShotsPath = args[++i];
}
else if ( arg == QLatin1String( "--screenshots-categories" ) )
{
screenShotsCategories = args[++i].toInt();
}
#ifdef HAVE_OPENCL
else if ( arg == QLatin1String( "--openclprogramfolder" ) )
{
Expand Down Expand Up @@ -1233,7 +1248,7 @@ int main( int argc, char *argv[] )
int h = 300 * qApp->desktop()->logicalDpiY() / 96;

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

#endif

if ( takeScreenShots )
{
qgis->takeAppScreenShots( screenShotsPath, screenShotsCategories );
}

/////////////////////////////////////////////////////////////////////
// Continue on to interactive gui...
/////////////////////////////////////////////////////////////////////
Expand Down
23 changes: 18 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -149,6 +149,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsauthcertutils.h"
#include "qgsauthsslerrorsdialog.h"
#endif
#include "qgsappscreenshots.h"
#include "qgsbookmarks.h"
#include "qgsbrowserdockwidget.h"
#include "qgsadvanceddigitizingdockwidget.h"
Expand Down Expand Up @@ -10281,19 +10282,25 @@ QMap< QString, QString > QgisApp::optionsPagesMap()
return mOptionsPagesMap;
}

void QgisApp::showOptionsDialog( QWidget *parent, const QString &currentPage )
QgsOptions *QgisApp::createOptionsDialog( QWidget *parent )
{
QgsSettings mySettings;
QString oldScales = mySettings.value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString();

QList< QgsOptionsWidgetFactory * > factories;
Q_FOREACH ( const QPointer< QgsOptionsWidgetFactory > &f, mOptionsWidgetFactories )
{
// remove any deleted factories
if ( f )
factories << f;
}
std::unique_ptr< QgsOptions > optionsDialog( new QgsOptions( parent, QgsGuiUtils::ModalDialogFlags, factories ) );
return new QgsOptions( parent, QgsGuiUtils::ModalDialogFlags, factories );
}

void QgisApp::showOptionsDialog( QWidget *parent, const QString &currentPage )
{
std::unique_ptr< QgsOptions > optionsDialog( createOptionsDialog( parent ) );

QgsSettings mySettings;
QString oldScales = mySettings.value( QStringLiteral( "Map/scales" ), PROJECT_SCALES ).toString();

if ( !currentPage.isEmpty() )
{
optionsDialog->setCurrentPage( currentPage );
Expand Down Expand Up @@ -13062,6 +13069,12 @@ void QgisApp::zoomToBookmarkIndex( const QModelIndex &index )
mBookMarksDockWidget->zoomToBookmarkIndex( index );
}

void QgisApp::takeAppScreenShots( const QString &saveDirectory, const int categories )
{
QgsAppScreenShots ass( saveDirectory );
ass.takePicturesOf( QgsAppScreenShots::Categories( categories ) );
}

// Slot that gets called when the project file was saved with an older
// version of QGIS

Expand Down
14 changes: 13 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -76,6 +76,7 @@ class QgsMapToolDigitizeFeature;
class QgsMapToolAdvancedDigitizing;
class QgsMapToolIdentifyAction;
class QgsMapToolSelect;
class QgsOptions;
class QgsPluginLayer;
class QgsPluginLayer;
class QgsPluginManager;
Expand Down Expand Up @@ -696,6 +697,13 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Returns pointer to the identify map tool - used by identify tool in 3D view
QgsMapToolIdentifyAction *identifyMapTool() const { return mMapTools.mIdentify; }

/**
* Take screenshots for user documentation
* @param saveDirectory path were the screenshots will be saved
* @param categories an int as a flag value of QgsAppScreenShots::Categories
*/
void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 );

public slots:
//! save current vector layer
void saveAsFile( QgsMapLayer *layer = nullptr, bool onlySelected = false );
Expand Down Expand Up @@ -1955,6 +1963,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Populates project "load from" / "save to" menu based on project storages (when the menu is about to be shown)
void populateProjectStorageMenu( QMenu *menu, bool saving );

//! Create the option dialog
QgsOptions *createOptionsDialog( QWidget *parent = nullptr );

QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

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

//! interface to QgisApp for plugins
QgisAppInterface *mQgisInterface = nullptr;
friend class QgisAppInterface;

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

friend class TestQgisAppPython;
friend class QgisAppInterface;
friend class QgsAppScreenShots;
};

#ifdef ANDROID
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisappinterface.cpp
Expand Up @@ -789,3 +789,8 @@ bool QgisAppInterface::askForDatumTransform( QgsCoordinateReferenceSystem source
{
return qgis->askUserForDatumTransform( sourceCrs, destinationCrs );
}

void QgisAppInterface::takeAppScreenShots( const QString &saveDirectory, const int categories )
{
return qgis->takeAppScreenShots( saveDirectory, categories );
}
2 changes: 2 additions & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -551,6 +551,8 @@ class APP_EXPORT QgisAppInterface : public QgisInterface

bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs ) override;

void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 ) override;


private slots:

Expand Down

0 comments on commit 8f4d3ba

Please sign in to comment.