23#include <QDialogButtonBox>
26#include "moc_qgsunitselectionwidget.cpp"
28using namespace Qt::StringLiterals;
34 mComboBoxMinScale->setScale( 10000000.0 );
35 mComboBoxMaxScale->setScale( 1 );
36 mSpinBoxMinSize->setShowClearButton(
false );
37 mSpinBoxMaxSize->setShowClearButton(
false );
38 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMinComboBox );
39 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMaxComboBox );
44 connect( mCheckBoxMinSize, &QCheckBox::toggled, mSpinBoxMinSize, &QgsDoubleSpinBox::setEnabled );
45 connect( mCheckBoxMaxSize, &QCheckBox::toggled, mSpinBoxMaxSize, &QgsDoubleSpinBox::setEnabled );
48 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
49 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
52 connect( mCheckBoxMinSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
53 connect( mCheckBoxMaxSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
54 connect( mSpinBoxMinSize,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
55 connect( mSpinBoxMaxSize,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
56 mBlockSignals =
false;
64 mComboBoxMinScale->setScale( scale.
minScale > 0.0 ? scale.
minScale : 10000000 );
65 mCheckBoxMinScale->setChecked( scale.
minScale != 0.0 );
66 mComboBoxMinScale->setEnabled( scale.
minScale != 0.0 );
68 mCheckBoxMaxScale->setChecked( scale.
maxScale > 0.0 );
69 mComboBoxMaxScale->setEnabled( scale.
maxScale > 0.0 );
73 mSpinBoxMinSize->setValue( scale.
minSizeMM );
77 mSpinBoxMaxSize->setValue( scale.
maxSizeMM );
78 mBlockSignals =
false;
85 mComboBoxMinScale->setMapCanvas( canvas );
86 mComboBoxMinScale->setShowCurrentScaleButton(
true );
87 mComboBoxMaxScale->setMapCanvas( canvas );
88 mComboBoxMaxScale->setShowCurrentScaleButton(
true );
91void QgsMapUnitScaleWidget::configureMinComboBox()
93 mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
94 if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() < mComboBoxMaxScale->scale() )
96 mComboBoxMinScale->setScale( mComboBoxMaxScale->scale() );
100void QgsMapUnitScaleWidget::configureMaxComboBox()
102 mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
103 if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() > mComboBoxMinScale->scale() )
105 mComboBoxMaxScale->setScale( mComboBoxMinScale->scale() );
109void QgsMapUnitScaleWidget::settingsChanged()
120 scale.
minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
121 scale.
maxScale = mCheckBoxMaxScale->isChecked() ? mComboBoxMaxScale->scale() : 0;
123 scale.
minSizeMM = mSpinBoxMinSize->value();
125 scale.
maxSizeMM = mSpinBoxMaxSize->value();
137 mMapScaleButton->setVisible(
false );
138 mMapScaleButton->setToolTip( tr(
"Adjust scaling range" ) );
140 setFocusPolicy( Qt::StrongFocus );
141 setFocusProxy( mUnitCombo );
143 connect( mUnitCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsUnitSelectionWidget::toggleUnitRangeButton );
144 connect( mMapScaleButton, &QToolButton::clicked,
this, &QgsUnitSelectionWidget::showDialog );
150 blockSignals(
true );
151 mUnitCombo->addItems( units );
152 mMapUnitIdx = mapUnitIdx;
153 blockSignals(
false );
158 blockSignals(
true );
193 blockSignals(
false );
198 if ( mUnitCombo->count() == 0 )
201 const QVariant currentData = mUnitCombo->currentData();
202 if ( currentData.isValid() )
212 blockSignals(
true );
213 mUnitCombo->setCurrentIndex( unitIndex );
214 blockSignals(
false );
219 const int idx = mUnitCombo->findData( QVariant(
static_cast<int>(
unit ) ) );
220 mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
228void QgsUnitSelectionWidget::showDialog()
242 QgsMapUnitScaleDialog dlg(
this );
243 dlg.setMapUnitScale( mMapUnitScale );
244 dlg.setMapCanvas( mCanvas );
245 if ( dlg.exec() == QDialog::Accepted )
247 if ( mMapUnitScale != dlg.getMapUnitScale() )
249 mMapUnitScale = dlg.getMapUnitScale();
255void QgsUnitSelectionWidget::toggleUnitRangeButton()
263 mMapScaleButton->setVisible( mShowMapScaleButton && mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
267void QgsUnitSelectionWidget::widgetChanged(
const QgsMapUnitScale &scale )
269 mMapUnitScale = scale;
275 return mShowMapScaleButton;
280 mShowMapScaleButton = show;
282 mMapScaleButton->hide();
290 QVBoxLayout *vLayout =
new QVBoxLayout();
292 vLayout->addWidget( mWidget );
293 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
294 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsMapUnitScaleDialog::accept );
295 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsMapUnitScaleDialog::reject );
296 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsMapUnitScaleDialog::showHelp );
297 vLayout->addWidget( bbox );
298 setLayout( vLayout );
299 setWindowTitle( tr(
"Adjust Scaling Range" ) );
304 return mWidget->mapUnitScale();
309 mWidget->setMapUnitScale( scale );
314 mWidget->setMapCanvas( canvas );
317void QgsMapUnitScaleDialog::showHelp()
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.
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.