QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
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 "ui_qgspalettedrendererwidgetbase.h"
27#include "qgis_gui.h"
28
29#include <QThread>
30#include <QSortFilterProxyModel>
31
32class QgsRasterLayer;
33class QgsLocaleAwareNumericLineEditDelegate;
34
35#ifndef SIP_RUN
37
42class QgsPalettedRendererClassGatherer: public QThread
43{
44 Q_OBJECT
45
46 public:
47 QgsPalettedRendererClassGatherer( QgsRasterLayer *layer, int bandNumber, const QgsPalettedRasterRenderer::ClassData &existingClasses, QgsColorRamp *ramp = nullptr );
48
49 void run() override;
50
52 void stop()
53 {
54 // be cautious, in case gatherer stops naturally just as we are canceling it and mFeedback gets deleted
55 mFeedbackMutex.lock();
56 if ( mFeedback )
57 mFeedback->cancel();
58 mFeedbackMutex.unlock();
59
60 mWasCanceled = true;
61 }
62
64 bool wasCanceled() const { return mWasCanceled; }
65
66 QgsPalettedRasterRenderer::ClassData classes() const { return mClasses; }
67
68 signals:
69
73 void collectedClasses();
74
75 signals:
77 void canceled();
78
79 void progressChanged( double progress );
80
81 private:
82
83 std::unique_ptr< QgsRasterDataProvider > mProvider;
84 int mBandNumber;
85 std::unique_ptr< QgsColorRamp > mRamp;
86 QString mSubstring;
88 QgsRasterBlockFeedback *mFeedback = nullptr;
89 QMutex mFeedbackMutex;
90 bool mWasCanceled;
91};
92
93class QgsPalettedRendererModel : public QAbstractItemModel
94{
95 Q_OBJECT
96
97 public:
98
99 enum Column
100 {
101 ValueColumn = 0,
102 ColorColumn = 1,
103 LabelColumn = 2,
104 };
105
106 QgsPalettedRendererModel( QObject *parent = nullptr );
107
108 void setClassData( const QgsPalettedRasterRenderer::ClassData &data );
109
110 QgsPalettedRasterRenderer::ClassData classData() const { return mData; }
111 QgsPalettedRasterRenderer::Class classAtIndex( const QModelIndex &index ) const { return mData.at( index.row() ); }
112
113 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
114 QModelIndex parent( const QModelIndex &index ) const override;
115 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
116 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
117 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
118 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
119 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
120 Qt::ItemFlags flags( const QModelIndex &index ) const override;
121 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
122 bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
123 Qt::DropActions supportedDropActions() const override;
124 QStringList mimeTypes() const override;
125 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
126 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
127
128 QModelIndex addEntry( const QColor &color );
129
130 public slots:
131
132 void deleteAll();
133
134 signals:
135
136 void classesChanged();
137
138 private:
139
141
142
143};
144
145class QgsPalettedRendererProxyModel: public QSortFilterProxyModel
146{
147 Q_OBJECT
148
149 public:
150
151 QgsPalettedRendererProxyModel( QObject *parent = 0 )
152 : QSortFilterProxyModel( parent )
153 {
154 }
155
157 QgsPalettedRasterRenderer::ClassData classData() const;
158
159 protected:
160
161 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override
162 {
163 const QModelIndex lv { left.model()->index( left.row(), static_cast<int>( QgsPalettedRendererModel::Column::ValueColumn ), left.parent() ) };
164 const QModelIndex rv { right.model()->index( right.row(), static_cast<int>( QgsPalettedRendererModel::Column::ValueColumn ), right.parent() ) };
165 const double leftData { sourceModel()->data( lv ).toDouble( ) };
166 const double rightData { sourceModel()->data( rv ).toDouble( ) };
167 return leftData < rightData;
168 }
169
170};
171
173#endif
174
179class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, private Ui::QgsPalettedRendererWidgetBase
180{
181 Q_OBJECT
182
183 public:
184
187 static QgsRasterRendererWidget *create( QgsRasterLayer *layer, const QgsRectangle &extent ) SIP_FACTORY { return new QgsPalettedRendererWidget( layer, extent ); }
188
190
194 void setFromRenderer( const QgsRasterRenderer *r );
195
196 private:
197
198 QMenu *mContextMenu = nullptr;
199 QMenu *mAdvancedMenu = nullptr;
200 QgsPalettedRendererModel *mModel = nullptr;
201 QgsPalettedRendererProxyModel *mProxyModel = nullptr;
202
204 QgsPalettedRendererClassGatherer *mGatherer = nullptr;
205
206 int mBand = -1;
207
208 QgsLocaleAwareNumericLineEditDelegate *mValueDelegate = nullptr;
209
210 void setSelectionColor( const QItemSelection &selection, const QColor &color );
211
212 private slots:
213
214 void deleteEntry();
215 void addEntry();
216 void changeColor();
217 void changeOpacity();
218 void changeLabel();
219 void applyColorRamp();
220 void loadColorTable();
221 void saveColorTable();
222 void classify();
223 void loadFromLayer();
224 void bandChanged( int band );
225
226 void gatheredClasses();
227 void gathererThreadFinished();
228 void layerWillBeRemoved( QgsMapLayer *layer );
229
230};
231
232#endif // QGSPALETTEDRENDERERWIDGET_H
Abstract base class for color ramps.
Base class for all map layer types.
Definition qgsmaplayer.h:76
QList< QgsPalettedRasterRenderer::Class > ClassData
Map of value to class properties.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Feedback object tailored for raster block reading.
Represents a raster layer.
Abstract base class for widgets which configure a QgsRasterRenderer.
virtual QgsRasterRenderer * renderer()=0
Creates a new renderer, using the properties defined in the widget.
Raster renderer pipe that applies colors to a raster.
A rectangle specified with double values.
#define SIP_FACTORY
Definition qgis_sip.h:76
Properties of a single value class.