QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrulebasedrendererv2widget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrulebasedrendererv2widget.h - Settings widget for rule-based renderer
3  ---------------------
4  begin : May 2010
5  copyright : (C) 2010 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 
16 #ifndef QGSRULEBASEDRENDERERV2WIDGET_H
17 #define QGSRULEBASEDRENDERERV2WIDGET_H
18 
19 #include "qgsrendererv2widget.h"
20 
21 #include "qgsrulebasedrendererv2.h"
22 class QMenu;
23 
25 
26 #include <QAbstractItemModel>
27 
28 /* Features count fro rule */
30 {
31  int count; // number of features
32  int duplicateCount; // number of features present also in other rule(s)
33  // map of feature counts in other rules
35 };
36 
37 /*
38 Tree model for the rules:
39 
40 (invalid) == root node
41  +--- top level rule
42  +--- top level rule
43 */
45 {
46  public:
48 
49  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
50  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
51  virtual QVariant headerData( int section, Qt::Orientation orientation,
52  int role = Qt::DisplayRole ) const override;
53  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
54  virtual int columnCount( const QModelIndex & = QModelIndex() ) const override;
56  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
58  virtual QModelIndex parent( const QModelIndex &index ) const override;
59 
60  // editing support
61  virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) override;
62 
63  // drag'n'drop support
64  Qt::DropActions supportedDropActions() const override;
65  QStringList mimeTypes() const override;
66  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
67  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
68 
69  bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ) override;
70 
71  // new methods
72 
73  QgsRuleBasedRendererV2::Rule* ruleForIndex( const QModelIndex& index ) const;
74 
75  void insertRule( const QModelIndex& parent, int before, QgsRuleBasedRendererV2::Rule* newrule );
76  void updateRule( const QModelIndex& parent, int row );
77  // update rule and all its descendants
78  void updateRule( const QModelIndex& index );
79  void removeRule( const QModelIndex& index );
80 
81  void willAddRules( const QModelIndex& parent, int count ); // call beginInsertRows
82  void finishedAddingRules(); // call endInsertRows
83 
85  void setFeatureCounts( QMap<QgsRuleBasedRendererV2::Rule*, QgsRuleBasedRendererV2Count> theCountMap );
86  void clearFeatureCounts();
87 
88  protected:
91 };
92 
93 
95 
96 #include "ui_qgsrulebasedrendererv2widget.h"
97 
98 class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsRuleBasedRendererV2Widget
99 {
100  Q_OBJECT
101 
102  public:
103 
104  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
105 
108 
109  virtual QgsFeatureRendererV2* renderer() override;
110 
111  public slots:
112 
113  void addRule();
114  void editRule();
115  void editRule( const QModelIndex& index );
116  void removeRule();
117  void countFeatures();
118  void clearFeatureCounts() { mModel->clearFeatureCounts(); }
119 
120  void refineRuleScales();
121  void refineRuleCategories();
122  void refineRuleRanges();
123 
124  void setRenderingOrder();
125 
126  void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
127 
128  void saveSectionWidth( int section, int oldSize, int newSize );
129  void restoreSectionWidths();
130 
131  protected:
132  void refineRule( int type );
133  void refineRuleCategoriesGui( const QModelIndexList& index );
134  void refineRuleRangesGui( const QModelIndexList& index );
135  void refineRuleScalesGui( const QModelIndexList& index );
136 
137  QgsRuleBasedRendererV2::Rule* currentRule();
138 
140  QgsRuleBasedRendererV2::RuleList selectedRules();
141  void refreshSymbolView() override;
142  void keyPressEvent( QKeyEvent* event ) override;
143 
146 
149 
151 
152  protected slots:
153  void copy() override;
154  void paste() override;
155 };
156 
158 
159 #include <QDialog>
160 
161 #include "ui_qgsrendererrulepropsdialogbase.h"
162 
163 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog, private Ui::QgsRendererRulePropsDialog
164 {
165  Q_OBJECT
166 
167  public:
170 
171  QgsRuleBasedRendererV2::Rule* rule() { return mRule; }
172 
173  public slots:
174  void testFilter();
175  void buildExpression();
176  void accept() override;
177 
178  protected:
181 
183  QgsSymbolV2* mSymbol; // a clone of original symbol
184 };
185 
186 
187 #endif // QGSRULEBASEDRENDERERV2WIDGET_H
virtual QList< QgsSymbolV2 * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
static unsigned index
QMap< QgsRuleBasedRendererV2::Rule *, int > duplicateCountMap
virtual int rowCount(const QModelIndex &parent) const =0
QgsSymbolV2SelectorDialog * mSymbolSelector
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
void create(WId window, bool initializeWindow, bool destroyOldWindow)
QgsRuleBasedRendererV2Model * mModel
QgsRuleBasedRendererV2::RuleList mCopyBuffer
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual QStringList mimeTypes() const
virtual Qt::DropActions supportedDropActions() const
This class keeps data about a rules for rule-based renderer.
virtual QVariant data(const QModelIndex &index, int role) const =0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > mFeatureCountMap
virtual void accept()
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual bool removeRows(int row, int count, const QModelIndex &parent)
typedef DropActions
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
virtual int columnCount(const QModelIndex &parent) const =0
virtual void keyPressEvent(QKeyEvent *event)
Base class for renderer settings widgets.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QgsRuleBasedRendererV2::Rule * mRule
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QgsRuleBasedRendererV2::Rule * rule()
virtual void refreshSymbolView()
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
virtual QgsFeatureRendererV2 * renderer()=0
return pointer to the renderer (no transfer of ownership)
typedef ItemFlags