21 #include <QDialogButtonBox>
27 mComboBoxMinScale->setScale( 10000000.0 );
28 mComboBoxMaxScale->setScale( 1 );
29 mSpinBoxMinSize->setShowClearButton(
false );
30 mSpinBoxMaxSize->setShowClearButton(
false );
31 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMinComboBox );
32 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMaxComboBox );
37 connect( mCheckBoxMinSize, &QCheckBox::toggled, mSpinBoxMinSize, &QgsDoubleSpinBox::setEnabled );
38 connect( mCheckBoxMaxSize, &QCheckBox::toggled, mSpinBoxMaxSize, &QgsDoubleSpinBox::setEnabled );
41 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
42 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
45 connect( mCheckBoxMinSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
46 connect( mCheckBoxMaxSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
47 connect( mSpinBoxMinSize,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
48 connect( mSpinBoxMaxSize,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
49 mBlockSignals =
false;
57 mComboBoxMinScale->setScale( scale.
minScale > 0.0 ? scale.
minScale : 10000000 );
58 mCheckBoxMinScale->setChecked( scale.
minScale != 0.0 );
59 mComboBoxMinScale->setEnabled( scale.
minScale != 0.0 );
61 mCheckBoxMaxScale->setChecked( scale.
maxScale > 0.0 );
62 mComboBoxMaxScale->setEnabled( scale.
maxScale > 0.0 );
66 mSpinBoxMinSize->setValue( scale.
minSizeMM );
70 mSpinBoxMaxSize->setValue( scale.
maxSizeMM );
71 mBlockSignals =
false;
78 mComboBoxMinScale->setMapCanvas( canvas );
79 mComboBoxMinScale->setShowCurrentScaleButton(
true );
80 mComboBoxMaxScale->setMapCanvas( canvas );
81 mComboBoxMaxScale->setShowCurrentScaleButton(
true );
84 void QgsMapUnitScaleWidget::configureMinComboBox()
86 mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
87 if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() < mComboBoxMaxScale->scale() )
89 mComboBoxMinScale->setScale( mComboBoxMaxScale->scale() );
93 void QgsMapUnitScaleWidget::configureMaxComboBox()
95 mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
96 if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() > mComboBoxMinScale->scale() )
98 mComboBoxMaxScale->setScale( mComboBoxMinScale->scale() );
102 void QgsMapUnitScaleWidget::settingsChanged()
113 scale.
minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
114 scale.
maxScale = mCheckBoxMaxScale->isChecked() ? mComboBoxMaxScale->scale() : 0;
116 scale.
minSizeMM = mSpinBoxMinSize->value();
118 scale.
maxSizeMM = mSpinBoxMaxSize->value();
133 mMapScaleButton->setVisible(
false );
134 mMapScaleButton->setToolTip( tr(
"Adjust scaling range" ) );
136 setFocusPolicy( Qt::StrongFocus );
137 setFocusProxy( mUnitCombo );
139 connect( mUnitCombo,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsUnitSelectionWidget::toggleUnitRangeButton );
140 connect( mMapScaleButton, &QToolButton::clicked,
this, &QgsUnitSelectionWidget::showDialog );
146 blockSignals(
true );
147 mUnitCombo->addItems( units );
148 mMapUnitIdx = mapUnitIdx;
149 blockSignals(
false );
154 blockSignals(
true );
189 blockSignals(
false );
194 if ( mUnitCombo->count() == 0 )
197 QVariant currentData = mUnitCombo->currentData();
198 if ( currentData.isValid() )
208 blockSignals(
true );
209 mUnitCombo->setCurrentIndex( unitIndex );
210 blockSignals(
false );
215 int idx = mUnitCombo->findData( QVariant(
static_cast< int >(
unit ) ) );
216 mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
224 void QgsUnitSelectionWidget::showDialog()
239 dlg.setMapUnitScale( mMapUnitScale );
240 dlg.setMapCanvas( mCanvas );
241 if ( dlg.exec() == QDialog::Accepted )
243 if ( mMapUnitScale != dlg.getMapUnitScale() )
245 mMapUnitScale = dlg.getMapUnitScale();
251 void QgsUnitSelectionWidget::toggleUnitRangeButton()
259 mMapScaleButton->setVisible( mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
263 void QgsUnitSelectionWidget::widgetChanged(
const QgsMapUnitScale &scale )
265 mMapUnitScale = scale;
274 QVBoxLayout *vLayout =
new QVBoxLayout();
276 vLayout->addWidget( mWidget );
277 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
278 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsMapUnitScaleDialog::accept );
279 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsMapUnitScaleDialog::reject );
280 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsMapUnitScaleDialog::showHelp );
281 vLayout->addWidget( bbox );
282 setLayout( vLayout );
283 setWindowTitle( tr(
"Adjust Scaling Range" ) );
301 void QgsMapUnitScaleDialog::showHelp()
303 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#unit-selector" ) );
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< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
RenderUnit
Rendering size units.
@ RenderUnknownUnit
Mixed or unknown units.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.