Skip to content
Permalink
Browse files

[layouts] Use standard CRS selector widget for map grid CRS choice

instead of custom button

Fixes #26548
  • Loading branch information
nyalldawson committed Sep 23, 2020
1 parent c3a26db commit 4c7fbc0260ef95f7dd6dd4b6954ee2086ad3da70
@@ -76,7 +76,6 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
connect( mGridFrameFill1ColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFrameFill1ColorButton_colorChanged );
connect( mGridFrameFill2ColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFrameFill2ColorButton_colorChanged );
connect( mGridTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mGridTypeComboBox_currentIndexChanged );
connect( mMapGridCRSButton, &QPushButton::clicked, this, &QgsLayoutMapGridWidget::mMapGridCRSButton_clicked );
connect( mMapGridUnitComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::intervalUnitChanged );
connect( mGridBlendComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mGridBlendComboBox_currentIndexChanged );
connect( mCheckGridLeftSide, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mCheckGridLeftSide_toggled );
@@ -109,6 +108,10 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
connect( mEnabledCheckBox, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::gridEnabledToggled );
setPanelTitle( tr( "Map Grid Properties" ) );

mMapGridCrsSelector->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
mMapGridCrsSelector->setNotSetText( tr( "Use Map CRS" ) );

connect( mMapGridCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsLayoutMapGridWidget::mapGridCrsChanged );

blockAllSignals( true );

@@ -631,10 +634,7 @@ void QgsLayoutMapGridWidget::setGridItems()
mMinWidthSpinBox->setValue( mMapGrid->minimumIntervalWidth() );
mMaxWidthSpinBox->setValue( mMapGrid->maximumIntervalWidth() );

//CRS button
QgsCoordinateReferenceSystem gridCrs = mMapGrid->crs();
QString crsButtonText = gridCrs.isValid() ? gridCrs.authid() : tr( "Change…" );
mMapGridCRSButton->setText( crsButtonText );
whileBlocking( mMapGridCrsSelector )->setCrs( mMapGrid->crs() );
}

void QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished()
@@ -1144,25 +1144,21 @@ void QgsLayoutMapGridWidget::mGridTypeComboBox_currentIndexChanged( int )
mMap->endCommand();
}

void QgsLayoutMapGridWidget::mMapGridCRSButton_clicked()
void QgsLayoutMapGridWidget::mapGridCrsChanged( const QgsCoordinateReferenceSystem &crs )
{
if ( !mMapGrid || !mMap )
{
return;
}

QgsProjectionSelectionDialog crsDialog( this );
QgsCoordinateReferenceSystem crs = mMapGrid->crs();
crsDialog.setCrs( crs.isValid() ? crs : mMap->crs() );
if ( mMapGrid->crs() == crs )
return;

if ( crsDialog.exec() == QDialog::Accepted )
{
mMap->beginCommand( tr( "Change Grid CRS" ) );
mMapGrid->setCrs( crsDialog.crs() );
mMap->updateBoundingRect();
mMapGridCRSButton->setText( crsDialog.crs().authid() );
mMap->endCommand();
}
mMap->beginCommand( tr( "Change Grid CRS" ) );
mMapGrid->setCrs( crs );
mMap->updateBoundingRect();
mMap->update();
mMap->endCommand();
}

