30#include "moc_qgslayoutimageexportoptionsdialog.cpp"
33 : QDialog( parent, flags )
34 , mFileExtension( fileExtension )
37 connect( mWidthSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged );
38 connect( mHeightSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged );
39 connect( mResolutionSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ),
this, &QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged );
41 connect( mClipToContentGroupBox, &QGroupBox::toggled,
this, &QgsLayoutImageExportOptionsDialog::clipToContentsToggled );
42 connect( mHelpButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLayoutImageExportOptionsDialog::showHelp );
44 const bool showQuality = shouldShowQuality();
45 mQualitySpinBox->setVisible( showQuality );
46 mQualitySlider->setVisible( showQuality );
47 mQualityLabel->setVisible( showQuality );
48 mQualityLabel->setText( tr(
"%1 quality",
"Image format" ).arg( mFileExtension.toUpper() ) );
50 connect( mQualitySpinBox, qOverload<int>( &QSpinBox::valueChanged ), mQualitySlider, &QSlider::setValue );
51 connect( mQualitySlider, &QSlider::valueChanged, mQualitySpinBox, &QSpinBox::setValue );
60 if ( mImageSize.isValid() )
62 mWidthSpinBox->blockSignals(
true );
63 mHeightSpinBox->blockSignals(
true );
64 if ( mClipToContentGroupBox->isChecked() )
66 mWidthSpinBox->setValue( 0 );
67 mHeightSpinBox->setValue( 0 );
71 mWidthSpinBox->setValue( mImageSize.width() *
resolution / 25.4 );
72 mHeightSpinBox->setValue( mImageSize.height() *
resolution / 25.4 );
74 mWidthSpinBox->blockSignals(
false );
75 mHeightSpinBox->blockSignals(
false );
81 return mResolutionSpinBox->value();
87 mWidthSpinBox->blockSignals(
true );
88 mHeightSpinBox->blockSignals(
true );
89 mWidthSpinBox->setValue( size.width() * mResolutionSpinBox->value() / 25.4 );
90 mHeightSpinBox->setValue( size.height() * mResolutionSpinBox->value() / 25.4 );
91 mWidthSpinBox->blockSignals(
false );
92 mHeightSpinBox->blockSignals(
false );
97 return mWidthSpinBox->value();
102 return mHeightSpinBox->value();
107 mClipToContentGroupBox->setChecked( crop );
112 return mClipToContentGroupBox->isChecked();
117 mGenerateWorldFile->setChecked( generate );
122 return mGenerateWorldFile->isChecked();
127 mAntialiasingCheckBox->setChecked( antialias );
132 return mAntialiasingCheckBox->isChecked();
137 topMargin = mTopMarginSpinBox->value();
138 rightMargin = mRightMarginSpinBox->value();
139 bottomMargin = mBottomMarginSpinBox->value();
140 leftMargin = mLeftMarginSpinBox->value();
145 mTopMarginSpinBox->setValue( topMargin );
146 mRightMarginSpinBox->setValue( rightMargin );
147 mBottomMarginSpinBox->setValue( bottomMargin );
148 mLeftMarginSpinBox->setValue( leftMargin );
153 return mOpenAfterExportingCheckBox->isChecked();
158 mOpenAfterExportingCheckBox->setChecked( enabled );
163 if ( !shouldShowQuality() )
167 return mQualitySpinBox->value();
172 mQualitySpinBox->setValue(
quality );
175void QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged(
int value )
177 mHeightSpinBox->blockSignals(
true );
178 mResolutionSpinBox->blockSignals(
true );
179 mHeightSpinBox->setValue( mImageSize.height() * value / mImageSize.width() );
180 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.width() );
181 mHeightSpinBox->blockSignals(
false );
182 mResolutionSpinBox->blockSignals(
false );
185void QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged(
int value )
187 mWidthSpinBox->blockSignals(
true );
188 mResolutionSpinBox->blockSignals(
true );
189 mWidthSpinBox->setValue( mImageSize.width() * value / mImageSize.height() );
190 mResolutionSpinBox->setValue( value * 25.4 / mImageSize.height() );
191 mWidthSpinBox->blockSignals(
false );
192 mResolutionSpinBox->blockSignals(
false );
195void QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged(
int value )
197 mWidthSpinBox->blockSignals(
true );
198 mHeightSpinBox->blockSignals(
true );
199 if ( mClipToContentGroupBox->isChecked() )
201 mWidthSpinBox->setValue( 0 );
202 mHeightSpinBox->setValue( 0 );
206 mWidthSpinBox->setValue( mImageSize.width() * value / 25.4 );
207 mHeightSpinBox->setValue( mImageSize.height() * value / 25.4 );
209 mWidthSpinBox->blockSignals(
false );
210 mHeightSpinBox->blockSignals(
false );
213void QgsLayoutImageExportOptionsDialog::clipToContentsToggled(
bool state )
215 mWidthSpinBox->setEnabled( !state );
216 mHeightSpinBox->setEnabled( !state );
225 whileBlocking( mWidthSpinBox )->setValue( mImageSize.width() * mResolutionSpinBox->value() / 25.4 );
226 whileBlocking( mHeightSpinBox )->setValue( mImageSize.height() * mResolutionSpinBox->value() / 25.4 );
230void QgsLayoutImageExportOptionsDialog::showHelp()
235bool QgsLayoutImageExportOptionsDialog::shouldShowQuality()
const
237 const QStringList validExtensions = {
"jpeg",
"jpg" };
238 for (
const QString &ext : validExtensions )
240 if ( mFileExtension.toLower() == ext )
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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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.