19#include "moc_qgslayoutimageexportoptionsdialog.cpp" 
   31  : QDialog( parent, flags )
 
   32  , mFileExtension( fileExtension )
 
   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 );
 
   39  connect( mClipToContentGroupBox, &QGroupBox::toggled, 
this, &QgsLayoutImageExportOptionsDialog::clipToContentsToggled );
 
   40  connect( mHelpButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsLayoutImageExportOptionsDialog::showHelp );
 
   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() ) );
 
   48  connect( mQualitySpinBox, qOverload<int>( &QSpinBox::valueChanged ), mQualitySlider, &QSlider::setValue );
 
   49  connect( mQualitySlider, &QSlider::valueChanged, mQualitySpinBox, &QSpinBox::setValue );
 
 
   58  if ( mImageSize.isValid() )
 
   60    mWidthSpinBox->blockSignals( 
true );
 
   61    mHeightSpinBox->blockSignals( 
true );
 
   62    if ( mClipToContentGroupBox->isChecked() )
 
   64      mWidthSpinBox->setValue( 0 );
 
   65      mHeightSpinBox->setValue( 0 );
 
   69      mWidthSpinBox->setValue( mImageSize.width() * 
resolution / 25.4 );
 
   70      mHeightSpinBox->setValue( mImageSize.height() * 
resolution / 25.4 );
 
   72    mWidthSpinBox->blockSignals( 
false );
 
   73    mHeightSpinBox->blockSignals( 
false );
 
 
   79  return mResolutionSpinBox->value();
 
 
   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 );
 
 
   95  return mWidthSpinBox->value();
 
 
  100  return mHeightSpinBox->value();
 
 
  105  mClipToContentGroupBox->setChecked( crop );
 
 
  110  return mClipToContentGroupBox->isChecked();
 
 
  115  mGenerateWorldFile->setChecked( generate );
 
 
  120  return mGenerateWorldFile->isChecked();
 
 
  125  mAntialiasingCheckBox->setChecked( antialias );
 
 
  130  return mAntialiasingCheckBox->isChecked();
 
 
  135  topMargin = mTopMarginSpinBox->value();
 
  136  rightMargin = mRightMarginSpinBox->value();
 
  137  bottomMargin = mBottomMarginSpinBox->value();
 
  138  leftMargin = mLeftMarginSpinBox->value();
 
 
  143  mTopMarginSpinBox->setValue( topMargin );
 
  144  mRightMarginSpinBox->setValue( rightMargin );
 
  145  mBottomMarginSpinBox->setValue( bottomMargin );
 
  146  mLeftMarginSpinBox->setValue( leftMargin );
 
 
  151  return mOpenAfterExportingCheckBox->isChecked();
 
 
  156  mOpenAfterExportingCheckBox->setChecked( enabled );
 
 
  161  if ( !shouldShowQuality() )
 
  165  return mQualitySpinBox->value();
 
 
  170  mQualitySpinBox->setValue( 
quality );
 
 
  173void QgsLayoutImageExportOptionsDialog::mWidthSpinBox_valueChanged( 
int value )
 
  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 );
 
  183void QgsLayoutImageExportOptionsDialog::mHeightSpinBox_valueChanged( 
int value )
 
  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 );
 
  193void QgsLayoutImageExportOptionsDialog::mResolutionSpinBox_valueChanged( 
int value )
 
  195  mWidthSpinBox->blockSignals( 
true );
 
  196  mHeightSpinBox->blockSignals( 
true );
 
  197  if ( mClipToContentGroupBox->isChecked() )
 
  199    mWidthSpinBox->setValue( 0 );
 
  200    mHeightSpinBox->setValue( 0 );
 
  204    mWidthSpinBox->setValue( mImageSize.width() * value / 25.4 );
 
  205    mHeightSpinBox->setValue( mImageSize.height() * value / 25.4 );
 
  207  mWidthSpinBox->blockSignals( 
false );
 
  208  mHeightSpinBox->blockSignals( 
false );
 
  211void QgsLayoutImageExportOptionsDialog::clipToContentsToggled( 
bool state )
 
  213  mWidthSpinBox->setEnabled( !state );
 
  214  mHeightSpinBox->setEnabled( !state );
 
  223    whileBlocking( mWidthSpinBox )->setValue( mImageSize.width() * mResolutionSpinBox->value() / 25.4 );
 
  224    whileBlocking( mHeightSpinBox )->setValue( mImageSize.height() * mResolutionSpinBox->value() / 25.4 );
 
  228void QgsLayoutImageExportOptionsDialog::showHelp()
 
  233bool QgsLayoutImageExportOptionsDialog::shouldShowQuality()
 const 
  235  const QStringList validExtensions = { 
"jpeg", 
"jpg" };
 
  236  for ( 
const QString &ext : validExtensions )
 
  238    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.