16 #include <QSharedPointer>
74 typedef QSharedPointer<ccColorScale>
Shared;
99 static const unsigned MIN_STEPS = 2;
104 static const unsigned DEFAULT_STEPS = 256;
109 static const unsigned MAX_STEPS = 1024;
112 inline const QString&
getName()
const {
return m_name; }
121 void generateNewUuid();
132 void setAbsolute(
double minVal,
double maxVal);
137 void getAbsoluteBoundaries(
double& minVal,
double& maxVal)
const;
149 Label(
double v,
const QString& t) : value(v), text(t) {}
155 return value < otherLabel.
value;
171 m_customLabels = labels;
184 return m_steps[index];
196 void remove(
int index,
bool autoUpdate =
true);
216 assert(m_updated && !m_relative);
217 return (value - m_absoluteMinValue) / m_absoluteRange;
229 assert(m_updated && !m_relative);
230 double relativePos = getRelativePosition(value);
231 return (relativePos >= 0.0 && relativePos <= 1.0
232 ? getColorByRelativePos(relativePos)
245 if (relativePos >= 0.0 && relativePos <= 1.0)
246 return &getColorByIndex(
247 static_cast<unsigned>(relativePos * (MAX_STEPS - 1)));
249 return outOfRangeColor;
263 if (relativePos >= 0.0 && relativePos <= 1.0) {
266 (
static_cast<unsigned>((relativePos * steps) * 65535.0)) >>
268 return &getColorByIndex((index * (MAX_STEPS - 1)) / steps);
270 return outOfRangeColor;
279 assert(m_updated && index < MAX_STEPS);
280 return m_rgbaScale[index];
284 bool saveAsXML(QString
filename)
const;
286 static Shared LoadFromXML(QString
filename);
290 bool toFile(QFile& out,
short dataVersion)
const override;
295 LoadedIDMap& oldToNewIDMap)
override;
Color scale element: one value + one color.
const QColor & getColor() const
Returns color.
ccColorScaleElement()
Default constructor.
double m_relativePos
Step (relative) position.
ccColorScaleElement(double relativePos, QColor color)
Constructor from a (relative) position and a color.
double getRelativePos() const
Returns step position (relative to scale boundaries)
static bool IsSmaller(const ccColorScaleElement &e1, const ccColorScaleElement &e2)
Comparison operator between two color scale elements.
void setRelativePos(double pos)
Sets associated value (relative to scale boundaries)
void setColor(QColor color)
Sets color.
ccColorScaleElement & step(int index)
Access to a given step.
QString getUuid() const
Returns unique ID.
void setRelative()
Sets scale as relative.
LabelSet & customLabels()
Returns the list of custom labels (if any)
void setLocked(bool state)
Sets whether scale is locked or not.
QList< ccColorScaleElement > m_steps
Elements.
const QString & getName() const
Returns name.
bool m_relative
Whether scale is relative or not.
const ecvColor::Rgb & getColorByIndex(unsigned index) const
Returns color by index.
bool isRelative() const
Returns whether scale is relative or absoute.
bool m_locked
Whether scale is locked or not.
double getRelativePosition(double value) const
bool isSerializable() const override
Returns whether object is serializable of not.
const LabelSet & customLabels() const
Returns the list of custom labels (if any - const version)
const ecvColor::Rgb * getColorByRelativePos(double relativePos, const ecvColor::Rgb *outOfRangeColor=nullptr) const
Returns color by relative position in scale.
double m_absoluteMinValue
'Absolute' minimum value
double m_absoluteRange
'Absolute' range
int stepCount() const
Returns the current number of steps.
const ccColorScaleElement & step(int index) const
Access to a given step (const)
const ecvColor::Rgb * getColorByRelativePos(double relativePos, unsigned steps, const ecvColor::Rgb *outOfRangeColor=nullptr) const
Returns color by relative position in scale with a given 'resolution'.
QSharedPointer< ccColorScale > Shared
Shared pointer type.
const ecvColor::Rgb * getColorByValue(double value, const ecvColor::Rgb *outOfRangeColor=nullptr) const
Returns color by value.
void setUuid(QString uuid)
Sets unique ID.
LabelSet m_customLabels
List of custom labels.
void setName(const QString &name)
Sets name.
std::set< Label > LabelSet
Type of a list of custom labels.
bool m_updated
Internal representation validity.
bool isLocked() const
Returns whether scale is locked or not.
void setCustomLabels(const LabelSet &labels)
Sets the list of custom labels (only if the scale is absolute)
Serializable object interface.
virtual short minimumFileVersion() const =0
Returns the minimum file version required to save this instance.
virtual bool toFile(QFile &out, short dataVersion) const
Saves data to binary stream.
virtual bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap)
Loads data from binary stream.
constexpr Rgb black(0, 0, 0)
Color scale label (value + optional text)
Label(double v, const QString &t)
bool operator<(const Label &otherLabel) const