QGIS API Documentation 3.27.0-Master (75dc696944)
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 "qgis.h"
20#include "qgssettings.h"
21#include "qgsgui.h"
22#include "qgshelp.h"
23
24#include <QCheckBox>
25#include <QPushButton>
26
28 : QDialog( parent, flags )
29{
30 setupUi( this );
31 connect( mWidthSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged );
32 connect( mHeightSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged );
33 connect( mResolutionSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged );
34
35 connect( mClipToContentGroupBox, &QGroupBox::toggled, this, &QgsLayoutImageExportOptionsDialog::clipToContentsToggled );
36 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutImageExportOptionsDialog::showHelp );
38}
39
41{
42 mResolutionSpinBox->setValue( resolution );
43
44 if ( mImageSize.isValid() )
45 {
46 mWidthSpinBox->blockSignals( true );
47 mHeightSpinBox->blockSignals( true );
48 if ( mClipToContentGroupBox->isChecked() )
49 {
50 mWidthSpinBox->setValue( 0 );
51 mHeightSpinBox->setValue( 0 );
52 }
53 else
54 {
55 mWidthSpinBox->setValue( mImageSize.width() * resolution / 25.4 );
56 mHeightSpinBox->setValue( mImageSize.height() * resolution / 25.4 );
57 }
58 mWidthSpinBox->blockSignals( false );
59 mHeightSpinBox->blockSignals( false );
60 }
61}
62
64{
65 return mResolutionSpinBox->value();
66}
67
69{
70 mImageSize = size;
71 mWidthSpinBox->blockSignals( true );
72 mHeightSpinBox->blockSignals( true );
73 mWidthSpinBox->setValue( size.width() * mResolutionSpinBox->value() / 25.4 );
74 mHeightSpinBox->setValue( size.height() * mResolutionSpinBox->value() / 25.4 );
75 mWidthSpinBox->blockSignals( false );
76 mHeightSpinBox->blockSignals( false );
77}
78
80{
81 return mWidthSpinBox->value();
82}
83
85{
86 return mHeightSpinBox->value();
87}
88
90{
91 mClipToContentGroupBox->setChecked( crop );
92}
93
95{
96 return mClipToContentGroupBox->isChecked();
97}
98
100{
101 mGenerateWorldFile->setChecked( generate );
102}
103
105{
106 return mGenerateWorldFile->isChecked();
107}
108
110{
111 mAntialiasingCheckBox->setChecked( antialias );
112}
113
115{
116 return mAntialiasingCheckBox->isChecked();
117}
118
119void QgsLayoutImageExportOptionsDialog::getCropMargins( int &topMargin, int &rightMargin, int &bottomMargin, int &leftMargin ) const
120{
121 topMargin = mTopMarginSpinBox->value();
122 rightMargin = mRightMarginSpinBox->value();
123 bottomMargin = mBottomMarginSpinBox->value();
124 leftMargin = mLeftMarginSpinBox->value();
125}
126
127void QgsLayoutImageExportOptionsDialog::setCropMargins( int topMargin, int rightMargin, int bottomMargin, int leftMargin )
128{
129 mTopMarginSpinBox->setValue( topMargin );
130 mRightMarginSpinBox->setValue( rightMargin );
131 mBottomMarginSpinBox->setValue( bottomMargin );
132 mLeftMarginSpinBox->setValue( leftMargin );
133}
134
135void QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged( int value )
136{
137 mHeightSpinBox->blockSignals( true );
138 mResolutionSpinBox->blockSignals( true );
139 mHeightSpinBox->setValue( mImageSize.height() * value / mImageSize.width() );
140 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.width() );
141 mHeightSpinBox->blockSignals( false );
142 mResolutionSpinBox->blockSignals( false );
143}
144
145void QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged( int value )
146{
147 mWidthSpinBox->blockSignals( true );
148 mResolutionSpinBox->blockSignals( true );
149 mWidthSpinBox->setValue( mImageSize.width() * value / mImageSize.height() );
150 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.height() );
151 mWidthSpinBox->blockSignals( false );
152 mResolutionSpinBox->blockSignals( false );
153}
154
155void QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged( int value )
156{
157 mWidthSpinBox->blockSignals( true );
158 mHeightSpinBox->blockSignals( true );
159 if ( mClipToContentGroupBox->isChecked() )
160 {
161 mWidthSpinBox->setValue( 0 );
162 mHeightSpinBox->setValue( 0 );
163 }
164 else
165 {
166 mWidthSpinBox->setValue( mImageSize.width() * value / 25.4 );
167 mHeightSpinBox->setValue( mImageSize.height() * value / 25.4 );
168 }
169 mWidthSpinBox->blockSignals( false );
170 mHeightSpinBox->blockSignals( false );
171}
172
173void QgsLayoutImageExportOptionsDialog::clipToContentsToggled( bool state )
174{
175 mWidthSpinBox->setEnabled( !state );
176 mHeightSpinBox->setEnabled( !state );
177
178 if ( state )
179 {
180 whileBlocking( mWidthSpinBox )->setValue( 0 );
181 whileBlocking( mHeightSpinBox )->setValue( 0 );
182 }
183 else
184 {
185 whileBlocking( mWidthSpinBox )->setValue( mImageSize.width() * mResolutionSpinBox->value() / 25.4 );
186 whileBlocking( mHeightSpinBox )->setValue( mImageSize.height() * mResolutionSpinBox->value() / 25.4 );
187 }
188}
189
190void QgsLayoutImageExportOptionsDialog::showHelp()
191{
192 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
193}
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:180
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
bool antialiasing() const
Returns whether antialiasing should be used in the export.
QgsLayoutImageExportOptionsDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutImageExportOptionsDialog.
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.
double resolution() const
Returns the selected resolution from the dialog.
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.
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.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:2330