QGIS API Documentation 3.29.0-Master (19d7edcfed)
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
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"
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
245void 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
263void 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
315void 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
328void 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
342void 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
370void 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
376void 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
388void QgsLayoutMapGridWidget::initFrameDisplayBox( QComboBox *c, QgsLayoutItemMapGrid::DisplayMode display )
389{
390 if ( !c )
391 {
392 return;
393 }
394 c->setCurrentIndex( c->findData( display ) );
395}
396
397void 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
412void 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
426void 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
433void 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
441void 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
458void QgsLayoutMapGridWidget::initAnnotationDirectionBox( QComboBox *c, QgsLayoutItemMapGrid::AnnotationDirection dir )
459{
460 if ( !c )
461 {
462 return;
463 }
464 c->setCurrentIndex( c->findData( dir ) );
465}
466
467bool 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
483void 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 mMarkerStyleFrame->setVisible( true );
530 mMarkerStyleLabel->setVisible( true );
531 mGridBlendComboBox->setVisible( true );
532 mGridBlendLabel->setVisible( true );
533 break;
535 mCrossWidthSpinBox->setVisible( false );
536 mCrossWidthDDBtn->setVisible( false );
537 mCrossWidthLabel->setVisible( false );
538 mGridLineStyleButton->setVisible( true );
539 mLineStyleLabel->setVisible( true );
540 mGridMarkerStyleButton->setVisible( false );
541 mMarkerStyleFrame->setVisible( false );
542 mMarkerStyleLabel->setVisible( false );
543 mGridBlendComboBox->setVisible( true );
544 mGridBlendLabel->setVisible( true );
545 break;
547 mCrossWidthSpinBox->setVisible( false );
548 mCrossWidthDDBtn->setVisible( false );
549 mCrossWidthLabel->setVisible( false );
550 mGridLineStyleButton->setVisible( false );
551 mLineStyleLabel->setVisible( false );
552 mGridMarkerStyleButton->setVisible( false );
553 mMarkerStyleFrame->setVisible( false );
554 mMarkerStyleLabel->setVisible( false );
555 mGridBlendComboBox->setVisible( false );
556 mGridBlendLabel->setVisible( false );
557 break;
558 }
559
560 //grid frame
561 mFrameWidthSpinBox->setValue( mMapGrid->frameWidth() );
562 mGridFrameMarginSpinBox->setValue( mMapGrid->frameMargin() );
563 const QgsLayoutItemMapGrid::FrameStyle gridFrameStyle = mMapGrid->frameStyle();
564 mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findData( gridFrameStyle ) );
565 switch ( gridFrameStyle )
566 {
569 toggleFrameControls( true, true, true, false );
570 break;
574 toggleFrameControls( true, false, true, true );
575 break;
578 toggleFrameControls( true, false, false, false );
579 break;
581 toggleFrameControls( false, false, false, false );
582 break;
583 }
584
585 mCheckGridLeftSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameLeft ) );
586 mCheckGridRightSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameRight ) );
587 mCheckGridTopSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameTop ) );
588 mCheckGridBottomSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameBottom ) );
589
590 mRotatedTicksGroupBox->setChecked( mMapGrid->rotatedTicksEnabled() );
591 mRotatedTicksLengthModeComboBox->setCurrentIndex( mRotatedTicksLengthModeComboBox->findData( mMapGrid->rotatedTicksLengthMode() ) );
592 mRotatedTicksThresholdSpinBox->setValue( mMapGrid->rotatedTicksMinimumAngle() );
593 mRotatedTicksMarginToCornerSpinBox->setValue( mMapGrid->rotatedTicksMarginToCorner() );
594
595 mRotatedAnnotationsGroupBox->setChecked( mMapGrid->rotatedAnnotationsEnabled() );
596 mRotatedAnnotationsLengthModeComboBox->setCurrentIndex( mRotatedAnnotationsLengthModeComboBox->findData( mMapGrid->rotatedAnnotationsLengthMode() ) );
597 mRotatedAnnotationsThresholdSpinBox->setValue( mMapGrid->rotatedAnnotationsMinimumAngle() );
598 mRotatedAnnotationsMarginToCornerSpinBox->setValue( mMapGrid->rotatedAnnotationsMarginToCorner() );
599
600 initFrameDisplayBox( mFrameDivisionsLeftComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Left ) );
601 initFrameDisplayBox( mFrameDivisionsRightComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Right ) );
602 initFrameDisplayBox( mFrameDivisionsTopComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Top ) );
603 initFrameDisplayBox( mFrameDivisionsBottomComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Bottom ) );
604
605 //line style
606 mGridLineStyleButton->setSymbol( mMapGrid->lineSymbol()->clone() );
607 //marker style
608 mGridMarkerStyleButton->setSymbol( mMapGrid->markerSymbol()->clone() );
609
610 mGridBlendComboBox->setBlendMode( mMapGrid->blendMode() );
611
612 mDrawAnnotationGroupBox->setChecked( mMapGrid->annotationEnabled() );
613 mAnnotationDisplayLeftComboBox->setCurrentIndex( mAnnotationDisplayLeftComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Left ) ) );
614 mAnnotationDisplayRightComboBox->setCurrentIndex( mAnnotationDisplayRightComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Right ) ) );
615 mAnnotationDisplayTopComboBox->setCurrentIndex( mAnnotationDisplayTopComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Top ) ) );
616 mAnnotationDisplayBottomComboBox->setCurrentIndex( mAnnotationDisplayBottomComboBox->findData( mMapGrid->annotationDisplay( QgsLayoutItemMapGrid::Bottom ) ) );
617
618 mAnnotationPositionLeftComboBox->setCurrentIndex( mAnnotationPositionLeftComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Left ) ) );
619 mAnnotationPositionRightComboBox->setCurrentIndex( mAnnotationPositionRightComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Right ) ) );
620 mAnnotationPositionTopComboBox->setCurrentIndex( mAnnotationPositionTopComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Top ) ) );
621 mAnnotationPositionBottomComboBox->setCurrentIndex( mAnnotationPositionBottomComboBox->findData( mMapGrid->annotationPosition( QgsLayoutItemMapGrid::Bottom ) ) );
622
623 initAnnotationDirectionBox( mAnnotationDirectionComboBoxLeft, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Left ) );
624 initAnnotationDirectionBox( mAnnotationDirectionComboBoxRight, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Right ) );
625 initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Top ) );
626 initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mMapGrid->annotationDirection( QgsLayoutItemMapGrid::Bottom ) );
627
628 mAnnotationFontButton->setDialogTitle( tr( "Grid Annotation Font" ) );
629 mAnnotationFontButton->setMode( QgsFontButton::ModeTextRenderer );
630 mAnnotationFontButton->setTextFormat( mMapGrid->annotationTextFormat() );
631
632 mAnnotationFormatComboBox->setCurrentIndex( mAnnotationFormatComboBox->findData( mMapGrid->annotationFormat() ) );
633 mAnnotationFormatButton->setEnabled( mMapGrid->annotationFormat() == QgsLayoutItemMapGrid::CustomFormat );
634 mDistanceToMapFrameSpinBox->setValue( mMapGrid->annotationFrameDistance() );
635 mCoordinatePrecisionSpinBox->setValue( mMapGrid->annotationPrecision() );
636
637 //Unit
638 mMapGridUnitComboBox->setCurrentIndex( mMapGridUnitComboBox->findData( mMapGrid->units() ) );
639 switch ( mMapGrid->units() )
640 {
644 mIntervalStackedWidget->setCurrentIndex( 0 );
645 break;
646
648 mIntervalStackedWidget->setCurrentIndex( 1 );
649 break;
650 }
651 mMinWidthSpinBox->setValue( mMapGrid->minimumIntervalWidth() );
652 mMaxWidthSpinBox->setValue( mMapGrid->maximumIntervalWidth() );
653
654 whileBlocking( mMapGridCrsSelector )->setCrs( mMapGrid->crs() );
655}
656
657void QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished()
658{
659 if ( !mMapGrid || !mMap )
660 {
661 return;
662 }
663
664 mMap->beginCommand( tr( "Change Grid Interval" ) );
665 mMapGrid->setIntervalX( mIntervalXSpinBox->value() );
666 mMap->updateBoundingRect();
667 mMap->update();
668 mMap->endCommand();
669}
670
671void QgsLayoutMapGridWidget::mIntervalYSpinBox_editingFinished()
672{
673 if ( !mMapGrid || !mMap )
674 {
675 return;
676 }
677
678 mMap->beginCommand( tr( "Change Grid Interval" ) );
679 mMapGrid->setIntervalY( mIntervalYSpinBox->value() );
680 mMap->updateBoundingRect();
681 mMap->update();
682 mMap->endCommand();
683}
684
685void QgsLayoutMapGridWidget::mOffsetXSpinBox_valueChanged( double value )
686{
687 if ( !mMapGrid || !mMap )
688 {
689 return;
690 }
691
692 mMap->beginCommand( tr( "Change Grid Offset" ) );
693 mMapGrid->setOffsetX( value );
694 mMap->updateBoundingRect();
695 mMap->update();
696 mMap->endCommand();
697}
698
699void QgsLayoutMapGridWidget::mOffsetYSpinBox_valueChanged( double value )
700{
701 if ( !mMapGrid || !mMap )
702 {
703 return;
704 }
705
706 mMap->beginCommand( tr( "Change Grid Offset" ) );
707 mMapGrid->setOffsetY( value );
708 mMap->updateBoundingRect();
709 mMap->update();
710 mMap->endCommand();
711}
712
713void QgsLayoutMapGridWidget::mCrossWidthSpinBox_valueChanged( double val )
714{
715 if ( !mMapGrid || !mMap )
716 {
717 return;
718 }
719
720 mMap->beginCommand( tr( "Change Cross Width" ) );
721 mMapGrid->setCrossLength( val );
722 mMap->update();
723 mMap->endCommand();
724}
725
726void QgsLayoutMapGridWidget::mFrameWidthSpinBox_valueChanged( double val )
727{
728 if ( !mMapGrid || !mMap )
729 {
730 return;
731 }
732
733 mMap->beginCommand( tr( "Change Frame Width" ) );
734 mMapGrid->setFrameWidth( val );
735 mMap->updateBoundingRect();
736 mMap->update();
737 mMap->endCommand();
738}
739
740void QgsLayoutMapGridWidget::mGridFrameMarginSpinBox_valueChanged( double val )
741{
742 if ( !mMapGrid || !mMap )
743 {
744 return;
745 }
746
747 mMap->beginCommand( tr( "Change Grid Frame Margin" ) );
748 mMapGrid->setFrameMargin( val );
749 mMap->updateBoundingRect();
750 mMap->update();
751 mMap->endCommand();
752}
753
754void QgsLayoutMapGridWidget::mCheckGridLeftSide_toggled( bool checked )
755{
756 if ( !mMapGrid || !mMap )
757 {
758 return;
759 }
760
761 mMap->beginCommand( tr( "Change Frame Left" ) );
762 mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameLeft, checked );
763 mMap->updateBoundingRect();
764 mMap->update();
765 mMap->endCommand();
766}
767
768void QgsLayoutMapGridWidget::mCheckGridRightSide_toggled( bool checked )
769{
770 if ( !mMapGrid || !mMap )
771 {
772 return;
773 }
774
775 mMap->beginCommand( tr( "Change Frame Right" ) );
776 mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameRight, checked );
777 mMap->updateBoundingRect();
778 mMap->update();
779 mMap->endCommand();
780}
781
782void QgsLayoutMapGridWidget::mCheckGridTopSide_toggled( bool checked )
783{
784 if ( !mMapGrid || !mMap )
785 {
786 return;
787 }
788
789 mMap->beginCommand( tr( "Change Frame Top" ) );
790 mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameTop, checked );
791 mMap->updateBoundingRect();
792 mMap->update();
793 mMap->endCommand();
794}
795
796void QgsLayoutMapGridWidget::mCheckGridBottomSide_toggled( bool checked )
797{
798 if ( !mMapGrid || !mMap )
799 {
800 return;
801 }
802
803 mMap->beginCommand( tr( "Change Frame Bottom" ) );
804 mMapGrid->setFrameSideFlag( QgsLayoutItemMapGrid::FrameBottom, checked );
805 mMap->updateBoundingRect();
806 mMap->update();
807 mMap->endCommand();
808}
809
810void QgsLayoutMapGridWidget::mFrameDivisionsLeftComboBox_currentIndexChanged( int index )
811{
812 handleChangedFrameDisplay( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsLeftComboBox->itemData( index ).toInt() ) );
813}
814
815void QgsLayoutMapGridWidget::mFrameDivisionsRightComboBox_currentIndexChanged( int index )
816{
817 handleChangedFrameDisplay( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsRightComboBox->itemData( index ).toInt() ) );
818}
819
820void QgsLayoutMapGridWidget::mFrameDivisionsTopComboBox_currentIndexChanged( int index )
821{
822 handleChangedFrameDisplay( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsTopComboBox->itemData( index ).toInt() ) );
823}
824
825void QgsLayoutMapGridWidget::mFrameDivisionsBottomComboBox_currentIndexChanged( int index )
826{
827 handleChangedFrameDisplay( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mFrameDivisionsBottomComboBox->itemData( index ).toInt() ) );
828}
829
830void QgsLayoutMapGridWidget::mGridFramePenSizeSpinBox_valueChanged( double d )
831{
832 if ( !mMapGrid || !mMap )
833 {
834 return;
835 }
836
837 mMap->beginCommand( tr( "Change Frame Thickness" ) );
838 mMapGrid->setFramePenSize( d );
839 mMap->updateBoundingRect();
840 mMap->update();
841 mMap->endCommand();
842}
843
844void QgsLayoutMapGridWidget::mGridFramePenColorButton_colorChanged( const QColor &newColor )
845{
846 if ( !mMapGrid || !mMap )
847 {
848 return;
849 }
850
851 mMap->beginCommand( tr( "Change Frame Color" ), QgsLayoutItem::UndoGridFramePenColor );
852 mMapGrid->setFramePenColor( newColor );
853 mMap->update();
854 mMap->endCommand();
855}
856
857void QgsLayoutMapGridWidget::mGridFrameFill1ColorButton_colorChanged( const QColor &newColor )
858{
859 if ( !mMapGrid || !mMap )
860 {
861 return;
862 }
863
864 mMap->beginCommand( tr( "Change Frame Fill Color" ), QgsLayoutItem::UndoMapGridFrameFill1Color );
865 mMapGrid->setFrameFillColor1( newColor );
866 mMap->update();
867 mMap->endCommand();
868}
869
870void QgsLayoutMapGridWidget::mGridFrameFill2ColorButton_colorChanged( const QColor &newColor )
871{
872 if ( !mMapGrid || !mMap )
873 {
874 return;
875 }
876
877 mMap->beginCommand( tr( "Change Frame Fill Color" ), QgsLayoutItem::UndoMapGridFrameFill2Color );
878 mMapGrid->setFrameFillColor2( newColor );
879 mMap->update();
880 mMap->endCommand();
881}
882
883void QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged( int )
884{
885 if ( !mMapGrid || !mMap )
886 {
887 return;
888 }
889
890 const QgsLayoutItemMapGrid::FrameStyle style = static_cast< QgsLayoutItemMapGrid::FrameStyle >( mFrameStyleComboBox->currentData().toInt() );
891 mMap->beginCommand( tr( "Change Frame Style" ) );
892 mMapGrid->setFrameStyle( style );
893 switch ( style )
894 {
897 toggleFrameControls( true, true, true, false );
898 break;
902 toggleFrameControls( true, false, true, true );
903 break;
906 toggleFrameControls( true, false, false, false );
907 break;
909 toggleFrameControls( false, false, false, false );
910 break;
911 }
912 mMap->updateBoundingRect();
913 mMap->update();
914 mMap->endCommand();
915}
916
917void QgsLayoutMapGridWidget::mRotatedTicksGroupBox_toggled( bool state )
918{
919 if ( !mMapGrid || !mMap )
920 {
921 return;
922 }
923
924 mMap->beginCommand( tr( "Change Tick Rotation Enabled" ) );
925 mMapGrid->setRotatedTicksEnabled( state );
926 mMap->update();
927 mMap->endCommand();
928}
929
930void QgsLayoutMapGridWidget::mRotatedTicksLengthModeComboBox_currentIndexChanged( int )
931{
932 if ( !mMapGrid || !mMap )
933 {
934 return;
935 }
936
937 const QgsLayoutItemMapGrid::TickLengthMode mode = static_cast< QgsLayoutItemMapGrid::TickLengthMode >( mRotatedTicksLengthModeComboBox->currentData().toInt() );
938 mMap->beginCommand( tr( "Change Tick Length Mode" ) );
939 mMapGrid->setRotatedTicksLengthMode( mode );
940 mMap->update();
941 mMap->endCommand();
942}
943
944void QgsLayoutMapGridWidget::mRotatedTicksThresholdSpinBox_valueChanged( double val )
945{
946 if ( !mMapGrid || !mMap )
947 {
948 return;
949 }
950
951 mMap->beginCommand( tr( "Change Rotated Ticks Threshold" ) );
952 mMapGrid->setRotatedTicksMinimumAngle( val );
953 mMap->update();
954 mMap->endCommand();
955}
956
957void QgsLayoutMapGridWidget::mRotatedTicksMarginToCornerSpinBox_valueChanged( double val )
958{
959 if ( !mMapGrid || !mMap )
960 {
961 return;
962 }
963
964 mMap->beginCommand( tr( "Change Rotated Ticks Margin to Corner" ) );
965 mMapGrid->setRotatedTicksMarginToCorner( val );
966 mMap->update();
967 mMap->endCommand();
968}
969
970void QgsLayoutMapGridWidget::mRotatedAnnotationsGroupBox_toggled( bool state )
971{
972 if ( !mMapGrid || !mMap )
973 {
974 return;
975 }
976
977 mMap->beginCommand( tr( "Change Annotation Rotation Enabled" ) );
978 mMapGrid->setRotatedAnnotationsEnabled( state );
979 mMap->update();
980 mMap->endCommand();
981}
982
983void QgsLayoutMapGridWidget::mRotatedAnnotationsLengthModeComboBox_currentIndexChanged( int )
984{
985 if ( !mMapGrid || !mMap )
986 {
987 return;
988 }
989
990 const QgsLayoutItemMapGrid::TickLengthMode mode = static_cast< QgsLayoutItemMapGrid::TickLengthMode >( mRotatedAnnotationsLengthModeComboBox->currentData().toInt() );
991 mMap->beginCommand( tr( "Change Annotation Length Mode" ) );
992 mMapGrid->setRotatedAnnotationsLengthMode( mode );
993 mMap->update();
994 mMap->endCommand();
995}
996
997void QgsLayoutMapGridWidget::mRotatedAnnotationsThresholdSpinBox_valueChanged( double val )
998{
999 if ( !mMapGrid || !mMap )
1000 {
1001 return;
1002 }
1003
1004 mMap->beginCommand( tr( "Change Rotated Annotations Threshold" ) );
1005 mMapGrid->setRotatedAnnotationsMinimumAngle( val );
1006 mMap->update();
1007 mMap->endCommand();
1008}
1009
1010void QgsLayoutMapGridWidget::mRotatedAnnotationsMarginToCornerSpinBox_valueChanged( double val )
1011{
1012 if ( !mMapGrid || !mMap )
1013 {
1014 return;
1015 }
1016
1017 mMap->beginCommand( tr( "Change Rotated Annotations Margin to Corner" ) );
1018 mMapGrid->setRotatedAnnotationsMarginToCorner( val );
1019 mMap->update();
1020 mMap->endCommand();
1021}
1022
1023void QgsLayoutMapGridWidget::intervalUnitChanged( int )
1024{
1025 if ( !mMapGrid || !mMap )
1026 {
1027 return;
1028 }
1029
1030 const QgsLayoutItemMapGrid::GridUnit unit = static_cast< QgsLayoutItemMapGrid::GridUnit >( mMapGridUnitComboBox->currentData().toInt() );
1031 switch ( unit )
1032 {
1036 mIntervalStackedWidget->setCurrentIndex( 0 );
1037 break;
1038
1040 mIntervalStackedWidget->setCurrentIndex( 1 );
1041 break;
1042 }
1043
1044 mMap->beginCommand( tr( "Change Grid Unit" ) );
1045 mMapGrid->setUnits( unit );
1046 mMap->updateBoundingRect();
1047 mMap->update();
1048 mMap->endCommand();
1049}
1050
1051void QgsLayoutMapGridWidget::minIntervalChanged( double interval )
1052{
1053 mMap->beginCommand( tr( "Change Grid Interval Range" ), QgsLayoutItem::UndoMapGridIntervalRange );
1054 mMapGrid->setMinimumIntervalWidth( interval );
1055 mMap->endCommand();
1056 mMap->updateBoundingRect();
1057 mMap->update();
1058}
1059
1060void QgsLayoutMapGridWidget::maxIntervalChanged( double interval )
1061{
1062 mMap->beginCommand( tr( "Change Grid Interval Range" ), QgsLayoutItem::UndoMapGridIntervalRange );
1063 mMapGrid->setMaximumIntervalWidth( interval );
1064 mMap->endCommand();
1065 mMap->updateBoundingRect();
1066 mMap->update();
1067}
1068
1069void QgsLayoutMapGridWidget::annotationTextFormatChanged()
1070{
1071 if ( !mMapGrid || !mMap )
1072 {
1073 return;
1074 }
1075
1076 mMap->beginCommand( tr( "Change Annotation Font" ) );
1077 mMapGrid->setAnnotationTextFormat( mAnnotationFontButton->textFormat() );
1078 mMap->endCommand();
1079 mMap->updateBoundingRect();
1080 mMap->update();
1081}
1082
1083void QgsLayoutMapGridWidget::onCrsChanged()
1084{
1085 mBlockAnnotationFormatUpdates++;
1086 const QgsLayoutItemMapGrid::AnnotationFormat prevFormat = static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->currentData().toInt() );
1087
1088 mAnnotationFormatComboBox->clear();
1089 mAnnotationFormatComboBox->addItem( tr( "Decimal" ), QgsLayoutItemMapGrid::Decimal );
1090 mAnnotationFormatComboBox->addItem( tr( "Decimal with Suffix" ), QgsLayoutItemMapGrid::DecimalWithSuffix );
1091
1092 // only show degree based options for geographic CRSes
1093 const QgsCoordinateReferenceSystem crs = mMapGrid->crs().isValid() ? mMapGrid->crs() : mMap->crs();
1094 switch ( crs.mapUnits() )
1095 {
1104 break;
1105
1108 mAnnotationFormatComboBox->addItem( tr( "Degree, Minute" ), QgsLayoutItemMapGrid::DegreeMinuteNoSuffix );
1109 mAnnotationFormatComboBox->addItem( tr( "Degree, Minute with Suffix" ), QgsLayoutItemMapGrid::DegreeMinute );
1110 mAnnotationFormatComboBox->addItem( tr( "Degree, Minute Aligned" ), QgsLayoutItemMapGrid::DegreeMinutePadded );
1111 mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second" ), QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix );
1112 mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second with Suffix" ), QgsLayoutItemMapGrid::DegreeMinuteSecond );
1113 mAnnotationFormatComboBox->addItem( tr( "Degree, Minute, Second Aligned" ), QgsLayoutItemMapGrid::DegreeMinuteSecondPadded );
1114 break;
1115 }
1116 mAnnotationFormatComboBox->addItem( tr( "Custom" ), QgsLayoutItemMapGrid::CustomFormat );
1117
1118 const int prevIndex = mAnnotationFormatComboBox->findData( prevFormat );
1119 if ( prevIndex >= 0 )
1120 mAnnotationFormatComboBox->setCurrentIndex( prevIndex );
1121 else
1122 mAnnotationFormatComboBox->setCurrentIndex( 0 );
1123 mBlockAnnotationFormatUpdates--;
1124
1125 const QgsLayoutItemMapGrid::AnnotationFormat newFormat = static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->currentData().toInt() );
1126 if ( newFormat != prevFormat )
1127 {
1128 mAnnotationFormatComboBox_currentIndexChanged( mAnnotationFormatComboBox->currentIndex() );
1129 }
1130}
1131
1132void QgsLayoutMapGridWidget::mGridBlendComboBox_currentIndexChanged( int index )
1133{
1134 Q_UNUSED( index )
1135 if ( mMapGrid )
1136 {
1137 mMap->beginCommand( tr( "Change Grid Blend Mode" ) );
1138 mMapGrid->setBlendMode( mGridBlendComboBox->blendMode() );
1139 mMap->update();
1140 mMap->endCommand();
1141 }
1142
1143}
1144
1145void QgsLayoutMapGridWidget::mGridTypeComboBox_currentIndexChanged( int )
1146{
1147 if ( !mMapGrid || !mMap )
1148 {
1149 return;
1150 }
1151
1152 mMap->beginCommand( tr( "Change Grid Type" ) );
1153 switch ( static_cast< QgsLayoutItemMapGrid::GridStyle >( mGridTypeComboBox->currentData().toInt() ) )
1154 {
1156 mMapGrid->setStyle( QgsLayoutItemMapGrid::Cross );
1157 mCrossWidthSpinBox->setVisible( true );
1158 mCrossWidthDDBtn->setVisible( true );
1159 mCrossWidthLabel->setVisible( true );
1160 mGridLineStyleButton->setVisible( true );
1161 mLineStyleLabel->setVisible( true );
1162 mGridMarkerStyleButton->setVisible( false );
1163 mMarkerStyleFrame->setVisible( false );
1164 mMarkerStyleFrame->setVisible( false );
1165 mMarkerStyleLabel->setVisible( false );
1166 mGridBlendComboBox->setVisible( true );
1167 mGridBlendLabel->setVisible( true );
1168 break;
1169
1171 mMapGrid->setStyle( QgsLayoutItemMapGrid::Markers );
1172 mCrossWidthSpinBox->setVisible( false );
1173 mCrossWidthDDBtn->setVisible( false );
1174 mCrossWidthLabel->setVisible( false );
1175 mGridLineStyleButton->setVisible( false );
1176 mLineStyleLabel->setVisible( false );
1177 mGridMarkerStyleButton->setVisible( true );
1178 mMarkerStyleFrame->setVisible( true );
1179 mMarkerStyleLabel->setVisible( true );
1180 mGridBlendComboBox->setVisible( true );
1181 mGridBlendLabel->setVisible( true );
1182 break;
1183
1185 mMapGrid->setStyle( QgsLayoutItemMapGrid::Solid );
1186 mCrossWidthSpinBox->setVisible( false );
1187 mCrossWidthDDBtn->setVisible( false );
1188 mCrossWidthLabel->setVisible( false );
1189 mGridLineStyleButton->setVisible( true );
1190 mLineStyleLabel->setVisible( true );
1191 mGridMarkerStyleButton->setVisible( false );
1192 mMarkerStyleFrame->setVisible( false );
1193 mMarkerStyleLabel->setVisible( false );
1194 mGridBlendComboBox->setVisible( true );
1195 mGridBlendLabel->setVisible( true );
1196 break;
1197
1199 mMapGrid->setStyle( QgsLayoutItemMapGrid::FrameAnnotationsOnly );
1200 mCrossWidthSpinBox->setVisible( false );
1201 mCrossWidthDDBtn->setVisible( false );
1202 mCrossWidthLabel->setVisible( false );
1203 mGridLineStyleButton->setVisible( false );
1204 mLineStyleLabel->setVisible( false );
1205 mGridMarkerStyleButton->setVisible( false );
1206 mMarkerStyleFrame->setVisible( false );
1207 mMarkerStyleLabel->setVisible( false );
1208 mGridBlendComboBox->setVisible( false );
1209 mGridBlendLabel->setVisible( false );
1210 break;
1211 }
1212
1213 mMap->updateBoundingRect();
1214 mMap->update();
1215 mMap->endCommand();
1216}
1217
1218void QgsLayoutMapGridWidget::mapGridCrsChanged( const QgsCoordinateReferenceSystem &crs )
1219{
1220 if ( !mMapGrid || !mMap )
1221 {
1222 return;
1223 }
1224
1225 if ( mMapGrid->crs() == crs )
1226 return;
1227
1228 mMap->beginCommand( tr( "Change Grid CRS" ) );
1229 mMapGrid->setCrs( crs );
1230 mMap->updateBoundingRect();
1231 mMap->update();
1232 mMap->endCommand();
1233}
1234
1235void QgsLayoutMapGridWidget::mDrawAnnotationGroupBox_toggled( bool state )
1236{
1237 if ( !mMapGrid || !mMap )
1238 {
1239 return;
1240 }
1241
1242 mMap->beginCommand( tr( "Toggle Annotations" ) );
1243 mMapGrid->setAnnotationEnabled( state );
1244 mMap->updateBoundingRect();
1245 mMap->update();
1246 mMap->endCommand();
1247}
1248
1249void QgsLayoutMapGridWidget::mAnnotationFormatButton_clicked()
1250{
1251 if ( !mMapGrid || !mMap )
1252 {
1253 return;
1254 }
1255
1256 QgsExpressionContext expressionContext = mMapGrid->createExpressionContext();
1257 expressionContext.setHighlightedFunctions( QStringList() << QStringLiteral( "to_dms" ) << QStringLiteral( "to_dm" ) );
1258
1259 QgsExpressionBuilderDialog exprDlg( coverageLayer(), mMapGrid->annotationExpression(), this, QStringLiteral( "generic" ), expressionContext );
1260 exprDlg.setWindowTitle( tr( "Expression Based Annotation" ) );
1261
1262 if ( exprDlg.exec() == QDialog::Accepted )
1263 {
1264 const QString expression = exprDlg.expressionText();
1265 mMap->beginCommand( tr( "Change Annotation Format" ) );
1266 mMapGrid->setAnnotationExpression( expression );
1267 mMap->updateBoundingRect();
1268 mMap->update();
1269 mMap->endCommand();
1270 }
1271}
1272
1273void QgsLayoutMapGridWidget::mAnnotationDisplayLeftComboBox_currentIndexChanged( int )
1274{
1275 handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayLeftComboBox->currentData().toInt() ) );
1276}
1277
1278void QgsLayoutMapGridWidget::mAnnotationDisplayRightComboBox_currentIndexChanged( int )
1279{
1280 handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayRightComboBox->currentData().toInt() ) );
1281}
1282
1283void QgsLayoutMapGridWidget::mAnnotationDisplayTopComboBox_currentIndexChanged( int )
1284{
1285 handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayTopComboBox->currentData().toInt() ) );
1286}
1287
1288void QgsLayoutMapGridWidget::mAnnotationDisplayBottomComboBox_currentIndexChanged( int )
1289{
1290 handleChangedAnnotationDisplay( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::DisplayMode >( mAnnotationDisplayBottomComboBox->currentData().toInt() ) );
1291}
1292
1293void QgsLayoutMapGridWidget::mAnnotationPositionLeftComboBox_currentIndexChanged( int )
1294{
1295 handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionLeftComboBox->currentData().toInt() ) );
1296}
1297
1298void QgsLayoutMapGridWidget::mAnnotationPositionRightComboBox_currentIndexChanged( int )
1299{
1300 handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionRightComboBox->currentData().toInt() ) );
1301}
1302
1303void QgsLayoutMapGridWidget::mAnnotationPositionTopComboBox_currentIndexChanged( int )
1304{
1305 handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionTopComboBox->currentData().toInt() ) );
1306}
1307
1308void QgsLayoutMapGridWidget::mAnnotationPositionBottomComboBox_currentIndexChanged( int )
1309{
1310 handleChangedAnnotationPosition( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::AnnotationPosition >( mAnnotationPositionBottomComboBox->currentData().toInt() ) );
1311}
1312
1313void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxLeft_currentIndexChanged( int index )
1314{
1315 handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Left, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxLeft->itemData( index ).toInt() ) );
1316}
1317
1318void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxRight_currentIndexChanged( int index )
1319{
1320 handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Right, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxRight->itemData( index ).toInt() ) );
1321}
1322
1323void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxTop_currentIndexChanged( int index )
1324{
1325 handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Top, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxTop->itemData( index ).toInt() ) );
1326}
1327
1328void QgsLayoutMapGridWidget::mAnnotationDirectionComboBoxBottom_currentIndexChanged( int index )
1329{
1330 handleChangedAnnotationDirection( QgsLayoutItemMapGrid::Bottom, static_cast< QgsLayoutItemMapGrid::AnnotationDirection >( mAnnotationDirectionComboBoxBottom->itemData( index ).toInt() ) );
1331}
1332
1333void QgsLayoutMapGridWidget::mDistanceToMapFrameSpinBox_valueChanged( double d )
1334{
1335 if ( !mMapGrid || !mMap )
1336 {
1337 return;
1338 }
1339
1340 mMap->beginCommand( tr( "Change Annotation Distance" ), QgsLayoutItem::UndoMapAnnotationDistance );
1341 mMapGrid->setAnnotationFrameDistance( d );
1342 mMap->updateBoundingRect();
1343 mMap->update();
1344 mMap->endCommand();
1345}
1346
1347void QgsLayoutMapGridWidget::lineSymbolChanged()
1348{
1349 if ( !mMapGrid || !mMap )
1350 {
1351 return;
1352 }
1353
1354 mMap->beginCommand( tr( "Change Grid Line Style" ), QgsLayoutItem::UndoMapGridLineSymbol );
1355 mMapGrid->setLineSymbol( mGridLineStyleButton->clonedSymbol<QgsLineSymbol>() );
1356 mMap->endCommand();
1357 mMap->update();
1358}
1359
1360void QgsLayoutMapGridWidget::markerSymbolChanged()
1361{
1362 if ( !mMapGrid || !mMap )
1363 {
1364 return;
1365 }
1366
1367 mMap->beginCommand( tr( "Change Grid Marker Style" ), QgsLayoutItem::UndoMapGridMarkerSymbol );
1368 mMapGrid->setMarkerSymbol( mGridMarkerStyleButton->clonedSymbol<QgsMarkerSymbol>() );
1369 mMap->endCommand();
1370 mMap->update();
1371}
1372
1373void QgsLayoutMapGridWidget::gridEnabledToggled( bool active )
1374{
1375 if ( !mMapGrid || !mMap )
1376 {
1377 return;
1378 }
1379
1380 mMap->beginCommand( tr( "Toggle Grid Display" ) );
1381 mMapGrid->setEnabled( active );
1382 mMap->endCommand();
1383 mMap->updateBoundingRect();
1384 mMap->update();
1385}
1386
1387void QgsLayoutMapGridWidget::mAnnotationFormatComboBox_currentIndexChanged( int index )
1388{
1389 if ( !mMapGrid || !mMap )
1390 {
1391 return;
1392 }
1393 if ( mBlockAnnotationFormatUpdates )
1394 return;
1395
1396 mMap->beginCommand( tr( "Change Annotation Format" ) );
1397
1398 mMapGrid->setAnnotationFormat( static_cast< QgsLayoutItemMapGrid::AnnotationFormat >( mAnnotationFormatComboBox->itemData( index ).toInt() ) );
1399 mAnnotationFormatButton->setEnabled( mMapGrid->annotationFormat() == QgsLayoutItemMapGrid::CustomFormat );
1400
1401 mMap->updateBoundingRect();
1402 mMap->update();
1403 mMap->endCommand();
1404}
1405
1406void QgsLayoutMapGridWidget::mCoordinatePrecisionSpinBox_valueChanged( int value )
1407{
1408 if ( !mMapGrid || !mMap )
1409 {
1410 return;
1411 }
1412 mMap->beginCommand( tr( "Change Annotation Precision" ) );
1413 mMapGrid->setAnnotationPrecision( value );
1414 mMap->updateBoundingRect();
1415 mMap->update();
1416 mMap->endCommand();
1417}
static QString defaultProjectScales()
A string with default project scales.
Definition: qgis.cpp:271
@ 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:62
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:477
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)
This class is a composition of two QSettings instances:
Definition: qgssettings.h:63
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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:3003
const QgsCoordinateReferenceSystem & crs