23#include <QDialogButtonBox>
25#include "moc_qgsunitselectionwidget.cpp"
31 mComboBoxMinScale->setScale( 10000000.0 );
32 mComboBoxMaxScale->setScale( 1 );
33 mSpinBoxMinSize->setShowClearButton(
false );
34 mSpinBoxMaxSize->setShowClearButton(
false );
35 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMinComboBox );
36 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMaxComboBox );
41 connect( mCheckBoxMinSize, &QCheckBox::toggled, mSpinBoxMinSize, &QgsDoubleSpinBox::setEnabled );
42 connect( mCheckBoxMaxSize, &QCheckBox::toggled, mSpinBoxMaxSize, &QgsDoubleSpinBox::setEnabled );
45 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
46 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
49 connect( mCheckBoxMinSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
50 connect( mCheckBoxMaxSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
51 connect( mSpinBoxMinSize,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
52 connect( mSpinBoxMaxSize,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
53 mBlockSignals =
false;
61 mComboBoxMinScale->setScale( scale.
minScale > 0.0 ? scale.
minScale : 10000000 );
62 mCheckBoxMinScale->setChecked( scale.
minScale != 0.0 );
63 mComboBoxMinScale->setEnabled( scale.
minScale != 0.0 );
65 mCheckBoxMaxScale->setChecked( scale.
maxScale > 0.0 );
66 mComboBoxMaxScale->setEnabled( scale.
maxScale > 0.0 );
70 mSpinBoxMinSize->setValue( scale.
minSizeMM );
74 mSpinBoxMaxSize->setValue( scale.
maxSizeMM );
75 mBlockSignals =
false;
82 mComboBoxMinScale->setMapCanvas( canvas );
83 mComboBoxMinScale->setShowCurrentScaleButton(
true );
84 mComboBoxMaxScale->setMapCanvas( canvas );
85 mComboBoxMaxScale->setShowCurrentScaleButton(
true );
88void QgsMapUnitScaleWidget::configureMinComboBox()
90 mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
91 if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() < mComboBoxMaxScale->scale() )
93 mComboBoxMinScale->setScale( mComboBoxMaxScale->scale() );
97void QgsMapUnitScaleWidget::configureMaxComboBox()
99 mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
100 if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() > mComboBoxMinScale->scale() )
102 mComboBoxMaxScale->setScale( mComboBoxMinScale->scale() );
106void QgsMapUnitScaleWidget::settingsChanged()
117 scale.
minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
118 scale.
maxScale = mCheckBoxMaxScale->isChecked() ? mComboBoxMaxScale->scale() : 0;
120 scale.
minSizeMM = mSpinBoxMinSize->value();
122 scale.
maxSizeMM = mSpinBoxMaxSize->value();
134 mMapScaleButton->setVisible(
false );
135 mMapScaleButton->setToolTip( tr(
"Adjust scaling range" ) );
137 setFocusPolicy( Qt::StrongFocus );
138 setFocusProxy( mUnitCombo );
140 connect( mUnitCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsUnitSelectionWidget::toggleUnitRangeButton );
141 connect( mMapScaleButton, &QToolButton::clicked,
this, &QgsUnitSelectionWidget::showDialog );
147 blockSignals(
true );
148 mUnitCombo->addItems( units );
149 mMapUnitIdx = mapUnitIdx;
150 blockSignals(
false );
155 blockSignals(
true );
190 blockSignals(
false );
195 if ( mUnitCombo->count() == 0 )
198 const QVariant currentData = mUnitCombo->currentData();
199 if ( currentData.isValid() )
209 blockSignals(
true );
210 mUnitCombo->setCurrentIndex( unitIndex );
211 blockSignals(
false );
216 const int idx = mUnitCombo->findData( QVariant(
static_cast<int>(
unit ) ) );
217 mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
225void QgsUnitSelectionWidget::showDialog()
239 QgsMapUnitScaleDialog dlg(
this );
240 dlg.setMapUnitScale( mMapUnitScale );
241 dlg.setMapCanvas( mCanvas );
242 if ( dlg.exec() == QDialog::Accepted )
244 if ( mMapUnitScale != dlg.getMapUnitScale() )
246 mMapUnitScale = dlg.getMapUnitScale();
252void QgsUnitSelectionWidget::toggleUnitRangeButton()
260 mMapScaleButton->setVisible( mShowMapScaleButton && mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
264void QgsUnitSelectionWidget::widgetChanged(
const QgsMapUnitScale &scale )
266 mMapUnitScale = scale;
272 return mShowMapScaleButton;
277 mShowMapScaleButton = show;
279 mMapScaleButton->hide();
287 QVBoxLayout *vLayout =
new QVBoxLayout();
289 vLayout->addWidget( mWidget );
290 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
291 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsMapUnitScaleDialog::accept );
292 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsMapUnitScaleDialog::reject );
293 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsMapUnitScaleDialog::showHelp );
294 vLayout->addWidget( bbox );
295 setLayout( vLayout );
296 setWindowTitle( tr(
"Adjust Scaling Range" ) );
301 return mWidget->mapUnitScale();
306 mWidget->setMapUnitScale( scale );
311 mWidget->setMapCanvas( canvas );
314void QgsMapUnitScaleDialog::showHelp()
316 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.
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.