@@ -33,8 +33,6 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
33
33
, mMapGrid( mapGrid )
34
34
{
35
35
setupUi ( this );
36
- connect ( mGridLineStyleButton , &QPushButton::clicked, this , &QgsLayoutMapGridWidget::mGridLineStyleButton_clicked );
37
- connect ( mGridMarkerStyleButton , &QPushButton::clicked, this , &QgsLayoutMapGridWidget::mGridMarkerStyleButton_clicked );
38
36
connect ( mIntervalXSpinBox , &QgsDoubleSpinBox::editingFinished, this , &QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished );
39
37
connect ( mIntervalYSpinBox , &QgsDoubleSpinBox::editingFinished, this , &QgsLayoutMapGridWidget::mIntervalYSpinBox_editingFinished );
40
38
connect ( mOffsetXSpinBox , static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this , &QgsLayoutMapGridWidget::mOffsetXSpinBox_valueChanged );
@@ -139,79 +137,25 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
139
137
mGridFrameFill2ColorButton ->setNoColorString ( tr ( " Transparent fill" ) );
140
138
mGridFrameFill2ColorButton ->setShowNoColor ( true );
141
139
140
+ mGridLineStyleButton ->setSymbolType ( QgsSymbol::Line );
141
+ mGridMarkerStyleButton ->setSymbolType ( QgsSymbol::Marker );
142
+
142
143
// set initial state of frame style controls
143
144
toggleFrameControls ( false , false , false );
144
145
145
146
updateGuiElements ();
146
147
147
148
blockAllSignals ( false );
148
149
connect ( mAnnotationFontButton , &QgsFontButton::changed, this , &QgsLayoutMapGridWidget::annotationFontChanged );
150
+ connect ( mGridLineStyleButton , &QgsSymbolButton::changed, this , &QgsLayoutMapGridWidget::lineSymbolChanged );
151
+ connect ( mGridMarkerStyleButton , &QgsSymbolButton::changed, this , &QgsLayoutMapGridWidget::markerSymbolChanged );
149
152
}
150
153
151
154
void QgsLayoutMapGridWidget::populateDataDefinedButtons ()
152
155
{
153
156
// none for now
154
157
}
155
158
156
-
157
- void QgsLayoutMapGridWidget::updateGridLineStyleFromWidget ()
158
- {
159
- if ( !mMapGrid || !mMap )
160
- {
161
- return ;
162
- }
163
-
164
- QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender () );
165
- mMapGrid ->setLineSymbol ( dynamic_cast < QgsLineSymbol * >( w->symbol ()->clone () ) );
166
- mMap ->update ();
167
- }
168
-
169
- void QgsLayoutMapGridWidget::cleanUpGridLineStyleSelector ( QgsPanelWidget *container )
170
- {
171
- QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
172
- if ( !w )
173
- return ;
174
-
175
- delete w->symbol ();
176
-
177
- if ( !mMapGrid || !mMap )
178
- {
179
- return ;
180
- }
181
-
182
- updateGridLineSymbolMarker ();
183
- mMap ->endCommand ();
184
- }
185
-
186
- void QgsLayoutMapGridWidget::updateGridMarkerStyleFromWidget ()
187
- {
188
- if ( !mMapGrid || !mMap )
189
- {
190
- return ;
191
- }
192
-
193
- QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( sender () );
194
- mMapGrid ->setMarkerSymbol ( dynamic_cast < QgsMarkerSymbol * >( w->symbol ()->clone () ) );
195
- mMap ->update ();
196
- }
197
-
198
- void QgsLayoutMapGridWidget::cleanUpGridMarkerStyleSelector ( QgsPanelWidget *container )
199
- {
200
- QgsSymbolSelectorWidget *w = qobject_cast<QgsSymbolSelectorWidget *>( container );
201
- if ( !w )
202
- return ;
203
-
204
- delete w->symbol ();
205
-
206
- if ( !mMapGrid || !mMap )
207
- {
208
- return ;
209
- }
210
-
211
- updateGridMarkerSymbolMarker ();
212
- mMap ->endCommand ();
213
- }
214
-
215
159
void QgsLayoutMapGridWidget::setGuiElementValues ()
216
160
{
217
161
updateGuiElements ();
@@ -256,6 +200,7 @@ void QgsLayoutMapGridWidget::blockAllSignals( bool block )
256
200
mFrameDivisionsRightComboBox ->blockSignals ( block );
257
201
mFrameDivisionsTopComboBox ->blockSignals ( block );
258
202
mFrameDivisionsBottomComboBox ->blockSignals ( block );
203
+ mGridMarkerStyleButton ->blockSignals ( block );
259
204
260
205
// grid annotation
261
206
mDrawAnnotationGroupBox ->blockSignals ( block );
@@ -493,6 +438,9 @@ void QgsLayoutMapGridWidget::setGridItems()
493
438
return ;
494
439
}
495
440
441
+ mGridMarkerStyleButton ->registerExpressionContextGenerator ( mMapGrid );
442
+ mGridLineStyleButton ->registerExpressionContextGenerator ( mMapGrid );
443
+
496
444
mIntervalXSpinBox ->setValue ( mMapGrid ->intervalX () );
497
445
mIntervalYSpinBox ->setValue ( mMapGrid ->intervalY () );
498
446
mOffsetXSpinBox ->setValue ( mMapGrid ->offsetX () );
@@ -595,9 +543,9 @@ void QgsLayoutMapGridWidget::setGridItems()
595
543
initFrameDisplayBox ( mFrameDivisionsBottomComboBox , mMapGrid ->frameDivisions ( QgsLayoutItemMapGrid::Bottom ) );
596
544
597
545
// line style
598
- updateGridLineSymbolMarker ( );
546
+ mGridLineStyleButton -> setSymbol ( mMapGrid -> lineSymbol ()-> clone () );
599
547
// marker style
600
- updateGridMarkerSymbolMarker ( );
548
+ mGridMarkerStyleButton -> setSymbol ( mMapGrid -> markerSymbol ()-> clone () );
601
549
602
550
mGridBlendComboBox ->setBlendMode ( mMapGrid ->blendMode () );
603
551
@@ -646,80 +594,6 @@ void QgsLayoutMapGridWidget::setGridItems()
646
594
mMapGridCRSButton ->setText ( crsButtonText );
647
595
}
648
596
649
- void QgsLayoutMapGridWidget::updateGridLineSymbolMarker ()
650
- {
651
- if ( mMapGrid )
652
- {
653
- QgsLineSymbol *nonConstSymbol = const_cast <QgsLineSymbol *>( mMapGrid ->lineSymbol () ); // bad
654
- QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon ( nonConstSymbol, mGridLineStyleButton ->iconSize () );
655
- mGridLineStyleButton ->setIcon ( icon );
656
- }
657
- }
658
-
659
- void QgsLayoutMapGridWidget::updateGridMarkerSymbolMarker ()
660
- {
661
- if ( mMapGrid )
662
- {
663
- QgsMarkerSymbol *nonConstSymbol = const_cast <QgsMarkerSymbol *>( mMapGrid ->markerSymbol () ); // bad
664
- QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon ( nonConstSymbol, mGridMarkerStyleButton ->iconSize () );
665
- mGridMarkerStyleButton ->setIcon ( icon );
666
- }
667
- }
668
-
669
- void QgsLayoutMapGridWidget::mGridLineStyleButton_clicked ()
670
- {
671
- if ( !mMapGrid || !mMap )
672
- {
673
- return ;
674
- }
675
-
676
- #if 0 //TODO
677
- // use the atlas coverage layer, if any
678
- QgsVectorLayer *coverageLayer = atlasCoverageLayer();
679
- #endif
680
- QgsVectorLayer *coverageLayer = nullptr ;
681
-
682
- QgsLineSymbol *newSymbol = static_cast <QgsLineSymbol *>( mMapGrid ->lineSymbol ()->clone () );
683
- QgsExpressionContext context = mMap ->createExpressionContext ();
684
-
685
- QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget ( newSymbol, QgsStyle::defaultStyle (), coverageLayer, nullptr );
686
- QgsSymbolWidgetContext symbolContext;
687
- symbolContext.setExpressionContext ( &context );
688
- d->setContext ( symbolContext );
689
-
690
- connect ( d, &QgsPanelWidget::widgetChanged, this , &QgsLayoutMapGridWidget::updateGridLineStyleFromWidget );
691
- connect ( d, &QgsPanelWidget::panelAccepted, this , &QgsLayoutMapGridWidget::cleanUpGridLineStyleSelector );
692
- openPanel ( d );
693
- mMap ->beginCommand ( tr ( " Grid line style changed" ) );
694
- }
695
-
696
- void QgsLayoutMapGridWidget::mGridMarkerStyleButton_clicked ()
697
- {
698
- if ( !mMapGrid || !mMap )
699
- {
700
- return ;
701
- }
702
-
703
- #if 0 //TODO
704
- // use the atlas coverage layer, if any
705
- QgsVectorLayer *coverageLayer = atlasCoverageLayer();
706
- #endif
707
- QgsVectorLayer *coverageLayer = nullptr ;
708
-
709
- QgsMarkerSymbol *newSymbol = static_cast <QgsMarkerSymbol *>( mMapGrid ->markerSymbol ()->clone () );
710
- QgsExpressionContext context = mMap ->createExpressionContext ();
711
-
712
- QgsSymbolSelectorWidget *d = new QgsSymbolSelectorWidget ( newSymbol, QgsStyle::defaultStyle (), coverageLayer, nullptr );
713
- QgsSymbolWidgetContext symbolContext;
714
- symbolContext.setExpressionContext ( &context );
715
- d->setContext ( symbolContext );
716
-
717
- connect ( d, &QgsPanelWidget::widgetChanged, this , &QgsLayoutMapGridWidget::updateGridMarkerStyleFromWidget );
718
- connect ( d, &QgsPanelWidget::panelAccepted, this , &QgsLayoutMapGridWidget::cleanUpGridMarkerStyleSelector );
719
- openPanel ( d );
720
- mMap ->beginCommand ( tr ( " Grid markers style changed" ) );
721
- }
722
-
723
597
void QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished ()
724
598
{
725
599
if ( !mMapGrid || !mMap )
@@ -1221,6 +1095,32 @@ void QgsLayoutMapGridWidget::annotationFontChanged()
1221
1095
mMap ->endCommand ();
1222
1096
}
1223
1097
1098
+ void QgsLayoutMapGridWidget::lineSymbolChanged ()
1099
+ {
1100
+ if ( !mMapGrid || !mMap )
1101
+ {
1102
+ return ;
1103
+ }
1104
+
1105
+ mMap ->beginCommand ( tr ( " Change Grid Line Style" ), QgsLayoutItem::UndoMapGridLineSymbol );
1106
+ mMapGrid ->setLineSymbol ( mGridLineStyleButton ->clonedSymbol <QgsLineSymbol>() );
1107
+ mMap ->endCommand ();
1108
+ mMap ->update ();
1109
+ }
1110
+
1111
+ void QgsLayoutMapGridWidget::markerSymbolChanged ()
1112
+ {
1113
+ if ( !mMapGrid || !mMap )
1114
+ {
1115
+ return ;
1116
+ }
1117
+
1118
+ mMap ->beginCommand ( tr ( " Change Grid Marker Style" ), QgsLayoutItem::UndoMapGridMarkerSymbol );
1119
+ mMapGrid ->setMarkerSymbol ( mGridMarkerStyleButton ->clonedSymbol <QgsMarkerSymbol>() );
1120
+ mMap ->endCommand ();
1121
+ mMap ->update ();
1122
+ }
1123
+
1224
1124
void QgsLayoutMapGridWidget::mAnnotationFontColorButton_colorChanged ( const QColor &color )
1225
1125
{
1226
1126
if ( !mMapGrid || !mMap )
0 commit comments