QGIS API Documentation 3.43.0-Master (c67cf405802)
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 "qgis_gui.h"
25#include "qgsdiagramrenderer.h"
26#include "ui_qgsstackeddiagrampropertiesbase.h"
27#include "qgsproxystyle.h"
28
29#include <QWidget>
30#include <QDialog>
31#include <QDialogButtonBox>
32
33class QgsVectorLayer;
34class QgsMapCanvas;
37
38
46class GUI_EXPORT QgsStackedDiagramPropertiesModel : public QAbstractTableModel
47{
48 Q_OBJECT
49
50 public:
52 QgsStackedDiagramPropertiesModel( QObject *parent = nullptr );
53
55
56 Qt::ItemFlags flags( const QModelIndex &index ) const override;
57 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
58 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
59 int rowCount( const QModelIndex & = QModelIndex() ) const override;
60 int columnCount( const QModelIndex & = QModelIndex() ) const override;
61
62 // editing support
63 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
64 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
65
66 // drag'n'drop support
67 Qt::DropActions supportedDropActions() const override;
68 QStringList mimeTypes() const override;
69 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
70 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
71
72 // new methods
74 QgsDiagramRenderer *subDiagramForIndex( const QModelIndex &index ) const;
75
77 void insertSubDiagram( const int index, QgsDiagramRenderer *newSubDiagram );
79 void updateSubDiagram( const QModelIndex &index, QgsDiagramRenderer *dr );
80
82 QList<QgsDiagramRenderer *> subRenderers() const;
83
85 QgsDiagramLayerSettings diagramLayerSettings() const;
86
90 void updateDiagramLayerSettings( QgsDiagramLayerSettings dls );
91
92 signals:
95
96 protected:
97 QList<QgsDiagramRenderer *> mRenderers;
99};
100
108{
109 Q_OBJECT
110
111 public:
116 explicit QgsStackedDiagramsViewStyle( QWidget *parent );
117
118 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
119};
120
128class GUI_EXPORT QgsStackedDiagramProperties : public QgsPanelWidget, private Ui::QgsStackedDiagramPropertiesBase
129{
130 Q_OBJECT
131
132 public:
133 explicit QgsStackedDiagramProperties( QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas );
134
138 void syncToLayer();
139
140 signals:
142
143 public slots:
144 void apply();
145
151 void clearCurrentIndex();
152
153 private slots:
154
158 void addSubDiagramRenderer();
159
164 void appendSubDiagramRenderer( QgsDiagramRenderer *dr );
165
169 void editSubDiagramRenderer();
170
174 void editSubDiagramRenderer( const QModelIndex &index );
175
179 void removeSubDiagramRenderer();
180
181 private:
182 QgsVectorLayer *mLayer = nullptr;
183 QgsMapCanvas *mMapCanvas = nullptr;
184
185 QgsStackedDiagramPropertiesModel *mModel = nullptr;
186
193 bool couldBeFirstSubDiagram( const QModelIndex &index ) const;
194
195 private slots:
196 void subDiagramWidgetPanelAccepted( QgsPanelWidget *panel );
197 void liveUpdateSubDiagramFromPanel();
198};
199
208class GUI_EXPORT QgsStackedDiagramPropertiesDialog : public QDialog
209{
210 Q_OBJECT
211
212 public:
219 QgsStackedDiagramPropertiesDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
220
224 void syncToRenderer( const QgsDiagramRenderer *dr ) const;
225
229 void syncToSettings( const QgsDiagramLayerSettings *dls ) const;
230
235 QgsDiagramRenderer *renderer();
236
240 QgsDiagramLayerSettings diagramLayerSettings() const;
241
248 void setAllowedToEditDiagramLayerSettings( bool allowed ) const;
249
253 bool isAllowedToEditDiagramLayerSettings() const;
254
255 public slots:
256
260 void accept() override;
261
262 private slots:
263 void showHelp();
264
265 private:
266 QgsDiagramProperties *mPropsWidget = nullptr;
267 std::unique_ptr<QgsDiagramRenderer> mRenderer;
268 QgsDiagramLayerSettings mDiagramLayerSettings;
269 QDialogButtonBox *buttonBox = nullptr;
270};
271
272#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.
Base class for any widget that can be shown as an inline panel.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
Model for sub diagrams in a stacked diagram view.
QList< QgsDiagramRenderer * > mRenderers
void subDiagramsMoved()
Informs views that subdiagrams were moved in the model.
A widget for editing sub diagrams.
View style which shows a drop indicator line between items.
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.