QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
47 explicit QgsLabelingEngineRulesModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
49
50 // QAbstractItemModel interface
51 Qt::ItemFlags flags( const QModelIndex &index ) const override;
52 QModelIndex parent( const QModelIndex &child ) const override;
53 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
54 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
55 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
56 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
57 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
58 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
59
65 void setRules( const QList<QgsAbstractLabelingEngineRule *> &rules );
66
70 void addRule( std::unique_ptr<QgsAbstractLabelingEngineRule> &rule );
71
75 QgsAbstractLabelingEngineRule *ruleAtIndex( const QModelIndex &index ) const;
76
80 void changeRule( const QModelIndex &index, std::unique_ptr<QgsAbstractLabelingEngineRule> &rule );
81
87 QList<QgsAbstractLabelingEngineRule *> rules() const;
88
89 private:
90 std::vector<std::unique_ptr<QgsAbstractLabelingEngineRule>> mRules;
91};
92
93#endif
94
95
108class GUI_EXPORT QgsLabelingEngineRulesWidget : public QgsPanelWidget, private Ui_QgsLabelingEngineRulesWidgetBase
109{
110 Q_OBJECT
111
112 public:
116 QgsLabelingEngineRulesWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
117
123 void setRules( const QList<QgsAbstractLabelingEngineRule *> &rules );
124
130 QList<QgsAbstractLabelingEngineRule *> rules() const SIP_TRANSFERBACK;
131
132 signals:
133
137 void changed();
138
139 private slots:
140
141 void createTypesMenu();
142 void createRule( const QString &id );
143 void editSelectedRule();
144 void editRule( const QModelIndex &index );
145 void removeRules();
146
147 private:
148 QgsLabelingEngineRulesModel *mModel = nullptr;
149 QMenu *mAddRuleMenu = nullptr;
150};
151
152
164class GUI_EXPORT QgsLabelingEngineRulesDialog : public QDialog
165{
166 Q_OBJECT
167
168 public:
174 QgsLabelingEngineRulesDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags );
175
181 void setRules( const QList<QgsAbstractLabelingEngineRule *> &rules );
182
188 QList<QgsAbstractLabelingEngineRule *> rules() const SIP_TRANSFERBACK;
189
190 private:
191 QgsLabelingEngineRulesWidget *mWidget = nullptr;
192 QDialogButtonBox *mButtonBox = nullptr;
193};
194
195
196#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