QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgis_sip.h"
22 #include "qgscolorrampshader.h"
23 #include "qgsrasterrenderer.h"
24 #include "qgscolorschemelist.h"
25 #include "ui_qgscolorrampshaderwidgetbase.h"
26 #include "qgis_gui.h"
28 
30 
42 class GUI_EXPORT QgsColorRampShaderWidget: public QWidget, protected Ui::QgsColorRampShaderWidgetBase
43 {
44 
45  Q_OBJECT
46 
47  public:
48 
50  QgsColorRampShaderWidget( QWidget *parent = nullptr );
51 
53  void initializeForUseWithRasterLayer();
54 
56  void setRasterDataProvider( QgsRasterDataProvider *dp );
57 
59  void setRasterBand( int band );
60 
62  void setExtent( const QgsRectangle &extent );
63 
65  void setMinimumMaximumAndClassify( double minimum, double maximum );
66 
68  void setMinimumMaximum( double minimum, double maximum );
69 
71  double minimum() const;
72 
74  double maximum() const;
75 
77  QgsColorRampShader shader() const;
78 
80  void setFromShader( const QgsColorRampShader &colorRampShader );
81 
82  signals:
84  void minimumMaximumChangedFromTree( double minimum, double maximum );
85 
87  void widgetChanged();
88 
91 
92  public slots:
93 
97  void classify();
98 
100  void loadMinimumMaximumFromTree();
101 
102  protected:
104  void populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem> &colorRampItems );
105 
106  private:
107 
108  enum Column
109  {
110  ValueColumn = 0,
111  ColorColumn = 1,
112  LabelColumn = 2,
113  };
114 
120  void autoLabel();
121 
123  bool colormapMinMax( double &min, double &max ) const;
124 
126  void setUnitFromLabels();
127 
128  QMenu *contextMenu = nullptr;
129 
130  private slots:
131 
132  void applyColorRamp();
133  void mAddEntryButton_clicked();
134  void mDeleteEntryButton_clicked();
135  void mLoadFromBandButton_clicked();
136  void mLoadFromFileButton_clicked();
137  void mExportToFileButton_clicked();
138  void mUnitLineEdit_textEdited( const QString &text ) { Q_UNUSED( text ) autoLabel(); }
139  void mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem *item, int column );
140  void mColormapTreeWidget_itemEdited( QTreeWidgetItem *item, int column );
141  void mColorInterpolationComboBox_currentIndexChanged( int index );
142  void mClassificationModeComboBox_currentIndexChanged( int index );
143  void changeColor();
144  void changeOpacity();
145 
146  private:
147  void setLineEditValue( QLineEdit *lineEdit, double value );
148  double lineEditValue( const QLineEdit *lineEdit ) const;
149  void resetClassifyButton();
150 
151  QgsColorSwatchDelegate *mSwatchDelegate = nullptr;
152 
153  double mMin = std::numeric_limits<double>::quiet_NaN();
154  double mMax = std::numeric_limits<double>::quiet_NaN();
155 
156  // For mode with raster layer
157  QgsRasterDataProvider *mRasterDataProvider = nullptr;
158  int mBand = -1;
159  QgsRectangle mExtent;
160 
161 };
162 
163 #endif // QGSCOLORRAMPSHADERWIDGET_H
QgsColorSwatchDelegate
A delegate for showing a color swatch in a list.
Definition: qgscolorschemelist.h:37
QgsColorRampShaderWidget
It has 2 ways how to use it.
Definition: qgscolorrampshaderwidget.h:43
QgsColorRampShaderWidget::minimumMaximumChangedFromTree
void minimumMaximumChangedFromTree(double minimum, double maximum)
Color ramp tree has changed.
qgscolorrampshader.h
qgsrasterrenderer.h
QgsColorRampShader
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:40
qgsrasterrendererwidget.h
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
qgis_sip.h
QgsColorRampShaderWidget::classificationModeChanged
void classificationModeChanged(QgsColorRampShader::ClassificationMode mode)
Classification mode changed.
QgsColorRampShader::ClassificationMode
ClassificationMode
Classification modes used to create the color ramp shader.
Definition: qgscolorrampshader.h:54
QgsColorRampShaderWidget::widgetChanged
void widgetChanged()
Widget changed.
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89
qgscolorschemelist.h