QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
17 #include "qgslayoutpolygonwidget.h"
19 #include "qgsstyle.h"
20 #include "qgslayout.h"
21 #include "qgssymbollayerutils.h"
22 #include "qgslayoutitemregistry.h"
23 #include "qgslayoutundostack.h"
24 #include "qgsvectorlayer.h"
25 
27  : QgsLayoutItemBaseWidget( nullptr, polygon )
28  , mPolygon( polygon )
29 {
30  setupUi( this );
31  setPanelTitle( tr( "Polygon Properties" ) );
32 
33  //add widget for general composer item properties
34  mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polygon );
35  //shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
36  mItemPropertiesWidget->showBackgroundGroup( false );
37  mItemPropertiesWidget->showFrameGroup( false );
38  mainLayout->addWidget( mItemPropertiesWidget );
39 
40  mPolygonStyleButton->setSymbolType( QgsSymbol::Fill );
41  connect( mPolygonStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolygonWidget::symbolChanged );
42 
43  if ( mPolygon )
44  {
45  connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
46  mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
47  }
48 
49  setGuiElementValues();
50 
51  mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
52  mPolygonStyleButton->setLayer( coverageLayer() );
53  if ( mPolygon->layout() )
54  {
55  connect( &mPolygon->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mPolygonStyleButton, &QgsSymbolButton::setLayer );
56  }
57 }
58 
60 {
61  if ( mItemPropertiesWidget )
62  mItemPropertiesWidget->setMasterLayout( masterLayout );
63 }
64 
66 {
68  return false;
69 
70  if ( mPolygon )
71  {
72  disconnect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
73  }
74 
75  mPolygon = qobject_cast< QgsLayoutItemPolygon * >( item );
76  mItemPropertiesWidget->setItem( mPolygon );
77 
78  if ( mPolygon )
79  {
80  connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
81  mPolygonStyleButton->registerExpressionContextGenerator( mPolygon );
82  }
83  setGuiElementValues();
84 
85  return true;
86 }
87 
88 void QgsLayoutPolygonWidget::setGuiElementValues()
89 {
90  if ( !mPolygon )
91  {
92  return;
93  }
94 
95  whileBlocking( mPolygonStyleButton )->setSymbol( mPolygon->symbol()->clone() );
96 }
97 
98 void QgsLayoutPolygonWidget::symbolChanged()
99 {
100  if ( !mPolygon )
101  return;
102 
103  mPolygon->layout()->undoStack()->beginCommand( mPolygon, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
104  mPolygon->setSymbol( mPolygonStyleButton->clonedSymbol<QgsFillSymbol>() );
105  mPolygon->layout()->undoStack()->endCommand();
106 }
QgsLayoutItemRegistry::LayoutPolygon
@ LayoutPolygon
Polygon shape item.
Definition: qgslayoutitemregistry.h:322
QgsSymbolButton::changed
void changed()
Emitted when the symbol's settings are changed.
qgslayoutundostack.h
QgsLayoutItem::UndoShapeStyle
@ UndoShapeStyle
Shape symbol style.
Definition: qgslayoutitem.h:226
QgsLayoutItemPropertiesWidget::showBackgroundGroup
void showBackgroundGroup(bool showGroup)
Determines if the background of the group box shall be shown.
Definition: qgslayoutitemwidget.cpp:352
qgssymbollayerutils.h
QgsLayoutObject::changed
void changed()
Emitted when the object's properties change.
QgsLayoutItemPropertiesWidget
A widget for controlling the common properties of layout items (e.g.
Definition: qgslayoutitemwidget.h:219
QgsLayoutItemBaseWidget::coverageLayer
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
Definition: qgslayoutitemwidget.cpp:217
QgsLayoutItemPropertiesWidget::showFrameGroup
void showFrameGroup(bool showGroup)
Determines if the frame of the group box shall be shown.
Definition: qgslayoutitemwidget.cpp:357
QgsLayoutItemPropertiesWidget::setMasterLayout
void setMasterLayout(QgsMasterLayoutInterface *masterLayout)
Sets the master layout associated with the item.
Definition: qgslayoutitemwidget.cpp:381
QgsLayoutItem::type
int type() const override
Returns a unique graphics item type identifier.
Definition: qgslayoutitem.cpp:124
QgsLayoutPolygonWidget::setMasterLayout
void setMasterLayout(QgsMasterLayoutInterface *masterLayout) override
Sets the master layout associated with the item.
Definition: qgslayoutpolygonwidget.cpp:59
qgslayoutpolygonwidget.h
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:262
QgsSymbol::Fill
@ Fill
Fill symbol.
Definition: qgssymbol.h:89
QgsLayoutPolygonWidget::QgsLayoutPolygonWidget
QgsLayoutPolygonWidget(QgsLayoutItemPolygon *polygon)
constructor
Definition: qgslayoutpolygonwidget.cpp:26
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsPanelWidget::setPanelTitle
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
Definition: qgspanelwidget.h:44
qgslayout.h
qgssymbolselectordialog.h
qgsstyle.h
QgsLayoutItemBaseWidget
A base class for property widgets for layout items.
Definition: qgslayoutitemwidget.h:123
qgsvectorlayer.h
QgsSymbolButton::setLayer
void setLayer(QgsVectorLayer *layer)
Sets a layer to associate with the widget.
Definition: qgssymbolbutton.cpp:180
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1234
QgsLayoutItemPolygon
Layout item for node based polygon shapes.
Definition: qgslayoutitempolygon.h:30
QgsLayoutPolygonWidget::setNewItem
bool setNewItem(QgsLayoutItem *item) override
Attempts to update the widget to show the properties for the specified item.
Definition: qgslayoutpolygonwidget.cpp:65
QgsMasterLayoutInterface
Interface for master layout type objects, such as print layouts and reports.
Definition: qgsmasterlayoutinterface.h:43
QgsLayoutItemPropertiesWidget::setItem
void setItem(QgsLayoutItem *item)
Sets the layout item.
Definition: qgslayoutitemwidget.cpp:362
QgsLayoutReportContext::layerChanged
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
qgslayoutitemregistry.h