QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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#define SIP_NO_FILE
23
24#include "ui_qgsstackeddiagrampropertiesbase.h"
25
26#include "qgis_gui.h"
27#include "qgsdiagramrenderer.h"
28#include "qgsproxystyle.h"
29
30#include <QDialog>
31#include <QDialogButtonBox>
32#include <QWidget>
33
34class QgsVectorLayer;
35class QgsMapCanvas;
38
39
47class GUI_EXPORT QgsStackedDiagramPropertiesModel : public QAbstractTableModel
48{
49 Q_OBJECT
50
51 public:
53 QgsStackedDiagramPropertiesModel( QObject *parent = nullptr );
54
56
57 Qt::ItemFlags flags( const QModelIndex &index ) const override;
58 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
59 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
60 int rowCount( const QModelIndex & = QModelIndex() ) const override;
61 int columnCount( const QModelIndex & = QModelIndex() ) const override;
62
63 // editing support
64 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
65 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
66
67 // drag'n'drop support
68 Qt::DropActions supportedDropActions() const override;
69 QStringList mimeTypes() const override;
70 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
71 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
72
73 // new methods
75 QgsDiagramRenderer *subDiagramForIndex( const QModelIndex &index ) const;
76
78 void insertSubDiagram( const int index, QgsDiagramRenderer *newSubDiagram );
80 void updateSubDiagram( const QModelIndex &index, QgsDiagramRenderer *dr );
81
83 QList<QgsDiagramRenderer *> subRenderers() const;
84
87
92
93 signals:
96
97 protected:
98 QList<QgsDiagramRenderer *> mRenderers;
100};
101
109{
110 Q_OBJECT
111
112 public:
117 explicit QgsStackedDiagramsViewStyle( QWidget *parent );
118
119 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
120};
121
129class GUI_EXPORT QgsStackedDiagramProperties : public QgsPanelWidget, private Ui::QgsStackedDiagramPropertiesBase
130{
131 Q_OBJECT
132
133 public:
134 explicit QgsStackedDiagramProperties( QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas );
135
139 void syncToLayer();
140
141 signals:
143
144 public slots:
145 void apply();
146
152 void clearCurrentIndex();
153
154 private slots:
155
159 void addSubDiagramRenderer();
160
165 void appendSubDiagramRenderer( QgsDiagramRenderer *dr );
166
170 void editSubDiagramRenderer();
171
175 void editSubDiagramRenderer( const QModelIndex &index );
176
180 void removeSubDiagramRenderer();
181
182 private:
183 QgsVectorLayer *mLayer = nullptr;
184 QgsMapCanvas *mMapCanvas = nullptr;
185
186 QgsStackedDiagramPropertiesModel *mModel = nullptr;
187
194 bool couldBeFirstSubDiagram( const QModelIndex &index ) const;
195
196 private slots:
197 void subDiagramWidgetPanelAccepted( QgsPanelWidget *panel );
198 void liveUpdateSubDiagramFromPanel();
199};
200
209class GUI_EXPORT QgsStackedDiagramPropertiesDialog : public QDialog
210{
211 Q_OBJECT
212
213 public:
220 QgsStackedDiagramPropertiesDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
221
225 void syncToRenderer( const QgsDiagramRenderer *dr ) const;
226
230 void syncToSettings( const QgsDiagramLayerSettings *dls ) const;
231
237
242
249 void setAllowedToEditDiagramLayerSettings( bool allowed ) const;
250
255
256 public slots:
257
261 void accept() override;
262
263 private slots:
264 void showHelp();
265
266 private:
267 QgsDiagramProperties *mPropsWidget = nullptr;
268 std::unique_ptr<QgsDiagramRenderer> mRenderer;
269 QgsDiagramLayerSettings mDiagramLayerSettings;
270 QDialogButtonBox *buttonBox = nullptr;
271};
272
273#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.