QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgscategorizedsymbolrendererwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscategorizedsymbolrendererwidget.h
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk 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 QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
16 #define QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
17 
19 #include "qgis_sip.h"
20 #include "qgsrendererwidget.h"
21 #include "qgsproxystyle.h"
22 #include <QStandardItem>
23 
24 
27 
28 #include "ui_qgscategorizedsymbolrendererwidget.h"
29 #include "qgis_gui.h"
30 
31 
32 #ifndef SIP_RUN
33 
35 class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QAbstractItemModel
36 {
37  Q_OBJECT
38  public:
39  QgsCategorizedSymbolRendererModel( QObject *parent = nullptr );
40  Qt::ItemFlags flags( const QModelIndex &index ) const override;
41  Qt::DropActions supportedDropActions() const override;
42  QVariant data( const QModelIndex &index, int role ) const override;
43  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
44  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
45  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
46  int columnCount( const QModelIndex & = QModelIndex() ) const override;
47  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
48  QModelIndex parent( const QModelIndex &index ) const override;
49  QStringList mimeTypes() const override;
50  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
51  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
52 
53  void setRenderer( QgsCategorizedSymbolRenderer *renderer );
54 
55  void addCategory( const QgsRendererCategory &cat );
56  QgsRendererCategory category( const QModelIndex &index );
57  void deleteRows( QList<int> rows );
58  void removeAllRows();
59  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
60  void updateSymbology();
61 
62  signals:
63  void rowsMoved();
64 
65  private:
66  QgsCategorizedSymbolRenderer *mRenderer = nullptr;
67  QString mMimeFormat;
68 };
69 
74 class QgsCategorizedSymbolRendererViewStyle: public QgsProxyStyle
75 {
76  Q_OBJECT
77 
78  public:
79  explicit QgsCategorizedSymbolRendererViewStyle( QWidget *parent );
80 
81  void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
82 };
83 
85 
86 #endif
87 
92 class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget, private QgsExpressionContextGenerator
93 {
94  Q_OBJECT
95  public:
96  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
97 
98  QgsCategorizedSymbolRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
99  ~QgsCategorizedSymbolRendererWidget() override;
100 
101  QgsFeatureRenderer *renderer() override;
102  void setContext( const QgsSymbolWidgetContext &context ) override;
103 
113  int matchToSymbols( QgsStyle *style );
114 
115  public slots:
116  void changeCategorizedSymbol();
117  void categoryColumnChanged( const QString &field );
118  void categoriesDoubleClicked( const QModelIndex &idx );
119  void addCategory();
120  void addCategories();
121 
125  void applyColorRamp();
126 
127  void deleteCategories();
128  void deleteAllCategories();
129 
130  void showSymbolLevels();
131 
132  void rowsMoved();
133 
141  void matchToSymbolsFromLibrary();
142 
150  void matchToSymbolsFromXml();
151 
152  protected slots:
153 
154  void pasteSymbolToSelection() override;
155 
156  private slots:
157 
158  void cleanUpSymbolSelector( QgsPanelWidget *container );
159  void updateSymbolsFromWidget();
160  void updateSymbolsFromButton();
161  void dataDefinedSizeLegend();
162 
168  void mergeSelectedCategories();
169 
175  void unmergeSelectedCategories();
176 
177  void showContextMenu( QPoint p );
178 
179  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
180 
181  protected:
182 
183  void updateUiFromRenderer();
184 
185  // Called by virtual refreshSymbolView()
186  void populateCategories();
187 
189  int currentCategoryRow();
190 
192  QList<int> selectedCategories();
193 
195  void changeSelectedSymbols();
196 
197  void changeCategorySymbol();
199  void applyChangeToSymbol();
200 
201  QList<QgsSymbol *> selectedSymbols() override;
202  QgsCategoryList selectedCategoryList();
203  void refreshSymbolView() override;
204  void keyPressEvent( QKeyEvent *event ) override;
205 
206  protected:
207  std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;
208 
209  std::unique_ptr< QgsSymbol > mCategorizedSymbol;
210 
211  QgsCategorizedSymbolRendererModel *mModel = nullptr;
212 
213  private:
214  QString mOldClassificationAttribute;
215  QgsCategoryList mCopyBuffer;
216  QMenu *mContextMenu = nullptr;
217  QAction *mMergeCategoriesAction = nullptr;
218  QAction *mUnmergeCategoriesAction = nullptr;
219 
221 
222  friend class TestQgsCategorizedRendererWidget;
223 };
224 
225 #endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
QgsRendererWidget::renderer
virtual QgsFeatureRenderer * renderer()=0
Returns pointer to the renderer (no transfer of ownership)
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsRendererWidget::refreshSymbolView
virtual void refreshSymbolView()
Definition: qgsrendererwidget.h:124
qgsproxystyle.h
qgscategorizedsymbolrenderer.h
QgsCategorizedSymbolRendererWidget::mCategorizedSymbol
std::unique_ptr< QgsSymbol > mCategorizedSymbol
Definition: qgscategorizedsymbolrendererwidget.h:209
QgsSymbolWidgetContext
Definition: qgssymbolwidgetcontext.h:35
QgsRendererCategory
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
Definition: qgscategorizedsymbolrenderer.h:35
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsCategoryList
QList< QgsRendererCategory > QgsCategoryList
Definition: qgscategorizedsymbolrenderer.h:145
QgsRendererWidget::pasteSymbolToSelection
virtual void pasteSymbolToSelection()
Pastes the clipboard symbol over selected items.
Definition: qgsrendererwidget.cpp:300
qgis_sip.h
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsPanelWidget::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Overridden key press event to handle the esc event on the widget.
Definition: qgspanelwidget.cpp:112
QgsRendererWidget
Definition: qgsrendererwidget.h:44
QgsRendererWidget::selectedSymbols
virtual QList< QgsSymbol * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
Definition: qgsrendererwidget.h:123
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsStyle
Definition: qgsstyle.h:159
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgsrendererwidget.h
QgsCategorizedSymbolRenderer
Definition: qgscategorizedsymbolrenderer.h:151
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
QgsRendererWidget::setContext
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
Definition: qgsrendererwidget.cpp:337
QgsCategorizedSymbolRendererWidget::mRenderer
std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer
Definition: qgscategorizedsymbolrendererwidget.h:207
QgsProxyStyle
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
Definition: qgsproxystyle.h:30