20#include "moc_qgsunitselectionwidget.cpp" 
   22#include <QDialogButtonBox> 
   28  mComboBoxMinScale->setScale( 10000000.0 );
 
   29  mComboBoxMaxScale->setScale( 1 );
 
   30  mSpinBoxMinSize->setShowClearButton( 
false );
 
   31  mSpinBoxMaxSize->setShowClearButton( 
false );
 
   32  connect( mCheckBoxMinScale, &QCheckBox::toggled, 
this, &QgsMapUnitScaleWidget::configureMinComboBox );
 
   33  connect( mCheckBoxMaxScale, &QCheckBox::toggled, 
this, &QgsMapUnitScaleWidget::configureMaxComboBox );
 
   38  connect( mCheckBoxMinSize, &QCheckBox::toggled, mSpinBoxMinSize, &QgsDoubleSpinBox::setEnabled );
 
   39  connect( mCheckBoxMaxSize, &QCheckBox::toggled, mSpinBoxMaxSize, &QgsDoubleSpinBox::setEnabled );
 
   42  connect( mCheckBoxMinScale, &QCheckBox::toggled, 
this, &QgsMapUnitScaleWidget::settingsChanged );
 
   43  connect( mCheckBoxMaxScale, &QCheckBox::toggled, 
this, &QgsMapUnitScaleWidget::settingsChanged );
 
   46  connect( mCheckBoxMinSize, &QCheckBox::toggled, 
this, &QgsMapUnitScaleWidget::settingsChanged );
 
   47  connect( mCheckBoxMaxSize, &QCheckBox::toggled, 
this, &QgsMapUnitScaleWidget::settingsChanged );
 
   48  connect( mSpinBoxMinSize, 
static_cast<void ( 
QgsDoubleSpinBox::* )( 
double )
>( &QgsDoubleSpinBox::valueChanged ), 
this, &QgsMapUnitScaleWidget::settingsChanged );
 
   49  connect( mSpinBoxMaxSize, 
static_cast<void ( 
QgsDoubleSpinBox::* )( 
double )
>( &QgsDoubleSpinBox::valueChanged ), 
this, &QgsMapUnitScaleWidget::settingsChanged );
 
   50  mBlockSignals = 
false;
 
 
   58  mComboBoxMinScale->setScale( scale.
minScale > 0.0 ? scale.
minScale : 10000000 );
 
   59  mCheckBoxMinScale->setChecked( scale.
minScale != 0.0 );
 
   60  mComboBoxMinScale->setEnabled( scale.
minScale != 0.0 );
 
   62  mCheckBoxMaxScale->setChecked( scale.
maxScale > 0.0 );
 
   63  mComboBoxMaxScale->setEnabled( scale.
maxScale > 0.0 );
 
   67  mSpinBoxMinSize->setValue( scale.
minSizeMM );
 
   71  mSpinBoxMaxSize->setValue( scale.
maxSizeMM );
 
   72  mBlockSignals = 
false;
 
 
   79  mComboBoxMinScale->setMapCanvas( canvas );
 
   80  mComboBoxMinScale->setShowCurrentScaleButton( 
true );
 
   81  mComboBoxMaxScale->setMapCanvas( canvas );
 
   82  mComboBoxMaxScale->setShowCurrentScaleButton( 
true );
 
 
   85void QgsMapUnitScaleWidget::configureMinComboBox()
 
   87  mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
 
   88  if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() < mComboBoxMaxScale->scale() )
 
   90    mComboBoxMinScale->setScale( mComboBoxMaxScale->scale() );
 
   94void QgsMapUnitScaleWidget::configureMaxComboBox()
 
   96  mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
 
   97  if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() > mComboBoxMinScale->scale() )
 
   99    mComboBoxMaxScale->setScale( mComboBoxMinScale->scale() );
 
  103void QgsMapUnitScaleWidget::settingsChanged()
 
  114  scale.
minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
 
  115  scale.
maxScale = mCheckBoxMaxScale->isChecked() ? mComboBoxMaxScale->scale() : 0;
 
  117  scale.
minSizeMM = mSpinBoxMinSize->value();
 
  119  scale.
