QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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;
30 
31 // NOTE - the inheritance here is tricky, as we need to avoid the multiple inheritance
32 // diamond problem and the ideal base object (QgsLayoutConfigObject) MUST be a QObject
33 // because of its slots.
34 
35 // So here we go:
36 // QgsLayoutItemWidget is just a QWidget which is embedded inside specific item property
37 // widgets and contains common settings like position and rotation of the items. While the
38 // actual individual item type widgets MUST be QgsPanelWidgets unfortunately QgsLayoutItemWidget
39 // CANNOT be a QgsPanelWidget and must instead be a generic QWidget (otherwise a QgsPanelWidget
40 // contains a child QgsPanelWidget, which breaks lots of assumptions made in QgsPanelWidget
41 // and related classes).
42 // So QgsLayoutItemWidget HAS a QgsLayoutConfigObject to handle these common tasks.
43 // Specific item property widgets (e.g., QgsLayoutMapWidget) should inherit from QgsLayoutItemBaseWidget
44 // (which is a QgsPanelWidget) and also HAS a QgsLayoutConfigObject, with protected methods
45 // which are just proxied through to the QgsLayoutConfigObject.
46 // phew!
47 // long story short - don't change this without good reason. If you add a new item type, inherit
48 // from QgsLayoutItemBaseWidget and trust that everything else has been done for you.
49 
62 class GUI_EXPORT QgsLayoutConfigObject: public QObject
63 {
64  Q_OBJECT
65  public:
66 
70  QgsLayoutConfigObject( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );
71 
76  void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key );
77 
81  void updateDataDefinedButton( QgsPropertyOverrideButton *button );
82 
86  QgsVectorLayer *coverageLayer() const;
87 
89  QgsLayoutAtlas *layoutAtlas() const;
90 
98  void setObject( QgsLayoutObject *object ) SIP_SKIP;
99 
100  private slots:
102  void updateDataDefinedProperty();
103 
105  void updateDataDefinedButtons();
106 
107  private:
108 
109  QPointer< QgsLayoutObject > mLayoutObject;
110 };
111 
122 class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
123 {
124  Q_OBJECT
125 
126  public:
127 
131  QgsLayoutItemBaseWidget( QWidget *parent SIP_TRANSFERTHIS, QgsLayoutObject *layoutObject );
132 
136  QgsLayoutObject *layoutObject();
137 
146  bool setItem( QgsLayoutItem *item );
147 
154  virtual void setReportTypeString( const QString &string );
155 
162  virtual void setDesignerInterface( QgsLayoutDesignerInterface *iface );
163 
169  virtual void setMasterLayout( QgsMasterLayoutInterface *masterLayout );
170 
171  protected:
172 
177  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property );
178 
182  void updateDataDefinedButton( QgsPropertyOverrideButton *button );
183 
187  QgsVectorLayer *coverageLayer() const;
188 
198  virtual bool setNewItem( QgsLayoutItem *item );
199 
201  QgsLayoutAtlas *layoutAtlas() const;
202 
203  private:
204 
205  QgsLayoutConfigObject *mConfigObject = nullptr;
206 
207  QgsLayoutObject *mObject = nullptr;
208 };
209 
210 
218 class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsLayoutItemWidgetBase
219 {
220  Q_OBJECT
221  public:
222 
226  QgsLayoutItemPropertiesWidget( QWidget *parent, QgsLayoutItem *item );
227 
229  QgsLayoutItem::ReferencePoint positionMode() const;
230 
232  void showBackgroundGroup( bool showGroup );
233 
235  void showFrameGroup( bool showGroup );
236 
238  void setItem( QgsLayoutItem *item );
239 
245  void setMasterLayout( QgsMasterLayoutInterface *masterLayout );
246 
252  void updateVariables();
253 
254  protected slots:
256  void initializeDataDefinedButtons();
258  void populateDataDefinedButtons();
259 
260  private slots:
261 
265  void mFrameColorButton_colorChanged( const QColor &newFrameColor );
266 
270  void mBackgroundColorButton_colorChanged( const QColor &newBackgroundColor );
271 // void on_mTransparencySlider_valueChanged( int value );
272 // void on_mTransparencySpinBox_valueChanged( int value );
273  void mStrokeWidthSpinBox_valueChanged( double d );
274  void strokeUnitChanged( QgsUnitTypes::LayoutUnit unit );
275  void mFrameGroupBox_toggled( bool state );
276  void mFrameJoinStyleCombo_currentIndexChanged( int index );
277  void mBackgroundGroupBox_toggled( bool state );
278  void mItemIdLineEdit_editingFinished();
279 
280  //adjust coordinates in line edits
281  void mPageSpinBox_valueChanged( int );
282  void mXPosSpin_valueChanged( double );
283  void mYPosSpin_valueChanged( double );
284  void positionUnitsChanged( QgsUnitTypes::LayoutUnit unit );
285  void mWidthSpin_valueChanged( double );
286  void mHeightSpin_valueChanged( double );
287  void sizeUnitsChanged( QgsUnitTypes::LayoutUnit unit );
288 
289  void mUpperLeftCheckBox_stateChanged( bool state );
290  void mUpperMiddleCheckBox_stateChanged( bool state );
291  void mUpperRightCheckBox_stateChanged( bool state );
292  void mMiddleLeftCheckBox_stateChanged( bool state );
293  void mMiddleCheckBox_stateChanged( bool state );
294  void mMiddleRightCheckBox_stateChanged( bool state );
295  void mLowerLeftCheckBox_stateChanged( bool state );
296  void mLowerMiddleCheckBox_stateChanged( bool state );
297  void mLowerRightCheckBox_stateChanged( bool state );
298 
299  void mBlendModeCombo_currentIndexChanged( int index );
300  void opacityChanged( double value );
301 
302  void mItemRotationSpinBox_valueChanged( double val );
303  void mExcludeFromPrintsCheckBox_toggled( bool checked );
304 
305  void setValuesForGuiElements();
306  //sets the values for all position related (x, y, width, height) elements
307  void setValuesForGuiPositionElements();
308  //sets the values for all non-position related elements
309  void setValuesForGuiNonPositionElements();
310 
311  void variablesChanged();
312 
313  private:
314 
315  QPointer< QgsLayoutItem > mItem;
316  QgsLayoutConfigObject *mConfigObject = nullptr;
317 
318  bool mFreezeXPosSpin = false;
319  bool mFreezeYPosSpin = false;
320  bool mFreezeWidthSpin = false;
321  bool mFreezeHeightSpin = false;
322  bool mFreezePageSpin = false;
323  bool mBlockVariableUpdates = false;
324 // void changeItemTransparency( int value );
325  void changeItemPosition();
326  void changeItemReference( QgsLayoutItem::ReferencePoint point );
327  void changeItemSize();
328 
329 };
330 
331 
332 #endif // QGSLAYOUTITEMWIDGET_H
Base class for graphical items within a QgsLayout.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
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:126
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:159
Interface for master layout type objects, such as print layouts and reports.
Represents a vector layer which manages a vector based data sets.
DataDefinedProperty
Data defined properties for different item types.