QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 "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( mHelpButtonBox, &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
136{
137 return mOpenAfterExportingCheckBox->isChecked();
138}
139
141{
142 mOpenAfterExportingCheckBox->setChecked( enabled );
143}
144
145void QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged( int value )
146{
147 mHeightSpinBox->blockSignals( true );
148 mResolutionSpinBox->blockSignals( true );
149 mHeightSpinBox->setValue( mImageSize.height() * value / mImageSize.width() );
150 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.width() );
151 mHeightSpinBox->blockSignals( false );
152 mResolutionSpinBox->blockSignals( false );
153}
154
155void QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged( int value )
156{
157 mWidthSpinBox->blockSignals( true );
158 mResolutionSpinBox->blockSignals( true );
159 mWidthSpinBox->setValue( mImageSize.width() * value / mImageSize.height() );
160 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.height() );
161 mWidthSpinBox->blockSignals( false );
162 mResolutionSpinBox->blockSignals( false );
163}
164
165void QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged( int value )
166{
167 mWidthSpinBox->blockSignals( true );
168 mHeightSpinBox->blockSignals( true );
169 if ( mClipToContentGroupBox->isChecked() )
170 {
171 mWidthSpinBox->setValue( 0 );
172 mHeightSpinBox->setValue( 0 );
173 }
174 else
175 {
176 mWidthSpinBox->setValue( mImageSize.width() * value / 25.4 );
177 mHeightSpinBox->setValue( mImageSize.height() * value / 25.4 );
178 }
179 mWidthSpinBox->blockSignals( false );
180 mHeightSpinBox->blockSignals( false );
181}
182
183void QgsLayoutImageExportOptionsDialog::clipToContentsToggled( bool state )
184{
185 mWidthSpinBox->setEnabled( !state );
186 mHeightSpinBox->setEnabled( !state );
187
188 if ( state )
189 {
190 whileBlocking( mWidthSpinBox )->setValue( 0 );
191 whileBlocking( mHeightSpinBox )->setValue( 0 );
192 }
193 else
194 {
195 whileBlocking( mWidthSpinBox )->setValue( mImageSize.width() * mResolutionSpinBox->value() / 25.4 );
196 whileBlocking( mHeightSpinBox )->setValue( mImageSize.height() * mResolutionSpinBox->value() / 25.4 );
197 }
198}
199
200void QgsLayoutImageExportOptionsDialog::showHelp()
201{
202 QgsHelp::openHelp( QStringLiteral( "print_composer/create_output.html" ) );
203}
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:194
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
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.
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:4258