Main Page · Class Overview · Hierarchy · All Classes
colorgradient.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
25 
26 #ifndef QCP_COLORGRADIENT_H
27 #define QCP_COLORGRADIENT_H
28 
29 #include "global.h"
30 #include "range.h"
31 
32 class QCP_LIB_DECL QCPColorGradient
33 {
34  Q_GADGET
35 public:
41  enum ColorInterpolation { ciRGB
42  ,ciHSV
43  };
44  Q_ENUMS(ColorInterpolation)
45 
46 
50  enum GradientPreset { gpGrayscale
51  ,gpHot
52  ,gpCold
53  ,gpNight
54  ,gpCandy
55  ,gpGeography
56  ,gpIon
57  ,gpThermal
58  ,gpPolar
59  ,gpSpectrum
60  ,gpJet
61  ,gpHues
62  };
63  Q_ENUMS(GradientPreset)
64 
65  QCPColorGradient(GradientPreset preset=gpCold);
66  bool operator==(const QCPColorGradient &other) const;
67  bool operator!=(const QCPColorGradient &other) const { return !(*this == other); }
68 
69  // getters:
70  int levelCount() const { return mLevelCount; }
71  QMap<double, QColor> colorStops() const { return mColorStops; }
72  ColorInterpolation colorInterpolation() const { return mColorInterpolation; }
73  bool periodic() const { return mPeriodic; }
74 
75  // setters:
76  void setLevelCount(int n);
77  void setColorStops(const QMap<double, QColor> &colorStops);
78  void setColorStopAt(double position, const QColor &color);
79  void setColorInterpolation(ColorInterpolation interpolation);
80  void setPeriodic(bool enabled);
81 
82  // non-property methods:
83  void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
84  QRgb color(double position, const QCPRange &range, bool logarithmic=false);
85  void loadPreset(GradientPreset preset);
86  void clearColorStops();
87  QCPColorGradient inverted() const;
88 
89 protected:
90  void updateColorBuffer();
91 
92  // property members:
93  int mLevelCount;
94  QMap<double, QColor> mColorStops;
95  ColorInterpolation mColorInterpolation;
96  bool mPeriodic;
97 
98  // non-property members:
99  QVector<QRgb> mColorBuffer;
100  bool mColorBufferInvalidated;
101 };
102 
103 #endif // QCP_COLORGRADIENT_H