Skip to content

Commit 9de83cf

Browse files
committedApr 1, 2023
Secondary canvas extent options should be checkboxes, not radio buttons
Otherwise it is IMPOSSIBLE to disable one of the "sync extent" options after enabling them!
1 parent 8b319c4 commit 9de83cf

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed
 

‎src/app/qgsmapcanvasdockwidget.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,34 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
123123
mActionShowLabels->setChecked( true );
124124
connect( mActionShowLabels, &QAction::toggled, this, &QgsMapCanvasDockWidget::showLabels );
125125

126-
127-
mSyncExtentRadio = settingsAction->syncExtentRadio();
128-
mSyncSelectionRadio = settingsAction->syncSelectionRadio();
126+
mSyncExtentCheck = settingsAction->syncExtentCheck();
127+
mSyncSelectionCheck = settingsAction->syncSelectionCheck();
129128
mScaleCombo = settingsAction->scaleCombo();
130129
mRotationEdit = settingsAction->rotationSpinBox();
131130
mMagnificationEdit = settingsAction->magnifierSpinBox();
132131
mSyncScaleCheckBox = settingsAction->syncScaleCheckBox();
133132
mScaleFactorWidget = settingsAction->scaleFactorSpinBox();
134133

135-
connect( mSyncSelectionRadio, &QRadioButton::toggled, this, [ = ]( bool checked )
134+
connect( mSyncSelectionCheck, &QCheckBox::toggled, this, [ = ]( bool checked )
136135
{
137136
autoZoomToSelection( checked );
138137
if ( checked )
139138
{
140139
syncSelection();
140+
141+
// sync extent and selection options are mutually exclusive
142+
whileBlocking( mSyncExtentCheck )->setChecked( false );
141143
}
142144
} );
143145

144-
connect( mSyncExtentRadio, &QRadioButton::toggled, this, [ = ]( bool checked )
146+
connect( mSyncExtentCheck, &QCheckBox::toggled, this, [ = ]( bool checked )
145147
{
146148
if ( checked )
147149
{
148150
syncViewCenter( mMainCanvas );
151+
152+
// sync extent and selection options are mutually exclusive
153+
whileBlocking( mSyncSelectionCheck )->setChecked( false );
149154
}
150155
} );
151156

@@ -222,7 +227,7 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
222227
connect( &mResizeTimer, &QTimer::timeout, this, [ = ]
223228
{
224229
mBlockExtentSync = false;
225-
if ( mSyncExtentRadio->isChecked() )
230+
if ( mSyncExtentCheck->isChecked() )
226231
syncViewCenter( mMainCanvas );
227232
} );
228233

@@ -257,22 +262,22 @@ QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
257262

258263
void QgsMapCanvasDockWidget::setViewCenterSynchronized( bool enabled )
259264
{
260-
mSyncExtentRadio->setChecked( enabled );
265+
mSyncExtentCheck->setChecked( enabled );
261266
}
262267

263268
bool QgsMapCanvasDockWidget::isViewCenterSynchronized() const
264269
{
265-
return mSyncExtentRadio->isChecked();
270+
return mSyncExtentCheck->isChecked();
266271
}
267272

268273
bool QgsMapCanvasDockWidget::isAutoZoomToSelected() const
269274
{
270-
return mSyncSelectionRadio->isChecked();
275+
return mSyncSelectionCheck->isChecked();
271276
}
272277

273278
void QgsMapCanvasDockWidget::setAutoZoomToSelected( bool autoZoom )
274279
{
275-
mSyncSelectionRadio->setChecked( autoZoom );
280+
mSyncSelectionCheck->setChecked( autoZoom );
276281
}
277282

278283
void QgsMapCanvasDockWidget::setCursorMarkerVisible( bool visible )
@@ -392,7 +397,7 @@ void QgsMapCanvasDockWidget::mapExtentChanged()
392397
mScaleFactorWidget->setValue( newScaleFactor );
393398
}
394399

395-
if ( mSyncExtentRadio->isChecked() )
400+
if ( mSyncExtentCheck->isChecked() )
396401
syncViewCenter( sourceCanvas );
397402
}
398403

@@ -537,11 +542,11 @@ QgsMapSettingsAction::QgsMapSettingsAction( QWidget *parent )
537542
QGridLayout *gLayout = new QGridLayout();
538543
gLayout->setContentsMargins( 3, 2, 3, 2 );
539544

540-
mSyncExtentRadio = new QRadioButton( tr( "Synchronize View Center with Main Map" ) );
541-
gLayout->addWidget( mSyncExtentRadio, 0, 0, 1, 2 );
545+
mSyncExtentCheck = new QCheckBox( tr( "Synchronize View Center with Main Map" ) );
546+
gLayout->addWidget( mSyncExtentCheck, 0, 0, 1, 2 );
542547

543-
mSyncSelectionRadio = new QRadioButton( tr( "Synchronize View to Selection" ) );
544-
gLayout->addWidget( mSyncSelectionRadio, 1, 0, 1, 2 );
548+
mSyncSelectionCheck = new QCheckBox( tr( "Synchronize View to Selection" ) );
549+
gLayout->addWidget( mSyncSelectionCheck, 1, 0, 1, 2 );
545550

546551
QLabel *label = new QLabel( tr( "Scale" ) );
547552
gLayout->addWidget( label, 2, 0 );

‎src/app/qgsmapcanvasdockwidget.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
173173
QgsMapCanvas *mMainCanvas = nullptr;
174174
QMenu *mMenu = nullptr;
175175
QList<QAction *> mMenuPresetActions;
176-
QRadioButton *mSyncExtentRadio = nullptr;
177-
QRadioButton *mSyncSelectionRadio = nullptr;
176+
QCheckBox *mSyncExtentCheck = nullptr;
177+
QCheckBox *mSyncSelectionCheck = nullptr;
178178
QgsScaleComboBox *mScaleCombo = nullptr;
179179
QgsDoubleSpinBox *mRotationEdit = nullptr;
180180
QgsDoubleSpinBox *mMagnificationEdit = nullptr;
@@ -206,17 +206,17 @@ class QgsMapSettingsAction: public QWidgetAction
206206

207207
QgsMapSettingsAction( QWidget *parent = nullptr );
208208

209-
QRadioButton *syncExtentRadio() { return mSyncExtentRadio; }
210-
QRadioButton *syncSelectionRadio() { return mSyncSelectionRadio; }
209+
QCheckBox *syncExtentCheck() { return mSyncExtentCheck; }
210+
QCheckBox *syncSelectionCheck() { return mSyncSelectionCheck; }
211211
QgsScaleComboBox *scaleCombo() { return mScaleCombo; }
212212
QgsDoubleSpinBox *rotationSpinBox() { return mRotationWidget; }
213213
QgsDoubleSpinBox *magnifierSpinBox() { return mMagnifierWidget; }
214214
QgsDoubleSpinBox *scaleFactorSpinBox() { return mScaleFactorWidget; }
215215
QCheckBox *syncScaleCheckBox() { return mSyncScaleCheckBox; }
216216

217217
private:
218-
QRadioButton *mSyncSelectionRadio = nullptr;
219-
QRadioButton *mSyncExtentRadio = nullptr;
218+
QCheckBox *mSyncSelectionCheck = nullptr;
219+
QCheckBox *mSyncExtentCheck = nullptr;
220220
QgsScaleComboBox *mScaleCombo = nullptr;
221221
QgsDoubleSpinBox *mRotationWidget = nullptr;
222222
QgsDoubleSpinBox *mMagnifierWidget = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.