20 #include <QDialogButtonBox> 26 mComboBoxMinScale->setScale( 10000000.0 );
27 mComboBoxMaxScale->setScale( 1 );
28 mSpinBoxMinSize->setShowClearButton(
false );
29 mSpinBoxMaxSize->setShowClearButton(
false );
30 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMinComboBox );
31 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::configureMaxComboBox );
36 connect( mCheckBoxMinSize, &QCheckBox::toggled, mSpinBoxMinSize, &QgsDoubleSpinBox::setEnabled );
37 connect( mCheckBoxMaxSize, &QCheckBox::toggled, mSpinBoxMaxSize, &QgsDoubleSpinBox::setEnabled );
40 connect( mCheckBoxMinScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
41 connect( mCheckBoxMaxScale, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
44 connect( mCheckBoxMinSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
45 connect( mCheckBoxMaxSize, &QCheckBox::toggled,
this, &QgsMapUnitScaleWidget::settingsChanged );
46 connect( mSpinBoxMinSize, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
47 connect( mSpinBoxMaxSize, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMapUnitScaleWidget::settingsChanged );
48 mBlockSignals =
false;
56 mComboBoxMinScale->setScale( scale.
minScale > 0.0 ? scale.
minScale : 10000000 );
57 mCheckBoxMinScale->setChecked( scale.
minScale != 0.0 );
58 mComboBoxMinScale->setEnabled( scale.
minScale != 0.0 );
60 mCheckBoxMaxScale->setChecked( scale.
maxScale > 0.0 );
61 mComboBoxMaxScale->setEnabled( scale.
maxScale > 0.0 );
65 mSpinBoxMinSize->setValue( scale.
minSizeMM );
69 mSpinBoxMaxSize->setValue( scale.
maxSizeMM );
70 mBlockSignals =
false;
77 mComboBoxMinScale->setMapCanvas( canvas );
78 mComboBoxMinScale->setShowCurrentScaleButton(
true );
79 mComboBoxMaxScale->setMapCanvas( canvas );
80 mComboBoxMaxScale->setShowCurrentScaleButton(
true );
83 void QgsMapUnitScaleWidget::configureMinComboBox()
85 mComboBoxMinScale->setEnabled( mCheckBoxMinScale->isChecked() );
86 if ( mCheckBoxMinScale->isChecked() && mComboBoxMinScale->scale() < mComboBoxMaxScale->scale() )
88 mComboBoxMinScale->setScale( mComboBoxMaxScale->scale() );
92 void QgsMapUnitScaleWidget::configureMaxComboBox()
94 mComboBoxMaxScale->setEnabled( mCheckBoxMaxScale->isChecked() );
95 if ( mCheckBoxMaxScale->isChecked() && mComboBoxMaxScale->scale() > mComboBoxMinScale->scale() )
97 mComboBoxMaxScale->setScale( mComboBoxMinScale->scale() );
101 void QgsMapUnitScaleWidget::settingsChanged()
112 scale.
minScale = mCheckBoxMinScale->isChecked() ? mComboBoxMinScale->scale() : 0;
113 scale.
maxScale = mCheckBoxMaxScale->isChecked() ? mComboBoxMaxScale->scale() : 0;
115 scale.
minSizeMM = mSpinBoxMinSize->value();
117 scale.
maxSizeMM = mSpinBoxMaxSize->value();
132 mMapScaleButton->setVisible(
false );
133 mMapScaleButton->setToolTip( tr(
"Adjust scaling range" ) );
135 setFocusPolicy( Qt::StrongFocus );
136 setFocusProxy( mUnitCombo );
138 connect( mUnitCombo, static_cast <
void ( QComboBox::* )(
int ) > ( &QComboBox::currentIndexChanged ),
this, &QgsUnitSelectionWidget::toggleUnitRangeButton );
139 connect( mMapScaleButton, &QPushButton::clicked,
this, &QgsUnitSelectionWidget::showDialog );
145 blockSignals(
true );
146 mUnitCombo->addItems( units );
147 mMapUnitIdx = mapUnitIdx;
148 blockSignals(
false );
153 blockSignals(
true );
188 blockSignals(
false );
193 if ( mUnitCombo->count() == 0 )
196 QVariant currentData = mUnitCombo->currentData();
197 if ( currentData.isValid() )
207 blockSignals(
true );
208 mUnitCombo->setCurrentIndex( unitIndex );
209 blockSignals(
false );
214 int idx = mUnitCombo->findData( QVariant( (
int ) unit ) );
215 mUnitCombo->setCurrentIndex( idx == -1 ? 0 : idx );
223 void QgsUnitSelectionWidget::showDialog()
240 if ( dlg.exec() == QDialog::Accepted )
250 void QgsUnitSelectionWidget::toggleUnitRangeButton()
258 mMapScaleButton->setVisible( mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
262 void QgsUnitSelectionWidget::widgetChanged(
const QgsMapUnitScale &scale )
264 mMapUnitScale = scale;
273 QVBoxLayout *vLayout =
new QVBoxLayout();
275 vLayout->addWidget( mWidget );
276 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
277 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsMapUnitScaleDialog::accept );
278 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsMapUnitScaleDialog::reject );
279 vLayout->addWidget( bbox );
280 setLayout( vLayout );
281 setWindowTitle( tr(
"Adjust Scaling Range" ) );
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
Meters value as Map units.
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
QgsMapUnitScaleDialog(QWidget *parent=nullptr)
Constructor for QgsMapUnitScaleDialog.
Percentage of another measurement (e.g., canvas size, feature size)
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Map canvas is a class for displaying all GIS data types on a canvas.
double maxScale
The maximum scale, or 0.0 if unset.
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
QgsMapUnitScale getMapUnitScale() const
Returns a QgsMapUnitScale representing the settings shown in the dialog.
void setMapUnitScale(const QgsMapUnitScale &scale)
Updates the dialog to reflect the settings from the specified QgsMapUnitScale object.
A dialog which allows the user to choose the minimum and maximum scale of an object in map units and ...
points (e.g., for font sizes)
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
Struct for storing maximum and minimum scales for measurements in map units.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the dialog.
double minScale
The minimum scale, or 0.0 if unset.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
RenderUnit
Rendering size units.