Skip to content

Commit cb7416a

Browse files
committedMar 28, 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 fe3818d commit cb7416a

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
@@ -122,29 +122,34 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
122122
mActionShowLabels->setChecked( true );
123123
connect( mActionShowLabels, &QAction::toggled, this, &QgsMapCanvasDockWidget::showLabels );
124124

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

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

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

@@ -221,7 +226,7 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
221226
connect( &mResizeTimer, &QTimer::timeout, this, [ = ]
222227
{
223228
mBlockExtentSync = false;
224-
if ( mSyncExtentRadio->isChecked() )
229+
if ( mSyncExtentCheck->isChecked() )
225230
syncViewCenter( mMainCanvas );
226231
} );
227232

@@ -256,22 +261,22 @@ QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
256261

257262
void QgsMapCanvasDockWidget::setViewCenterSynchronized( bool enabled )
258263
{
259-
mSyncExtentRadio->setChecked( enabled );
264+
mSyncExtentCheck->setChecked( enabled );
260265
}
261266

262267
bool QgsMapCanvasDockWidget::isViewCenterSynchronized() const
263268
{
264-
return mSyncExtentRadio->isChecked();
269+
return mSyncExtentCheck->isChecked();
265270
}
266271

267272
bool QgsMapCanvasDockWidget::isAutoZoomToSelected() const
268273
{
269-
return mSyncSelectionRadio->isChecked();
274+
return mSyncSelectionCheck->isChecked();
270275
}
271276

272277
void QgsMapCanvasDockWidget::setAutoZoomToSelected( bool autoZoom )
273278
{
274-
mSyncSelectionRadio->setChecked( autoZoom );
279+
mSyncSelectionCheck->setChecked( autoZoom );
275280
}
276281

277282
void QgsMapCanvasDockWidget::setCursorMarkerVisible( bool visible )
@@ -391,7 +396,7 @@ void QgsMapCanvasDockWidget::mapExtentChanged()
391396
mScaleFactorWidget->setValue( newScaleFactor );
392397
}
393398

394-
if ( mSyncExtentRadio->isChecked() )
399+
if ( mSyncExtentCheck->isChecked() )
395400
syncViewCenter( sourceCanvas );
396401
}
397402

@@ -536,11 +541,11 @@ QgsMapSettingsAction::QgsMapSettingsAction( QWidget *parent )
536541
QGridLayout *gLayout = new QGridLayout();
537542
gLayout->setContentsMargins( 3, 2, 3, 2 );
538543

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

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

545550
QLabel *label = new QLabel( tr( "Scale" ) );
546551
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.