QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgslayoutpolygonwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutpolygonwidget.cpp
3 begin : March 2016
4 copyright : (C) 2016 Paul Blottiere, Oslandia
5 email : paul dot blottiere at oslandia dot com
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18#include "qgslayout.h"
20#include "qgslayoutundostack.h"
21#include "qgsvectorlayer.h"
22#include "qgsfillsymbol.h"
24
26 : QgsLayoutItemBaseWidget( nullptr, polygon )
27 , mPolygon( polygon )
28{
29 setupUi( this );
30 setPanelTitle( tr( "Polygon Properties" ) );
31
32 //add widget for general composer item properties
33 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polygon );
34 //shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
35 mItemPropertiesWidget->showBackgroundGroup( false );
36 mItemPropertiesWidget->showFrameGroup( false );
37 mainLayout->addWidget( mItemPropertiesWidget );
38
39 mPolygonStyleButton->setSymbolType( Qgis::SymbolType::Fill );
40 connect( mPolygonStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolygonWidget::symbolChanged );
41
42 if ( mPolygon )
43 {
44 connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
45 mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
46 }
47
48 setGuiElementValues();
49
50 mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
51 mPolygonStyleButton->setLayer( coverageLayer() );
52 if ( mPolygon->layout() )
53 {
54 connect( &mPolygon->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mPolygonStyleButton, &QgsSymbolButton::setLayer );
55 }
56}
57
59{
60 if ( mItemPropertiesWidget )
61 mItemPropertiesWidget->setMasterLayout( masterLayout );
62}
63
65{
67 return false;
68
69 if ( mPolygon )
70 {
71 disconnect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
72 }
73
74 mPolygon = qobject_cast< QgsLayoutItemPolygon * >( item );
75 mItemPropertiesWidget->setItem( mPolygon );
76
77 if ( mPolygon )
78 {
79 connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
80 mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
81 }
82 setGuiElementValues();
83
84 return true;
85}
86
87void QgsLayoutPolygonWidget::setGuiElementValues()
88{
89 if ( !mPolygon )
90 {
91 return;
92 }
93
94 whileBlocking( mPolygonStyleButton )->setSymbol( mPolygon->symbol()->clone() );
95}
96
97void QgsLayoutPolygonWidget::symbolChanged()
98{
99 if ( !mPolygon )
100 return;
101
102 mPolygon->layout()->undoStack()->beginCommand( mPolygon, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
103 mPolygon->setSymbol( mPolygonStyleButton->clonedSymbol<QgsFillSymbol>() );
104 mPolygon->layout()->undoStack()->endCommand();
105}
@ Fill
Fill symbol.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A base class for property widgets for layout items.
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
Layout item for node based polygon shapes.
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.
void showBackgroundGroup(bool showGroup)
Determines if the background of the group box shall be shown.
@ LayoutPolygon
Polygon shape item.
Base class for graphical items within a QgsLayout.
@ UndoShapeStyle
Shape symbol style.
int type() const override
Returns a unique graphics item type identifier.
void changed()
Emitted when the object's properties change.
bool setNewItem(QgsLayoutItem *item) override
Attempts to update the widget to show the properties for the specified item.
void setMasterLayout(QgsMasterLayoutInterface *masterLayout) override
Sets the master layout associated with the item.
QgsLayoutPolygonWidget(QgsLayoutItemPolygon *polygon)
constructor
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.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:4258