QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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#include "moc_qgslayoutmarkerwidget.cpp"
20#include "qgsstyle.h"
21#include "qgslayoutitemmarker.h"
22#include "qgslayout.h"
23#include "qgslayoutundostack.h"
24#include "qgsvectorlayer.h"
25#include "qgslayoutitemmap.h"
26#include "qgsmarkersymbol.h"
28
30 : QgsLayoutItemBaseWidget( nullptr, marker )
31 , mMarker( marker )
32{
33 Q_ASSERT( mMarker );
34
35 setupUi( this );
36 setPanelTitle( tr( "Marker Properties" ) );
37
38 //add widget for general composer item properties
39 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, marker );
40 mItemPropertiesWidget->showFrameGroup( false );
41 mainLayout->addWidget( mItemPropertiesWidget );
42
43 blockAllSignals( true );
44
45 mShapeStyleButton->setSymbolType( Qgis::SymbolType::Marker );
46
47 blockAllSignals( false );
48
49 connect( mMarker, &QgsLayoutObject::changed, this, &QgsLayoutMarkerWidget::setGuiElementValues );
50 mShapeStyleButton->registerExpressionContextGenerator( mMarker );
51
52 connect( mShapeStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMarkerWidget::symbolChanged );
53
54 connect( mRotationFromMapCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutMarkerWidget::rotationFromMapCheckBoxChanged );
55 connect( mNorthOffsetSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMarkerWidget::northOffsetSpinBoxChanged );
56 connect( mNorthTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMarkerWidget::northTypeComboBoxChanged );
57
58 mNorthTypeComboBox->blockSignals( true );
59 mNorthTypeComboBox->addItem( tr( "Grid North" ), QgsLayoutNorthArrowHandler::GridNorth );
60 mNorthTypeComboBox->addItem( tr( "True North" ), QgsLayoutNorthArrowHandler::TrueNorth );
61 mNorthTypeComboBox->blockSignals( false );
62 mNorthOffsetSpinBox->setClearValue( 0.0 );
63
64 mShapeStyleButton->setLayer( coverageLayer() );
65 if ( mMarker->layout() )
66 {
67 connect( &mMarker->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mShapeStyleButton, &QgsSymbolButton::setLayer );
68 mMapComboBox->setCurrentLayout( mMarker->layout() );
69 mMapComboBox->setItemType( QgsLayoutItemRegistry::LayoutMap );
70 connect( mMapComboBox, &QgsLayoutItemComboBox::itemChanged, this, &QgsLayoutMarkerWidget::mapChanged );
71 }
72
73 setGuiElementValues();
74}
75
77{
78 if ( mItemPropertiesWidget )
79 mItemPropertiesWidget->setMasterLayout( masterLayout );
80}
81
83{
85 return false;
86
87 if ( mMarker )
88 {
89 disconnect( mMarker, &QgsLayoutObject::changed, this, &QgsLayoutMarkerWidget::setGuiElementValues );
90 }
91
92 mMarker = qobject_cast< QgsLayoutItemMarker * >( item );
93 mItemPropertiesWidget->setItem( mMarker );
94
95 if ( mMarker )
96 {
97 connect( mMarker, &QgsLayoutObject::changed, this, &QgsLayoutMarkerWidget::setGuiElementValues );
98 mShapeStyleButton->registerExpressionContextGenerator( mMarker );
99 }
100
101 setGuiElementValues();
102
103 return true;
104}
105
106void QgsLayoutMarkerWidget::blockAllSignals( bool block )
107{
108 mShapeStyleButton->blockSignals( block );
109 mMapComboBox->blockSignals( block );
110 mRotationFromMapCheckBox->blockSignals( block );
111 mNorthTypeComboBox->blockSignals( block );
112 mNorthOffsetSpinBox->blockSignals( block );
113}
114
115void QgsLayoutMarkerWidget::setGuiElementValues()
116{
117 if ( !mMarker )
118 {
119 return;
120 }
121
122 blockAllSignals( true );
123
124 mShapeStyleButton->setSymbol( mMarker->symbol()->clone() );
125
126 mMapComboBox->setItem( mMarker->linkedMap() );
127 if ( mMarker->linkedMap() )
128 {
129 mRotationFromMapCheckBox->setCheckState( Qt::Checked );
130 mMapComboBox->setEnabled( true );
131 mNorthTypeComboBox->setEnabled( true );
132 mNorthOffsetSpinBox->setEnabled( true );
133 }
134 else
135 {
136 mRotationFromMapCheckBox->setCheckState( Qt::Unchecked );
137 mMapComboBox->setEnabled( false );
138 mNorthTypeComboBox->setEnabled( false );
139 mNorthOffsetSpinBox->setEnabled( false );
140 }
141 mNorthTypeComboBox->setCurrentIndex( mNorthTypeComboBox->findData( mMarker->northMode() ) );
142 mNorthOffsetSpinBox->setValue( mMarker->northOffset() );
143
144 blockAllSignals( false );
145}
146
147void QgsLayoutMarkerWidget::symbolChanged()
148{
149 if ( !mMarker )
150 return;
151
152 mMarker->layout()->undoStack()->beginCommand( mMarker, tr( "Change Marker Symbol" ), QgsLayoutItem::UndoShapeStyle );
153 mMarker->setSymbol( mShapeStyleButton->clonedSymbol<QgsMarkerSymbol>() );
154 mMarker->layout()->undoStack()->endCommand();
155}
156
157void QgsLayoutMarkerWidget::rotationFromMapCheckBoxChanged( int state )
158{
159 if ( !mMarker )
160 {
161 return;
162 }
163
164 mMarker->beginCommand( tr( "Toggle Rotation Sync" ) );
165 if ( state == Qt::Unchecked )
166 {
167 mMarker->setLinkedMap( nullptr );
168 mMapComboBox->setEnabled( false );
169 mNorthTypeComboBox->setEnabled( false );
170 mNorthOffsetSpinBox->setEnabled( false );
171 }
172 else
173 {
174 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( mMapComboBox->currentItem() );
175 mMarker->setLinkedMap( map );
176 mNorthTypeComboBox->setEnabled( true );
177 mNorthOffsetSpinBox->setEnabled( true );
178 mMapComboBox->setEnabled( true );
179 }
180 mMarker->endCommand();
181}
182
183void QgsLayoutMarkerWidget::mapChanged( QgsLayoutItem *item )
184{
185 if ( !mMarker )
186 {
187 return;
188 }
189
190 const QgsLayout *layout = mMarker->layout();
191 if ( !layout )
192 {
193 return;
194 }
195
196 QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap *>( item );
197 if ( !map )
198 {
199 return;
200 }
201
202 mMarker->beginCommand( tr( "Change Rotation Map" ) );
203 mMarker->setLinkedMap( map );
204 mMarker->update();
205 mMarker->endCommand();
206}
207
208void QgsLayoutMarkerWidget::northOffsetSpinBoxChanged( double d )
209{
210 mMarker->beginCommand( tr( "Change Marker North Offset" ), QgsLayoutItem::UndoPictureNorthOffset );
211 mMarker->setNorthOffset( d );
212 mMarker->endCommand();
213 mMarker->update();
214}
215
216void QgsLayoutMarkerWidget::northTypeComboBoxChanged( int index )
217{
218 mMarker->beginCommand( tr( "Change Marker North Mode" ) );
219 mMarker->setNorthMode( static_cast< QgsLayoutNorthArrowHandler::NorthMode >( mNorthTypeComboBox->itemData( index ).toInt() ) );
220 mMarker->endCommand();
221 mMarker->update();
222}
@ Marker
Marker symbol.
A base class for property widgets for layout items.
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
Layout graphical items for displaying a map.
A layout item for showing marker symbols.
A widget for controlling the common properties of layout items (e.g.
void setMasterLayout(QgsMasterLayoutInterface *masterLayout)
Sets the master layout associated with the item.
void showFrameGroup(bool showGroup)
Determines if the frame of the group box shall be shown.
void setItem(QgsLayoutItem *item)
Sets the layout item.
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.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
A marker symbol type, for rendering Point and MultiPoint geometries.
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.