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