QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 std::unique_ptr<QgsRasterDataProvider> mProvider;
83 int mBandNumber;
84 std::unique_ptr<QgsColorRamp> mRamp;
85 QString mSubstring;
87 QgsRasterBlockFeedback *mFeedback = nullptr;
88 QMutex mFeedbackMutex;
89 bool mWasCanceled;
90};
91
92class QgsPalettedRendererModel : public QAbstractItemModel
93{
94 Q_OBJECT
95
96 public:
97 enum Column
98 {
99 ValueColumn = 0,
100 ColorColumn = 1,
101 LabelColumn = 2,
102 };
103
104 QgsPalettedRendererModel( QObject *parent = nullptr );
105
106 void setClassData( const QgsPalettedRasterRenderer::ClassData &data );
107
108 QgsPalettedRasterRenderer::ClassData classData() const { return mData; }
109 QgsPalettedRasterRenderer::Class classAtIndex( const QModelIndex &index ) const { return mData.at( index.row() ); }
110
111 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
112 QModelIndex parent( const QModelIndex &index ) const override;
113 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
114 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
115 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
116 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
117 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
118 Qt::ItemFlags flags( const QModelIndex &index ) const override;
119 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
120 bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
121 Qt::DropActions supportedDropActions() const override;
122 QStringList mimeTypes() const override;
123 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
124 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
125
126 QModelIndex addEntry( const QColor &color );
127
128 public slots:
129
130 void deleteAll();
131
132 signals:
133
134 void classesChanged();
135
136 private:
138};
139
140class QgsPalettedRendererProxyModel : public QSortFilterProxyModel
141{
142 Q_OBJECT
143
144 public:
145 QgsPalettedRendererProxyModel( QObject *parent = 0 )
146 : QSortFilterProxyModel( parent )
147 {
148 }
149
151 QgsPalettedRasterRenderer::ClassData classData() const;
152
153 protected:
154 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override
155 {
156 const QModelIndex lv { left.model()->index( left.row(), static_cast<int>( QgsPalettedRendererModel::Column::ValueColumn ), left.parent() ) };
157 const QModelIndex rv { right.model()->index( right.row(), static_cast<int>( QgsPalettedRendererModel::Column::ValueColumn ), right.parent() ) };
158 const double leftData { sourceModel()->data( lv ).toDouble() };
159 const double rightData { sourceModel()->data( rv ).toDouble() };
160 return leftData < rightData;
161 }
162};
163
165#endif
166
171class GUI_EXPORT QgsPalettedRendererWidget : public QgsRasterRendererWidget, private Ui::QgsPalettedRendererWidgetBase
172{
173 Q_OBJECT
174
175 public:
178 static QgsRasterRendererWidget *create( QgsRasterLayer *layer, const QgsRectangle &extent ) SIP_FACTORY { return new QgsPalettedRendererWidget( layer, extent ); }
179
181
185 void setFromRenderer( const QgsRasterRenderer *r );
186
187 private:
188 QMenu *mContextMenu = nullptr;
189 QMenu *mAdvancedMenu = nullptr;
190 QgsPalettedRendererModel *mModel = nullptr;
191 QgsPalettedRendererProxyModel *mProxyModel = nullptr;
192
194 QgsPalettedRendererClassGatherer *mGatherer = nullptr;
195
196 int mBand = -1;
197
198 QgsLocaleAwareNumericLineEditDelegate *mValueDelegate = nullptr;
199
200 void setSelectionColor( const QItemSelection &selection, const QColor &color );
201
202 private slots:
203
204 void deleteEntry();
205 void addEntry();
206 void changeColor();
207 void changeOpacity();
208 void changeLabel();
209 void applyColorRamp();
210 void loadColorTable();
211 void saveColorTable();
212 void classify();
213 void loadFromLayer();
214 void bandChanged( int band );
215
216 void gatheredClasses();
217 void gathererThreadFinished();
218 void layerWillBeRemoved( QgsMapLayer *layer );
219};
220
221#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.