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();
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()
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" ) );
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.
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.