1 #include "CmdMediator.h"
2 #include "ColorConstants.h"
3 #include "ColorFilterSettings.h"
4 #include "DocumentSerialize.h"
5 #include "EngaugeAssert.h"
6 #include "GridCoordDisable.h"
9 #include <QXmlStreamWriter>
13 m_colorFilterMode (COLOR_FILTER_MODE_INTENSITY),
14 m_intensityLow (INTENSITY_LOW_DEFAULT),
15 m_intensityHigh (INTENSITY_HIGH_DEFAULT),
16 m_foregroundLow (FOREGROUND_LOW_DEFAULT),
17 m_foregroundHigh (FOREGROUND_HIGH_DEFAULT),
18 m_hueLow (HUE_LOW_DEFAULT),
19 m_hueHigh (HUE_HIGH_DEFAULT),
20 m_saturationLow (SATURATION_LOW_DEFAULT),
21 m_saturationHigh (SATURATION_HIGH_DEFAULT),
22 m_valueLow (VALUE_LOW_DEFAULT),
23 m_valueHigh (VALUE_HIGH_DEFAULT)
38 m_colorFilterMode (colorFilterMode),
39 m_intensityLow (intensityLow),
40 m_intensityHigh (intensityHigh),
41 m_foregroundLow (foregroundLow),
42 m_foregroundHigh (foregroundHigh),
45 m_saturationLow (saturationLow),
46 m_saturationHigh (saturationHigh),
47 m_valueLow (valueLow),
48 m_valueHigh (valueHigh)
53 m_colorFilterMode (other.colorFilterMode()),
54 m_intensityLow (other.intensityLow()),
55 m_intensityHigh (other.intensityHigh()),
56 m_foregroundLow (other.foregroundLow()),
57 m_foregroundHigh (other.foregroundHigh()),
58 m_hueLow (other.hueLow()),
59 m_hueHigh (other.hueHigh()),
60 m_saturationLow (other.saturationLow()),
61 m_saturationHigh (other.saturationHigh()),
62 m_valueLow (other.valueLow()),
63 m_valueHigh (other.valueHigh())
91 return m_colorFilterMode;
101 return m_foregroundHigh;
106 return m_foregroundLow;
111 switch (m_colorFilterMode)
113 case COLOR_FILTER_MODE_FOREGROUND:
114 return (
double) (m_foregroundHigh - FOREGROUND_MIN) /
115 (
double) (FOREGROUND_MAX - FOREGROUND_MIN);
117 case COLOR_FILTER_MODE_HUE:
118 return (
double) (m_hueHigh - HUE_MIN) /
119 ((
double) HUE_MAX - HUE_MIN);
121 case COLOR_FILTER_MODE_INTENSITY:
122 return (
double) (m_intensityHigh - INTENSITY_MIN) /
123 (
double) (INTENSITY_MAX - INTENSITY_MIN);
125 case COLOR_FILTER_MODE_SATURATION:
126 return (
double) (m_saturationHigh - SATURATION_MIN) /
127 (
double) (SATURATION_MAX - SATURATION_MIN);
129 case COLOR_FILTER_MODE_VALUE:
130 return (
double) (m_valueHigh - VALUE_MIN) /
131 (
double) (VALUE_MAX - VALUE_MIN);
134 ENGAUGE_ASSERT (
false);
150 return m_intensityHigh;
155 return m_intensityLow;
160 LOG4CPP_INFO_S ((*mainCat)) <<
"ColorFilterSettings::loadXml";
164 QXmlStreamAttributes attributes = reader.attributes();
166 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE) &&
167 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW) &&
168 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH) &&
169 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW) &&
170 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH) &&
171 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW) &&
172 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH) &&
173 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW) &&
174 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH) &&
175 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW) &&
176 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH)) {
178 setColorFilterMode ((ColorFilterMode) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE).toInt());
179 setIntensityLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW).toInt());
180 setIntensityHigh ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH).toInt());
181 setForegroundLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW).toInt());
182 setForegroundHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH).toInt());
183 setHueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW).toInt());
184 setHueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH).toInt());
185 setSaturationLow ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW).toInt());
186 setSaturationHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH).toInt());
187 setValueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW).toInt());
188 setValueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH).toInt());
191 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
192 (reader.name() != DOCUMENT_SERIALIZE_COLOR_FILTER)){
193 loadNextFromReader(reader);
195 if (reader.atEnd()) {
203 reader.raiseError (
"Cannot read curve filter data");
209 switch (m_colorFilterMode)
211 case COLOR_FILTER_MODE_FOREGROUND:
212 return (
double) (m_foregroundLow - FOREGROUND_MIN) /
213 (
double) (FOREGROUND_MAX - FOREGROUND_MIN);
215 case COLOR_FILTER_MODE_HUE:
216 return (
double) (m_hueLow - HUE_MIN) /
217 ((
double) HUE_MAX - HUE_MIN);
219 case COLOR_FILTER_MODE_INTENSITY:
220 return (
double) (m_intensityLow - INTENSITY_MIN) /
221 (
double) (INTENSITY_MAX - INTENSITY_MIN);
223 case COLOR_FILTER_MODE_SATURATION:
224 return (
double) (m_saturationLow - SATURATION_MIN) /
225 (
double) (SATURATION_MAX - SATURATION_MIN);
227 case COLOR_FILTER_MODE_VALUE:
228 return (
double) (m_valueLow - VALUE_MIN) /
229 (
double) (VALUE_MAX - VALUE_MIN);
232 ENGAUGE_ASSERT (
false);
237 QTextStream &str)
const
239 str << indentation <<
"ColorFilterSettings\n";
241 indentation += INDENTATION_DELTA;
243 switch (m_colorFilterMode) {
244 case COLOR_FILTER_MODE_INTENSITY:
245 str << indentation <<
"intensityLow=" << m_intensityLow <<
"\n";
246 str << indentation <<
"intensityHigh=" << m_intensityHigh <<
"\n";
249 case COLOR_FILTER_MODE_FOREGROUND:
250 str << indentation <<
"foregroundLow=" << m_foregroundLow <<
"\n";
251 str << indentation <<
"foregroundHigh=" << m_foregroundHigh <<
"\n";
254 case COLOR_FILTER_MODE_HUE:
255 str << indentation <<
"hueLow=" << m_hueLow <<
"\n";
256 str << indentation <<
"hueHigh=" << m_hueHigh <<
"\n";
259 case COLOR_FILTER_MODE_SATURATION:
260 str << indentation <<
"saturationLow" << m_saturationLow <<
"\n";
261 str << indentation <<
"saturationHigh" << m_saturationHigh <<
"\n";
264 case COLOR_FILTER_MODE_VALUE:
265 str << indentation <<
"valueLow=" << m_valueLow <<
"\n";
266 str << indentation <<
"valueHigh=" << m_valueHigh <<
"\n";
276 return m_saturationHigh;
281 return m_saturationLow;
286 LOG4CPP_INFO_S ((*mainCat)) <<
"ColorFilterSettings::saveXml";
288 writer.writeStartElement(DOCUMENT_SERIALIZE_COLOR_FILTER);
289 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE, QString::number (m_colorFilterMode));
290 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE_STRING, colorFilterModeToString (m_colorFilterMode));
291 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW, QString::number (m_intensityLow));
292 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH, QString::number (m_intensityHigh));
293 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW, QString::number (m_foregroundLow));
294 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH, QString::number (m_foregroundHigh));
295 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW, QString::number (m_hueLow));
296 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH, QString::number (m_hueHigh));
297 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW, QString::number (m_saturationLow));
298 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH, QString::number (m_saturationHigh));
299 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW, QString::number (m_valueLow));
300 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH, QString::number (m_valueHigh));
301 writer.writeEndElement();
311 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundHigh && foregroundHigh <= FOREGROUND_MAX);
317 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundLow && foregroundLow <= FOREGROUND_MAX);
323 switch (m_colorFilterMode) {
324 case COLOR_FILTER_MODE_FOREGROUND:
328 case COLOR_FILTER_MODE_HUE:
329 setHueHigh (HUE_MIN + s0To1 * (HUE_MAX - HUE_MIN));
332 case COLOR_FILTER_MODE_INTENSITY:
336 case COLOR_FILTER_MODE_SATURATION:
340 case COLOR_FILTER_MODE_VALUE:
341 setValueHigh (VALUE_MIN + s0To1 * (VALUE_MAX - VALUE_MIN));
345 ENGAUGE_ASSERT (
false);
351 ENGAUGE_ASSERT (HUE_MIN <= hueHigh && hueHigh <= HUE_MAX);
357 ENGAUGE_ASSERT (HUE_MIN <= hueLow && hueLow <= HUE_MAX);
363 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityHigh && intensityHigh <= INTENSITY_MAX);
369 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityLow && intensityLow <= INTENSITY_MAX);
375 switch (m_colorFilterMode) {
376 case COLOR_FILTER_MODE_FOREGROUND:
377 setForegroundLow (FOREGROUND_MIN + s0To1 * (FOREGROUND_MAX - FOREGROUND_MIN));
380 case COLOR_FILTER_MODE_HUE:
381 setHueLow (HUE_MIN + s0To1 * (HUE_MAX - HUE_MIN));
384 case COLOR_FILTER_MODE_INTENSITY:
385 setIntensityLow (INTENSITY_MIN + s0To1 * (INTENSITY_MAX - INTENSITY_MIN));
388 case COLOR_FILTER_MODE_SATURATION:
389 setSaturationLow (SATURATION_MIN + s0To1 * (SATURATION_MAX - SATURATION_MIN));
392 case COLOR_FILTER_MODE_VALUE:
393 setValueLow (VALUE_MIN + s0To1 * (VALUE_MAX - VALUE_MIN));
397 ENGAUGE_ASSERT (
false);
403 ENGAUGE_ASSERT (SATURATION_MIN <= saturationHigh && saturationHigh <= SATURATION_MAX);
409 ENGAUGE_ASSERT (SATURATION_MIN <= saturationLow && saturationLow <= SATURATION_MAX);
415 ENGAUGE_ASSERT (VALUE_MIN <= valueHigh && valueHigh <= VALUE_MAX);
421 ENGAUGE_ASSERT (VALUE_MIN <= valueLow && valueLow <= VALUE_MAX);
void setSaturationLow(int saturationLow)
Set method for saturation low.
void setLow(double s0To1)
Set the low value for the current filter mode.
void setHueLow(int hueLow)
Set method for hue lower bound.
int saturationLow() const
Get method for saturation lower bound.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
void setColorFilterMode(ColorFilterMode colorFilterMode)
Set method for filter mode.
int hueLow() const
Get method for hue lower bound.
int foregroundHigh() const
Get method for foreground higher bound.
int hueHigh() const
Get method for hue higher bound.
int saturationHigh() const
Get method for saturation higher bound.
ColorFilterSettings & operator=(const ColorFilterSettings &other)
Assignment operator.
void setForegroundLow(int foregroundLow)
Set method for foreground lower bound.
void setHigh(double s0To1)
Set the high value for the current filter mode.
int foregroundLow() const
Get method for foreground lower bound.
void setHueHigh(int hueHigh)
Set method for hue higher bound.
ColorFilterMode colorFilterMode() const
Get method for filter mode.
int valueLow() const
Get method for value low.
void setForegroundHigh(int foregroundHigh)
Set method for foreground higher bound.
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
void setIntensityHigh(int intensityHigh)
Set method for intensity higher bound.
int intensityHigh() const
Get method for intensity higher bound.
void saveXml(QXmlStreamWriter &writer) const
Save curve filter to stream.
void setValueHigh(int valueHigh)
Set method for value high.
void setIntensityLow(int intensityLow)
Set method for intensity lower bound.
int valueHigh() const
Get method for value high.
double low() const
Low value of foreground, hue, intensity, saturation or value according to current filter mode...
void setValueLow(int valueLow)
Set method for value low.
void setSaturationHigh(int saturationHigh)
Set method for saturation high.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
double high() const
High value of foreground, hue, intensity, saturation or value according to current filter mode...
ColorFilterSettings()
Default constructor only for use when this class is being stored by a container that requires the def...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
int intensityLow() const
Get method for intensity lower bound.