void QgsLayoutMapGridWidget::mDrawAnnotationGroupBox_toggled( bool state )
@@ -65,7 +65,7 @@ class GUI_EXPORT QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private
void mGridFrameFill1ColorButton_colorChanged( const QColor &newColor );
void mGridFrameFill2ColorButton_colorChanged( const QColor &newColor );
void mGridTypeComboBox_currentIndexChanged( int );
void mMapGridCRSButton_clicked();
void mapGridCrsChanged( const QgsCoordinateReferenceSystem &crs );
void mGridBlendComboBox_currentIndexChanged( int index );
void mCheckGridLeftSide_toggled( bool checked );
void mCheckGridRightSide_toggled( bool checked );
@@ -48,8 +48,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>1600</height>
<width>425</width>
<height>1660</height>
</rect>
</property>
<property name="sizePolicy">
@@ -108,56 +108,32 @@
<string>Appearance</string>
</property>
<layout class="QGridLayout" name="gridLayout_6" columnstretch="0,0,0">
<item row="3" column="1" colspan="2">
<widget class="QPushButton" name="mMapGridCRSButton">
<item row="7" column="0">
<widget class="QLabel" name="mCrossWidthLabel">
<property name="text">
<string>Change…</string>
<string>Cross width</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<layout class="QGridLayout" name="gridLayout_5">
<item row="2" column="1">
<widget class="QgsPropertyOverrideButton" name="mOffsetYDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsPropertyOverrideButton" name="mOffsetXDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QgsDoubleSpinBox" name="mOffsetYSpinBox">
<property name="prefix">
<string>Y </string>
</property>
<property name="decimals">
<number>12</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QgsDoubleSpinBox" name="mOffsetXSpinBox">
<property name="prefix">
<string>X </string>
</property>
<property name="decimals">
<number>12</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="mGridTypeComboBox"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="mGridBlendLabel">
<property name="text">
<string>Blend mode</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mMapGridCRSLabel">
<property name="text">
<string>CRS</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QgsDoubleSpinBox" name="mCrossWidthSpinBox">
@@ -172,6 +148,33 @@
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QgsProjectionSelectionWidget" name="mMapGridCrsSelector" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mLineStyleLabel">
<property name="text">
<string>Line style</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mIntervalXLabel_2">
<property name="text">
<string>Interval</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QgsSymbolButton" name="mGridLineStyleButton">
<property name="sizePolicy">
@@ -331,30 +334,13 @@
</widget>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mLineStyleLabel">
<property name="text">
<string>Line style</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mIntervalXLabel_2">
<property name="text">
<string>Interval</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
<item row="10" column="1" colspan="2">
<widget class="QgsBlendModeComboBox" name="mGridBlendComboBox"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mCrossWidthLabel">
<item row="9" column="0">
<widget class="QLabel" name="mMarkerStyleLabel">
<property name="text">
<string>Cross width</string>
<string>Marker style</string>
</property>
<property name="wordWrap">
<bool>false</bool>
@@ -371,33 +357,6 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mMapGridCRSLabel">
<property name="text">
<string>CRS</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="mGridBlendLabel">
<property name="text">
<string>Blend mode</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QgsPropertyOverrideButton" name="mCrossWidthDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="mGridTypeComboBox"/>
</item>
<item row="10" column="1" colspan="2">
<widget class="QgsBlendModeComboBox" name="mGridBlendComboBox"/>
</item>
<item row="9" column="1" colspan="2">
<widget class="QgsSymbolButton" name="mGridMarkerStyleButton">
<property name="sizePolicy">
@@ -411,18 +370,59 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="mMarkerStyleLabel">
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="mMapGridUnitComboBox"/>
</item>
<item row="7" column="2">
<widget class="QgsPropertyOverrideButton" name="mCrossWidthDDBtn">
<property name="text">
<string>Marker style</string>
</property>
<property name="wordWrap">
<bool>false</bool>
<string>…</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="mMapGridUnitComboBox"/>
<item row="6" column="1" colspan="2">
<layout class="QGridLayout" name="gridLayout_5">
<item row="2" column="1">
<widget class="QgsPropertyOverrideButton" name="mOffsetYDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsPropertyOverrideButton" name="mOffsetXDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QgsDoubleSpinBox" name="mOffsetYSpinBox">
<property name="prefix">
<string>Y </string>
</property>
<property name="decimals">
<number>12</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QgsDoubleSpinBox" name="mOffsetXSpinBox">
<property name="prefix">
<string>X </string>
</property>
<property name="decimals">
<number>12</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
@@ -995,16 +995,22 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>qgsdoublespinbox.h</header>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFontButton</class>
@@ -1026,12 +1032,6 @@
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
@@ -1043,13 +1043,19 @@
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>mEnabledCheckBox</tabstop>
<tabstop>mEnabledDDBtn</tabstop>
<tabstop>mGridTypeComboBox</tabstop>
<tabstop>mMapGridCRSButton</tabstop>
<tabstop>mMapGridCrsSelector</tabstop>
<tabstop>mMapGridUnitComboBox</tabstop>
<tabstop>mMinWidthSpinBox</tabstop>
<tabstop>mMaxWidthSpinBox</tabstop>

0 comments on commit 4c7fbc0

Please sign in to comment.
You can’t perform that action at this time.