Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEATURE] New "Save as image" settings dialog (#4390)
* Resolution dpi setting * Extent setting * Scale setting * Draw annotations / decorations setting
- Loading branch information
Showing
9 changed files
with
439 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/*************************************************************************** | ||
qgsmapsavedialog.cpp | ||
------------------------------------- | ||
begin : April 2017 | ||
copyright : (C) 2017 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsmapsavedialog.h" | ||
|
||
#include "qgis.h" | ||
#include "qgsscalecalculator.h" | ||
#include "qgsdecorationitem.h" | ||
#include "qgsextentgroupbox.h" | ||
#include "qgsmapsettings.h" | ||
|
||
#include <QCheckBox> | ||
#include <QSpinBox> | ||
#include <QList> | ||
|
||
Q_GUI_EXPORT extern int qt_defaultDpiX(); | ||
|
||
QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, const QString &activeDecorations ) | ||
: QDialog( parent ) | ||
{ | ||
setupUi( this ); | ||
|
||
mExtent = mapCanvas->mapSettings().visibleExtent(); | ||
mDpi = mapCanvas->mapSettings().outputDpi(); | ||
mSize = mapCanvas->mapSettings().outputSize(); | ||
|
||
mResolutionSpinBox->setValue( qt_defaultDpiX() ); | ||
|
||
mExtentGroupBox->setOutputCrs( mapCanvas->mapSettings().destinationCrs() ); | ||
mExtentGroupBox->setCurrentExtent( mapCanvas->mapSettings().visibleExtent(), mapCanvas->mapSettings().destinationCrs() ); | ||
mExtentGroupBox->setOutputExtentFromCurrent(); | ||
|
||
mScaleWidget->setScale( 1 / mapCanvas->mapSettings().scale() ); | ||
mScaleWidget->setMapCanvas( mapCanvas ); | ||
mScaleWidget->setShowCurrentScaleButton( true ); | ||
|
||
mDrawDecorations->setText( QString( "Draw active decorations: %1" ).arg( !activeDecorations.isEmpty() ? activeDecorations : tr( "none" ) ) ); | ||
|
||
connect( mResolutionSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsMapSaveDialog::updateDpi ); | ||
connect( mExtentGroupBox, &QgsExtentGroupBox::extentChanged, this, &QgsMapSaveDialog::updateExtent ); | ||
connect( mScaleWidget, &QgsScaleWidget::scaleChanged, this, &QgsMapSaveDialog::updateScale ); | ||
|
||
updateOutputSize(); | ||
} | ||
|
||
void QgsMapSaveDialog::updateDpi( int dpi ) | ||
{ | ||
mSize *= ( double )dpi / mDpi; | ||
mDpi = dpi; | ||
|
||
updateOutputSize(); | ||
} | ||
|
||
void QgsMapSaveDialog::updateExtent( const QgsRectangle &extent ) | ||
{ | ||
mSize.setWidth( mSize.width() * extent.width() / mExtent.width() ); | ||
mSize.setHeight( mSize.height() * extent.height() / mExtent.height() ); | ||
mExtent = extent; | ||
|
||
updateOutputSize(); | ||
} | ||
|
||
void QgsMapSaveDialog::updateScale( double scale ) | ||
{ | ||
QgsScaleCalculator calculator; | ||
calculator.setMapUnits( mExtentGroupBox->currentCrs().mapUnits() ); | ||
calculator.setDpi( mDpi ); | ||
|
||
double oldScale = 1 / ( calculator.calculate( mExtent, mSize.width() ) ); | ||
double scaleRatio = oldScale / scale; | ||
mExtent.scale( scaleRatio ); | ||
mExtentGroupBox->setOutputExtentFromUser( mExtent, mExtentGroupBox->currentCrs() ); | ||
} | ||
|
||
void QgsMapSaveDialog::updateOutputSize() | ||
{ | ||
mOutputSize->setText( QString( "Output size: %1 x %2 pixels" ).arg( mSize.width() ).arg( mSize.height() ) ); | ||
} | ||
|
||
QgsRectangle QgsMapSaveDialog::extent() const | ||
{ | ||
return mExtentGroupBox->outputExtent(); | ||
} | ||
|
||
int QgsMapSaveDialog::dpi() const | ||
{ | ||
return mResolutionSpinBox->value(); | ||
} | ||
|
||
QSize QgsMapSaveDialog::size() const | ||
{ | ||
return mSize; | ||
} | ||
|
||
bool QgsMapSaveDialog::drawAnnotations() const | ||
{ | ||
return mDrawAnnotations->isChecked(); | ||
} | ||
|
||
bool QgsMapSaveDialog::drawDecorations() const | ||
{ | ||
return mDrawDecorations->isChecked(); | ||
} |
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,72 @@ | ||
/*************************************************************************** | ||
qgsmapsavedialog.h | ||
------------------------------------- | ||
begin : April 2017 | ||
copyright : (C) 2017 by Mathieu Pellerin | ||
email : nirvn dot asia at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSMAPSAVEDIALOG_H | ||
#define QGSMAPSAVEDIALOG_H | ||
|
||
#include "ui_qgsmapsavedialog.h" | ||
|
||
#include "qgisapp.h" | ||
#include "qgsrectangle.h" | ||
#include "qgsmapcanvas.h" | ||
|
||
#include <QDialog> | ||
#include <QSize> | ||
|
||
/** \ingroup app | ||
* \brief a dialog for saving a map to an image. | ||
* \since QGIS 3.0 | ||
*/ | ||
class APP_EXPORT QgsMapSaveDialog: public QDialog, private Ui::QgsMapSaveDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** Constructor for QgsMapSaveDialog | ||
*/ | ||
QgsMapSaveDialog( QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr, const QString &activeDecorations = QString() ); | ||
|
||
//! returns extent rectangle | ||
QgsRectangle extent() const; | ||
|
||
//! returns the numerical value of the dpi spin box | ||
int dpi() const; | ||
|
||
//! returns the output size | ||
QSize size() const; | ||
|
||
//! returns whether the draw annotations element is checked | ||
bool drawAnnotations() const; | ||
|
||
//! returns whether the draw decorations element is checked | ||
bool drawDecorations() const; | ||
|
||
private: | ||
|
||
void updateDpi( int dpi ); | ||
void updateExtent( const QgsRectangle &extent ); | ||
void updateScale( double scale ); | ||
void updateOutputSize(); | ||
|
||
QgsRectangle mExtent; | ||
int mDpi; | ||
QSize mSize; | ||
|
||
}; | ||
|
||
#endif // QGSMAPSAVEDIALOG_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
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
Oops, something went wrong.