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