QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgslabelingengineruleswidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslabelingengineruleswidget.h
3 ------------------------
4 begin : September 2024
5 copyright : (C) 2024 by Nyall Dawson
6 email : nyall dot dawson 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 QGSLABELINGENGINERULESWIDGET_H
16#define QGSLABELINGENGINERULESWIDGET_H
17
18#include "qgis_sip.h"
19#include "qgspanelwidget.h"
20#include "qgsguiutils.h"
21#include "ui_qgslabelingengineruleswidgetbase.h"
22
23#include <QAbstractItemModel>
24#include <QDialog>
25
27class QDialogButtonBox;
28
29#ifndef SIP_RUN
39class QgsLabelingEngineRulesModel : public QAbstractItemModel
40{
41 Q_OBJECT
42
43 public:
44
48 explicit QgsLabelingEngineRulesModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
50
51 // QAbstractItemModel interface
52 Qt::ItemFlags flags( const QModelIndex &index ) const override;
53 QModelIndex parent( const QModelIndex &child ) const override;
54 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
55 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
56 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
57 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
58 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
59 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
60
66 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
67
71 void addRule( std::unique_ptr< QgsAbstractLabelingEngineRule > &rule );
72
76 QgsAbstractLabelingEngineRule *ruleAtIndex( const QModelIndex &index ) const;
77
81 void changeRule( const QModelIndex &index, std::unique_ptr< QgsAbstractLabelingEngineRule > &rule );
82
88 QList<QgsAbstractLabelingEngineRule * > rules() const;
89
90 private:
91
92 std::vector< std::unique_ptr< QgsAbstractLabelingEngineRule > > mRules;
93
94};
95
96#endif
97
98
99
100
113class GUI_EXPORT QgsLabelingEngineRulesWidget : public QgsPanelWidget, private Ui_QgsLabelingEngineRulesWidgetBase
114{
115 Q_OBJECT
116
117 public:
118
122 QgsLabelingEngineRulesWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
123
129 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
130
136 QList<QgsAbstractLabelingEngineRule * > rules() const SIP_TRANSFERBACK;
137
138 signals:
139
143 void changed();
144
145 private slots:
146
147 void createTypesMenu();
148 void createRule( const QString &id );
149 void editSelectedRule();
150 void editRule( const QModelIndex &index );
151 void removeRules();
152
153 private:
154
155 QgsLabelingEngineRulesModel *mModel = nullptr;
156 QMenu *mAddRuleMenu = nullptr;
157
158};
159
160
172class GUI_EXPORT QgsLabelingEngineRulesDialog : public QDialog
173{
174 Q_OBJECT
175
176 public:
177
183 QgsLabelingEngineRulesDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags );
184
190 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
191
197 QList<QgsAbstractLabelingEngineRule * > rules() const SIP_TRANSFERBACK;
198
199 private:
200
201 QgsLabelingEngineRulesWidget *mWidget = nullptr;
202 QDialogButtonBox *mButtonBox = nullptr;
203
204};
205
206
207
208#endif // QGSLABELINGENGINERULESWIDGET_H
Abstract base class for labeling engine rules.
A dialog which allows configuration of a list of labeling engine rules.
A model for configuration of a list of labeling engine rules.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the rules to include in the model.
QModelIndex parent(const QModelIndex &child) const override
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules shown in the widget.
QgsAbstractLabelingEngineRule * ruleAtIndex(const QModelIndex &index) const
Returns the rule at the specified model index.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
void addRule(std::unique_ptr< QgsAbstractLabelingEngineRule > &rule)
Adds a rule to the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
~QgsLabelingEngineRulesModel() override
void changeRule(const QModelIndex &index, std::unique_ptr< QgsAbstractLabelingEngineRule > &rule)
Swaps the rule at the specified index for a new rule.
A widget which allows configuration of a list of labeling engine rules.
void changed()
Emitted when the rules configured in the widget are changed.
Base class for any widget that can be shown as a inline panel.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48