QGIS API Documentation 3.43.0-Master (b60ef06885e)
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
28#include "qgis_gui.h"
29
30class QgsMapCanvas;
31class QgsVectorLayer;
32
33
41class 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, int role = Qt::DisplayRole ) const override;
52 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
53 int columnCount( const QModelIndex & = QModelIndex() ) const override;
55 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
57 QModelIndex parent( const QModelIndex &index ) const override;
58
59 // editing support
60 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
61
62 // drag'n'drop support
63 Qt::DropActions supportedDropActions() const override;
64 QStringList mimeTypes() const override;
65 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
66 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
67
68 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
69
70 // new methods
71
73 QgsRuleBasedLabeling::Rule *ruleForIndex( const QModelIndex &index ) const;
74
76 void insertRule( const QModelIndex &parent, int before, QgsRuleBasedLabeling::Rule *newrule );
78 void updateRule( const QModelIndex &parent, int row );
80 void updateRule( const QModelIndex &index );
82 void removeRule( const QModelIndex &index );
83
85 void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
86
91 void finishedAddingRules(); // call endInsertRows
92
93 protected:
94 QgsRuleBasedLabeling::Rule *mRootRule = nullptr;
95};
96
97
99
100
108class GUI_EXPORT QgsRuleBasedLabelingWidget : public QgsPanelWidget, private Ui::QgsRuleBasedLabelingWidget
109{
110 Q_OBJECT
111 public:
113 QgsRuleBasedLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
115
117 const QgsRuleBasedLabeling::Rule *rootRule() const { return mRootRule; }
118
119 void setDockMode( bool dockMode ) override;
120
121 private slots:
122 void addRule();
123 void editRule();
124 void editRule( const QModelIndex &index );
125 void removeRule();
126 void copy();
127 void paste();
128 void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
129 void liveUpdateRuleFromPanel();
130
131 private:
132 QgsRuleBasedLabeling::Rule *currentRule();
133
134 QgsVectorLayer *mLayer = nullptr;
135 QgsMapCanvas *mCanvas = nullptr;
136
137 QgsRuleBasedLabeling::Rule *mRootRule = nullptr;
138 QgsRuleBasedLabelingModel *mModel = nullptr;
139
140 QAction *mCopyAction = nullptr;
141 QAction *mPasteAction = nullptr;
142 QAction *mDeleteAction = nullptr;
143};
144
145
147
148class QgsLabelingGui;
149
150#include <QDialog>
151#include <QDialogButtonBox>
152
153#include "ui_qgslabelingrulepropswidget.h"
154#include "qgsgui.h"
155
163class GUI_EXPORT QgsLabelingRulePropsWidget : public QgsPanelWidget, private Ui::QgsLabelingRulePropsWidget
164{
165 Q_OBJECT
166
167 public:
169 QgsLabelingRulePropsWidget( QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
171
173 QgsRuleBasedLabeling::Rule *rule() { return mRule; }
174
179 void setDockMode( bool dockMode ) override;
180
181 public slots:
183 void apply();
184
188 void testFilter();
189
193 void buildExpression();
194
195 private:
196 static QgsExpressionContext createExpressionContext( QgsMapCanvas *mapCanvas, const QgsMapLayer *layer );
197
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
215class GUI_EXPORT QgsLabelingRulePropsDialog : public QDialog
216{
217 Q_OBJECT
218
219 public:
227 QgsLabelingRulePropsDialog( QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
228
233 QgsRuleBasedLabeling::Rule *rule() { return mPropsWidget->rule(); }
234
235 public slots:
236
240 void testFilter();
241
245 void buildExpression();
246
250 void accept() override;
251
252 private slots:
253 void showHelp();
254
255 private:
256 QgsLabelingRulePropsWidget *mPropsWidget = nullptr;
257 QDialogButtonBox *buttonBox = nullptr;
258};
259
260#endif // QGSRULEBASEDLABELINGWIDGET_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Dialog for editing labeling rule.
QgsRuleBasedLabeling::Rule * rule()
Returns the current set rule.
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.
Base class for all map layer types.
Definition qgsmaplayer.h:77
Contains settings for how a map layer will be labeled.
Base class for any widget that can be shown as an 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 dataset.