maxSizeMM = mSpinBoxMaxSize->value();
 
 
  131  mMapScaleButton->setVisible( 
false );
 
  132  mMapScaleButton->setToolTip( tr( 
"Adjust scaling range" ) );
 
  134  setFocusPolicy( Qt::StrongFocus );
 
  135  setFocusProxy( mUnitCombo );
 
  137  connect( mUnitCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsUnitSelectionWidget::toggleUnitRangeButton );
 
  138  connect( mMapScaleButton, &QToolButton::clicked, 
this, &QgsUnitSelectionWidget::showDialog );
 
 
  144  blockSignals( 
true );
 
  145  mUnitCombo->addItems( units );
 
  146  mMapUnitIdx = mapUnitIdx;
 
  147  blockSignals( 
false );
 
 
  152  blockSignals( 
true );
 
  187  blockSignals( 
false );
 
 
  192  if ( mUnitCombo->count() == 0 )
 
  195  const QVariant currentData = mUnitCombo->currentData();
 
  196  if ( currentData.isValid() )
 
 
  206  blockSignals( 
true );
 
  207  mUnitCombo->setCurrentIndex( unitIndex );
 
  208  blockSignals( 
false );
 
 
  213  const int idx = mUnitCombo->findData( QVariant( 
static_cast<int>( 
unit ) ) );
 
  214  mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
 
 
  222void QgsUnitSelectionWidget::showDialog()
 
  237  dlg.setMapUnitScale( mMapUnitScale );
 
  238  dlg.setMapCanvas( mCanvas );
 
  239  if ( dlg.exec() == QDialog::Accepted )
 
  241    if ( mMapUnitScale != dlg.getMapUnitScale() )
 
  243      mMapUnitScale = dlg.getMapUnitScale();
 
  249void QgsUnitSelectionWidget::toggleUnitRangeButton()
 
  257    mMapScaleButton->setVisible( mShowMapScaleButton && mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
 
  261void QgsUnitSelectionWidget::widgetChanged( 
const QgsMapUnitScale &scale )
 
  263  mMapUnitScale = scale;
 
  269  return mShowMapScaleButton;
 
 
  274  mShowMapScaleButton = show;
 
  276    mMapScaleButton->hide();
 
 
  284  QVBoxLayout *vLayout = 
new QVBoxLayout();
 
  286  vLayout->addWidget( mWidget );
 
  287  QDialogButtonBox *bbox = 
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
 
  288  connect( bbox, &QDialogButtonBox::accepted, 
this, &QgsMapUnitScaleDialog::accept );
 
  289  connect( bbox, &QDialogButtonBox::rejected, 
this, &QgsMapUnitScaleDialog::reject );
 
  290  connect( bbox, &QDialogButtonBox::helpRequested, 
this, &QgsMapUnitScaleDialog::showHelp );
 
  291  vLayout->addWidget( bbox );
 
  292  setLayout( vLayout );
 
  293  setWindowTitle( tr( 
"Adjust Scaling Range" ) );
 
 
  311void QgsMapUnitScaleDialog::showHelp()
 
  313  QgsHelp::openHelp( QStringLiteral( 
"introduction/general_tools.html#unit-selector" ) );
 
RenderUnit
Rendering size units.
 
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size)
 
@ Millimeters
Millimeters.
 
@ Points
Points (e.g., for font sizes)
 
@ Unknown
Mixed or unknown units.
 
@ MetersInMapUnits
Meters value as Map units.
 
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
 
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
 
Map canvas is a class for displaying all GIS data types on a canvas.
 
A dialog which allows the user to choose the minimum and maximum scale of an object in map units and ...
 
QgsMapUnitScale getMapUnitScale() const
Returns a QgsMapUnitScale representing the settings shown in the dialog.
 
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the dialog.
 
void setMapUnitScale(const QgsMapUnitScale &scale)
Updates the dialog to reflect the settings from the specified QgsMapUnitScale object.
 
QgsMapUnitScaleDialog(QWidget *parent=nullptr)
Constructor for QgsMapUnitScaleDialog.
 
Struct for storing maximum and minimum scales for measurements in map units.
 
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
 
double maxScale
The maximum scale, or 0.0 if unset.
 
double minScale
The minimum scale, or 0.0 if unset.
 
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
 
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
 
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
 
QList< Qgis::RenderUnit > RenderUnitList
List of render units.