QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgslayoutmapgridwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutmapgridwidget.cpp
3  ----------------------------
4  begin : October 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgslayoutmapgridwidget.h"
20 #include "qgssymbol.h"
21 #include "qgslayoutitemmap.h"
22 #include "qgsproject.h"
23 #include "qgssymbollayerutils.h"
24 #include "qgsstyle.h"
26 #include "qgslayout.h"
27 #include "qgsmapsettings.h"
29 #include "qgsvectorlayer.h"
30 #include "qgsprojectviewsettings.h"
31 #include "qgstextformatwidget.h"
32 #include "qgsguiutils.h"
33 #include "qgsmarkersymbol.h"
34 #include "qgslinesymbol.h"
35 
37  : QgsLayoutItemBaseWidget( nullptr, mapGrid )
38  , mMap( map )
39  , mMapGrid( mapGrid )
40 {
41  setupUi( this );
42 
43  mFrameStyleComboBox->addItem( tr( "No Frame" ), QgsLayoutItemMapGrid::NoFrame );
44  mFrameStyleComboBox->addItem( tr( "Zebra" ), QgsLayoutItemMapGrid::Zebra );
45  mFrameStyleComboBox->addItem( tr( "Zebra (Nautical)" ), QgsLayoutItemMapGrid::ZebraNautical );
46  mFrameStyleComboBox->addItem( tr( "Interior Ticks" ), QgsLayoutItemMapGrid::InteriorTicks );
47  mFrameStyleComboBox->addItem( tr( "Exterior Ticks" ), QgsLayoutItemMapGrid::ExteriorTicks );
48  mFrameStyleComboBox->addItem( tr( "Interior and Exterior Ticks" ), QgsLayoutItemMapGrid::InteriorExteriorTicks );
49  mFrameStyleComboBox->addItem( tr( "Line Border" ), QgsLayoutItemMapGrid::LineBorder );
50  mFrameStyleComboBox->addItem( tr( "Line Border (Nautical)" ), QgsLayoutItemMapGrid::LineBorderNautical );
51 
52  mRotatedTicksLengthModeComboBox->addItem( tr( "Orthogonal" ), QgsLayoutItemMapGrid::OrthogonalTicks );
53  mRotatedTicksLengthModeComboBox->addItem( tr( "Fixed Length" ), QgsLayoutItemMapGrid::NormalizedTicks );
54  mRotatedAnnotationsLengthModeComboBox->addItem( tr( "Orthogonal" ), QgsLayoutItemMapGrid::OrthogonalTicks );
55  mRotatedAnnotationsLengthModeComboBox->addItem( tr( "Fixed Length" ), QgsLayoutItemMapGrid::NormalizedTicks );
56 
57  mGridFrameMarginSpinBox->setShowClearButton( true );
58  mGridFrameMarginSpinBox->setClearValue( 0 );
59 
60  mDistanceToMapFrameSpinBox->setShowClearButton( true );
61  mDistanceToMapFrameSpinBox->setClearValue( 0 );
62 
63  connect( mIntervalXSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished );
64  connect( mIntervalYSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsLayoutMapGridWidget::mIntervalYSpinBox_editingFinished );
65  connect( mOffsetXSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mOffsetXSpinBox_valueChanged );
66  connect( mOffsetYSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mOffsetYSpinBox_valueChanged );
67  connect( mCrossWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mCrossWidthSpinBox_valueChanged );
68  connect( mFrameWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mFrameWidthSpinBox_valueChanged );
69  connect( mGridFrameMarginSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mGridFrameMarginSpinBox_valueChanged );
70  connect( mFrameStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged );
71  connect( mRotatedTicksGroupBox, &QGroupBox::toggled, this, &QgsLayoutMapGridWidget::mRotatedTicksGroupBox_toggled );
72  connect( mRotatedTicksLengthModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mRotatedTicksLengthModeComboBox_currentIndexChanged );
73  connect( mRotatedTicksThresholdSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mRotatedTicksThresholdSpinBox_valueChanged );
74  connect( mRotatedTicksMarginToCornerSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mRotatedTicksMarginToCornerSpinBox_valueChanged );
75  connect( mRotatedAnnotationsGroupBox, &QGroupBox::toggled, this, &QgsLayoutMapGridWidget::mRotatedAnnotationsGroupBox_toggled );
76  connect( mRotatedAnnotationsLengthModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mRotatedAnnotationsLengthModeComboBox_currentIndexChanged );
77  connect( mRotatedAnnotationsThresholdSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mRotatedAnnotationsThresholdSpinBox_valueChanged );
78  connect( mRotatedAnnotationsMarginToCornerSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mRotatedAnnotationsMarginToCornerSpinBox_valueChanged );
79  connect( mGridFramePenSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mGridFramePenSizeSpinBox_valueChanged );
80  connect( mGridFramePenColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFramePenColorButton_colorChanged );
81  connect( mGridFrameFill1ColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFrameFill1ColorButton_colorChanged );
82  connect( mGridFrameFill2ColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFrameFill2ColorButton_colorChanged );
83  connect( mGridTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mGridTypeComboBox_currentIndexChanged );
84  connect( mMapGridUnitComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::intervalUnitChanged );
85  connect( mGridBlendComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mGridBlendComboBox_currentIndexChanged );
86  connect( mCheckGridLeftSide, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mCheckGridLeftSide_toggled );
87  connect( mCheckGridRightSide, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mCheckGridRightSide_toggled );
88  connect( mCheckGridTopSide, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mCheckGridTopSide_toggled );
89  connect( mCheckGridBottomSide, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mCheckGridBottomSide_toggled );
90  connect( mFrameDivisionsLeftComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameDivisionsLeftComboBox_currentIndexChanged );
91  connect( mFrameDivisionsRightComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameDivisionsRightComboBox_currentIndexChanged );
92  connect( mFrameDivisionsTopComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameDivisionsTopComboBox_currentIndexChanged );
93  connect( mFrameDivisionsBottomComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameDivisionsBottomComboBox_currentIndexChanged );
94  connect( mDrawAnnotationGroupBox, &QgsCollapsibleGroupBoxBasic::toggled, this, &QgsLayoutMapGridWidget::mDrawAnnotationGroupBox_toggled );
95  connect( mAnnotationFormatButton, &QToolButton::clicked, this, &QgsLayoutMapGridWidget::mAnnotationFormatButton_clicked );
96  connect( mAnnotationDisplayLeftComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDisplayLeftComboBox_currentIndexChanged );
97  connect( mAnnotationDisplayRightComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDisplayRightComboBox_currentIndexChanged );
98  connect( mAnnotationDisplayTopComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDisplayTopComboBox_currentIndexChanged );
99  connect( mAnnotationDisplayBottomComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDisplayBottomComboBox_currentIndexChanged );
100  connect( mAnnotationPositionLeftComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationPositionLeftComboBox_currentIndexChanged );
101  connect( mAnnotationPositionRightComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationPositionRightComboBox_currentIndexChanged );
102  connect( mAnnotationPositionTopComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationPositionTopComboBox_currentIndexChanged );
103  connect( mAnnotationPositionBottomComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationPositionBottomComboBox_currentIndexChanged );
104  connect( mAnnotationDirectionComboBoxLeft, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxLeft_currentIndexChanged );
105  connect( mAnnotationDirectionComboBoxRight, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxRight_currentIndexChanged );
106  connect( mAnnotationDirectionComboBoxTop, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxTop_currentIndexChanged );
107  connect( mAnnotationDirectionComboBoxBottom, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxBottom_currentIndexChanged );
108  connect( mAnnotationFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mAnnotationFormatComboBox_currentIndexChanged );
109  connect( mCoordinatePrecisionSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mCoordinatePrecisionSpinBox_valueChanged );
110  connect( mDistanceToMapFrameSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mDistanceToMapFrameSpinBox_valueChanged );
111  connect( mMinWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::minIntervalChanged );
112  connect( mMaxWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::maxIntervalChanged );
113  connect( mEnabledCheckBox, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::gridEnabledToggled );
114  setPanelTitle( tr( "Map Grid Properties" ) );
115 
116  mMapGridCrsSelector->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
117  mMapGridCrsSelector->setNotSetText( tr( "Use Map CRS" ) );
118  mMapGridCrsSelector->setDialogTitle( tr( "Grid CRS" ) );
119 
120  connect( mMapGridCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsLayoutMapGridWidget::mapGridCrsChanged );
121 
122  blockAllSignals( true );
123 
124  mMapGridUnitComboBox->addItem( tr( "Map Units" ), QgsLayoutItemMapGrid::MapUnit );
125  mMapGridUnitComboBox->addItem( tr( "Fit Segment Width" ), QgsLayoutItemMapGrid::DynamicPageSizeBased );
126  mMapGridUnitComboBox->addItem( tr( "Millimeters" ), QgsLayoutItemMapGrid::MM );
127  mMapGridUnitComboBox->addItem( tr( "Centimeters" ), QgsLayoutItemMapGrid::CM );
128 
129  mGridTypeComboBox->insertItem( 0, tr( "Solid" ), QgsLayoutItemMapGrid::Solid );
130  mGridTypeComboBox->insertItem( 1, tr( "Cross" ), QgsLayoutItemMapGrid::Cross );
131  mGridTypeComboBox->insertItem( 2, tr( "Markers" ), QgsLayoutItemMapGrid::Markers );
132  mGridTypeComboBox->insertItem( 3, tr( "Frame and annotations only" ), QgsLayoutItemMapGrid::FrameAnnotationsOnly );
133 
134  insertFrameDisplayEntries( mFrameDivisionsLeftComboBox );
135  insertFrameDisplayEntries( mFrameDivisionsRightComboBox );
136  insertFrameDisplayEntries( mFrameDivisionsTopComboBox );
137  insertFrameDisplayEntries( mFrameDivisionsBottomComboBox );
138 
139  insertAnnotationDisplayEntries( mAnnotationDisplayLeftComboBox );
140  insertAnnotationDisplayEntries( mAnnotationDisplayRightComboBox );
141  insertAnnotationDisplayEntries( mAnnotationDisplayTopComboBox );
142  insertAnnotationDisplayEntries( mAnnotationDisplayBottomComboBox );
143 
144  insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
145  insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
146  insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
147  insertAnnotationPositionEntries( mAnnotationPositionBottomComboBox );
148 
149  insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxLeft );
150  insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxRight );
151  insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxTop );
152  insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxBottom );
153 
154  mGridFramePenColorButton->setColorDialogTitle( tr( "Select Grid Frame Color" ) );
155  mGridFramePenColorButton->setAllowOpacity( true );
156  mGridFramePenColorButton->setContext( QStringLiteral( "composer" ) );
157  mGridFramePenColorButton->setNoColorString( tr( "Transparent Frame" ) );
158  mGridFramePenColorButton->setShowNoColor( true );
159 
160  mGridFrameFill1ColorButton->setColorDialogTitle( tr( "Select Grid Frame Fill Color" ) );
161  mGridFrameFill1ColorButton->setAllowOpacity( true );
162  mGridFrameFill1ColorButton->setContext( QStringLiteral( "composer" ) );
163  mGridFrameFill1ColorButton->setNoColorString( tr( "Transparent Fill" ) );
164  mGridFrameFill1ColorButton->setShowNoColor( true );
165 
166  mGridFrameFill2ColorButton->setColorDialogTitle( tr( "Select Grid Frame Fill Color" ) );
167  mGridFrameFill2ColorButton->setAllowOpacity( true );
168  mGridFrameFill2ColorButton->setContext( QStringLiteral( "composer" ) );
169  mGridFrameFill2ColorButton->setNoColorString( tr( "Transparent Fill" ) );
170  mGridFrameFill2ColorButton->setShowNoColor( true );
171 
172  mGridLineStyleButton->setSymbolType( Qgis::SymbolType::Line );
173  mGridMarkerStyleButton->setSymbolType( Qgis::SymbolType::Marker );
174 
175  //set initial state of frame style controls
176  toggleFrameControls( false, false, false, false );
177 
196 
197  // call to initially populate mAnnotationFormatComboBox
198  onCrsChanged();
199 
201 
202  blockAllSignals( false );
203  connect( mAnnotationFontButton, &QgsFontButton::changed, this, &QgsLayoutMapGridWidget::annotationTextFormatChanged );
204  connect( mGridLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapGridWidget::lineSymbolChanged );
205  connect( mGridMarkerStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapGridWidget::markerSymbolChanged );
206 
207  mGridLineStyleButton->registerExpressionContextGenerator( mMapGrid );
208  mGridLineStyleButton->setLayer( coverageLayer() );
209  mGridMarkerStyleButton->registerExpressionContextGenerator( mMapGrid );
210  mGridMarkerStyleButton->setLayer( coverageLayer() );
211  if ( mMap->layout() )
212  {
213  connect( &mMap->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mGridLineStyleButton, &QgsSymbolButton::setLayer );
214  connect( &mMap->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mGridMarkerStyleButton, &QgsSymbolButton::setLayer );
215  connect( &mMap->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mAnnotationFontButton, &QgsFontButton::setLayer );
216  }
217  mAnnotationFontButton->setLayer( coverageLayer() );
218  mAnnotationFontButton->registerExpressionContextGenerator( mMapGrid );
219 
220  connect( mMapGrid, &QgsLayoutItemMapGrid::crsChanged, this, &QgsLayoutMapGridWidget::onCrsChanged );
221 }
222 
224 {
225  updateDataDefinedButton( mEnabledDDBtn );
226  updateDataDefinedButton( mIntervalXDDBtn );
227  updateDataDefinedButton( mIntervalYDDBtn );
228  updateDataDefinedButton( mOffsetXDDBtn );
229  updateDataDefinedButton( mOffsetYDDBtn );
230  updateDataDefinedButton( mFrameSizeDDBtn );
231  updateDataDefinedButton( mFrameMarginDDBtn );
232  updateDataDefinedButton( mLabelDistDDBtn );
233  updateDataDefinedButton( mCrossWidthDDBtn );
234  updateDataDefinedButton( mFrameLineThicknessDDBtn );
235  updateDataDefinedButton( mAnnotationDisplayLeftDDBtn );
236  updateDataDefinedButton( mAnnotationDisplayRightDDBtn );
237  updateDataDefinedButton( mAnnotationDisplayTopDDBtn );
238  updateDataDefinedButton( mAnnotationDisplayBottomDDBtn );
239  updateDataDefinedButton( mFrameDivisionsLeftDDBtn );
240  updateDataDefinedButton( mFrameDivisionsRightDDBtn );
241  updateDataDefinedButton( mFrameDivisionsTopDDBtn );
242  updateDataDefinedButton( mFrameDivisionsBottomDDBtn );
243 }
244 
245 void QgsLayoutMapGridWidget::setGuiElementValues()
246 {
248 }
249 
251 {
252  if ( !mMapGrid || !mMap )
253  {
254  return;
255  }
256 
257  blockAllSignals( true );
259  setGridItems();
260  blockAllSignals( false );
261 }
262 
263 void QgsLayoutMapGridWidget::blockAllSignals( bool block )
264 {
265  //grid
266  mEnabledCheckBox->blockSignals( block );
267  mGridTypeComboBox->blockSignals( block );
268  mIntervalXSpinBox->blockSignals( block );
269  mIntervalYSpinBox->blockSignals( block );
270  mOffsetXSpinBox->blockSignals( block );
271  mOffsetYSpinBox->blockSignals( block );
272  mCrossWidthSpinBox->blockSignals( block );
273  mFrameStyleComboBox->blockSignals( block );
274  mFrameWidthSpinBox->blockSignals( block );
275  mGridFrameMarginSpinBox->blockSignals( block );
276  mGridLineStyleButton->blockSignals( block );
277  mMapGridUnitComboBox->blockSignals( block );
278  mGridFramePenSizeSpinBox->blockSignals( block );
279  mGridFramePenColorButton->blockSignals( block );
280  mGridFrameFill1ColorButton->blockSignals( block );
281  mGridFrameFill2ColorButton->blockSignals( block );
282  mGridBlendComboBox->blockSignals( block );
283  mCheckGridLeftSide->blockSignals( block );
284  mCheckGridRightSide->blockSignals( block );
285  mCheckGridTopSide->blockSignals( block );
286  mCheckGridBottomSide->blockSignals( block );
287  mFrameDivisionsLeftComboBox->blockSignals( block );
288  mFrameDivisionsRightComboBox->blockSignals( block );
289  mFrameDivisionsTopComboBox->blockSignals( block );
290  mFrameDivisionsBottomComboBox->blockSignals( block );
291  mGridMarkerStyleButton->blockSignals( block );
292 
293  //grid annotation
294  mDrawAnnotationGroupBox->blockSignals( block );
295  mAnnotationFormatComboBox->blockSignals( block );
296  mAnnotationDisplayLeftComboBox->blockSignals( block );
297  mAnnotationPositionLeftComboBox->blockSignals( block );
298  mAnnotationDirectionComboBoxLeft->blockSignals( block );
299  mAnnotationDisplayRightComboBox->blockSignals( block );
300  mAnnotationPositionRightComboBox->blockSignals( block );
301  mAnnotationDirectionComboBoxRight->blockSignals( block );
302  mAnnotationDisplayTopComboBox->blockSignals( block );
303  mAnnotationPositionTopComboBox->blockSignals( block );
304  mAnnotationDirectionComboBoxTop->blockSignals( block );
305  mAnnotationDisplayBottomComboBox->blockSignals( block );
306  mAnnotationPositionBottomComboBox->blockSignals( block );
307  mAnnotationDirectionComboBoxBottom->blockSignals( block );
308  mDistanceToMapFrameSpinBox->blockSignals( block );
309  mCoordinatePrecisionSpinBox->blockSignals( block );
310  mAnnotationFontButton->blockSignals( block );
311  mMinWidthSpinBox->blockSignals( block );
312  mMaxWidthSpinBox->blockSignals( block );
313 }
314 
315 void QgsLayoutMapGridWidget::handleChangedFrameDisplay( QgsLayoutItemMapGrid::BorderSide border, const QgsLayoutItemMapGrid::DisplayMode mode )
316 {
317  if ( !mMapGrid || !mMap )
318  {
319  return;
320  }
321 
322  mMap->beginCommand( tr( "Change Frame Divisions" ) );
323  mMapGrid->setFrameDivisions( mode, border );
324  mMap->endCommand();
325  mMap->updateBoundingRect();
326 }
327 
328 void QgsLayoutMapGridWidget::handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::BorderSide border, const QgsLayoutItemMapGrid::DisplayMode mode )
329 {
330  if ( !mMapGrid || !mMap )
331  {
332  return;
333  }
334 
335  mMap->beginCommand( tr( "Change Annotation Format" ) );
336  mMapGrid->setAnnotationDisplay( mode, border );
337  mMap->updateBoundingRect();
338  mMap->update();
339  mMap->endCommand();
340 }
341 
342 void QgsLayoutMapGridWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled, bool rotationEnabled )
343 {
344  //set status of frame controls
345  mFrameWidthSpinBox->setEnabled( frameSizeEnabled );
346  mGridFrameMarginSpinBox->setEnabled( frameEnabled );
347  mGridFramePenSizeSpinBox->setEnabled( frameEnabled );
348  mGridFramePenColorButton->setEnabled( frameEnabled );
349  mGridFrameFill1ColorButton->setEnabled( frameFillEnabled );
350  mGridFrameFill2ColorButton->setEnabled( frameFillEnabled );
351  mFrameWidthLabel->setEnabled( frameSizeEnabled );
352  mFrameMarginLabel->setEnabled( frameEnabled );
353  mFramePenLabel->setEnabled( frameEnabled );
354  mFrameFillLabel->setEnabled( frameFillEnabled );
355  mCheckGridLeftSide->setEnabled( frameEnabled );
356  mCheckGridRightSide->setEnabled( frameEnabled );
357  mCheckGridTopSide->setEnabled( frameEnabled );
358  mCheckGridBottomSide->setEnabled( frameEnabled );
359  mFrameDivisionsLeftComboBox->setEnabled( frameEnabled );
360  mFrameDivisionsRightComboBox->setEnabled( frameEnabled );
361  mFrameDivisionsTopComboBox->setEnabled( frameEnabled );
362  mFrameDivisionsBottomComboBox->setEnabled( frameEnabled );
363  mLeftDivisionsLabel->setEnabled( frameEnabled );
364  mRightDivisionsLabel->setEnabled( frameEnabled );
365  mTopDivisionsLabel->setEnabled( frameEnabled );
366  mBottomDivisionsLabel->setEnabled( frameEnabled );
367  mRotatedTicksGroupBox->setEnabled( rotationEnabled );
368 }
369 
370 void QgsLayoutMapGridWidget::insertAnnotationPositionEntries( QComboBox *c )
371 {
372  c->insertItem( 0, tr( "Inside Frame" ), QgsLayoutItemMapGrid::InsideMapFrame );
373  c->insertItem( 1, tr( "Outside Frame" ), QgsLayoutItemMapGrid::OutsideMapFrame );
374 }
375 
376 void QgsLayoutMapGridWidget::insertAnnotationDirectionEntries( QComboBox *c )
377 {
378  c->addItem( tr( "Horizontal" ), QgsLayoutItemMapGrid::Horizontal );
379  c->addItem( tr( "Vertical Ascending" ), QgsLayoutItemMapGrid::Vertical );
380  c->addItem( tr( "Vertical Descending" ), QgsLayoutItemMapGrid::VerticalDescending );
381  c->addItem( tr( "Boundary Direction" ), QgsLayoutItemMapGrid::BoundaryDirection );
382  // c->addItem( tr( "Parallel to Tick" ), QgsLayoutItemMapGrid::ParallelToTick );
383  c->addItem( tr( "Above Tick" ), QgsLayoutItemMapGrid::AboveTick );
384  c->addItem( tr( "On Tick" ), QgsLayoutItemMapGrid::OnTick );
385  c->addItem( tr( "Under Tick" ), QgsLayoutItemMapGrid::UnderTick );
386 }
387 
388 void QgsLayoutMapGridWidget::initFrameDisplayBox( QComboBox *c, QgsLayoutItemMapGrid::DisplayMode display )
389 {
390  if ( !c )
391  {
392  return;
393  }
394  c->setCurrentIndex( c->findData( display ) );
395 }
396 
397 void QgsLayoutMapGridWidget::handleChangedAnnotationPosition( QgsLayoutItemMapGrid::BorderSide border, const QgsLayoutItemMapGrid::AnnotationPosition position )
398 {
399  if ( !mMapGrid || !mMap )
400  {
401  return;
402  }
403 
404  mMap->beginCommand( tr( "Change Annotation Position" ) );
405  mMapGrid->setAnnotationPosition( position, border );
406 
407  mMap->updateBoundingRect();
408  mMap->update();
409  mMap->endCommand();
410 }
411 
412 void QgsLayoutMapGridWidget::handleChangedAnnotationDirection( QgsLayoutItemMapGrid::BorderSide border, QgsLayoutItemMapGrid::AnnotationDirection direction )
413 {
414  if ( !mMapGrid || !mMap )
415  {
416  return;
417  }
418 
419  mMap->beginCommand( tr( "Change Annotation Direction" ) );
420  mMapGrid->setAnnotationDirection( direction, border );
421  mMap->updateBoundingRect();
422  mMap->update();
423  mMap->endCommand();
424 }
425 
426 void QgsLayoutMapGridWidget::insertFrameDisplayEntries( QComboBox *c )
427 {
428  c->addItem( tr( "All" ), QgsLayoutItemMapGrid::ShowAll );
429  c->addItem( tr( "Latitude/Y Only" ), QgsLayoutItemMapGrid::LatitudeOnly );
430  c->addItem( tr( "Longitude/X Only" ), QgsLayoutItemMapGrid::LongitudeOnly );
431 }
432 
433 void QgsLayoutMapGridWidget::insertAnnotationDisplayEntries( QComboBox *c )
434 {
435  c->insertItem( 0, tr( "Show All" ), QgsLayoutItemMapGrid::ShowAll );
436  c->insertItem( 1, tr( "Show Latitude/Y Only" ), QgsLayoutItemMapGrid::LatitudeOnly );
437  c->insertItem( 2, tr( "Show Longitude/X Only" ), QgsLayoutItemMapGrid::LongitudeOnly );
438  c->insertItem( 3, tr( "Disabled" ), QgsLayoutItemMapGrid::HideAll );
439 }
440 
441 void QgsLayoutMapGridWidget::initAnnotationPositionBox( QComboBox *c, QgsLayoutItemMapGrid::AnnotationPosition pos )
442 {
443  if ( !c )
444  {
445  return;
446  }
447 
449  {
450  c->setCurrentIndex( c->findText( tr( "Inside Frame" ) ) );
451  }
452  else
453  {
454  c->setCurrentIndex( c->findText( tr( "Outside Frame" ) ) );
455  }
456 }
457 
458 void QgsLayoutMapGridWidget::initAnnotationDirectionBox( QComboBox *c, QgsLayoutItemMapGrid::AnnotationDirection dir )
459 {
460  if ( !c )
461  {
462  return;
463  }
464  c->setCurrentIndex( c->findData( dir ) );
465 }
466 
467 bool QgsLayoutMapGridWidget::hasPredefinedScales() const
468 {
469  // first look at project's scales
470  const QVector< double > scales = QgsProject::instance()->viewSettings()->mapScales();
471  const bool hasProjectScales( QgsProject::instance()->viewSettings()->useProjectScales() );
472  if ( !hasProjectScales || scales.isEmpty() )
473  {
474  // default to global map tool scales
475  const QgsSettings settings;
476  const QString scalesStr( settings.value( QStringLiteral( "Map/scales" ), Qgis::defaultProjectScales() ).toString() );
477  QStringList myScalesList = scalesStr.split( ',' );
478  return !myScalesList.isEmpty() && !myScalesList[0].isEmpty();
479  }
480  return true;
481 }
482 
483 void QgsLayoutMapGridWidget::setGridItems()
484 {
485  if ( !mMapGrid )
486  {
487  return;
488  }
489 
490  mGridMarkerStyleButton->registerExpressionContextGenerator( mMapGrid );
491  mGridLineStyleButton->registerExpressionContextGenerator( mMapGrid );
492  mAnnotationFontButton->registerExpressionContextGenerator( mMapGrid );
493 
494  mEnabledCheckBox->setChecked( mMapGrid->enabled() );
495  mIntervalXSpinBox->setValue( mMapGrid->intervalX() );
496  mIntervalYSpinBox->setValue( mMapGrid->intervalY() );
497  mOffsetXSpinBox->setValue( mMapGrid->offsetX() );
498  mOffsetYSpinBox->setValue( mMapGrid->offsetY() );
499  mCrossWidthSpinBox->setValue( mMapGrid->crossLength() );
500  mFrameWidthSpinBox->setValue( mMapGrid->frameWidth() );
501  mGridFrameMarginSpinBox->setValue( mMapGrid->frameMargin() );
502  mGridFramePenSizeSpinBox->setValue( mMapGrid->framePenSize() );
503  mGridFramePenColorButton->setColor( mMapGrid->framePenColor() );
504  mGridFrameFill1ColorButton->setColor( mMapGrid->frameFillColor1() );
505  mGridFrameFill2ColorButton->setColor( mMapGrid->frameFillColor2() );
506 
507  const QgsLayoutItemMapGrid::GridStyle gridStyle = mMapGrid->style();
508  mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findData( gridStyle ) );
509  switch ( gridStyle )
510  {
512  mCrossWidthSpinBox->setVisible( true );
513  mCrossWidthDDBtn->setVisible( true );
514  mCrossWidthLabel->setVisible( true );
515  mGridLineStyleButton->setVisible( true );
516  mLineStyleLabel->setVisible( true );
517  mGridMarkerStyleButton->setVisible( false );
518  mMarkerStyleLabel->setVisible( false );
519  mGridBlendComboBox->setVisible( true );
520  mGridBlendLabel->setVisible( true );
521  break;
523  mCrossWidthSpinBox->setVisible( false );
524  mCrossWidthDDBtn->setVisible( false );
525  mCrossWidthLabel->setVisible( false );
526  mGridLineStyleButton->setVisible( false );
527  mLineStyleLabel->setVisible( false );
528  mGridMarkerStyleButton->setVisible( true );
529  mMarkerStyleLabel->setVisible( true );
530  mGridBlendComboBox->setVisible( true );
531  mGridBlendLabel->setVisible( true );
532  break;
534  mCrossWidthSpinBox->setVisible( false );
535  mCrossWidthDDBtn->setVisible( false );
536  mCrossWidthLabel->setVisible( false );
537  mGridLineStyleButton->setVisible( true );
538  mLineStyleLabel->setVisible( true );
539  mGridMarkerStyleButton->setVisible( false );
540  mMarkerStyleLabel->setVisible( false );
541  mGridBlendComboBox->setVisible( true );
542  mGridBlendLabel->setVisible( true );
543  break;
545  mCrossWidthSpinBox->setVisible( false );
546  mCrossWidthDDBtn->setVisible( false );
547  mCrossWidthLabel->setVisible( false );
548  mGridLineStyleButton->setVisible( false );
549  mLineStyleLabel->setVisible( false );
550  mGridMarkerStyleButton->setVisible( false );
551  mMarkerStyleLabel->setVisible( false );
552  mGridBlendComboBox->setVisible( false );
553  mGridBlendLabel->setVisible( false );
554  break;
555  }
556 
557  //grid frame
558  mFrameWidthSpinBox->setValue( mMapGrid->frameWidth() );
559  mGridFrameMarginSpinBox->setValue( mMapGrid->frameMargin() );
560  const QgsLayoutItemMapGrid::FrameStyle gridFrameStyle = mMapGrid->frameStyle();
561  mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findData( gridFrameStyle ) );
562  switch ( gridFrameStyle )
563  {
566  toggleFrameControls( true, true, true, false );
567  break;
571  toggleFrameControls( true, false, true, true );
572  break;
575  toggleFrameControls( true, false, false, false );
576  break;
578  toggleFrameControls( false, false, false, false );
579  break;
580  }
581 
582  mCheckGridLeftSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameLeft ) );
583  mCheckGridRightSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameRight ) );
584  mCheckGridTopSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameTop ) );
585  mCheckGridBottomSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameBottom ) );
586 
587  mRotatedTicksGroupBox->setChecked( mMapGrid->rotatedTicksEnabled() );
588  mRotatedTicksLengthModeComboBox->setCurrentIndex( mRotatedTicksLengthModeComboBox->findData( mMapGrid->rotatedTicksLengthMode() ) );
589  mRotatedTicksThresholdSpinBox->setValue( mMapGrid->rotatedTicksMinimumAngle() );
590  mRotatedTicksMarginToCornerSpinBox->setValue( mMapGrid->rotatedTicksMarginToCorner() );
591 
592  mRotatedAnnotationsGroupBox->setChecked( mMapGrid->rotatedAnnotationsEnabled() );
593  mRotatedAnnotationsLengthModeComboBox->setCurrentIndex( mRotatedAnnotationsLengthModeComboBox->findData( mMapGrid->rotatedAnnotationsLengthMode() ) );
594  mRotatedAnnotationsThresholdSpinBox->setValue( mMapGrid->rotatedAnnotationsMinimumAngle() );
595  mRotatedAnnotationsMarginToCornerSpinBox->setValue( mMapGrid->rotatedAnnotationsMarginToCorner() );
596 
597  initFrameDisplayBox( mFrameDivisionsLeftComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Left ) );
598  initFrameDisplayBox( mFrameDivisionsRightComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Right ) );
599  initFrameDisplayBox( mFrameDivisionsTopComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Top ) );
600  initFrameDisplayBox( mFrameDivisionsBottomComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Bottom ) );
601 
602  //line style
603  mGridLineStyleButton->setSymbol( mMapGrid->lineSymbol()->clone() );
604  //marker style
605  mGridMarkerStyleButton->setSymbol( mMapGrid->markerSymbol()->clone() );
606 
607  mGridBlendComboBox->setBlendMode( mMapGrid->blendMode() );
608 
609  mDrawAnnotationGroupBox->setChecked( mMapGrid->annotationEnabled() );
610  mAnnotationDisplayLeftComboBox->setCurrentIndex( mAnnotationDisplayLeftComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Left ) ) );
611  mAnnotationDisplayRightComboBox->setCurrentIndex( mAnnotationDisplayRightComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Right ) ) );
612  mAnnotationDisplayTopComboBox->setCurrentIndex( mAnnotationDisplayTopComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Top ) ) );
613  mAnnotationDisplayBottomComboBox->setCurrentIndex( mAnnotationDisplayBottomComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Bottom ) ) );
614 
615  mAnnotationPositionLeftComboBox->setCurrentIndex( mAnnotationPositionLeftComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Left ) ) );
616  mAnnotationPositionRightComboBox->setCurrentIndex( mAnnotationPositionRightComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Right ) ) );
617  mAnnotationPositionTopComboBox->setCurrentIndex( mAnnotationPositionTopComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Top ) ) );
618  mAnnotationPositionBottomComboBox->setCurrentIndex( mAnnotationPositionBottomComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Bottom ) ) );
619 
620  initAnnotationDirectionBox( mAnnotationDirectionComboBoxLeft, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Left ) );
621  initAnnotationDirectionBox( mAnnotationDirectionComboBoxRight, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Right ) );
622  initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Top ) );
623  initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Bottom ) );
624 
625  mAnnotationFontButton->setDialogTitle( tr( "Grid Annotation Font" ) );
626  mAnnotationFontButton->setMode( QgsFontButton::ModeTextRenderer );
627  mAnnotationFontButton->setTextFormat( mMapGrid->annotationTextFormat() );
628 
629  mAnnotationFormatComboBox->setCurrentIndex( mAnnotationFormatComboBox->findData( mMapGrid->annotationFormat() ) );
630  mAnnotationFormatButton->setEnabled( mMapGrid->annotationFormat() == QgsLayoutItemMapGrid::CustomFormat );
631  mDistanceToMapFrameSpinBox->setValue( mMapGrid->annotationFrameDistance() );
632  mCoordinatePrecisionSpinBox->setValue( mMapGrid->annotationPrecision() );
633 
634  //Unit
635  mMapGridUnitComboBox->setCurrentIndex( mMapGridUnitComboBox->findData( mMapGrid->units() ) );
636  switch ( mMapGrid->units() )
637  {
641  mIntervalStackedWidget->setCurrentIndex( 0 );
642  break;
643 
645  mIntervalStackedWidget->setCurrentIndex( 1 );
646  break;
647  }
648  mMinWidthSpinBox->setValue( mMapGrid->minimumIntervalWidth() );
649  mMaxWidthSpinBox->setValue( mMapGrid->maximumIntervalWidth() );
650 
651  whileBlocking( mMapGridCrsSelector )->setCrs( mMapGrid->crs() );
652 }
653 
654 void QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished()
655 {
656  if ( !mMapGrid || !mMap )
657  {
658  return;
659  }
660 
661  mMap->beginCommand( tr( "Change Grid Interval" ) );
662  mMapGrid->setIntervalX( mIntervalXSpinBox->value() );
663  mMap->updateBoundingRect();
664  mMap->update();
665  mMap->endCommand();
666 }
667 
668 void QgsLayoutMapGridWidget::mIntervalYSpinBox_editingFinished()
669 {
670  if ( !mMapGrid || !mMap )
671  {
672  return;
673  }
674 
675  mMap->beginCommand( tr( "Change Grid Interval" ) );
676  mMapGrid->setIntervalY( mIntervalYSpinBox->value() );
677  mMap->updateBoundingRect();
678  mMap->update();
679  mMap->endCommand();
680 }
681 
682 void QgsLayoutMapGridWidget::mOffsetXSpinBox_valueChanged( double value )
683 {
684  if ( !mMapGrid || !mMap )
685  {
686  return;
687  }
688 
689  mMap->beginCommand( tr( "Change Grid Offset" ) );
690  mMapGrid->setOffsetX( value );
691  mMap->updateBoundingRect();
692  mMap->update();
693  mMap->endCommand();
694 }
695 
696 void QgsLayoutMapGridWidget::mOffsetYSpinBox_valueChanged( double value )
697 {
698  if ( !mMapGrid || !mMap )
699  {
700  return;
701  }
702 
703  mMap->beginCommand( tr( "Change Grid Offset" ) );
704  mMapGrid->setOffsetY( value );
705  mMap->updateBoundingRect();
706  mMap->update();
707  mMap->endCommand();
708 }
709 
710 void QgsLayoutMapGridWidget::mCrossWidthSpinBox_valueChanged( double val )
711 {
712  if ( !mMapGrid || !mMap )
713  {
714  return;
715  }
716 
717  mMap->beginCommand( tr( "Change Cross Width" ) );
718  mMapGrid->setCrossLength( val );
719  mMap->update();
720  mMap->endCommand();
721 }
722 
723 void QgsLayoutMapGridWidget::mFrameWidthSpinBox_valueChanged( double val )
724 {
725  if ( !mMapGrid || !mMap )
726  {
727  return;
728  }
729 
730  mMap->beginCommand( tr( "Change Frame Width" ) );
731  mMapGrid->setFrameWidth( val );
732  mMap->updateBoundingRect();
733  mMap->update();
734  mMap->endCommand();
735 }
736 
737 void QgsLayoutMapGridWidget::mGridFrameMarginSpinBox_valueChanged( double val )
738 {
739  if ( !mMapGrid || !mMap )
740  {
741  return;
742  }
743 
744  mMap->beginCommand( tr( "Change Grid Frame Margin" ) );
745  mMapGrid->setFrameMargin( val );
746  mMap->updateBoundingRect();
747  mMap->update();
748  mMap->endCommand();
749 }
750 
751 void QgsLayoutMapGridWidget::mCheckGridLeftSide_toggled( bool checked )
752 {
753  if ( !mMapGrid || !mMap )
754  {
755  return;
756  }
757 
758  mMap->beginCommand( tr( "Change Frame Left" ) );
759  mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameLeft, checked );
760  mMap->updateBoundingRect();
761  mMap->update();
762  mMap->endCommand();
763 }
764 
765 void QgsLayoutMapGridWidget::mCheckGridRightSide_toggled( bool checked )
766 {
767  if ( !mMapGrid || !mMap )
768  {
769  return;
770  }
771 
772  mMap->beginCommand( tr( "Change Frame Right" ) );
773  mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameRight, checked );
774  mMap->updateBoundingRect();
775  mMap->update();
776  mMap->endCommand();
777 }
778 
779 void QgsLayoutMapGridWidget::mCheckGridTopSide_toggled( bool checked )
780 {
781  if ( !mMapGrid || !mMap )
782  {
783  return;
784  }
785 
786  mMap->beginCommand( tr( "Change Frame Top" ) );
787  mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameTop, checked );
788  mMap->updateBoundingRect();
789  mMap->update();
790  mMap->endCommand();
791 }
792 
793 void QgsLayoutMapGridWidget::mCheckGridBottomSide_toggled( bool checked )
794 {
795  if ( !mMapGrid || !mMap )
796  {
797  return;
798  }
799 
800  mMap->beginCommand( tr( "Change Frame Bottom" ) );
801  mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameBottom, checked );
802  mMap->updateBoundingRect();
803  mMap->update();
804  mMap->endCommand();
805 }
806 
807 void QgsLayoutMapGridWidget::mFrameDivisionsLeftComboBox_currentIndexChanged( int index )
808 {
809  handleChangedFrameDisplay( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsLeftComboBox->itemData( index ).toInt() ) );
810 }
811 
812 void QgsLayoutMapGridWidget::mFrameDivisionsRightComboBox_currentIndexChanged( int index )
813 {
814  handleChangedFrameDisplay( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsRightComboBox->itemData( index ).toInt() ) );
815 }
816 
817 void QgsLayoutMapGridWidget::mFrameDivisionsTopComboBox_currentIndexChanged( int index )
818 {
819  handleChangedFrameDisplay( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsTopComboBox->itemData( index ).toInt() ) );
820 }
821 
822 void QgsLayoutMapGridWidget::mFrameDivisionsBottomComboBox_currentIndexChanged( int index )
823 {
824  handleChangedFrameDisplay( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsBottomComboBox->itemData( index ).toInt() ) );
825 }
826 
827 void QgsLayoutMapGridWidget::mGridFramePenSizeSpinBox_valueChanged( double d )
828 {
829  if ( !mMapGrid || !mMap )
830  {
831  return;
832  }
833 
834  mMap->beginCommand( tr( "Change Frame Thickness" ) );
835  mMapGrid->setFramePenSize( d );
836  mMap->updateBoundingRect();
837  mMap->update();
838  mMap->endCommand();
839 }
840 
841 void QgsLayoutMapGridWidget::mGridFramePenColorButton_colorChanged( const QColor &newColor )
842 {
843  if ( !mMapGrid || !mMap )
844  {
845  return;
846  }
847 
848  mMap->beginCommand( tr( "Change Frame Color" ), QgsLayoutItem::UndoGridFramePenColor );
849  mMapGrid->setFramePenColor( newColor );
850  mMap->update();
851  mMap->endCommand();
852 }
853 
854 void QgsLayoutMapGridWidget::mGridFrameFill1ColorButton_colorChanged( const QColor &newColor )
855 {
856  if ( !mMapGrid || !mMap )
857  {
858  return;
859  }
860 
861  mMap->beginCommand( tr( "Change Frame Fill Color" ), QgsLayoutItem::UndoMapGridFrameFill1Color );
862  mMapGrid->setFrameFillColor1( newColor );
863  mMap->update();
864  mMap->endCommand();
865 }
866 
867 void QgsLayoutMapGridWidget::mGridFrameFill2ColorButton_colorChanged( const QColor &newColor )
868 {
869  if ( !mMapGrid || !mMap )
870  {
871  return;
872  }
873 
874  mMap->beginCommand( tr( "Change Frame Fill Color" ), QgsLayoutItem::UndoMapGridFrameFill2Color );
875  mMapGrid->setFrameFillColor2( newColor );
876  mMap->update();
877  mMap->endCommand();
878 }
879 
880 void QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged( int )
881 {
882  if ( !mMapGrid || !mMap )
883  {
884  return;
885  }
886 
887  const QgsLayoutItemMapGrid::FrameStyle style = static_cast< QgsLayoutItemMapGrid::FrameStyle >( mFrameStyleComboBox->currentData().toInt() );
888  mMap->beginCommand( tr( "Change Frame Style" ) );
889  mMapGrid->setFrameStyle( style );
890  switch ( style )
891  {
894  toggleFrameControls( true, true, true, false );
895  break;
899  toggleFrameControls( true, false, true, true );
900  break;
903  toggleFrameControls( true, false, false, false );
904  break;
906  toggleFrameControls( false, false, false, false );
907  break;
908  }
909  mMap->updateBoundingRect();
910  mMap->update();
911  mMap->endCommand();
912 }
913 
914 void QgsLayoutMapGridWidget::mRotatedTicksGroupBox_toggled( bool state )
915 {
916  if ( !mMapGrid || !mMap )
917  {
918  return;
919  }
920 
921  mMap->beginCommand( tr( "Change Tick Rotation Enabled" ) );
922  mMapGrid->setRotatedTicksEnabled( state );
923  mMap->update();
924  mMap->endCommand();
925 }
926 
927 void QgsLayoutMapGridWidget::mRotatedTicksLengthModeComboBox_currentIndexChanged( int )
928 {
929  if ( !mMapGrid || !mMap )
930  {
931  return;
932  }
933 
934  const QgsLayoutItemMapGrid::TickLengthMode mode = static_cast< QgsLayoutItemMapGrid::TickLengthMode >( mRotatedTicksLengthModeComboBox->currentData().toInt() );
935  mMap->beginCommand( tr( "Change Tick Length Mode" ) );
936  mMapGrid->setRotatedTicksLengthMode( mode );
937  mMap->update();
938  mMap->endCommand();
939 }
940 
941 void QgsLayoutMapGridWidget::mRotatedTicksThresholdSpinBox_valueChanged( double val )
942 {
943  if ( !mMapGrid || !mMap )
944  {
945  return;
946  }
947 
948  mMap->beginCommand( tr( "Change Rotated Ticks Threshold" ) );
949  mMapGrid->setRotatedTicksMinimumAngle( val );
950  mMap->update();
951  mMap->endCommand();
952 }
953 
954 void QgsLayoutMapGridWidget::mRotatedTicksMarginToCornerSpinBox_valueChanged( double val )
955 {
956  if ( !mMapGrid || !mMap )
957  {
958  return;
959  }
960 
961  mMap->beginCommand( tr( "Change Rotated Ticks Margin to Corner" ) );
962  mMapGrid->setRotatedTicksMarginToCorner( val );
963  mMap->update();
964  mMap->endCommand();
965 }
966 
967 void QgsLayoutMapGridWidget::mRotatedAnnotationsGroupBox_toggled( bool state )
968 {
969  if ( !mMapGrid || !mMap )
970  {
971  return;
972  }
973 
974  mMap->beginCommand( tr( "Change Annotation Rotation Enabled" ) );
975  mMapGrid->setRotatedAnnotationsEnabled( state );
976  mMap->update();
977  mMap->endCommand();
978 }
979 
980 void QgsLayoutMapGridWidget::mRotatedAnnotationsLengthModeComboBox_currentIndexChanged( int )
981 {
982  if ( !mMapGrid || !mMap )
983  {
984  return;
985  }
986 
987  const QgsLayoutItemMapGrid::TickLengthMode mode = static_cast< QgsLayoutItemMapGrid::TickLengthMode >( mRotatedAnnotationsLengthModeComboBox->currentData().toInt() );
988  mMap->beginCommand( tr( "Change Annotation Length Mode" ) );
989  mMapGrid->setRotatedAnnotationsLengthMode( mode );
990  mMap->update();
991  mMap->endCommand();
992 }
993 
994 void QgsLayoutMapGridWidget::mRotatedAnnotationsThresholdSpinBox_valueChanged( double val )
995 {
996  if ( !mMapGrid || !mMap )
997  {
998  return;
999  }
1000 
1001  mMap->beginCommand( tr( "Change Rotated Annotations Threshold" ) );
1002  mMapGrid->setRotatedAnnotationsMinimumAngle( val );
1003  mMap->update();
1004  mMap->endCommand();
1005 }
1006 
1007 void QgsLayoutMapGridWidget::mRotatedAnnotationsMarginToCornerSpinBox_valueChanged( double val )
1008 {
1009  if ( !mMapGrid || !mMap )
1010  {
1011  return;
1012  }
1013 
1014  mMap->beginCommand( tr( "Change Rotated Annotations Margin to Corner" ) );
1015  mMapGrid->setRotatedAnnotationsMarginToCorner( val );
1016  mMap->update();
1017  mMap->endCommand();
1018 }
1019 
1020 void QgsLayoutMapGridWidget::intervalUnitChanged( int )
1021 {
1022  if ( !mMapGrid || !mMap )
1023  {
1024  return;
1025  }
1026 
1027  const QgsLayoutItemMapGrid::GridUnit unit = static_cast< QgsLayoutItemMapGrid::GridUnit >( mMapGridUnitComboBox->currentData().toInt() );
1028  switch ( unit )
1029  {
1033  mIntervalStackedWidget->setCurrentIndex( 0 );
1034  break;
1035 
1037  mIntervalStackedWidget->setCurrentIndex( 1 );
1038  break;
1039  }
1040 
1041  mMap->beginCommand( tr( "Change Grid Unit" ) );
1042  mMapGrid->setUnits( unit );
1043  mMap->updateBoundingRect();
1044  mMap->update();
1045  mMap->endCommand();
1046 }
1047 
1048 void QgsLayoutMapGridWidget::minIntervalChanged( double interval )
1049 {
1050  mMap->beginCommand( tr( "Change Grid Interval Range" ), QgsLayoutItem::UndoMapGridIntervalRange );
1051  mMapGrid->setMinimumIntervalWidth( interval );
1052  mMap->endCommand();
1053  mMap->updateBoundingRect();
1054  mMap->update();
1055 }
1056 
1057 void QgsLayoutMapGridWidget::maxIntervalChanged( double interval )
1058 {
1059  mMap->beginCommand( tr( "Change Grid Interval Range" ), QgsLayoutItem::UndoMapGridIntervalRange );
1060  mMapGrid->setMaximumIntervalWidth( interval );
1061  mMap->endCommand();
1062  mMap->updateBoundingRect();
1063  mMap->update();
1064 }
1065 
1066 void QgsLayoutMapGridWidget::annotationTextFormatChanged()
1067 {
1068  if ( !mMapGrid || !mMap )
1069  {
1070  return;
1071  }
1072 
1073  mMap->beginCommand( tr( "Change Annotation Font" ) );
1074  mMapGrid->setAnnotationTextFormat( mAnnotationFontButton->textFormat() );
1075  mMap->endCommand();
1076  mMap->updateBoundingRect();
1077  mMap->update();
1078 }
1079 
1080 void QgsLayoutMapGridWidget::onCrsChanged()
1081 {
1082  mBlockAnnotationFormatUpdates++;
1083  const QgsLayoutItemMapGrid::AnnotationFormat prevFormat = static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->currentData().toInt() );
1084 
1085  mAnnotationFormatComboBox->clear();
1086  mAnnotationFormatComboBox->addItem( tr( "Decimal" ), QgsLayoutItemMapGrid::Decimal );
1087  mAnnotationFormatComboBox->addItem( tr( "Decimal with Suffix" ), QgsLayoutItemMapGrid::DecimalWithSuffix );
1088 
1089  // only show degree based options for geographic CRSes
1090  const QgsCoordinateReferenceSystem crs = mMapGrid->crs().isValid() ? mMapGrid->crs() : mMap->crs();
1091  switch ( crs.mapUnits() )
1092  {
1101  break;
1102 
1105  mAnnotationFormatComboBox->addItem( tr( "Degree, Minute" ), QgsLayoutItemMapGrid::DegreeMinuteNoSuffix );
1106  mAnnotationFormatComboBox->addItem( tr( "Degree, Minute with Suffix" ), QgsLayoutItemMapGrid::DegreeMinute );
1107  mAnnotationFormatComboBox->addItem( tr( "Degree, Minute Aligned" ), QgsLayoutItemMapGrid::DegreeMinutePadded );
1108  mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second" ), QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix );
1109  mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second with Suffix" ), QgsLayoutItemMapGrid::DegreeMinuteSecond );
1110  mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second Aligned" ), QgsLayoutItemMapGrid::DegreeMinuteSecondPadded );
1111  break;
1112  }
1113  mAnnotationFormatComboBox->addItem( tr( "Custom" ), QgsLayoutItemMapGrid::CustomFormat );
1114 
1115  const int prevIndex = mAnnotationFormatComboBox->findData( prevFormat );
1116  if ( prevIndex >= 0 )
1117  mAnnotationFormatComboBox->setCurrentIndex( prevIndex );
1118  else
1119  mAnnotationFormatComboBox->setCurrentIndex( 0 );
1120  mBlockAnnotationFormatUpdates--;
1121 
1122  const QgsLayoutItemMapGrid::AnnotationFormat newFormat = static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->currentData().toInt() );
1123  if ( newFormat != prevFormat )
1124  {
1125  mAnnotationFormatComboBox_currentIndexChanged( mAnnotationFormatComboBox->currentIndex() );
1126  }
1127 }
1128 
1129 void QgsLayoutMapGridWidget::mGridBlendComboBox_currentIndexChanged( int index )
1130 {
1131  Q_UNUSED( index )
1132  if ( mMapGrid )
1133  {
1134  mMap->beginCommand( tr( "Change Grid Blend Mode" ) );
1135  mMapGrid->setBlendMode( mGridBlendComboBox->blendMode() );
1136  mMap->update();
1137  mMap->endCommand();
1138  }
1139 
1140 }
1141 
1142 void QgsLayoutMapGridWidget::mGridTypeComboBox_currentIndexChanged( int )
1143 {
1144  if ( !mMapGrid || !mMap )
1145  {
1146  return;
1147  }
1148 
1149  mMap->beginCommand( tr( "Change Grid Type" ) );
1150  switch ( static_cast< QgsLayoutItemMapGrid::GridStyle >( mGridTypeComboBox->currentData().toInt() ) )
1151  {
1153  mMapGrid->setStyle( QgsLayoutItemMapGrid::Cross );
1154  mCrossWidthSpinBox->setVisible( true );
1155  mCrossWidthDDBtn->setVisible( true );
1156  mCrossWidthLabel->setVisible( true );
1157  mGridLineStyleButton->setVisible( true );
1158  mLineStyleLabel->setVisible( true );
1159  mGridMarkerStyleButton->setVisible( false );
1160  mMarkerStyleLabel->setVisible( false );
1161  mGridBlendComboBox->setVisible( true );
1162  mGridBlendLabel->setVisible( true );
1163  break;
1164 
1166  mMapGrid->setStyle( QgsLayoutItemMapGrid::Markers );
1167  mCrossWidthSpinBox->setVisible( false );
1168  mCrossWidthDDBtn->setVisible( false );
1169  mCrossWidthLabel->setVisible( false );
1170  mGridLineStyleButton->setVisible( false );
1171  mLineStyleLabel->setVisible( false );
1172  mGridMarkerStyleButton->setVisible( true );
1173  mMarkerStyleLabel->setVisible( true );
1174  mGridBlendComboBox->setVisible( true );
1175  mGridBlendLabel->setVisible( true );
1176  break;
1177 
1179  mMapGrid->setStyle( QgsLayoutItemMapGrid::Solid );
1180  mCrossWidthSpinBox->setVisible( false );
1181  mCrossWidthDDBtn->setVisible( false );
1182  mCrossWidthLabel->setVisible( false );
1183  mGridLineStyleButton->setVisible( true );
1184  mLineStyleLabel->setVisible( true );
1185  mGridMarkerStyleButton->setVisible( false );
1186  mMarkerStyleLabel->setVisible( false );
1187  mGridBlendComboBox->setVisible( true );
1188  mGridBlendLabel->setVisible( true );
1189  break;
1190 
1192  mMapGrid->setStyle( QgsLayoutItemMapGrid::FrameAnnotationsOnly );
1193  mCrossWidthSpinBox->setVisible( false );
1194  mCrossWidthDDBtn->setVisible( false );
1195  mCrossWidthLabel->setVisible( false );
1196  mGridLineStyleButton->setVisible( false );
1197  mLineStyleLabel->setVisible( false );
1198  mGridMarkerStyleButton->setVisible( false );
1199  mMarkerStyleLabel->setVisible( false );
1200  mGridBlendComboBox->setVisible( false );
1201  mGridBlendLabel->setVisible( false );
1202  break;
1203  }
1204 
1205  mMap->updateBoundingRect();
1206  mMap->update();
1207  mMap->endCommand();
1208 }
1209 
1210 void QgsLayoutMapGridWidget::mapGridCrsChanged( const QgsCoordinateReferenceSystem &crs )
1211 {
1212  if ( !mMapGrid || !mMap )
1213  {
1214  return;
1215  }
1216 
1217  if ( mMapGrid->crs() == crs )
1218  return;
1219 
1220  mMap->beginCommand( tr( "Change Grid CRS" ) );
1221  mMapGrid->setCrs( crs );
1222  mMap->updateBoundingRect();
1223  mMap->update();
1224  mMap->endCommand();
1225 }
1226 
1227 void QgsLayoutMapGridWidget::mDrawAnnotationGroupBox_toggled( bool state )
1228 {
1229  if ( !mMapGrid || !mMap )
1230  {
1231  return;
1232  }
1233 
1234  mMap->beginCommand( tr( "Toggle Annotations" ) );
1235  mMapGrid->setAnnotationEnabled( state );
1236  mMap->updateBoundingRect();
1237  mMap->update();
1238  mMap->endCommand();
1239 }
1240 
1241 void QgsLayoutMapGridWidget::mAnnotationFormatButton_clicked()
1242 {
1243  if ( !mMapGrid || !mMap )
1244  {
1245  return;
1246  }
1247 
1248  QgsExpressionContext expressionContext = mMapGrid->createExpressionContext();
1249  expressionContext.setHighlightedFunctions( QStringList() << QStringLiteral( "to_dms" ) << QStringLiteral( "to_dm" ) );
1250 
1251  QgsExpressionBuilderDialog exprDlg( coverageLayer(), mMapGrid->annotationExpression(), this, QStringLiteral( "generic" ), expressionContext );
1252  exprDlg.setWindowTitle( tr( "Expression Based Annotation" ) );
1253 
1254  if ( exprDlg.exec() == QDialog::Accepted )
1255  {
1256  const QString expression = exprDlg.expressionText();
1257  mMap->beginCommand( tr( "Change Annotation Format" ) );
1258  mMapGrid->setAnnotationExpression( expression );
1259  mMap->updateBoundingRect();
1260  mMap->update();
1261  mMap->endCommand();
1262  }
1263 }
1264 
1265 void QgsLayoutMapGridWidget::mAnnotationDisplayLeftComboBox_currentIndexChanged( int )
1266 {
1267  handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayLeftComboBox->currentData().toInt() ) );
1268 }
1269 
1270 void QgsLayoutMapGridWidget::mAnnotationDisplayRightComboBox_currentIndexChanged( int )
1271 {
1272  handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayRightComboBox->currentData().toInt() ) );
1273 }
1274 
1275 void QgsLayoutMapGridWidget::mAnnotationDisplayTopComboBox_currentIndexChanged( int )
1276 {
1277  handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayTopComboBox->currentData().toInt() ) );
1278 }
1279 
1280 void QgsLayoutMapGridWidget::mAnnotationDisplayBottomComboBox_currentIndexChanged( int )
1281 {
1282  handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayBottomComboBox->currentData().toInt() ) );
1283 }
1284 
1285 void QgsLayoutMapGridWidget::mAnnotationPositionLeftComboBox_currentIndexChanged( int )
1286 {
1287  handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionLeftComboBox->currentData().toInt() ) );
1288 }
1289 
1290 void QgsLayoutMapGridWidget::mAnnotationPositionRightComboBox_currentIndexChanged( int )
1291 {
1292  handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionRightComboBox->currentData().toInt() ) );
1293 }
1294 
1295 void QgsLayoutMapGridWidget::mAnnotationPositionTopComboBox_currentIndexChanged( int )
1296 {
1297  handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionTopComboBox->currentData().toInt() ) );
1298 }
1299 
1300 void QgsLayoutMapGridWidget::mAnnotationPositionBottomComboBox_currentIndexChanged( int )
1301 {
1302  handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionBottomComboBox->currentData().toInt() ) );
1303 }
1304 
1305 void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxLeft_currentIndexChanged( int index )
1306 {
1307  handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxLeft->itemData( index ).toInt() ) );
1308 }
1309 
1310 void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxRight_currentIndexChanged( int index )
1311 {
1312  handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxRight->itemData( index ).toInt() ) );
1313 }
1314 
1315 void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxTop_currentIndexChanged( int index )
1316 {
1317  handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxTop->itemData( index ).toInt() ) );
1318 }
1319 
1320 void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxBottom_currentIndexChanged( int index )
1321 {
1322  handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxBottom->itemData( index ).toInt() ) );
1323 }
1324 
1325 void QgsLayoutMapGridWidget::mDistanceToMapFrameSpinBox_valueChanged( double d )
1326 {
1327  if ( !mMapGrid || !mMap )
1328  {
1329  return;
1330  }
1331 
1332  mMap->beginCommand( tr( "Change Annotation Distance" ), QgsLayoutItem::UndoMapAnnotationDistance );
1333  mMapGrid->setAnnotationFrameDistance( d );
1334  mMap->updateBoundingRect();
1335  mMap->update();
1336  mMap->endCommand();
1337 }
1338 
1339 void QgsLayoutMapGridWidget::lineSymbolChanged()
1340 {
1341  if ( !mMapGrid || !mMap )
1342  {
1343  return;
1344  }
1345 
1346  mMap->beginCommand( tr( "Change Grid Line Style" ), QgsLayoutItem::UndoMapGridLineSymbol );
1347  mMapGrid->setLineSymbol( mGridLineStyleButton->clonedSymbol<QgsLineSymbol>() );
1348  mMap->endCommand();
1349  mMap->update();
1350 }
1351 
1352 void QgsLayoutMapGridWidget::markerSymbolChanged()
1353 {
1354  if ( !mMapGrid || !mMap )
1355  {
1356  return;
1357  }
1358 
1359  mMap->beginCommand( tr( "Change Grid Marker Style" ), QgsLayoutItem::UndoMapGridMarkerSymbol );
1360  mMapGrid->setMarkerSymbol( mGridMarkerStyleButton->clonedSymbol<QgsMarkerSymbol>() );
1361  mMap->endCommand();
1362  mMap->update();
1363 }
1364 
1365 void QgsLayoutMapGridWidget::gridEnabledToggled( bool active )
1366 {
1367  if ( !mMapGrid || !mMap )
1368  {
1369  return;
1370  }
1371 
1372  mMap->beginCommand( tr( "Toggle Grid Display" ) );
1373  mMapGrid->setEnabled( active );
1374  mMap->endCommand();
1375  mMap->updateBoundingRect();
1376  mMap->update();
1377 }
1378 
1379 void QgsLayoutMapGridWidget::mAnnotationFormatComboBox_currentIndexChanged( int index )
1380 {
1381  if ( !mMapGrid || !mMap )
1382  {
1383  return;
1384  }
1385  if ( mBlockAnnotationFormatUpdates )
1386  return;
1387 
1388  mMap->beginCommand( tr( "Change Annotation Format" ) );
1389 
1390  mMapGrid->setAnnotationFormat( static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->itemData( index ).toInt() ) );
1391  mAnnotationFormatButton->setEnabled( mMapGrid->annotationFormat() == QgsLayoutItemMapGrid::CustomFormat );
1392 
1393  mMap->updateBoundingRect();
1394  mMap->update();
1395  mMap->endCommand();
1396 }
1397 
1398 void QgsLayoutMapGridWidget::mCoordinatePrecisionSpinBox_valueChanged( int value )
1399 {
1400  if ( !mMapGrid || !mMap )
1401  {
1402  return;
1403  }
1404  mMap->beginCommand( tr( "Change Annotation Precision" ) );
1405  mMapGrid->setAnnotationPrecision( value );
1406  mMap->updateBoundingRect();
1407  mMap->update();
1408  mMap->endCommand();
1409 }
QgsLayoutItemMapGrid::TickLengthMode
TickLengthMode
Tick length mode (useful for rotated grids)
Definition: qgslayoutitemmapgrid.h:248
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsLayoutItemBaseWidget::updateDataDefinedButton
void updateDataDefinedButton(QgsPropertyOverrideButton *button)
Updates a previously registered data defined button to reflect the item's current properties.
Definition: qgslayoutitemwidget.cpp:251
QgsLayoutObject::MapGridAnnotationDisplayTop
@ MapGridAnnotationDisplayTop
Map annotation display top.
Definition: qgslayoutobject.h:179
QgsLayoutItemMapGrid::FrameRight
@ FrameRight
Right side of map.
Definition: qgslayoutitemmapgrid.h:260
QgsLayoutItemMapGrid::Zebra
@ Zebra
Black/white pattern.
Definition: qgslayoutitemmapgrid.h:236
QgsLayoutItemMapGrid
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
Definition: qgslayoutitemmapgrid.h:140
QgsLayoutItemMapGrid::InteriorTicks
@ InteriorTicks
Tick markers drawn inside map frame.
Definition: qgslayoutitemmapgrid.h:237
QgsLayoutObject::MapGridFrameLineThickness
@ MapGridFrameLineThickness
Map grid frame line thickness.
Definition: qgslayoutobject.h:176
QgsLayoutItemMapGrid::VerticalDescending
@ VerticalDescending
Draw annotations vertically, descending.
Definition: qgslayoutitemmapgrid.h:196
QgsLayoutItemMapGrid::LongitudeOnly
@ LongitudeOnly
Show longitude/x annotations/divisions only.
Definition: qgslayoutitemmapgrid.h:176
QgsSymbolButton::changed
void changed()
Emitted when the symbol's settings are changed.
QgsProject::viewSettings
const QgsProjectViewSettings * viewSettings() const
Returns the project's view settings, which contains settings and properties relating to how a QgsProj...
Definition: qgsproject.cpp:3491
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:161
QgsLayoutItemMapGrid::DynamicPageSizeBased
@ DynamicPageSizeBased
Dynamically sized, based on a on-page size range.
Definition: qgslayoutitemmapgrid.h:155
qgslayoutmapgridwidget.h
QgsUnitTypes::DistanceUnknownUnit
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
QgsLayoutItemMapGrid::OutsideMapFrame
@ OutsideMapFrame
Draw annotations outside the map frame.
Definition: qgslayoutitemmapgrid.h:186
QgsLayoutItemMapGrid::FrameLeft
@ FrameLeft
Left side of map.
Definition: qgslayoutitemmapgrid.h:259
Qgis::defaultProjectScales
static QString defaultProjectScales()
A string with default project scales.
Definition: qgis.cpp:271
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsLayoutItemMapGrid::ExteriorTicks
@ ExteriorTicks
Tick markers drawn outside map frame.
Definition: qgslayoutitemmapgrid.h:238
QgsLayoutItemMapGrid::ShowAll
@ ShowAll
Show both latitude and longitude annotations/divisions.
Definition: qgslayoutitemmapgrid.h:174
qgssymbollayerutils.h
QgsProjectionSelectionWidget::crsChanged
void crsChanged(const QgsCoordinateReferenceSystem &)
Emitted when the selected CRS is changed.
QgsLayoutObject::MapGridAnnotationDisplayLeft
@ MapGridAnnotationDisplayLeft
Map annotation display left.
Definition: qgslayoutobject.h:177
QgsLayoutItemBaseWidget::registerDataDefinedButton
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property)
Registers a data defined button, setting up its initial value, connections and description.
Definition: qgslayoutitemwidget.cpp:246
QgsLayoutItemMapGrid::CustomFormat
@ CustomFormat
Custom expression-based format.
Definition: qgslayoutitemmapgrid.h:216
QgsLayoutItemMapGrid::GridStyle
GridStyle
Grid drawing style.
Definition: qgslayoutitemmapgrid.h:161
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsLayoutItemMapGrid::ZebraNautical
@ ZebraNautical
Black/white pattern, with nautical style diagonals on corners.
Definition: qgslayoutitemmapgrid.h:242
QgsLayoutItemMapGrid::DegreeMinutePadded
@ DegreeMinutePadded
Degree/minutes, with minutes using leading zeros where required.
Definition: qgslayoutitemmapgrid.h:213
QgsLayoutItemMapGrid::CM
@ CM
Grid units in centimeters.
Definition: qgslayoutitemmapgrid.h:154
qgsmapsettings.h
QgsLayoutItemMapGrid::DisplayMode
DisplayMode
Display settings for grid annotations and frames.
Definition: qgslayoutitemmapgrid.h:172
QgsUnitTypes::DistanceKilometers
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
QgsLayoutItemMapGrid::BoundaryDirection
@ BoundaryDirection
Annotations follow the boundary direction.
Definition: qgslayoutitemmapgrid.h:197
QgsLayoutObject::MapGridOffsetY
@ MapGridOffsetY
Map grid offset Y.
Definition: qgslayoutobject.h:171
QgsLayoutItemMapGrid::InteriorExteriorTicks
@ InteriorExteriorTicks
Tick markers drawn both inside and outside the map frame.
Definition: qgslayoutitemmapgrid.h:239
QgsLayoutItemBaseWidget::coverageLayer
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
Definition: qgslayoutitemwidget.cpp:256
QgsColorButton::colorChanged
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
QgsLayoutItemMapGrid::LatitudeOnly
@ LatitudeOnly
Show latitude/y annotations/divisions only.
Definition: qgslayoutitemmapgrid.h:175
QgsLayoutItemMapGrid::FrameBottom
@ FrameBottom
Bottom side of map.
Definition: qgslayoutitemmapgrid.h:262
QgsLayoutObject::MapGridFrameDivisionsTop
@ MapGridFrameDivisionsTop
Map frame division display top.
Definition: qgslayoutobject.h:183
QgsLayoutItem::UndoMapGridIntervalRange
@ UndoMapGridIntervalRange
Grid interval range.
Definition: qgslayoutitem.h:240
QgsLayoutItemMapGrid::NormalizedTicks
@ NormalizedTicks
Constant tick lengths.
Definition: qgslayoutitemmapgrid.h:251
qgsprojectionselectiondialog.h
QgsLayoutItem::UndoMapAnnotationDistance
@ UndoMapAnnotationDistance
Map frame annotation distance.
Definition: qgslayoutitem.h:236
QgsLayoutItemMapGrid::FrameTop
@ FrameTop
Top side of map.
Definition: qgslayoutitemmapgrid.h:261
QgsLayoutItem::UndoGridFramePenColor
@ UndoGridFramePenColor
Map grid frame pen color.
Definition: qgslayoutitem.h:233
QgsLayoutObject::MapGridFrameMargin
@ MapGridFrameMargin
Map grid frame margin.
Definition: qgslayoutobject.h:173
qgstextformatwidget.h
QgsExpressionContext::setHighlightedFunctions
void setHighlightedFunctions(const QStringList &names)
Sets the list of function names intended to be highlighted to the user.
Definition: qgsexpressioncontext.cpp:338
QgsLayoutObject::MapGridAnnotationDisplayBottom
@ MapGridAnnotationDisplayBottom
Map annotation display bottom.
Definition: qgslayoutobject.h:180
QgsUnitTypes::DistanceDegrees
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:2191
QgsLayoutItemMapGrid::GridUnit
GridUnit
Unit for grid values.
Definition: qgslayoutitemmapgrid.h:150
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsLayoutItemMapGrid::AnnotationDirection
AnnotationDirection
Direction of grid annotations.
Definition: qgslayoutitemmapgrid.h:192
QgsLayoutObject::MapGridIntervalX
@ MapGridIntervalX
Map grid interval X.
Definition: qgslayoutobject.h:168
QgsLayoutMapGridWidget::QgsLayoutMapGridWidget
QgsLayoutMapGridWidget(QgsLayoutItemMapGrid *mapGrid, QgsLayoutItemMap *map)
constructor
Definition: qgslayoutmapgridwidget.cpp:36
QgsExpressionBuilderDialog
A generic dialog for building expression strings.
Definition: qgsexpressionbuilderdialog.h:30
QgsLayoutItemMapGrid::crsChanged
void crsChanged()
Emitted whenever the grid's CRS is changed.
QgsLayoutItemMapGrid::MapUnit
@ MapUnit
Grid units follow map units.
Definition: qgslayoutitemmapgrid.h:152
QgsLayoutObject::MapGridCrossSize
@ MapGridCrossSize
Map grid cross size.
Definition: qgslayoutobject.h:175
QgsLayoutItemMapGrid::LineBorderNautical
@ LineBorderNautical
Simple solid line frame, with nautical style diagonals on corners.
Definition: qgslayoutitemmapgrid.h:241
QgsLayoutItemMapGrid::DegreeMinuteSecondPadded
@ DegreeMinuteSecondPadded
Degree/minutes/seconds, with minutes using leading zeros where required.
Definition: qgslayoutitemmapgrid.h:215
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsUnitTypes::DistanceFeet
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
QgsLayoutItemMapGrid::Right
@ Right
Right border.
Definition: qgslayoutitemmapgrid.h:225
QgsUnitTypes::DistanceMeters
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
QgsLayoutObject::MapGridOffsetX
@ MapGridOffsetX
Map grid offset X.
Definition: qgslayoutobject.h:170
QgsLayoutItemMapGrid::AnnotationPosition
AnnotationPosition
Position for grid annotations.
Definition: qgslayoutitemmapgrid.h:183
QgsLayoutItem::UndoMapGridMarkerSymbol
@ UndoMapGridMarkerSymbol
Grid marker symbol.
Definition: qgslayoutitem.h:239
QgsLayoutItemMapGrid::BorderSide
BorderSide
Border sides for annotations.
Definition: qgslayoutitemmapgrid.h:222
QgsPanelWidget::setPanelTitle
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
Definition: qgspanelwidget.h:44
qgslayout.h
QgsProjectionSelectionWidget::CrsNotSet
@ CrsNotSet
Not set (hidden by default)
Definition: qgsprojectionselectionwidget.h:55
QgsLayoutItemMapGrid::FrameAnnotationsOnly
@ FrameAnnotationsOnly
No grid lines over the map, only draw frame and annotations.
Definition: qgslayoutitemmapgrid.h:166
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsLayoutItem::UndoMapGridLineSymbol
@ UndoMapGridLineSymbol
Grid line symbol.
Definition: qgslayoutitem.h:238
QgsLayoutItemMapGrid::Solid
@ Solid
Definition: qgslayoutitemmapgrid.h:163
QgsLayoutItemMapGrid::Bottom
@ Bottom
Bottom border.
Definition: qgslayoutitemmapgrid.h:226
qgssymbolselectordialog.h
qgsstyle.h
QgsLayoutItemBaseWidget
A base class for property widgets for layout items. All layout item widgets should inherit from this ...
Definition: qgslayoutitemwidget.h:122
QgsLayoutObject::MapGridEnabled
@ MapGridEnabled
Map grid enabled.
Definition: qgslayoutobject.h:167
qgsvectorlayer.h
QgsLayoutItemMapGrid::Cross
@ Cross
Draw line crosses at intersections of grid lines.
Definition: qgslayoutitemmapgrid.h:164
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:317
QgsLayoutItemMapGrid::Horizontal
@ Horizontal
Draw annotations horizontally.
Definition: qgslayoutitemmapgrid.h:194
qgsprojectviewsettings.h
QgsLayoutMapGridWidget::updateGuiElements
virtual void updateGuiElements()
Sets the current composer map values to the GUI elements.
Definition: qgslayoutmapgridwidget.cpp:250
QgsCoordinateReferenceSystem::mapUnits
QgsUnitTypes::DistanceUnit mapUnits
Definition: qgscoordinatereferencesystem.h:215
QgsFontButton::ModeTextRenderer
@ ModeTextRenderer
Configure font settings for use with QgsTextRenderer.
Definition: qgsfontbutton.h:61
QgsLayoutItemMapGrid::Vertical
@ Vertical
Draw annotations vertically, ascending.
Definition: qgslayoutitemmapgrid.h:195
QgsLayoutItemMapGrid::InsideMapFrame
@ InsideMapFrame
Draw annotations inside the map frame.
Definition: qgslayoutitemmapgrid.h:185
QgsSymbolButton::setLayer
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
Definition: qgssymbolbutton.cpp:208
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsProjectViewSettings::mapScales
QVector< double > mapScales() const
Returns the list of custom project map scales.
Definition: qgsprojectviewsettings.cpp:115
QgsLayoutItemMapGrid::DegreeMinute
@ DegreeMinute
Degree/minutes, use NSEW suffix.
Definition: qgslayoutitemmapgrid.h:209
QgsUnitTypes::DistanceMillimeters
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
QgsUnitTypes::DistanceCentimeters
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
QgsLayoutItemMapGrid::DecimalWithSuffix
@ DecimalWithSuffix
Decimal degrees, use NSEW suffix.
Definition: qgslayoutitemmapgrid.h:211
QgsLayoutItemMapGrid::DegreeMinuteNoSuffix
@ DegreeMinuteNoSuffix
Degree/minutes, use - for S/W coordinates.
Definition: qgslayoutitemmapgrid.h:212
QgsLayoutObject::MapGridLabelDistance
@ MapGridLabelDistance
Map grid label distance.
Definition: qgslayoutobject.h:174
qgsmarkersymbol.h
QgsLayoutItemMapGrid::DegreeMinuteSecond
@ DegreeMinuteSecond
Degree/minutes/seconds, use NSEW suffix.
Definition: qgslayoutitemmapgrid.h:210
QgsLayoutItemMapGrid::NoFrame
@ NoFrame
Disable grid frame.
Definition: qgslayoutitemmapgrid.h:235
QgsLayoutItemMapGrid::Top
@ Top
Top border.
Definition: qgslayoutitemmapgrid.h:227
QgsUnitTypes::DistanceYards
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
QgsLayoutItemMapGrid::AnnotationFormat
AnnotationFormat
Format for displaying grid annotations.
Definition: qgslayoutitemmapgrid.h:206
QgsLayoutObject::MapGridFrameDivisionsRight
@ MapGridFrameDivisionsRight
Map frame division display right.
Definition: qgslayoutobject.h:182
QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix
@ DegreeMinuteSecondNoSuffix
Degree/minutes/seconds, use - for S/W coordinates.
Definition: qgslayoutitemmapgrid.h:214
QgsUnitTypes::DistanceMiles
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
QgsLayoutItemMapGrid::AboveTick
@ AboveTick
Draw annotations parallel to tick (above the line)
Definition: qgslayoutitemmapgrid.h:198
QgsLayoutObject::MapGridAnnotationDisplayRight
@ MapGridAnnotationDisplayRight
Map annotation display right.
Definition: qgslayoutobject.h:178
QgsLayoutObject::MapGridIntervalY
@ MapGridIntervalY
Map grid interval Y.
Definition: qgslayoutobject.h:169
QgsLayoutItemMapGrid::Decimal
@ Decimal
Decimal degrees, use - for S/W coordinates.
Definition: qgslayoutitemmapgrid.h:208
QgsFontButton::setLayer
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
Definition: qgsfontbutton.cpp:762
QgsUnitTypes::DistanceNauticalMiles
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
QgsLayoutMapGridWidget::populateDataDefinedButtons
void populateDataDefinedButtons()
Initializes data defined buttons to current atlas coverage layer.
Definition: qgslayoutmapgridwidget.cpp:223
QgsLayoutItem::UndoMapGridFrameFill1Color
@ UndoMapGridFrameFill1Color
Map grid frame fill color 1.
Definition: qgslayoutitem.h:234
QgsLayoutObject::MapGridFrameSize
@ MapGridFrameSize
Map grid frame size.
Definition: qgslayoutobject.h:172
qgsguiutils.h
QgsLayoutItemMapGrid::OrthogonalTicks
@ OrthogonalTicks
Align ticks orthogonaly.
Definition: qgslayoutitemmapgrid.h:250
QgsLayoutReportContext::layerChanged
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
QgsLayoutObject::MapGridFrameDivisionsBottom
@ MapGridFrameDivisionsBottom
Map frame division display bottom.
Definition: qgslayoutobject.h:184
QgsLayoutItemMapGrid::Markers
@ Markers
Draw markers at intersections of grid lines.
Definition: qgslayoutitemmapgrid.h:165
QgsLayoutObject::MapGridFrameDivisionsLeft
@ MapGridFrameDivisionsLeft
Map frame division display left.
Definition: qgslayoutobject.h:181
QgsLayoutItem::UndoMapGridFrameFill2Color
@ UndoMapGridFrameFill2Color
Map grid frame fill color 2.
Definition: qgslayoutitem.h:235
QgsLayoutItemMapGrid::LineBorder
@ LineBorder
Simple solid line frame.
Definition: qgslayoutitemmapgrid.h:240
qgssymbol.h
QgsLayoutItemMapGrid::UnderTick
@ UnderTick
Draw annotations parallel to tick (under the line)
Definition: qgslayoutitemmapgrid.h:200
QgsLayoutItemMapGrid::HideAll
@ HideAll
No annotations.
Definition: qgslayoutitemmapgrid.h:177
qgsproject.h
Qgis::SymbolType::Marker
@ Marker
Marker symbol.
QgsLayoutItemMapGrid::FrameStyle
FrameStyle
Style for grid frame.
Definition: qgslayoutitemmapgrid.h:233
QgsLayoutItemMapGrid::OnTick
@ OnTick
Draw annotations parallel to tick (on the line)
Definition: qgslayoutitemmapgrid.h:199
qgslinesymbol.h
qgslayoutitemmap.h
QgsLayoutItemMapGrid::Left
@ Left
Left border.
Definition: qgslayoutitemmapgrid.h:224
QgsLayoutItemMapGrid::MM
@ MM
Grid units in millimeters.
Definition: qgslayoutitemmapgrid.h:153
qgsexpressionbuilderdialog.h
QgsFontButton::changed
void changed()
Emitted when the widget's text format settings are changed.