QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgslayoutimageexportoptionsdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutimageexportoptionsdialog.cpp
3 -------------------------------------
4 begin : December 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgslayoutimageexportoptionsdialog.cpp"
20#include "qgis.h"
21#include "qgssettings.h"
22#include "qgsgui.h"
23#include "qgshelp.h"
24
25#include <QCheckBox>
26#include <QPushButton>
27#include <QSpinBox>
28#include <QSlider>
29
30QgsLayoutImageExportOptionsDialog::QgsLayoutImageExportOptionsDialog( QWidget *parent, const QString &fileExtension, Qt::WindowFlags flags )
31 : QDialog( parent, flags )
32 , mFileExtension( fileExtension )
33{
34 setupUi( this );
35 connect( mWidthSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged );
36 connect( mHeightSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged );
37 connect( mResolutionSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged );
38
39 connect( mClipToContentGroupBox, &QGroupBox::toggled, this, &QgsLayoutImageExportOptionsDialog::clipToContentsToggled );
40 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutImageExportOptionsDialog::showHelp );
41
42 const bool showQuality = shouldShowQuality();
43 mQualitySpinBox->setVisible( showQuality );
44 mQualitySlider->setVisible( showQuality );
45 mQualityLabel->setVisible( showQuality );
46 mQualityLabel->setText( tr( "%1 quality", "Image format" ).arg( mFileExtension.toUpper() ) );
47
48 connect( mQualitySpinBox, qOverload< int >( &QSpinBox::valueChanged ), mQualitySlider, &QSlider::setValue );
49 connect( mQualitySlider, &QSlider::valueChanged, mQualitySpinBox, &QSpinBox::setValue );
50
52}
53
55{
56 mResolutionSpinBox->setValue( resolution );
57
58 if ( mImageSize.isValid() )
59 {
60 mWidthSpinBox->blockSignals( true );
61 mHeightSpinBox->blockSignals( true );
62 if ( mClipToContentGroupBox->isChecked() )
63 {
64 mWidthSpinBox->setValue( 0 );
65 mHeightSpinBox->setValue( 0 );
66 }
67 else
68 {
69 mWidthSpinBox->setValue( mImageSize.width() * resolution / 25.4 );
70 mHeightSpinBox->setValue( mImageSize.height() * resolution / 25.4 );
71 }
72 mWidthSpinBox->blockSignals( false );
73 mHeightSpinBox->blockSignals( false );
74 }
75}
76
78{
79 return mResolutionSpinBox->value();
80}
81
83{
84 mImageSize = size;
85 mWidthSpinBox->blockSignals( true );
86 mHeightSpinBox->blockSignals( true );
87 mWidthSpinBox->setValue( size.width() * mResolutionSpinBox->value() / 25.4 );
88 mHeightSpinBox->setValue( size.height() * mResolutionSpinBox->value() / 25.4 );
89 mWidthSpinBox->blockSignals( false );
90 mHeightSpinBox->blockSignals( false );
91}
92
94{
95 return mWidthSpinBox->value();
96}
97
99{
100 return mHeightSpinBox->value();
101}
102
104{
105 mClipToContentGroupBox->setChecked( crop );
106}
107
109{
110 return mClipToContentGroupBox->isChecked();
111}
112
114{
115 mGenerateWorldFile->setChecked( generate );
116}
117
119{
120 return mGenerateWorldFile->isChecked();
121}
122
124{
125 mAntialiasingCheckBox->setChecked( antialias );
126}
127
129{
130 return mAntialiasingCheckBox->isChecked();
131}
132
133void QgsLayoutImageExportOptionsDialog::getCropMargins( int &topMargin, int &rightMargin, int &bottomMargin, int &leftMargin ) const
134{
135 topMargin = mTopMarginSpinBox->value();
136 rightMargin = mRightMarginSpinBox->value();
137 bottomMargin = mBottomMarginSpinBox->value();
138 leftMargin = mLeftMarginSpinBox->value();
139}
140
141void QgsLayoutImageExportOptionsDialog::setCropMargins( int topMargin, int rightMargin, int bottomMargin, int leftMargin )
142{
143 mTopMarginSpinBox->setValue( topMargin );
144 mRightMarginSpinBox->setValue( rightMargin );
145 mBottomMarginSpinBox->setValue( bottomMargin );
146 mLeftMarginSpinBox->setValue( leftMargin );
147}
148
150{
151 return mOpenAfterExportingCheckBox->isChecked();
152}
153
155{
156 mOpenAfterExportingCheckBox->setChecked( enabled );
157}
158
160{
161 if ( !shouldShowQuality() )
162 {
163 return -1;
164 }
165 return mQualitySpinBox->value();
166}
167
169{
170 mQualitySpinBox->setValue( quality );
171}
172
173void QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged( int value )
174{
175 mHeightSpinBox->blockSignals( true );
176 mResolutionSpinBox->blockSignals( true );
177 mHeightSpinBox->setValue( mImageSize.height() * value / mImageSize.width() );
178 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.width() );
179 mHeightSpinBox->blockSignals( false );
180 mResolutionSpinBox->blockSignals( false );
181}
182
183void QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged( int value )
184{
185 mWidthSpinBox->blockSignals( true );
186 mResolutionSpinBox->blockSignals( true );
187 mWidthSpinBox->setValue( mImageSize.width() * value / mImageSize.height() );
188 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.height() );
189 mWidthSpinBox->blockSignals( false );
190 mResolutionSpinBox->blockSignals( false );
191}
192
193void QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged( int value )
194{
195 mWidthSpinBox->blockSignals( true );
196 mHeightSpinBox->blockSignals( true );
197 if ( mClipToContentGroupBox->isChecked() )
198 {
199 mWidthSpinBox->setValue( 0 );
200 mHeightSpinBox->setValue( 0 );
201 }
202 else
203 {
204 mWidthSpinBox->setValue( mImageSize.width() * value / 25.4 );
205 mHeightSpinBox->setValue( mImageSize.height() * value / 25.4 );
206 }
207 mWidthSpinBox->blockSignals( false );
208 mHeightSpinBox->blockSignals( false );
209}
210
211void QgsLayoutImageExportOptionsDialog::clipToContentsToggled( bool state )
212{
213 mWidthSpinBox->setEnabled( !state );
214 mHeightSpinBox->setEnabled( !state );
215
216 if ( state )
217 {
218 whileBlocking( mWidthSpinBox )->setValue( 0 );
219 whileBlocking( mHeightSpinBox )->setValue( 0 );
220 }
221 else
222 {
223 whileBlocking( mWidthSpinBox )->setValue( mImageSize.width() * mResolutionSpinBox->value() / 25.4 );
224 whileBlocking( mHeightSpinBox )->setValue( mImageSize.height() * mResolutionSpinBox->value() / 25.4 );
225 }
226}
227
228void QgsLayoutImageExportOptionsDialog::showHelp()
229{
230 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
231}
232
233bool QgsLayoutImageExportOptionsDialog::shouldShowQuality() const
234{
235 const QStringList validExtensions = { "jpeg", "jpg" };
236 for ( const QString &ext : validExtensions )
237 {
238 if ( mFileExtension.toLower() == ext )
239 {
240 return true;
241 }
242 }
243 return false;
244}
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:209
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
bool antialiasing() const
Returns whether antialiasing should be used in the export.
void setQuality(int quality)
Sets the image quality (for JPEG)
void setCropToContents(bool crop)
Sets whether the crop to contents option should be checked in the dialog.
void setImageSize(QSizeF size)
Sets the target image size.
void setAntialiasing(bool antialias)
Sets whether antialiasing should be used in the export.
int quality() const
Returns the image quality.
double resolution() const
Returns the selected resolution from the dialog.
QgsLayoutImageExportOptionsDialog(QWidget *parent=nullptr, const QString &fileExtension=QString(), Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutImageExportOptionsDialog.
int imageWidth() const
Returns the user-set image width in pixels.
bool cropToContents() const
Returns whether the crop to contents option is checked in the dialog.
void setOpenAfterExporting(bool enabled)
Sets whether to open the pdf after exporting it.
bool generateWorldFile() const
Returns whether the generate world file option is checked in the dialog.
void setCropMargins(int topMargin, int rightMargin, int bottomMargin, int leftMargin)
Sets the current crop to contents margin values, in pixels.
void setResolution(double resolution)
Sets the initial resolution displayed in the dialog.
void getCropMargins(int &topMargin, int &rightMargin, int &bottomMargin, int &leftMargin) const
Fetches the current crop to contents margin values, in pixels.
int imageHeight() const
Returns the user-set image height in pixels.
void setGenerateWorldFile(bool generate)
Sets whether the generate world file option should be checked.
bool openAfterExporting() const
Returns whether the pdf should be opened after exporting it.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5862