QGIS API Documentation  master-6227475
src/gui/symbology-ng/qgsrulebasedrendererv2widget.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsrulebasedrendererv2widget.h - Settings widget for rule-based renderer
00003     ---------------------
00004     begin                : May 2010
00005     copyright            : (C) 2010 by Martin Dobias
00006     email                : wonder dot sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #ifndef QGSRULEBASEDRENDERERV2WIDGET_H
00017 #define QGSRULEBASEDRENDERERV2WIDGET_H
00018 
00019 #include "qgsrendererv2widget.h"
00020 
00021 #include "qgsrulebasedrendererv2.h"
00022 class QMenu;
00023 
00025 
00026 #include <QAbstractItemModel>
00027 
00028 /* Features count fro rule */
00029 struct QgsRuleBasedRendererV2Count
00030 {
00031   int count; // number of features
00032   int duplicateCount; // number of features present also in other rule(s)
00033   // map of feature counts in other rules
00034   QMap<QgsRuleBasedRendererV2::Rule*, int> duplicateCountMap;
00035 };
00036 
00037 /*
00038 Tree model for the rules:
00039 
00040 (invalid)  == root node
00041  +--- top level rule
00042  +--- top level rule
00043 */
00044 class GUI_EXPORT QgsRuleBasedRendererV2Model : public QAbstractItemModel
00045 {
00046   public:
00047     QgsRuleBasedRendererV2Model( QgsRuleBasedRendererV2* r );
00048 
00049     virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
00050     virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
00051     virtual QVariant headerData( int section, Qt::Orientation orientation,
00052                                  int role = Qt::DisplayRole ) const;
00053     virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
00054     virtual int columnCount( const QModelIndex & = QModelIndex() ) const;
00056     virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
00058     virtual QModelIndex parent( const QModelIndex &index ) const;
00059 
00060     // editing support
00061     virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
00062 
00063     // drag'n'drop support
00064     Qt::DropActions supportedDropActions() const;
00065     QStringList mimeTypes() const;
00066     QMimeData *mimeData( const QModelIndexList &indexes ) const;
00067     bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
00068 
00069     bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() );
00070 
00071     // new methods
00072 
00073     QgsRuleBasedRendererV2::Rule* ruleForIndex( const QModelIndex& index ) const;
00074 
00075     void insertRule( const QModelIndex& parent, int before, QgsRuleBasedRendererV2::Rule* newrule );
00076     void updateRule( const QModelIndex& parent, int row );
00077     // update rule and all its descendants
00078     void updateRule( const QModelIndex& index );
00079     void removeRule( const QModelIndex& index );
00080 
00081     void willAddRules( const QModelIndex& parent, int count ); // call beginInsertRows
00082     void finishedAddingRules(); // call endInsertRows
00083 
00084     void setFeatureCounts( QMap<QgsRuleBasedRendererV2::Rule*, QgsRuleBasedRendererV2Count> theCountMap );
00085     void clearFeatureCounts();
00086 
00087   protected:
00088     QgsRuleBasedRendererV2* mR;
00089     QMap<QgsRuleBasedRendererV2::Rule*, QgsRuleBasedRendererV2Count> mFeatureCountMap;
00090 };
00091 
00092 
00094 
00095 #include "ui_qgsrulebasedrendererv2widget.h"
00096 
00097 class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsRuleBasedRendererV2Widget
00098 {
00099     Q_OBJECT
00100 
00101   public:
00102 
00103     static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
00104 
00105     QgsRuleBasedRendererV2Widget( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
00106     ~QgsRuleBasedRendererV2Widget();
00107 
00108     virtual QgsFeatureRendererV2* renderer();
00109 
00110   public slots:
00111 
00112     void addRule();
00113     void editRule();
00114     void editRule( const QModelIndex& index );
00115     void removeRule();
00116     void countFeatures();
00117     void clearFeatureCounts() { mModel->clearFeatureCounts(); }
00118 
00119     void refineRuleScales();
00120     void refineRuleCategories();
00121     void refineRuleRanges();
00122 
00123     void setRenderingOrder();
00124 
00125     void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
00126 
00127     void saveSectionWidth( int section, int oldSize, int newSize );
00128     void restoreSectionWidths();
00129 
00130   protected:
00131 
00132     void refineRule( int type );
00133     void refineRuleCategoriesGui( const QModelIndexList& index );
00134     void refineRuleRangesGui( const QModelIndexList& index );
00135     void refineRuleScalesGui( const QModelIndexList& index );
00136 
00137     QgsRuleBasedRendererV2::Rule* currentRule();
00138 
00139     QList<QgsSymbolV2*> selectedSymbols();
00140     void refreshSymbolView();
00141 
00142     QgsRuleBasedRendererV2* mRenderer;
00143     QgsRuleBasedRendererV2Model* mModel;
00144 
00145     QMenu* mRefineMenu;
00146 };
00147 
00149 
00150 #include <QDialog>
00151 
00152 #include "ui_qgsrendererrulepropsdialogbase.h"
00153 
00154 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog, private Ui::QgsRendererRulePropsDialog
00155 {
00156     Q_OBJECT
00157 
00158   public:
00159     QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = 0 );
00160     ~QgsRendererRulePropsDialog();
00161 
00162     QgsRuleBasedRendererV2::Rule* rule() { return mRule; }
00163 
00164   public slots:
00165     void testFilter();
00166     void buildExpression();
00167     void accept();
00168 
00169   protected:
00170     QgsRuleBasedRendererV2::Rule* mRule; // borrowed
00171     QgsVectorLayer* mLayer;
00172     QgsStyleV2* mStyle;
00173 
00174     QgsSymbolV2SelectorDialog* mSymbolSelector;
00175     QgsSymbolV2* mSymbol; // a clone of original symbol
00176 };
00177 
00178 
00179 #endif // QGSRULEBASEDRENDERERV2WIDGET_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines