QGIS API Documentation 3.43.0-Master (3ee7834ace6)
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
127class GUI_EXPORT QgsStackedDiagramProperties : public QgsPanelWidget, private Ui::QgsStackedDiagramPropertiesBase
128{
129 Q_OBJECT
130
131 public:
132 explicit QgsStackedDiagramProperties( QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas );
133
137 void syncToLayer();
138
139 signals:
141
142 public slots:
143 void apply();
144
150 void clearCurrentIndex();
151
152 private slots:
153
157 void addSubDiagramRenderer();
158
163 void appendSubDiagramRenderer( QgsDiagramRenderer *dr );
164
168 void editSubDiagramRenderer();
169
173 void editSubDiagramRenderer( const QModelIndex &index );
174
178 void removeSubDiagramRenderer();
179
180 private:
181 QgsVectorLayer *mLayer = nullptr;
182 QgsMapCanvas *mMapCanvas = nullptr;
183
184 QgsStackedDiagramPropertiesModel *mModel = nullptr;
185
192 bool couldBeFirstSubDiagram( const QModelIndex &index ) const;
193
194 private slots:
195 void subDiagramWidgetPanelAccepted( QgsPanelWidget *panel );
196 void liveUpdateSubDiagramFromPanel();
197};
198
207class GUI_EXPORT QgsStackedDiagramPropertiesDialog : public QDialog
208{
209 Q_OBJECT
210
211 public:
218 QgsStackedDiagramPropertiesDialog( QgsVectorLayer *layer, QWidget *parent = nullptr, QgsMapCanvas *mapCanvas = nullptr );
219
223 void syncToRenderer( const QgsDiagramRenderer *dr ) const;
224
228 void syncToSettings( const QgsDiagramLayerSettings *dls ) const;
229
234 QgsDiagramRenderer *renderer();
235
239 QgsDiagramLayerSettings diagramLayerSettings() const;
240
247 void setAllowedToEditDiagramLayerSettings( bool allowed ) const;
248
252 bool isAllowedToEditDiagramLayerSettings() const;
253
254 public slots:
255
259 void accept() override;
260
261 private slots:
262 void showHelp();
263
264 private:
265 QgsDiagramProperties *mPropsWidget = nullptr;
266 std::unique_ptr<QgsDiagramRenderer> mRenderer;
267 QgsDiagramLayerSettings mDiagramLayerSettings;
268 QDialogButtonBox *buttonBox = nullptr;
269};
270
271#endif // QGSSTACKEDDIAGRAMPROPERTIES_H
Stores the settings for rendering of all diagrams for a 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 a 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.
View style which shows 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 data sets.