QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsrulebasedlabelingwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrulebasedlabelingwidget.h
3  ---------------------
4  begin : September 2015
5  copyright : (C) 2015 by Martin Dobias
6  email : wonder dot sk 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 QGSRULEBASEDLABELINGWIDGET_H
16 #define QGSRULEBASEDLABELINGWIDGET_H
17 
18 // We don't want to expose this in the public API
19 #define SIP_NO_FILE
20 
21 #include <QWidget>
22 
23 #include "qgspanelwidget.h"
24 
25 #include "ui_qgsrulebasedlabelingwidget.h"
26 
27 #include "qgsrulebasedlabeling.h"
28 #include "qgis_gui.h"
29 
30 class QgsMapCanvas;
31 class QgsVectorLayer;
32 
33 
41 class GUI_EXPORT QgsRuleBasedLabelingModel : public QAbstractItemModel
42 {
43  Q_OBJECT
44 
45  public:
47  QgsRuleBasedLabelingModel( QgsRuleBasedLabeling::Rule *rootRule, QObject *parent = nullptr );
48 
49  Qt::ItemFlags flags( const QModelIndex &index ) const override;
50  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
51  QVariant headerData( int section, Qt::Orientation orientation,
52  int role = Qt::DisplayRole ) const override;
53  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
54  int columnCount( const QModelIndex & = QModelIndex() ) const override;
56  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
58  QModelIndex parent( const QModelIndex &index ) const override;
59 
60  // editing support
61  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
62 
63  // drag'n'drop support
64  Qt::DropActions supportedDropActions() const override;
65  QStringList mimeTypes() const override;
66  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
67  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
68 
69  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
70 
71  // new methods
72 
74  QgsRuleBasedLabeling::Rule *ruleForIndex( const QModelIndex &index ) const;
75 
77  void insertRule( const QModelIndex &parent, int before, QgsRuleBasedLabeling::Rule *newrule );
79  void updateRule( const QModelIndex &parent, int row );
81  void updateRule( const QModelIndex &index );
83  void removeRule( const QModelIndex &index );
84 
86  void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
87 
92  void finishedAddingRules(); // call endInsertRows
93 
94  protected:
95  QgsRuleBasedLabeling::Rule *mRootRule = nullptr;
96 };
97 
98 
100 
101 
109 class GUI_EXPORT QgsRuleBasedLabelingWidget : public QgsPanelWidget, private Ui::QgsRuleBasedLabelingWidget
110 {
111  Q_OBJECT
112  public:
114  QgsRuleBasedLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
115  ~QgsRuleBasedLabelingWidget() override;
116 
118  const QgsRuleBasedLabeling::Rule *rootRule() const { return mRootRule; }
119 
120  void setDockMode( bool dockMode ) override;
121 
122  private slots:
123  void addRule();
124  void editRule();
125  void editRule( const QModelIndex &index );
126  void removeRule();
127  void copy();
128  void paste();
129  void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
130  void liveUpdateRuleFromPanel();
131 
132  private:
133  QgsRuleBasedLabeling::Rule *currentRule();
134 
135  QgsVectorLayer *mLayer = nullptr;
136  QgsMapCanvas *mCanvas = nullptr;
137 
138  QgsRuleBasedLabeling::Rule *mRootRule = nullptr;
139  QgsRuleBasedLabelingModel *mModel = nullptr;
140 
141  QAction *mCopyAction = nullptr;
142  QAction *mPasteAction = nullptr;
143  QAction *mDeleteAction = nullptr;
144 };
145 
146 
148 
149 class QgsLabelingGui;
150 
151 #include <QDialog>
152 #include <QDialogButtonBox>
153 
154 #include "ui_qgslabelingrulepropswidget.h"
155 #include "qgsgui.h"
156 
164 class GUI_EXPORT QgsLabelingRulePropsWidget : public QgsPanelWidget, private Ui::QgsLabelingRulePropsWidget
165 {
166  Q_OBJECT
167 
168  public:
170  QgsLabelingRulePropsWidget( QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer,
171  QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
172  ~QgsLabelingRulePropsWidget() override;
173 
175  QgsRuleBasedLabeling::Rule *rule() { return mRule; }
176 
181  void setDockMode( bool dockMode ) override;
182 
183  public slots:
185  void apply();
186 
190  void testFilter();
191 
195  void buildExpression();
196 
197  private:
198  QgsRuleBasedLabeling::Rule *mRule; // borrowed
199  QgsVectorLayer *mLayer = nullptr;
200 
201  QgsLabelingGui *mLabelingGui = nullptr;
202  QgsPalLayerSettings *mSettings; // a clone of original settings
203 
204  QgsMapCanvas *mMapCanvas = nullptr;
205 };
206 
215 class GUI_EXPORT QgsLabelingRulePropsDialog : public QDialog
216 {
217  Q_OBJECT
218 
219  public:
220 
229  QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
230 
235  QgsRuleBasedLabeling::Rule *rule() { return mPropsWidget->rule(); }
236 
237  public slots:
238 
242  void testFilter();
243 
247  void buildExpression();
248 
252  void accept() override;
253 
254  private slots:
255  void showHelp();
256 
257  private:
258  QgsLabelingRulePropsWidget *mPropsWidget = nullptr;
259  QDialogButtonBox *buttonBox = nullptr;
260 };
261 
262 #endif // QGSRULEBASEDLABELINGWIDGET_H
QgsRuleBasedLabeling::Rule
A child rule for QgsRuleBasedLabeling.
Definition: qgsrulebasedlabeling.h:55
QgsLabelingRulePropsDialog
Dialog for editing labeling rule.
Definition: qgsrulebasedlabelingwidget.h:215
QgsRuleBasedLabelingWidget::rootRule
const QgsRuleBasedLabeling::Rule * rootRule() const
Gives access to the internal root of the rule tree.
Definition: qgsrulebasedlabelingwidget.h:118
QgsPanelWidget::setDockMode
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Definition: qgspanelwidget.cpp:44
QgsPalLayerSettings
Contains settings for how a map layer will be labeled.
Definition: qgspallabeling.h:86
QgsLabelingRulePropsWidget::QgsLabelingRulePropsWidget
QgsLabelingRulePropsWidget(QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer, QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
constructor
Definition: qgsrulebasedlabelingwidget.cpp:658
qgsgui.h
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsLabelingRulePropsDialog::rule
QgsRuleBasedLabeling::Rule * rule()
Returns the current set rule.
Definition: qgsrulebasedlabelingwidget.h:235
qgsrulebasedlabeling.h
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsLabelingRulePropsWidget::rule
QgsRuleBasedLabeling::Rule * rule()
Returns the rule being edited.
Definition: qgsrulebasedlabelingwidget.h:175
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsRuleBasedLabelingModel
Model for rule based rendering rules view.
Definition: qgsrulebasedlabelingwidget.h:41
qgspanelwidget.h