QGIS API Documentation  3.6.0-Noosa (5873452)
qgslayoutitemwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemwidget.h
3  ------------------------
4  Date : July 2017
5  Copyright : (C) 2017 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSLAYOUTITEMWIDGET_H
16 #define QGSLAYOUTITEMWIDGET_H
17 
18 #include "qgis_gui.h"
19 #include "qgslayoutobject.h"
20 #include "qgspanelwidget.h"
21 #include "qgslayoutitem.h"
22 #include "ui_qgslayoutitemwidgetbase.h"
23 #include <QObject>
24 #include <QPointer>
25 
28 class QgsLayoutAtlas;
29 
30 // NOTE - the inheritance here is tricky, as we need to avoid the multiple inheritance
31 // diamond problem and the ideal base object (QgsLayoutConfigObject) MUST be a QObject
32 // because of its slots.
33 
34 // So here we go:
35 // QgsLayoutItemWidget is just a QWidget which is embedded inside specific item property
36 // widgets and contains common settings like position and rotation of the items. While the
37 // actual individual item type widgets MUST be QgsPanelWidgets unfortunately QgsLayoutItemWidget
38 // CANNOT be a QgsPanelWidget and must instead be a generic QWidget (otherwise a QgsPanelWidget
39 // contains a child QgsPanelWidget, which breaks lots of assumptions made in QgsPanelWidget
40 // and related classes).
41 // So QgsLayoutItemWidget HAS a QgsLayoutConfigObject to handle these common tasks.
42 // Specific item property widgets (e.g., QgsLayoutMapWidget) should inherit from QgsLayoutItemBaseWidget
43 // (which is a QgsPanelWidget) and also HAS a QgsLayoutConfigObject, with protected methods
44 // which are just proxied through to the QgsLayoutConfigObject.
45 // phew!
46 // long story short - don't change this without good reason. If you add a new item type, inherit
47 // from QgsLayoutItemBaseWidget and trust that everything else has been done for you.
48 
61 class GUI_EXPORT QgsLayoutConfigObject: public QObject
62 {
63  Q_OBJECT
64  public:
65 
69  QgsLayoutConfigObject( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );
70 
75  void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key );
76 
80  void updateDataDefinedButton( QgsPropertyOverrideButton *button );
81 
85  QgsVectorLayer *coverageLayer() const;
86 
88  QgsLayoutAtlas *layoutAtlas() const;
89 
97  void setObject( QgsLayoutObject *object ) SIP_SKIP;
98 
99  private slots:
101  void updateDataDefinedProperty();
102 
104  void updateDataDefinedButtons();
105 
106  private:
107 
108  QPointer< QgsLayoutObject > mLayoutObject;
109 };
110 
121 class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
122 {
123  Q_OBJECT
124 
125  public:
126 
130  QgsLayoutItemBaseWidget( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );
131 
135  QgsLayoutObject *layoutObject();
136 
145  bool setItem( QgsLayoutItem *item );
146 
153  virtual void setReportTypeString( const QString &string );
154 
161  virtual void setDesignerInterface( QgsLayoutDesignerInterface *iface );
162 
163  protected:
164 
169  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property );
170 
174  void updateDataDefinedButton( QgsPropertyOverrideButton *button );
175 
179  QgsVectorLayer *coverageLayer() const;
180 
190  virtual bool setNewItem( QgsLayoutItem *item );
191 
193  QgsLayoutAtlas *layoutAtlas() const;
194 
195  private:
196 
197  QgsLayoutConfigObject *mConfigObject = nullptr;
198 
199  QgsLayoutObject *mObject = nullptr;
200 };
201 
202 
210 class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsLayoutItemWidgetBase
211 {
212  Q_OBJECT
213  public:
214 
218  QgsLayoutItemPropertiesWidget( QWidget *parent, QgsLayoutItem *item );
219 
221  QgsLayoutItem::ReferencePoint positionMode() const;
222 
224  void showBackgroundGroup( bool showGroup );
225 
227  void showFrameGroup( bool showGroup );
228 
230  void setItem( QgsLayoutItem *item );
231 
232  protected slots:
234  void initializeDataDefinedButtons();
236  void populateDataDefinedButtons();
237 
238  private slots:
239 
243  void mFrameColorButton_colorChanged( const QColor &newFrameColor );
244 
248  void mBackgroundColorButton_colorChanged( const QColor &newBackgroundColor );
249 // void on_mTransparencySlider_valueChanged( int value );
250 // void on_mTransparencySpinBox_valueChanged( int value );
251  void mStrokeWidthSpinBox_valueChanged( double d );
252  void strokeUnitChanged( QgsUnitTypes::LayoutUnit unit );
253  void mFrameGroupBox_toggled( bool state );
254  void mFrameJoinStyleCombo_currentIndexChanged( int index );
255  void mBackgroundGroupBox_toggled( bool state );
256  void mItemIdLineEdit_editingFinished();
257 
258  //adjust coordinates in line edits
259  void mPageSpinBox_valueChanged( int );
260  void mXPosSpin_valueChanged( double );
261  void mYPosSpin_valueChanged( double );
262  void positionUnitsChanged( QgsUnitTypes::LayoutUnit unit );
263  void mWidthSpin_valueChanged( double );
264  void mHeightSpin_valueChanged( double );
265  void sizeUnitsChanged( QgsUnitTypes::LayoutUnit unit );
266 
267  void mUpperLeftCheckBox_stateChanged( bool state );
268  void mUpperMiddleCheckBox_stateChanged( bool state );
269  void mUpperRightCheckBox_stateChanged( bool state );
270  void mMiddleLeftCheckBox_stateChanged( bool state );
271  void mMiddleCheckBox_stateChanged( bool state );
272  void mMiddleRightCheckBox_stateChanged( bool state );
273  void mLowerLeftCheckBox_stateChanged( bool state );
274  void mLowerMiddleCheckBox_stateChanged( bool state );
275  void mLowerRightCheckBox_stateChanged( bool state );
276 
277  void mBlendModeCombo_currentIndexChanged( int index );
278  void opacityChanged( double value );
279 
280  void mItemRotationSpinBox_valueChanged( double val );
281  void mExcludeFromPrintsCheckBox_toggled( bool checked );
282 
283  void setValuesForGuiElements();
284  //sets the values for all position related (x, y, width, height) elements
285  void setValuesForGuiPositionElements();
286  //sets the values for all non-position related elements
287  void setValuesForGuiNonPositionElements();
288 
289  void variablesChanged();
290  void updateVariables();
291 
292  private:
293 
294  QPointer< QgsLayoutItem > mItem;
295  QgsLayoutConfigObject *mConfigObject = nullptr;
296 
297  bool mFreezeXPosSpin = false;
298  bool mFreezeYPosSpin = false;
299  bool mFreezeWidthSpin = false;
300  bool mFreezeHeightSpin = false;
301  bool mFreezePageSpin = false;
302 
303 // void changeItemTransparency( int value );
304  void changeItemPosition();
305  void changeItemReference( QgsLayoutItem::ReferencePoint point );
306  void changeItemSize();
307 
308 };
309 
310 
311 #endif // QGSLAYOUTITEMWIDGET_H
Base class for graphical items within a QgsLayout.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A widget for controlling the common properties of layout items (e.g.
A common interface for layout designer dialogs and widgets.
Base class for any widget that can be shown as a inline panel.
ReferencePoint
Fixed position reference point.
A button for controlling property overrides which may apply to a widget.
#define SIP_SKIP
Definition: qgis_sip.h:119
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
A base class for property widgets for layout items.
An object for property widgets for layout items.
A base class for objects which belong to a layout.
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:125
Represents a vector layer which manages a vector based data sets.
DataDefinedProperty
Data defined properties for different item types.