QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "ui_qgsrulebasedlabelingwidget.h"
22
23#include "qgis_gui.h"
24#include "qgspanelwidget.h"
26
27#include <QWidget>
28
29class QgsMapCanvas;
30class QgsVectorLayer;
31
32
40class GUI_EXPORT QgsRuleBasedLabelingModel : public QAbstractItemModel
41{
42 Q_OBJECT
43
44 public:
46 QgsRuleBasedLabelingModel( QgsRuleBasedLabeling::Rule *rootRule, QObject *parent = nullptr );
47
48 Qt::ItemFlags flags( const QModelIndex &index ) const override;
49 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
50 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
51 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
52 int columnCount( const QModelIndex & = QModelIndex() ) const override;
54 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
56 QModelIndex parent( const QModelIndex &index ) const override;
57
58 // editing support
59 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
60
61 // drag'n'drop support
62 Qt::DropActions supportedDropActions() const override;
63 QStringList mimeTypes() const override;
64 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
65 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
66
67 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
68
69 // new methods
70
72 QgsRuleBasedLabeling::Rule *ruleForIndex( const QModelIndex &index ) const;
73
75 void insertRule( const QModelIndex &parent, int before, QgsRuleBasedLabeling::Rule *newrule );
77 void updateRule( const QModelIndex &parent, int row );
79 void updateRule( const QModelIndex &index );
81 void removeRule( const QModelIndex &index );
82
84 void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
85
90 void finishedAddingRules(); // call endInsertRows
91
92 protected:
94};
95
96
98
99
107class GUI_EXPORT QgsRuleBasedLabelingWidget : public QgsPanelWidget, private Ui::QgsRuleBasedLabelingWidget
108{
109 Q_OBJECT
110 public:
112 QgsRuleBasedLabelingWidget( QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent = nullptr );
114
116 const QgsRuleBasedLabeling::Rule *rootRule() const { return mRootRule; }
117
118 void setDockMode( bool dockMode ) override;
119
120 private slots:
121 void addRule();
122 void editRule();
123 void editRule( const QModelIndex &index );
124 void removeRule();
125 void copy();
126 void paste();
127 void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
128 void liveUpdateRuleFromPanel();
129
130 private:
131 QgsRuleBasedLabeling::Rule *currentRule();
132
133 QgsVectorLayer *mLayer = nullptr;
134 QgsMapCanvas *mCanvas = nullptr;
135
136 QgsRuleBasedLabeling::Rule *mRootRule = nullptr;
137 QgsRuleBasedLabelingModel *mModel = nullptr;
138
139 QAction *mCopyAction = nullptr;
140 QAction *mPasteAction = nullptr;
141 QAction *mDeleteAction = nullptr;
142};
143
144
146
147class QgsLabelingGui;
148
149#include <QDialog>
150#include <QDialogButtonBox>
151
152#include "ui_qgslabelingrulepropswidget.h"
153#include "qgsgui.h"
154
162class GUI_EXPORT QgsLabelingRulePropsWidget : public QgsPanelWidget, private Ui::QgsLabelingRulePropsWidget
163{
164 Q_OBJECT
165
166 public:
168 QgsLabelingRulePropsWidget( QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
170
172 QgsRuleBasedLabeling::Rule *rule() { return mRule; }
173
178 void setDockMode( bool dockMode ) override;
179
180 public slots:
182 void apply();
183
187 void testFilter();
188
192 void buildExpression();
193
194 private:
195 static QgsExpressionContext createExpressionContext( QgsMapCanvas *mapCanvas, const QgsMapLayer *layer );
196
197 QgsRuleBasedLabeling::Rule *mRule; // borrowed
198 QgsVectorLayer *mLayer = nullptr;
199
200 QgsLabelingGui *mLabelingGui = nullptr;
201 QgsPalLayerSettings *mSettings; // a clone of original settings
202
203 QgsMapCanvas *mMapCanvas = nullptr;
204};
205
214class GUI_EXPORT QgsLabelingRulePropsDialog : public QDialog
215{
216 Q_OBJECT
217
218 public:
219
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...
QgsLabelingRulePropsDialog(QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer, QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
Constructor for QgsLabelingRulePropsDialog.
QgsRuleBasedLabeling::Rule * rule()
Returns the current set rule.
Widget for editing a labeling rule.
QgsRuleBasedLabeling::Rule * rule()
Returns the rule being edited.
QgsLabelingRulePropsWidget(QgsRuleBasedLabeling::Rule *rule, QgsVectorLayer *layer, QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
constructor
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Contains settings for how a map layer will be labeled.
Base class for any widget that can be shown as an inline panel.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
Model for rule based rendering rules view.
QgsRuleBasedLabelingModel(QgsRuleBasedLabeling::Rule *rootRule, QObject *parent=nullptr)
constructor
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
QStringList mimeTypes() const override
void finishedAddingRules()
Notify the model that one is done inserting new rules.
QgsRuleBasedLabeling::Rule * mRootRule
Qt::DropActions supportedDropActions() const override
void insertRule(const QModelIndex &parent, int before, QgsRuleBasedLabeling::Rule *newrule)
Inserts a new rule at the specified position.
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.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
provide model index for parent's child item
QgsRuleBasedLabeling::Rule * ruleForIndex(const QModelIndex &index) const
Returns the rule at the specified index.
void updateRule(const QModelIndex &index)
Update rule and all its descendants.
void updateRule(const QModelIndex &parent, int row)
Updates the rule at the specified position.
QMimeData * mimeData(const QModelIndexList &indexes) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QModelIndex parent(const QModelIndex &index) const override
provide parent model index
Qt::ItemFlags flags(const QModelIndex &index) const override
int columnCount(const QModelIndex &=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
const QgsRuleBasedLabeling::Rule * rootRule() const
Gives access to the internal root of the rule tree.
QgsRuleBasedLabelingWidget(QgsVectorLayer *layer, QgsMapCanvas *canvas, QWidget *parent=nullptr)
constructor
A child rule for QgsRuleBasedLabeling.
Represents a vector layer which manages a vector based dataset.