QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 "ui_qgslabelingrulepropswidget.h"
152 
160 class GUI_EXPORT QgsLabelingRulePropsWidget : public QgsPanelWidget, private Ui::QgsLabelingRulePropsWidget
161 {
162  Q_OBJECT
163 
164  public:
167  QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
168  ~QgsLabelingRulePropsWidget() override;
169 
171  QgsRuleBasedLabeling::Rule *rule() { return mRule; }
172 
173  void setDockMode( bool dockMode ) override;
174 
175  public slots:
177  void apply();
178 
179  private slots:
180  void testFilter();
181  void buildExpression();
182 
183  private:
184  QgsRuleBasedLabeling::Rule *mRule; // borrowed
185  QgsVectorLayer *mLayer = nullptr;
186 
187  QgsLabelingGui *mLabelingGui = nullptr;
188  QgsPalLayerSettings *mSettings; // a clone of original settings
189 
190  QgsMapCanvas *mMapCanvas = nullptr;
191 };
192 
193 
194 #endif // QGSRULEBASEDLABELINGWIDGET_H
Widget for editing a labeling rule.
QgsRuleBasedLabeling::Rule * rule()
Returns the rule being edited.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
Contains settings for how a map layer will be labeled.
Base class for any widget that can be shown as a inline panel.
Model for rule based rendering rules view.
void finishedAddingRules()
Notify the model that one is done inserting new rules.
void removeRule(const QModelIndex &index)
Removes the rule at the specified position.
void willAddRules(const QModelIndex &parent, int count)
Notify the model that new rules will be added.
void updateRule(const QModelIndex &index)
Update rule and all its descendants.
Widget for configuring rule based labeling.
const QgsRuleBasedLabeling::Rule * rootRule() const
Gives access to the internal root of the rule tree.
A child rule for QgsRuleBasedLabeling.
Represents a vector layer which manages a vector based data sets.