QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "ui_qgslabelingengineruleswidgetbase.h"
19
20#include "qgis_sip.h"
21#include "qgsguiutils.h"
22#include "qgspanelwidget.h"
23
24#include <QAbstractItemModel>
25#include <QDialog>
26
28class QDialogButtonBox;
29
30#ifndef SIP_RUN
40class QgsLabelingEngineRulesModel : public QAbstractItemModel
41{
42 Q_OBJECT
43
44 public:
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 std::vector<std::unique_ptr<QgsAbstractLabelingEngineRule>> mRules;
92};
93
94#endif
95
96
109class GUI_EXPORT QgsLabelingEngineRulesWidget : public QgsPanelWidget, private Ui_QgsLabelingEngineRulesWidgetBase
110{
111 Q_OBJECT
112
113 public:
117 QgsLabelingEngineRulesWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
118
124 void setRules( const QList<QgsAbstractLabelingEngineRule *> &rules );
125
131 QList<QgsAbstractLabelingEngineRule *> rules() const SIP_TRANSFERBACK;
132
133 signals:
134
138 void changed();
139
140 private slots:
141
142 void createTypesMenu();
143 void createRule( const QString &id );
144 void editSelectedRule();
145 void editRule( const QModelIndex &index );
146 void removeRules();
147
148 private:
149 QgsLabelingEngineRulesModel *mModel = nullptr;
150 QMenu *mAddRuleMenu = nullptr;
151};
152
153
165class GUI_EXPORT QgsLabelingEngineRulesDialog : public QDialog
166{
167 Q_OBJECT
168
169 public:
175 QgsLabelingEngineRulesDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags );
176
182 void setRules( const QList<QgsAbstractLabelingEngineRule *> &rules );
183
189 QList<QgsAbstractLabelingEngineRule *> rules() const SIP_TRANSFERBACK;
190
191 private:
192 QgsLabelingEngineRulesWidget *mWidget = nullptr;
193 QDialogButtonBox *mButtonBox = nullptr;
194};
195
196
197#endif // QGSLABELINGENGINERULESWIDGET_H
Abstract base class for labeling engine rules.
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules shown in the dialog.
void setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the rules to show in the dialog.
QgsLabelingEngineRulesDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsLabelingEngineRulesDialog.
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
QgsLabelingEngineRulesModel(QObject *parent=nullptr)
Constructor for QgsLabelingEngineRulesModel.
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 setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the rules to show in the widget.
QgsLabelingEngineRulesWidget(QWidget *parent=nullptr)
Constructor for QgsLabelingEngineRulesWidget.
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules shown in the widget.
void changed()
Emitted when the rules configured in the widget are changed.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48