QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
19#include "qgsfillsymbol.h"
20#include "qgslayout.h"
23#include "qgslayoutundostack.h"
24#include "qgsvectorlayer.h"
25
26#include "moc_qgslayoutpolygonwidget.cpp"
27
29 : QgsLayoutItemBaseWidget( nullptr, polygon )
30 , mPolygon( polygon )
31{
32 setupUi( this );
33 setPanelTitle( tr( "Polygon Properties" ) );
34
35 //add widget for general composer item properties
36 mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polygon );
37 //shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
38 mItemPropertiesWidget->showBackgroundGroup( false );
39 mItemPropertiesWidget->showFrameGroup( false );
40 mainLayout->addWidget( mItemPropertiesWidget );
41
42 mPolygonStyleButton->setSymbolType( Qgis::SymbolType::Fill );
43 connect( mPolygonStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolygonWidget::symbolChanged );
44
45 if ( mPolygon )
46 {
47 connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
48 mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
49 }
50
51 setGuiElementValues();
52
53 mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
54 mPolygonStyleButton->setLayer( coverageLayer() );
55 if ( mPolygon->layout() )
56 {
57 connect( &mPolygon->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mPolygonStyleButton, &QgsSymbolButton::setLayer );
58 }
59}
60
62{
63 if ( mItemPropertiesWidget )
64 mItemPropertiesWidget->setMasterLayout( masterLayout );
65}
66
68{
70 return false;
71
72 if ( mPolygon )
73 {
74 disconnect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
75 }
76
77 mPolygon = qobject_cast<QgsLayoutItemPolygon *>( item );
78 mItemPropertiesWidget->setItem( mPolygon );
79
80 if ( mPolygon )
81 {
82 connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
83 mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
84 }
85 setGuiElementValues();
86
87 return true;
88}
89
90void QgsLayoutPolygonWidget::setGuiElementValues()
91{
92 if ( !mPolygon )
93 {
94 return;
95 }
96
97 whileBlocking( mPolygonStyleButton )->setSymbol( mPolygon->symbol()->clone() );
98}
99
100void QgsLayoutPolygonWidget::symbolChanged()
101{
102 if ( !mPolygon )
103 return;
104
105 mPolygon->layout()->undoStack()->beginCommand( mPolygon, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
106 mPolygon->setSymbol( mPolygonStyleButton->clonedSymbol<QgsFillSymbol>() );
107 mPolygon->layout()->undoStack()->endCommand();
108}
@ Fill
Fill symbol.
Definition qgis.h:613
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.
Layout item for node based polygon shapes.
A widget for controlling the common properties of layout items (e.g.
@ 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:6511