QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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,
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
109class GUI_EXPORT QgsRuleBasedLabelingWidget : public QgsPanelWidget, private Ui::QgsRuleBasedLabelingWidget
110{
111 Q_OBJECT
112 public:
114 QgsRuleBasedLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
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
149class QgsLabelingGui;
150
151#include <QDialog>
152#include <QDialogButtonBox>
153
154#include "ui_qgslabelingrulepropswidget.h"
155#include "qgsgui.h"
156
164class GUI_EXPORT QgsLabelingRulePropsWidget : public QgsPanelWidget, private Ui::QgsLabelingRulePropsWidget
165{
166 Q_OBJECT
167
168 public:
171 QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
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 static QgsExpressionContext createExpressionContext( QgsMapCanvas *mapCanvas, const QgsMapLayer *layer );
199
200 QgsRuleBasedLabeling::Rule *mRule; // borrowed
201 QgsVectorLayer *mLayer = nullptr;
202
203 QgsLabelingGui *mLabelingGui = nullptr;
204 QgsPalLayerSettings *mSettings; // a clone of original settings
205
206 QgsMapCanvas *mMapCanvas = nullptr;
207};
208
217class GUI_EXPORT QgsLabelingRulePropsDialog : public QDialog
218{
219 Q_OBJECT
220
221 public:
222
231 QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
232
237 QgsRuleBasedLabeling::Rule *rule() { return mPropsWidget->rule(); }
238
239 public slots:
240
244 void testFilter();
245
249 void buildExpression();
250
254 void accept() override;
255
256 private slots:
257 void showHelp();
258
259 private:
260 QgsLabelingRulePropsWidget *mPropsWidget = nullptr;
261 QDialogButtonBox *buttonBox = nullptr;
262};
263
264#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:76
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.