QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
26 
28 
29 // NOTE - the inheritance here is tricky, as we need to avoid the multiple inheritance
30 // diamond problem and the ideal base object (QgsLayoutConfigObject) MUST be a QObject
31 // because of its slots.
32 
33 // So here we go:
34 // QgsLayoutItemWidget is just a QWidget which is embedded inside specific item property
35 // widgets and contains common settings like position and rotation of the items. While the
36 // actual individual item type widgets MUST be QgsPanelWidgets unfortunately QgsLayoutItemWidget
37 // CANNOT be a QgsPanelWidget and must instead be a generic QWidget (otherwise a QgsPanelWidget
38 // contains a child QgsPanelWidget, which breaks lots of assumptions made in QgsPanelWidget
39 // and related classes).
40 // So QgsLayoutItemWidget HAS a QgsLayoutConfigObject to handle these common tasks.
41 // Specific item property widgets (e.g., QgsLayoutMapWidget) should inherit from QgsLayoutItemBaseWidget
42 // (which is a QgsPanelWidget) and also HAS a QgsLayoutConfigObject, with protected methods
43 // which are just proxied through to the QgsLayoutConfigObject.
44 // phew!
45 // long story short - don't change this without good reason. If you add a new item type, inherit
46 // from QgsLayoutItemBaseWidget and trust that everything else has been done for you.
47 
60 class GUI_EXPORT QgsLayoutConfigObject: public QObject
61 {
62  Q_OBJECT
63  public:
64 
68  QgsLayoutConfigObject( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );
69 
74  void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key );
75 
79  void updateDataDefinedButton( QgsPropertyOverrideButton *button );
80 
84  QgsVectorLayer *coverageLayer() const;
85 
87  QgsLayoutAtlas *layoutAtlas() const;
88 
96  void setObject( QgsLayoutObject *object ) SIP_SKIP;
97 
98  private slots:
100  void updateDataDefinedProperty();
101 
103  void updateDataDefinedButtons();
104 
105  private:
106 
107  QPointer< QgsLayoutObject > mLayoutObject;
108 };
109 
120 class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
121 {
122  Q_OBJECT
123 
124  public:
125 
129  QgsLayoutItemBaseWidget( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );
130 
134  QgsLayoutObject *layoutObject();
135 
144  bool setItem( QgsLayoutItem *item );
145 
152  virtual void setReportTypeString( const QString &string );
153 
154  protected:
155 
160  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property );
161 
165  void updateDataDefinedButton( QgsPropertyOverrideButton *button );
166 
170  QgsVectorLayer *coverageLayer() const;
171 
181  virtual bool setNewItem( QgsLayoutItem *item );
182 
184  QgsLayoutAtlas *layoutAtlas() const;
185 
186  private:
187 
188  QgsLayoutConfigObject *mConfigObject = nullptr;
189 
190  QgsLayoutObject *mObject = nullptr;
191 };
192 
193 
201 class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsLayoutItemWidgetBase
202 {
203  Q_OBJECT
204  public:
205 
209  QgsLayoutItemPropertiesWidget( QWidget *parent, QgsLayoutItem *item );
210 
212  QgsLayoutItem::ReferencePoint positionMode() const;
213 
215  void showBackgroundGroup( bool showGroup );
216 
218  void showFrameGroup( bool showGroup );
219 
221  void setItem( QgsLayoutItem *item );
222 
223  protected slots:
225  void initializeDataDefinedButtons();
227  void populateDataDefinedButtons();
228 
229  private slots:
230 
234  void mFrameColorButton_colorChanged( const QColor &newFrameColor );
235 
239  void mBackgroundColorButton_colorChanged( const QColor &newBackgroundColor );
240 // void on_mTransparencySlider_valueChanged( int value );
241 // void on_mTransparencySpinBox_valueChanged( int value );
242  void mStrokeWidthSpinBox_valueChanged( double d );
243  void strokeUnitChanged( QgsUnitTypes::LayoutUnit unit );
244  void mFrameGroupBox_toggled( bool state );
245  void mFrameJoinStyleCombo_currentIndexChanged( int index );
246  void mBackgroundGroupBox_toggled( bool state );
247  void mItemIdLineEdit_editingFinished();
248 
249  //adjust coordinates in line edits
250  void mPageSpinBox_valueChanged( int );
251  void mXPosSpin_valueChanged( double );
252  void mYPosSpin_valueChanged( double );
253  void positionUnitsChanged( QgsUnitTypes::LayoutUnit unit );
254  void mWidthSpin_valueChanged( double );
255  void mHeightSpin_valueChanged( double );
256  void sizeUnitsChanged( QgsUnitTypes::LayoutUnit unit );
257 
258  void mUpperLeftCheckBox_stateChanged( bool state );
259  void mUpperMiddleCheckBox_stateChanged( bool state );
260  void mUpperRightCheckBox_stateChanged( bool state );
261  void mMiddleLeftCheckBox_stateChanged( bool state );
262  void mMiddleCheckBox_stateChanged( bool state );
263  void mMiddleRightCheckBox_stateChanged( bool state );
264  void mLowerLeftCheckBox_stateChanged( bool state );
265  void mLowerMiddleCheckBox_stateChanged( bool state );
266  void mLowerRightCheckBox_stateChanged( bool state );
267 
268  void mBlendModeCombo_currentIndexChanged( int index );
269  void opacityChanged( double value );
270 
271  void mItemRotationSpinBox_valueChanged( double val );
272  void mExcludeFromPrintsCheckBox_toggled( bool checked );
273 
274  void setValuesForGuiElements();
275  //sets the values for all position related (x, y, width, height) elements
276  void setValuesForGuiPositionElements();
277  //sets the values for all non-position related elements
278  void setValuesForGuiNonPositionElements();
279 
280  void variablesChanged();
281  void updateVariables();
282 
283  private:
284 
285  QPointer< QgsLayoutItem > mItem;
286  QgsLayoutConfigObject *mConfigObject = nullptr;
287 
288  bool mFreezeXPosSpin = false;
289  bool mFreezeYPosSpin = false;
290  bool mFreezeWidthSpin = false;
291  bool mFreezeHeightSpin = false;
292  bool mFreezePageSpin = false;
293  bool mBlockVariableUpdates = false;
294 // void changeItemTransparency( int value );
295  void changeItemPosition();
296  void changeItemReference( QgsLayoutItem::ReferencePoint point );
297  void changeItemSize();
298 
299 };
300 
301 
302 #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.
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:124
Represents a vector layer which manages a vector based data sets.
DataDefinedProperty
Data defined properties for different item types.