Navigation Menu

Skip to content

Commit

Permalink
add 2.5D screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Oct 4, 2018
1 parent 046f915 commit 2f93ef1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/app/main.cpp
Expand Up @@ -143,6 +143,7 @@ void usage( const QString &appName )
<< 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 @@ -532,6 +533,7 @@ int main( int argc, char *argv[] )

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
Expand Down Expand Up @@ -754,6 +756,10 @@ int main( int argc, char *argv[] )
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 @@ -1242,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 @@ -1468,7 +1474,7 @@ int main( int argc, char *argv[] )

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

/////////////////////////////////////////////////////////////////////
Expand Down
45 changes: 41 additions & 4 deletions src/app/qgsappscreenshots.cpp
Expand Up @@ -18,7 +18,7 @@
#include <QWindow>
#include <QScreen>
#include <QImageWriter>
#include <QTransform>
#include <QIcon>

#include "qgsappscreenshots.h"

Expand All @@ -27,13 +27,22 @@
#include "qgsproject.h"
#include "qgsmessagelog.h"
#include "qgisapp.h"
#include "qgsrendererpropertiesdialog.h"
#include "qgs25drendererwidget.h"
#include "qgsapplication.h"


QgsAppScreenShots::QgsAppScreenShots( const QString &saveDirectory )
: mSaveDirectory( saveDirectory )
{
QString layerDef = QStringLiteral( "Point?crs=epsg:4326&field=pk:integer&field=my_text:string&field=my_integer:integer&field=my_double:double&key=pk" );
mVectorLayer = new QgsVectorLayer( layerDef, QStringLiteral( "Layer" ), QStringLiteral( "memory" ) );
QgsProject::instance()->addMapLayer( mVectorLayer );
mLineLayer = new QgsVectorLayer( layerDef, QStringLiteral( "Line Layer" ), QStringLiteral( "memory" ) );
layerDef = QStringLiteral( "Polygon?crs=epsg:2056&field=pk:integer&field=my_text:string&field=my_integer:integer&field=height:double&key=pk" );
mPolygonLayer = new QgsVectorLayer( layerDef, QStringLiteral( "Polygon Layer" ), QStringLiteral( "memory" ) );

QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>()
<< mLineLayer
<< mPolygonLayer );
}

void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, GrabMode mode )
Expand Down Expand Up @@ -117,6 +126,9 @@ QScreen *QgsAppScreenShots::screen( QWidget *widget )

void QgsAppScreenShots::takePicturesOf( Categories categories )
{
if ( !categories || categories.testFlag( Symbol25D ) )
take25dSymbol();

if ( !categories || categories.testFlag( VectorLayerProperties ) )
takeVectorLayerProperties();
}
Expand All @@ -128,7 +140,7 @@ void QgsAppScreenShots::takePicturesOf( Categories categories )
void QgsAppScreenShots::takeVectorLayerProperties()
{
QString rootName = QLatin1String( "vectorlayerproperties_" );
QgsVectorLayerProperties *dlg = new QgsVectorLayerProperties( mVectorLayer, QgisApp::instance() );
QgsVectorLayerProperties *dlg = new QgsVectorLayerProperties( mLineLayer, QgisApp::instance() );
dlg->show();
// ----------------
// do all the pages
Expand Down Expand Up @@ -159,3 +171,28 @@ void QgsAppScreenShots::takeVectorLayerProperties()
dlg->deleteLater();
}

void QgsAppScreenShots::take25dSymbol()
{
QString rootName = QLatin1String( "vectorlayerproperties_" );
QgsVectorLayerProperties *dlg = new QgsVectorLayerProperties( mPolygonLayer, QgisApp::instance() );
dlg->show();
dlg->mOptionsListWidget->setCurrentRow( 2 );
Q_ASSERT( dlg->mOptionsListWidget->currentItem()->icon().pixmap( 24, 24 ).toImage()
== QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/symbology.svg" ) ).pixmap( 24, 24 ).toImage() );
int idx = dlg->mRendererDialog->cboRenderers->findData( QLatin1String( "25dRenderer" ) );
Q_ASSERT( idx >= 0 );
dlg->mRendererDialog->cboRenderers->setCurrentIndex( idx );
QCoreApplication::processEvents();
Qgs25DRendererWidget *w = dynamic_cast<Qgs25DRendererWidget *>( dlg->mRendererDialog->mActiveWidget );
w->mHeightWidget->setField( QLatin1String( "height" ) );
Q_ASSERT( w->mHeightWidget->expression() == QLatin1String( "\"height\"" ) );
QCoreApplication::processEvents();
dlg->adjustSize();
QCoreApplication::processEvents();
saveScreenshot( rootName + QLatin1String( "25dsymbol" ), dlg );

// exit properly
dlg->close();
dlg->deleteLater();
}

9 changes: 7 additions & 2 deletions src/app/qgsappscreenshots.h
Expand Up @@ -41,9 +41,12 @@ class QgsAppScreenShots
Screen
};

//! Not part of the API to avoid cluttering
enum Category
{
VectorLayerProperties = 1,
All = 0,
Symbol25D,
VectorLayerProperties,
};
Q_ENUM( Category )
Q_DECLARE_FLAGS( Categories, Category )
Expand All @@ -60,9 +63,11 @@ class QgsAppScreenShots
void saveScreenshot( const QString &name, QWidget *widget = nullptr, GrabMode mode = GrabWidgetAndFrame );

void takeVectorLayerProperties();
void take25dSymbol();

QString mSaveDirectory;
QgsVectorLayer *mVectorLayer = nullptr;
QgsVectorLayer *mLineLayer = nullptr;
QgsVectorLayer *mPolygonLayer = nullptr;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAppScreenShots::Categories )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology/qgs25drendererwidget.h
Expand Up @@ -58,6 +58,8 @@ class GUI_EXPORT Qgs25DRendererWidget : public QgsRendererWidget, protected Ui::
void apply() override SIP_FORCE;

Qgs25DRenderer *mRenderer = nullptr;

friend class QgsAppScreenShots;
};

#endif // QGS25DRENDERERWIDGET_H
2 changes: 2 additions & 0 deletions src/gui/symbology/qgsrendererpropertiesdialog.h
Expand Up @@ -153,6 +153,8 @@ class GUI_EXPORT QgsRendererPropertiesDialog : public QDialog, private Ui::QgsRe

private:
bool mDockMode;

friend class QgsAppScreenShots;
};


Expand Down

0 comments on commit 2f93ef1

Please sign in to comment.