QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
37 class GUI_EXPORT QgsSizeScaleWidget : public QgsDataDefinedAssistant, private Ui_SizeScaleBase
38 {
39  Q_OBJECT
40 
41  public:
42  QgsSizeScaleWidget( const QgsVectorLayer * layer, const QgsSymbolV2 * symbol );
43 
44  QgsDataDefined dataDefined() const override;
45 
49  const QgsVectorLayer* layer() const { return mLayer; }
50 
51  protected:
52 
53  virtual void showEvent( QShowEvent * ) override;
54 
55  private slots:
56  void computeFromLayerTriggered();
57  void updatePreview();
58 
59  private:
60 
61  const QgsSymbolV2* mSymbol;
62  QgsVectorLayer* mLayer;
63  QgsLayerTreeLayer* mLayerTreeLayer;
64  QgsLayerTreeGroup mRoot;
65  QStandardItemModel mPreviewList;
67 
68  QgsScaleExpression* createExpression() const;
69  void setFromSymbol();
70 
71 };
72 
74 class ItemDelegate : public QItemDelegate
75 {
76  Q_OBJECT
77 
78  public:
79  explicit ItemDelegate( QStandardItemModel* model ) : mModel( model ) {}
80 
81  QSize sizeHint( const QStyleOptionViewItem& /*option*/, const QModelIndex & index ) const override
82  {
83  return mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
84  }
85 
86  private:
87  QStandardItemModel* mModel;
88 
89 };
90 
92 
93 #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
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
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:109
int row() const
virtual void showEvent(QShowEvent *event)
Represents a vector layer which manages a vector based data sets.
Layer tree node points to a map layer.