QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgscolorrampshaderwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscolorrampshaderwidget.h
3  --------------------------
4  begin : Jun 2018
5  copyright : (C) 2018 by Peter Petrik
6  email : zilolv at gmail dot com
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 QGSCOLORRAMPSHADERWIDGET_H
19 #define QGSCOLORRAMPSHADERWIDGET_H
20 
21 #include <QStyledItemDelegate>
22 
23 #include "qgis_sip.h"
24 #include "qgscolorrampshader.h"
25 #include "qgsrasterrenderer.h"
26 #include "ui_qgscolorrampshaderwidgetbase.h"
27 #include "qgis_gui.h"
30 
32 class QgsLocaleAwareNumericLineEditDelegate;
33 
45 class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColorRampShaderWidgetBase
46 {
47 
48  Q_OBJECT
49 
50  public:
51 
53  QgsColorRampShaderWidget( QWidget *parent = nullptr );
54 
56  void initializeForUseWithRasterLayer();
57 
59  void setRasterDataProvider( QgsRasterDataProvider *dp );
60 
62  void setRasterBand( int band );
63 
65  void setExtent( const QgsRectangle &extent );
66 
68  void setMinimumMaximumAndClassify( double minimum, double maximum );
69 
71  void setMinimumMaximum( double minimum, double maximum );
72 
74  double minimum() const;
75 
77  double maximum() const;
78 
80  QgsColorRampShader shader() const;
81 
83  void setFromShader( const QgsColorRampShader &colorRampShader );
84 
85  signals:
87  void minimumMaximumChangedFromTree( double minimum, double maximum );
88 
90  void widgetChanged();
91 
94 
95  public slots:
96 
100  void classify();
101 
103  void loadMinimumMaximumFromTree();
104 
105  protected:
106 
108  void populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem> &colorRampItems );
109 
110  private:
111 
112  enum Column
113  {
114  ValueColumn = 0,
115  ColorColumn = 1,
116  LabelColumn = 2,
117  };
118 
124  void autoLabel();
125 
127  bool colormapMinMax( double &min, double &max ) const;
128 
130  void setUnitFromLabels();
131 
132  QMenu *contextMenu = nullptr;
133 
134  private slots:
135 
136  void applyColorRamp();
137  void updateColorRamp();
138  void mAddEntryButton_clicked();
139  void mDeleteEntryButton_clicked();
140  void mLoadFromBandButton_clicked();
141  void mLoadFromFileButton_clicked();
142  void mExportToFileButton_clicked();
143  void mUnitLineEdit_textEdited( const QString &text ) { Q_UNUSED( text ) autoLabel(); }
144  void mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem *item, int column );
145  void mColormapTreeWidget_itemEdited( QTreeWidgetItem *item, int column );
146  void mColorInterpolationComboBox_currentIndexChanged( int index );
147  void mClassificationModeComboBox_currentIndexChanged( int index );
148  void changeColor();
149  void changeOpacity();
150  void showLegendSettings();
151 
152  private:
153  void setLineEditValue( QLineEdit *lineEdit, double value );
154  double lineEditValue( const QLineEdit *lineEdit ) const;
155  void resetClassifyButton();
156 
157  QString createLabel( QTreeWidgetItem *item, int row, const QString unit );
158 
159 #ifdef QGISDEBUG
161  void dumpClasses();
162 #endif
163 
164  double mMin = std::numeric_limits<double>::quiet_NaN();
165  double mMax = std::numeric_limits<double>::quiet_NaN();
166 
167  // For mode with raster layer
168  QgsRasterDataProvider *mRasterDataProvider = nullptr;
169  int mBand = -1;
170  QgsRectangle mExtent;
171  QgsLocaleAwareNumericLineEditDelegate *mValueDelegate = nullptr;
172  QgsColorRampLegendNodeSettings mLegendSettings;
173 
174 
175 };
176 
177 #endif // QGSCOLORRAMPSHADERWIDGET_H
Settings for a color ramp legend node.
It has 2 ways how to use it.
void classificationModeChanged(QgsColorRampShader::ClassificationMode mode)
Classification mode changed.
void minimumMaximumChangedFromTree(double minimum, double maximum)
Color ramp tree has changed.
void widgetChanged()
Widget changed.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
ClassificationMode
Classification modes used to create the color ramp shader.
Base class for raster data providers.
A rectangle specified with double values.
Definition: qgsrectangle.h:42