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