QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgspalettedrendererwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspalettedrendererwidget.h
3  ---------------------------
4  begin : February 2012
5  copyright : (C) 2012 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPALETTEDRENDERERWIDGET_H
19 #define QGSPALETTEDRENDERERWIDGET_H
20 
22 #include "qgis_sip.h"
24 #include "qgscolorschemelist.h"
25 #include "qgsrasterlayer.h"
26 #include "qgsrasterdataprovider.h"
27 #include "ui_qgspalettedrendererwidgetbase.h"
28 #include "qgis_gui.h"
29 
30 class QgsRasterLayer;
31 
32 #ifndef SIP_RUN
33 
39 class QgsPalettedRendererClassGatherer: public QThread
40 {
41  Q_OBJECT
42 
43  public:
44  QgsPalettedRendererClassGatherer( QgsRasterLayer *layer, int bandNumber, const QgsPalettedRasterRenderer::ClassData &existingClasses, QgsColorRamp *ramp = nullptr )
45  : mLayer( layer )
46  , mBandNumber( bandNumber )
47  , mRamp( ramp )
48  , mClasses( existingClasses )
49  , mWasCanceled( false )
50  {}
51 
52  void run() override;
53 
55  void stop()
56  {
57  // be cautious, in case gatherer stops naturally just as we are canceling it and mFeedback gets deleted
58  mFeedbackMutex.lock();
59  if ( mFeedback )
60  mFeedback->cancel();
61  mFeedbackMutex.unlock();
62 
63  mWasCanceled = true;
64  }
65 
67  bool wasCanceled() const { return mWasCanceled; }
68 
69  QgsPalettedRasterRenderer::ClassData classes() const { return mClasses; }
70 
71  signals:
72 
76  void collectedClasses();
77 
78  signals:
80  void canceled();
81 
82  void progressChanged( double progress );
83 
84  private:
85 
86  QgsRasterLayer *mLayer = nullptr;
87  int mBandNumber;
88  std::unique_ptr< QgsColorRamp > mRamp;
89  QString mSubstring;
91  QgsRasterBlockFeedback *mFeedback = nullptr;
92  QMutex mFeedbackMutex;
93  bool mWasCanceled;
94 };
95 
96 class QgsPalettedRendererModel : public QAbstractItemModel
97 {
98  Q_OBJECT
99 
100  public:
101 
102  enum Column
103  {
104  ValueColumn = 0,
105  ColorColumn = 1,
106  LabelColumn = 2,
107  };
108 
109  QgsPalettedRendererModel( QObject *parent = nullptr );
110 
111  void setClassData( const QgsPalettedRasterRenderer::ClassData &data );
112 
113  QgsPalettedRasterRenderer::ClassData classData() const { return mData; }
114 
115  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
116  QModelIndex parent( const QModelIndex &index ) const override;
117  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
118  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
119  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
120  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
121  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
122  Qt::ItemFlags flags( const QModelIndex &index ) const override;
123  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
124  bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
125  Qt::DropActions supportedDropActions() const override;
126  QStringList mimeTypes() const override;
127  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
128  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
129 
130  QModelIndex addEntry( const QColor &color );
131 
132  public slots:
133 
134  void deleteAll();
135 
136  signals:
137 
138  void classesChanged();
139 
140  private:
141 
143 
144 
145 };
147 #endif
148 
153 class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, private Ui::QgsPalettedRendererWidgetBase
154 {
155  Q_OBJECT
156 
157  public:
158 
160  ~QgsPalettedRendererWidget() override;
161  static QgsRasterRendererWidget *create( QgsRasterLayer *layer, const QgsRectangle &extent ) SIP_FACTORY { return new QgsPalettedRendererWidget( layer, extent ); }
162 
163  QgsRasterRenderer *renderer() override;
164 
165  void setFromRenderer( const QgsRasterRenderer *r );
166 
167  private:
168 
169  QMenu *mContextMenu = nullptr;
170  QMenu *mAdvancedMenu = nullptr;
171  QAction *mLoadFromLayerAction = nullptr;
172  QgsPalettedRendererModel *mModel = nullptr;
173  QgsColorSwatchDelegate *mSwatchDelegate = nullptr;
174 
176  QgsPalettedRendererClassGatherer *mGatherer = nullptr;
177 
178  int mBand = -1;
179 
180  void setSelectionColor( const QItemSelection &selection, const QColor &color );
181 
182  private slots:
183 
184  void deleteEntry();
185  void addEntry();
186  void changeColor();
187  void changeOpacity();
188  void changeLabel();
189  void applyColorRamp();
190  void loadColorTable();
191  void saveColorTable();
192  void classify();
193  void loadFromLayer();
194  void bandChanged( int band );
195 
196  void gatheredClasses();
197  void gathererThreadFinished();
198  void layerWillBeRemoved( QgsMapLayer *layer );
199 
200 };
201 
202 #endif // QGSPALETTEDRENDERERWIDGET_H
QgsPalettedRasterRenderer::ClassData
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
Definition: qgspalettedrasterrenderer.h:59
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:32
qgsrasterlayer.h
QgsPalettedRendererWidget::create
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Definition: qgspalettedrendererwidget.h:161
QgsColorSwatchDelegate
A delegate for showing a color swatch in a list.
Definition: qgscolorschemelist.h:37
qgsrasterrendererwidget.h
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
qgspalettedrasterrenderer.h
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:39
qgis_sip.h
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsPalettedRendererWidget
Definition: qgspalettedrendererwidget.h:154
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterRendererWidget
Definition: qgsrasterrendererwidget.h:37
QgsRasterRendererWidget::renderer
virtual QgsRasterRenderer * renderer()=0
qgscolorschemelist.h
qgsrasterdataprovider.h