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 const QVariant currentData = mUnitCombo->currentData();
198 if ( currentData.isValid() )
208 blockSignals(
true );
209 mUnitCombo->setCurrentIndex( unitIndex );
210 blockSignals(
false );
215 const 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( mShowMapScaleButton && mMapUnitIdx != -1 && mUnitCombo->currentIndex() == mMapUnitIdx );
263 void QgsUnitSelectionWidget::widgetChanged(
const QgsMapUnitScale &scale )
265 mMapUnitScale = scale;
271 return mShowMapScaleButton;
276 mShowMapScaleButton = show;
278 mMapScaleButton->hide();
286 QVBoxLayout *vLayout =
new QVBoxLayout();
288 vLayout->addWidget( mWidget );
289 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
290 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsMapUnitScaleDialog::accept );
291 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsMapUnitScaleDialog::reject );
292 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsMapUnitScaleDialog::showHelp );
293 vLayout->addWidget( bbox );
294 setLayout( vLayout );
295 setWindowTitle( tr(
"Adjust Scaling Range" ) );
313 void QgsMapUnitScaleDialog::showHelp()
315 QgsHelp::openHelp( QStringLiteral(
"introduction/general_tools.html#unit-selector" ) );