Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
take screenshots in app for user documentation
- Loading branch information
Showing
10 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
|
||
#include <QWindow> | ||
#include <QScreen> | ||
#include <QImageWriter> | ||
|
||
#include "qgsappscreenshots.h" | ||
|
||
#include "qgsvectorlayerproperties.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsproject.h" | ||
#include "qgsmessagelog.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 ); | ||
} | ||
|
||
void QgsAppScreenShots::saveScreenshot( const QString &name, QWidget *widget, GrabMode mode ) | ||
{ | ||
QPixmap pix; | ||
int x = 0; | ||
int y = 0; | ||
int w = -1; | ||
int h = -1; | ||
|
||
QScreen *screen = QGuiApplication::primaryScreen(); | ||
if ( widget ) | ||
{ | ||
const QWindow *window = widget->windowHandle(); | ||
if ( window ) | ||
{ | ||
screen = window->screen(); | ||
} | ||
widget->raise(); | ||
if ( mode == GrabWidget ) | ||
{ | ||
pix = widget->grab(); | ||
} | ||
else if ( mode == GrabWidgetAndFrame ) | ||
{ | ||
const QRect geom = widget->frameGeometry(); | ||
QPoint tl = geom.topLeft(); | ||
x = tl.x(); | ||
y = tl.y(); | ||
w = geom.width(); | ||
h = geom.height(); | ||
} | ||
} | ||
if ( !widget || mode != GrabWidget ) | ||
{ | ||
pix = screen->grabWindow( 0, x, y, w, h ); | ||
} | ||
|
||
const QString &fileName = mSaveDirectory + "/" + name + ".png"; | ||
pix.save( fileName ); | ||
QMetaEnum metaEnum = QMetaEnum::fromType<GrabMode>(); | ||
QgsMessageLog::logMessage( QString( "Screenshot saved: %1 (%2)" ).arg( fileName, metaEnum.key( mode ) ) ); | ||
} | ||
|
||
void QgsAppScreenShots::takeScreenshots( Categories categories ) | ||
{ | ||
if ( !categories || categories.testFlag( VectorLayerProperties ) ) | ||
takeVectorLayerProperties(); | ||
} | ||
|
||
void QgsAppScreenShots::takeVectorLayerProperties() | ||
{ | ||
QgsVectorLayerProperties *dlg = new QgsVectorLayerProperties( mVectorLayer ); | ||
dlg->show(); | ||
// ---------------- | ||
// do all the pages | ||
for ( int row = 0; row < dlg->mOptionsListWidget->count(); ++row ) | ||
{ | ||
dlg->mOptionsListWidget->setCurrentRow( row ); | ||
dlg->adjustSize(); | ||
QCoreApplication::processEvents(); | ||
QString name = dlg->mOptionsListWidget->item( row )[0].text().toLower(); | ||
name.replace( " ", "_" ); | ||
saveScreenshot( name, dlg ); | ||
} | ||
// ------------------ | ||
// style menu clicked | ||
dlg->mOptionsListWidget->setCurrentRow( 0 ); | ||
QCoreApplication::processEvents(); | ||
dlg->mBtnStyle->click(); | ||
saveScreenshot( "style", dlg ); | ||
|
||
// exit properly | ||
dlg->close(); | ||
dlg->deleteLater(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef QGSAPPSCREENSHOTS_H | ||
#define QGSAPPSCREENSHOTS_H | ||
|
||
#include <QObject> | ||
|
||
class QgsVectorLayer; | ||
|
||
class QgsAppScreenShots | ||
{ | ||
Q_GADGET | ||
public: | ||
enum GrabMode | ||
{ | ||
GrabWidget, | ||
GrabWidgetAndFrame, | ||
GrabWholeWindow | ||
}; | ||
Q_ENUM( GrabMode ) | ||
|
||
enum Category | ||
{ | ||
VectorLayerProperties = 1, | ||
}; | ||
Q_ENUM( Category ) | ||
Q_DECLARE_FLAGS( Categories, Category ) | ||
Q_FLAG( Categories ) | ||
|
||
QgsAppScreenShots( const QString &saveDirectory ); | ||
|
||
//! if categories is null, then takes all categories | ||
void takeScreenshots( Categories categories = nullptr ); | ||
|
||
private: | ||
void takeVectorLayerProperties(); | ||
|
||
|
||
void saveScreenshot( const QString &name, QWidget *widget = nullptr, GrabMode mode = GrabWidgetAndFrame ); | ||
|
||
QString mSaveDirectory; | ||
QgsVectorLayer *mVectorLayer = nullptr; | ||
}; | ||
|
||
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAppScreenShots::Categories ) | ||
|
||
#endif // QGSAPPSCREENSHOTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters