7 #include "CmdMediator.h" 8 #include "ColorConstants.h" 9 #include "ColorFilterSettings.h" 10 #include "ColorFilterSettingsStrategyAbstractBase.h" 11 #include "ColorFilterSettingsStrategyForeground.h" 12 #include "ColorFilterSettingsStrategyHue.h" 13 #include "ColorFilterSettingsStrategyIntensity.h" 14 #include "ColorFilterSettingsStrategySaturation.h" 15 #include "ColorFilterSettingsStrategyValue.h" 16 #include "DocumentSerialize.h" 17 #include "EngaugeAssert.h" 18 #include "GridCoordDisable.h" 20 #include <QTextStream> 21 #include <QXmlStreamWriter> 25 m_colorFilterMode (COLOR_FILTER_MODE_INTENSITY),
26 m_intensityLow (INTENSITY_LOW_DEFAULT),
27 m_intensityHigh (INTENSITY_HIGH_DEFAULT),
28 m_foregroundLow (FOREGROUND_LOW_DEFAULT),
29 m_foregroundHigh (FOREGROUND_HIGH_DEFAULT),
30 m_hueLow (HUE_LOW_DEFAULT),
31 m_hueHigh (HUE_HIGH_DEFAULT),
32 m_saturationLow (SATURATION_LOW_DEFAULT),
33 m_saturationHigh (SATURATION_HIGH_DEFAULT),
34 m_valueLow (VALUE_LOW_DEFAULT),
35 m_valueHigh (VALUE_HIGH_DEFAULT)
51 m_colorFilterMode (colorFilterMode),
52 m_intensityLow (intensityLow),
53 m_intensityHigh (intensityHigh),
54 m_foregroundLow (foregroundLow),
55 m_foregroundHigh (foregroundHigh),
58 m_saturationLow (saturationLow),
59 m_saturationHigh (saturationHigh),
60 m_valueLow (valueLow),
61 m_valueHigh (valueHigh)
109 return m_colorFilterMode;
112 void ColorFilterSettings::createStrategies ()
128 return m_foregroundHigh;
133 return m_foregroundLow;
138 if (m_strategies.contains (m_colorFilterMode)) {
142 return strategy->
high (*
this);
144 ENGAUGE_ASSERT (
false);
145 return m_strategies [COLOR_FILTER_MODE_INTENSITY]->high (*
this);
161 return m_intensityHigh;
166 return m_intensityLow;
171 LOG4CPP_INFO_S ((*mainCat)) <<
"ColorFilterSettings::loadXml";
175 QXmlStreamAttributes attributes = reader.attributes();
177 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE) &&
178 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW) &&
179 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH) &&
180 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW) &&
181 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH) &&
182 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW) &&
183 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH) &&
184 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW) &&
185 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH) &&
186 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW) &&
187 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH)) {
189 setColorFilterMode ((ColorFilterMode) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE).toInt());
190 setIntensityLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW).toInt());
191 setIntensityHigh ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH).toInt());
192 setForegroundLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW).toInt());
193 setForegroundHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH).toInt());
194 setHueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW).toInt());
195 setHueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH).toInt());
196 setSaturationLow ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW).toInt());
197 setSaturationHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH).toInt());
198 setValueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW).toInt());
199 setValueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH).toInt());
202 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
203 (reader.name() != DOCUMENT_SERIALIZE_COLOR_FILTER)){
204 loadNextFromReader(reader);
206 if (reader.atEnd()) {
214 reader.raiseError (QObject::tr (
"Cannot read curve filter data"));
220 if (m_strategies.contains (m_colorFilterMode)) {
222 return strategy->
low (*
this);
224 ENGAUGE_ASSERT (
false);
225 return m_strategies [COLOR_FILTER_MODE_INTENSITY]->low (*
this);
230 QTextStream &str)
const 232 str << indentation <<
"ColorFilterSettings\n";
234 indentation += INDENTATION_DELTA;
236 if (m_strategies.contains (m_colorFilterMode)) {
246 return m_saturationHigh;
251 return m_saturationLow;
255 const QString &curveName)
const 257 LOG4CPP_INFO_S ((*mainCat)) <<
"ColorFilterSettings::saveXml";
259 writer.writeStartElement(DOCUMENT_SERIALIZE_COLOR_FILTER);
260 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, curveName);
261 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE, QString::number (m_colorFilterMode));
262 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE_STRING, colorFilterModeToString (m_colorFilterMode));
263 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW, QString::number (m_intensityLow));
264 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH, QString::number (m_intensityHigh));
265 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW, QString::number (m_foregroundLow));
266 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH, QString::number (m_foregroundHigh));
267 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW, QString::number (m_hueLow));
268 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH, QString::number (m_hueHigh));
269 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW, QString::number (m_saturationLow));
270 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH, QString::number (m_saturationHigh));
271 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW, QString::number (m_valueLow));
272 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH, QString::number (m_valueHigh));
273 writer.writeEndElement();
283 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundHigh && foregroundHigh <= FOREGROUND_MAX);
289 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundLow && foregroundLow <= FOREGROUND_MAX);
295 if (m_strategies.contains (m_colorFilterMode)) {
297 return strategy->
setHigh (*
this,
300 ENGAUGE_ASSERT (
false);
306 ENGAUGE_ASSERT (HUE_MIN <= hueHigh && hueHigh <= HUE_MAX);
312 ENGAUGE_ASSERT (HUE_MIN <= hueLow && hueLow <= HUE_MAX);
318 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityHigh && intensityHigh <= INTENSITY_MAX);
324 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityLow && intensityLow <= INTENSITY_MAX);
330 if (m_strategies.contains (m_colorFilterMode)) {
332 return strategy->
setLow (*
this,
335 ENGAUGE_ASSERT (
false);
341 ENGAUGE_ASSERT (SATURATION_MIN <= saturationHigh && saturationHigh <= SATURATION_MAX);
347 ENGAUGE_ASSERT (SATURATION_MIN <= saturationLow && saturationLow <= SATURATION_MAX);
353 ENGAUGE_ASSERT (VALUE_MIN <= valueHigh && valueHigh <= VALUE_MAX);
359 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.
int valueHigh() const
Get method for value high.
void setHueLow(int hueLow)
Set method for hue lower bound.
Leaf class for hue strategy for ColorFilterSettings.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
int hueHigh() const
Get method for hue higher bound.
Leaf class for saturation strategy for ColorFilterSettings.
void setColorFilterMode(ColorFilterMode colorFilterMode)
Set method for filter mode.
int foregroundLow() const
Get method for foreground lower bound.
Base class for strategy pattern whose subclasses process the different color filter settings modes (o...
virtual void printStream(const ColorFilterSettings &colorFilterSettings, QString indentation, QTextStream &str) const =0
Print the low and high values.
double high() const
High value of foreground, hue, intensity, saturation or value according to current filter mode...
ColorFilterSettings & operator=(const ColorFilterSettings &other)
Assignment operator.
void setForegroundLow(int foregroundLow)
Set method for foreground lower bound.
double low() const
Low value of foreground, hue, intensity, saturation or value according to current filter mode...
void setHigh(double s0To1)
Set the high value for the current filter mode.
virtual void setHigh(ColorFilterSettings &colorFilterSettings, double s0To1)=0
Set the high value given the normalized value.
virtual void setLow(ColorFilterSettings &colorFilterSettings, double s0To1)=0
Set the low value given the normalized value.
void setHueHigh(int hueHigh)
Set method for hue higher bound.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setForegroundHigh(int foregroundHigh)
Set method for foreground higher bound.
Leaf class for value strategy for ColorFilterSettings.
int foregroundHigh() const
Get method for foreground higher bound.
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
int intensityHigh() const
Get method for intensity higher bound.
void setIntensityHigh(int intensityHigh)
Set method for intensity higher bound.
int intensityLow() const
Get method for intensity lower bound.
Leaf class for intensity strategy for ColorFilterSettings.
int saturationHigh() const
Get method for saturation higher bound.
void setValueHigh(int valueHigh)
Set method for value high.
void setIntensityLow(int intensityLow)
Set method for intensity lower bound.
int valueLow() const
Get method for value low.
void setValueLow(int valueLow)
Set method for value low.
virtual double high(const ColorFilterSettings &colorFilterSettings) const =0
Return the high value normalized to 0 to 1.
ColorFilterMode colorFilterMode() const
Get method for filter mode.
void setSaturationHigh(int saturationHigh)
Set method for saturation high.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
Leaf class for foreground strategy for ColorFilterSettings.
void saveXml(QXmlStreamWriter &writer, const QString &curveName) const
Save curve filter to stream.
ColorFilterSettings()
Default constructor only for use when this class is being stored by a container that requires the def...
int hueLow() const
Get method for hue lower bound.
virtual double low(const ColorFilterSettings &colorFilterSettings) const =0
Return the low value normalized to 0 to 1.
int saturationLow() const
Get method for saturation lower bound.