QGIS API Documentation  2.14.0-Essen
qgssizescalewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssizescalewidget.h - continuous size scale assistant
3 
4  ---------------------
5  begin : March 2015
6  copyright : (C) 2015 by Vincent Mora
7  email : vincent dot mora at oslandia dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSSIZESCALEWIDGET_H
18 #define QGSSIZESCALEWIDGET_H
19 
20 #include "qgslayertreegroup.h"
21 #include "qgslayertreemodel.h"
22 #include "qgsdatadefinedbutton.h"
23 #include "ui_widget_size_scale.h"
24 #include <QStandardItemModel>
25 #include <QItemDelegate>
26 
27 class QgsVectorLayer;
28 class QgsSymbolV2;
29 class QgsLayerTreeLayer;
30 class QgsScaleExpression;
31 class QgsDataDefined;
32 class QgsMapCanvas;
33 
34 class GUI_EXPORT QgsSizeScaleWidget : public QgsDataDefinedAssistant, private Ui_SizeScaleBase
35 {
36  Q_OBJECT
37 
38  public:
39  QgsSizeScaleWidget( const QgsVectorLayer * layer, const QgsSymbolV2 * symbol );
40 
41  QgsDataDefined dataDefined() const override;
42 
46  const QgsVectorLayer* layer() const { return mLayer; }
47 
48  protected:
49 
50  virtual void showEvent( QShowEvent * ) override;
51 
52  private slots:
53  void computeFromLayerTriggered();
54  void updatePreview();
55 
56  private:
57 
58  const QgsSymbolV2* mSymbol;
59  QgsVectorLayer* mLayer;
60  QgsLayerTreeLayer* mLayerTreeLayer;
61  QgsLayerTreeGroup mRoot;
62  QStandardItemModel mPreviewList;
64 
65  QgsScaleExpression* createExpression() const;
66  void setFromSymbol();
67 
68 };
69 
71 class ItemDelegate : public QItemDelegate
72 {
73  Q_OBJECT
74 
75  public:
76  explicit ItemDelegate( QStandardItemModel* model ) : mModel( model ) {}
77 
78  QSize sizeHint( const QStyleOptionViewItem& /*option*/, const QModelIndex & index ) const override
79  {
80  return mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
81  }
82 
83  private:
84  QStandardItemModel* mModel;
85 
86 };
87 
89 
90 #endif //QGSSIZESCALEWIDGET_H
Layer tree group node serves as a container for layers and further groups.
static unsigned index
An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
A container class for data source field mapping or expression.
virtual QgsDataDefined dataDefined() const =0
Class storing parameters of a scale expression, which is a subclass of QgsExpression for expressions ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
int row() const
virtual void showEvent(QShowEvent *event)
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Represents a vector layer which manages a vector based data sets.
Layer tree node points to a map layer.