QGIS API Documentation 3.99.0-Master (a5475b57e34)
Loading...
Searching...
No Matches
qgsstackeddiagramproperties.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsstackeddiagramproperties.h
3 Properties for stacked diagram layers
4 -------------------
5 begin : August 2024
6 copyright : (C) Germán Carrillo
7 email : german at opengis dot ch
8
9 ***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSTACKEDDIAGRAMPROPERTIES_H
19#define QGSSTACKEDDIAGRAMPROPERTIES_H
20
21// We don't want to expose this in the public API
22
23#include "ui_qgsstackeddiagrampropertiesbase.h"
24
25#include "qgis_gui.h"
26#include "qgsdiagramrenderer.h"
27#include "qgsproxystyle.h"
28
29#include <QDialog>
30#include <QDialogButtonBox>
31#include <QWidget>
32
33#define SIP_NO_FILE
34
35class QgsVectorLayer;
36class QgsMapCanvas;
39
40
48class GUI_EXPORT QgsStackedDiagramPropertiesModel : public QAbstractTableModel
49{
50 Q_OBJECT
51
52 public:
54 QgsStackedDiagramPropertiesModel( QObject *parent = nullptr );
55
57
58 Qt::ItemFlags flags( const QModelIndex &index ) const override;
59 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
60 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
61 int rowCount( const QModelIndex & = QModelIndex() ) const override;
62 int columnCount( const QModelIndex & = QModelIndex() ) const override;
63
64 // editing support
65 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
66 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
67
68 // drag'n'drop support
69 Qt::DropActions supportedDropActions() const override;
70 QStringList mimeTypes() const override;
71 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
72 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
73
74 // new methods
76 QgsDiagramRenderer *subDiagramForIndex( const QModelIndex &index ) const;
77
79 void insertSubDiagram( const int index, QgsDiagramRenderer *newSubDiagram );
81 void updateSubDiagram( const QModelIndex &index, QgsDiagramRenderer *dr );
82
84 QList<QgsDiagramRenderer *> subRenderers() const;
85
88
93
94 signals:
97
98 protected:
99 QList<QgsDiagramRenderer *> mRenderers;
101};
102
110{
111 Q_OBJECT
112
113 public:
118 explicit QgsStackedDiagramsViewStyle( QWidget *parent );
119
120 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
121};
122
130class GUI_EXPORT QgsStackedDiagramProperties : public QgsPanelWidget, private Ui::QgsStackedDiagramPropertiesBase
131{
132 Q_OBJECT
133
134 public:
135 explicit QgsStackedDiagramProperties( QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas );
136
140 void syncToLayer();
141
142 signals:
144
145 public slots:
146 void apply();
147
153 void clearCurrentIndex();
154
155 private slots:
156
160 void addSubDiagramRenderer();
161
166 void appendSubDiagramRenderer( QgsDiagramRenderer *dr );
167
171 void editSubDiagramRenderer();
172
176 void editSubDiagramRenderer( const QModelIndex &index );
177
181 void removeSubDiagramRenderer();
182
183 private:
184 QgsVectorLayer *mLayer = nullptr;
185 QgsMapCanvas *mMapCanvas = nullptr;
186
187 QgsStackedDiagramPropertiesModel *mModel = nullptr;
188
195 bool couldBeFirstSubDiagram( const QModelIndex &index ) const;
196
197 private slots:
198 void subDiagramWidgetPanelAccepted( QgsPanelWidget *panel );
199 void liveUpdateSubDiagramFromPanel();
200};
201
210class GUI_EXPORT QgsStackedDiagramPropertiesDialog : public QDialog
211{
212 Q_OBJECT
213
214 public:
221 QgsStackedDiagramPropertiesDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
222
226 void syncToRenderer( const QgsDiagramRenderer *dr ) const;
227
231 void syncToSettings( const QgsDiagramLayerSettings *dls ) const;
232
238
243
250 void setAllowedToEditDiagramLayerSettings( bool allowed ) const;
251
256
257 public slots:
258
262 void accept() override;
263
264 private slots:
265 void showHelp();
266
267 private:
268 QgsDiagramProperties *mPropsWidget = nullptr;
269 std::unique_ptr<QgsDiagramRenderer> mRenderer;
270 QgsDiagramLayerSettings mDiagramLayerSettings;
271 QDialogButtonBox *buttonBox = nullptr;
272};
273
274#endif // QGSSTACKEDDIAGRAMPROPERTIES_H
Stores the settings for rendering of all diagrams for a layer.
A widget which configures diagrams for a vector layer.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
QgsProxyStyle(QWidget *parent)
Constructor for QgsProxyStyle.
QgsStackedDiagramPropertiesDialog(QgsVectorLayer *layer, QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
Constructor for QgsStackedDiagramPropertiesDialog.
QgsDiagramLayerSettings diagramLayerSettings() const
Gets diagram layer settings built from the diagram properties widget.
void setAllowedToEditDiagramLayerSettings(bool allowed) const
Delegates to the main widget to set whether the widget should show diagram layer settings to be edite...
void syncToRenderer(const QgsDiagramRenderer *dr) const
Delegates to the diagram properties widget to sync with the given renderer.
void syncToSettings(const QgsDiagramLayerSettings *dls) const
Delegates to the diagram properties widget to sync with the given diagram layer settings.
bool isAllowedToEditDiagramLayerSettings() const
Returns whether the main widget is allowed to edit diagram layer settings.
void accept() override
Applies changes from the widget to the internal renderer and diagram layer settings.
QgsDiagramRenderer * renderer()
Gets a renderer object built from the diagram properties widget.
Model for sub diagrams in a stacked diagram view.
Qt::DropActions supportedDropActions() const override
QMimeData * mimeData(const QModelIndexList &indexes) const override
void updateSubDiagram(const QModelIndex &index, QgsDiagramRenderer *dr)
Replaces the diagram located at index by dr. Takes ownership.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void insertSubDiagram(const int index, QgsDiagramRenderer *newSubDiagram)
Inserts a new diagram at the specified position. Takes ownership.
QList< QgsDiagramRenderer * > mRenderers
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QgsDiagramRenderer * subDiagramForIndex(const QModelIndex &index) const
Returns the diagram renderer at the specified index. Does not transfer ownership.
void updateDiagramLayerSettings(QgsDiagramLayerSettings dls)
Sets the diagram layer settings for the model.
Qt::ItemFlags flags(const QModelIndex &index) const override
QgsDiagramLayerSettings diagramLayerSettings() const
Returns the diagram layer settings from the model.
QList< QgsDiagramRenderer * > subRenderers() const
Returns the list of diagram renderers from the model. Does not transfer ownership.
int columnCount(const QModelIndex &=QModelIndex()) const override
void subDiagramsMoved()
Informs views that subdiagrams were moved in the model.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QgsStackedDiagramPropertiesModel(QObject *parent=nullptr)
constructor
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &=QModelIndex()) const override
void clearCurrentIndex()
Clears current item from the view.
void syncToLayer()
Updates the widget to reflect the layer's current diagram settings.
QgsStackedDiagramProperties(QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas)
QgsStackedDiagramsViewStyle(QWidget *parent)
Constructor for QgsStackedDiagramsViewStyle.
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
Represents a vector layer which manages a vector based dataset.