QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslayoutmarkerwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutmarkerwidget.cpp
3 --------------------------
4 begin : April 2020
5 copyright : (C) 2020 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
19
20#include "qgslayout.h"
21#include "qgslayoutitemmap.h"
22#include "qgslayoutitemmarker.h"
24#include "qgslayoutundostack.h"
25#include "qgsmarkersymbol.h"
26#include "qgsstyle.h"
27#include "qgsvectorlayer.h"
28
29#include "moc_qgslayoutmarkerwidget.cpp"
30
32 : QgsLayoutItemBaseWidget( nullptr, marker )
33 , mMarker( marker )
34{
35 Q_ASSERT( mMarker );
36
37 setupUi( this );
38 setPanelTitle( tr( "Marker Properties" ) );
39
40 //add widget for general composer item properties
41 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, marker );
42 mItemPropertiesWidget->showFrameGroup( false );
43 mainLayout->addWidget( mItemPropertiesWidget );
44
45 blockAllSignals( true );
46
47 mShapeStyleButton->setSymbolType( Qgis::SymbolType::Marker );
48
49 blockAllSignals( false );
50
51 connect( mMarker, &QgsLayoutObject::changed, this, &QgsLayoutMarkerWidget::setGuiElementValues );
52 mShapeStyleButton->registerExpressionContextGenerator( mMarker );
53
54 connect( mShapeStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMarkerWidget::symbolChanged );
55
56 connect( mRotationFromMapCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMarkerWidget::rotationFromMapCheckBoxChanged );
57 connect( mNorthOffsetSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMarkerWidget::northOffsetSpinBoxChanged );
58 connect( mNorthTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMarkerWidget::northTypeComboBoxChanged );
59
60 mNorthTypeComboBox->blockSignals( true );
61 mNorthTypeComboBox->addItem( tr( "Grid North" ), QgsLayoutNorthArrowHandler::GridNorth );
62 mNorthTypeComboBox->addItem( tr( "True North" ), QgsLayoutNorthArrowHandler::TrueNorth );
63 mNorthTypeComboBox->blockSignals( false );
64 mNorthOffsetSpinBox->setClearValue( 0.0 );
65
66 mShapeStyleButton->setLayer( coverageLayer() );
67 if ( mMarker->layout() )
68 {
69 connect( &mMarker->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mShapeStyleButton, &QgsSymbolButton::setLayer );
70 mMapComboBox->setCurrentLayout( mMarker->layout() );
71 mMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
72 connect( mMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutMarkerWidget::mapChanged );
73 }
74
75 setGuiElementValues();
76}
77
79{
80 if ( mItemPropertiesWidget )
81 mItemPropertiesWidget->setMasterLayout( masterLayout );
82}
83
85{
87 return false;
88
89 if ( mMarker )
90 {
91 disconnect( mMarker, &QgsLayoutObject::changed, this, &QgsLayoutMarkerWidget::setGuiElementValues );
92 }
93
94 mMarker = qobject_cast<QgsLayoutItemMarker *>( item );
95 mItemPropertiesWidget->setItem( mMarker );
96
97 if ( mMarker )
98 {
99 connect( mMarker, &QgsLayoutObject::changed, this, &QgsLayoutMarkerWidget::setGuiElementValues );
100 mShapeStyleButton->registerExpressionContextGenerator( mMarker );
101 }
102
103 setGuiElementValues();
104
105 return true;
106}
107
108void QgsLayoutMarkerWidget::blockAllSignals( bool block )
109{
110 mShapeStyleButton->blockSignals( block );
111 mMapComboBox->blockSignals( block );
112 mRotationFromMapCheckBox->blockSignals( block );
113 mNorthTypeComboBox->blockSignals( block );
114 mNorthOffsetSpinBox->blockSignals( block );
115}
116
117void QgsLayoutMarkerWidget::setGuiElementValues()
118{
119 if ( !mMarker )
120 {
121 return;
122 }
123
124 blockAllSignals( true );
125
126 mShapeStyleButton->setSymbol( mMarker->symbol()->clone() );
127
128 mMapComboBox->setItem( mMarker->linkedMap() );
129 if ( mMarker->linkedMap() )
130 {
131 mRotationFromMapCheckBox->setCheckState( Qt::Checked );
132 mMapComboBox->setEnabled( true );
133 mNorthTypeComboBox->setEnabled( true );
134 mNorthOffsetSpinBox->setEnabled( true );
135 }
136 else
137 {
138 mRotationFromMapCheckBox->setCheckState( Qt::Unchecked );
139 mMapComboBox->setEnabled( false );
140 mNorthTypeComboBox->setEnabled( false );
141 mNorthOffsetSpinBox->setEnabled( false );
142 }
143 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mMarker->northMode() ) );
144 mNorthOffsetSpinBox->setValue( mMarker->northOffset() );
145
146 blockAllSignals( false );
147}
148
149void QgsLayoutMarkerWidget::symbolChanged()
150{
151 if ( !mMarker )
152 return;
153
154 mMarker->layout()->undoStack()->beginCommand( mMarker, tr( "Change Marker Symbol" ), QgsLayoutItem::UndoShapeStyle );
155 mMarker->setSymbol( mShapeStyleButton->clonedSymbol<QgsMarkerSymbol>() );
156 mMarker->layout()->undoStack()->endCommand();
157}
158
159void QgsLayoutMarkerWidget::rotationFromMapCheckBoxChanged( int state )
160{
161 if ( !mMarker )
162 {
163 return;
164 }
165
166 mMarker->beginCommand( tr( "Toggle Rotation Sync" ) );
167 if ( state == Qt::Unchecked )
168 {
169 mMarker->setLinkedMap( nullptr );
170 mMapComboBox->setEnabled( false );
171 mNorthTypeComboBox->setEnabled( false );
172 mNorthOffsetSpinBox->setEnabled( false );
173 }
174 else
175 {
176 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( mMapComboBox->currentItem() );
177 mMarker->setLinkedMap( map );
178 mNorthTypeComboBox->setEnabled( true );
179 mNorthOffsetSpinBox->setEnabled( true );
180 mMapComboBox->setEnabled( true );
181 }
182 mMarker->endCommand();
183}
184
185void QgsLayoutMarkerWidget::mapChanged( QgsLayoutItem *item )
186{
187 if ( !mMarker )
188 {
189 return;
190 }
191
192 const QgsLayout *layout = mMarker->layout();
193 if ( !layout )
194 {
195 return;
196 }
197
198 QgsLayoutItemMap *map = qobject_cast<QgsLayoutItemMap *>( item );
199 if ( !map )
200 {
201 return;
202 }
203
204 mMarker->beginCommand( tr( "Change Rotation Map" ) );
205 mMarker->setLinkedMap( map );
206 mMarker->update();
207 mMarker->endCommand();
208}
209
210void QgsLayoutMarkerWidget::northOffsetSpinBoxChanged( double d )
211{
212 mMarker->beginCommand( tr( "Change Marker North Offset" ), QgsLayoutItem::UndoPictureNorthOffset );
213 mMarker->setNorthOffset( d );
214 mMarker->endCommand();
215 mMarker->update();
216}
217
218void QgsLayoutMarkerWidget::northTypeComboBoxChanged( int index )
219{
220 mMarker->beginCommand( tr( "Change Marker North Mode" ) );
221 mMarker->setNorthMode( static_cast<QgsLayoutNorthArrowHandler::NorthMode>( mNorthTypeComboBox->itemData( index ).toInt() ) );
222 mMarker->endCommand();
223 mMarker->update();
224}
@ Marker
Marker symbol.
Definition qgis.h:611
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
QgsLayoutItemBaseWidget(QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject)
Constructor for QgsLayoutItemBaseWidget, linked with the specified layoutObject.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
A layout item for showing marker symbols.
A widget for controlling the common properties of layout items (e.g.
Base class for graphical items within a QgsLayout.
@ UndoPictureNorthOffset
Picture north offset.
@ UndoShapeStyle
Shape symbol style.
int type() const override
Returns a unique graphics item type identifier.
void setMasterLayout(QgsMasterLayoutInterface *masterLayout) override
Sets the master layout associated with the item.
bool setNewItem(QgsLayoutItem *item) override
Attempts to update the widget to show the properties for the specified item.
QgsLayoutMarkerWidget(QgsLayoutItemMarker *marker)
constructor
NorthMode
Method for syncing rotation to a map's North direction.
void changed()
Emitted when the object's properties change.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
Interface for master layout type objects, such as print layouts and reports.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
void changed()
Emitted when the symbol's settings are changed.