00001
00002
00003
00004
00005
00006
00007 #include "CmdMediator.h"
00008 #include "DocumentModelGridDisplay.h"
00009 #include "DocumentSerialize.h"
00010 #include "EngaugeAssert.h"
00011 #include "Logger.h"
00012 #include <QObject>
00013 #include <QTextStream>
00014 #include "QtToString.h"
00015 #include <QXmlStreamWriter>
00016 #include "Xml.h"
00017
00018 const ColorPalette DEFAULT_COLOR = COLOR_PALETTE_BLACK;
00019
00020 DocumentModelGridDisplay::DocumentModelGridDisplay() :
00021 m_stable (false),
00022 m_disableX (GRID_COORD_DISABLE_COUNT),
00023 m_countX (2),
00024 m_startX (0.0),
00025 m_stepX (1.0),
00026 m_stopX (1.0),
00027 m_disableY (GRID_COORD_DISABLE_COUNT),
00028 m_countY (2),
00029 m_startY (0.0),
00030 m_stepY (1.0),
00031 m_stopY (1.0),
00032 m_paletteColor (DEFAULT_COLOR)
00033 {
00034 }
00035
00036 DocumentModelGridDisplay::DocumentModelGridDisplay(const Document &document) :
00037 m_stable (document.modelGridDisplay().stable()),
00038 m_disableX (document.modelGridDisplay().disableX()),
00039 m_countX (document.modelGridDisplay().countX()),
00040 m_startX (document.modelGridDisplay().startX()),
00041 m_stepX (document.modelGridDisplay().stepX()),
00042 m_stopX (document.modelGridDisplay().stopX()),
00043 m_disableY (document.modelGridDisplay().disableY()),
00044 m_countY (document.modelGridDisplay().countY()),
00045 m_startY (document.modelGridDisplay().startY()),
00046 m_stepY (document.modelGridDisplay().stepY()),
00047 m_stopY (document.modelGridDisplay().stopY()),
00048 m_paletteColor (document.modelGridDisplay().paletteColor())
00049 {
00050 }
00051
00052 DocumentModelGridDisplay::DocumentModelGridDisplay(const DocumentModelGridDisplay &other) :
00053 m_stable(other.stable()),
00054 m_disableX (other.disableX()),
00055 m_countX (other.countX()),
00056 m_startX (other.startX()),
00057 m_stepX (other.stepX()),
00058 m_stopX (other.stopX()),
00059 m_disableY (other.disableY()),
00060 m_countY (other.countY()),
00061 m_startY (other.startY()),
00062 m_stepY (other.stepY()),
00063 m_stopY (other.stopY()),
00064 m_paletteColor (other.paletteColor())
00065 {
00066 }
00067
00068 DocumentModelGridDisplay &DocumentModelGridDisplay::operator=(const DocumentModelGridDisplay &other)
00069 {
00070 m_stable = other.stable();
00071 m_disableX = other.disableX();
00072 m_countX = other.countX();
00073 m_startX = other.startX();
00074 m_stepX = other.stepX();
00075 m_stopX = other.stopX();
00076 m_disableY = other.disableY();
00077 m_countY = other.countY();
00078 m_startY = other.startY();
00079 m_stepY = other.stepY();
00080 m_stopY = other.stopY();
00081 m_paletteColor = other.paletteColor();
00082
00083 return *this;
00084 }
00085
00086 unsigned int DocumentModelGridDisplay::countX () const
00087 {
00088 return m_countX;
00089 }
00090
00091 unsigned int DocumentModelGridDisplay::countY () const
00092 {
00093 return m_countY;
00094 }
00095
00096 GridCoordDisable DocumentModelGridDisplay::disableX () const
00097 {
00098 return m_disableX;
00099 }
00100
00101 GridCoordDisable DocumentModelGridDisplay::disableY () const
00102 {
00103 return m_disableY;
00104 }
00105
00106 void DocumentModelGridDisplay::loadXml(QXmlStreamReader &reader)
00107 {
00108 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridDisplay::loadXml";
00109
00110 bool success = true;
00111
00112 QXmlStreamAttributes attributes = reader.attributes();
00113
00114 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE) &&
00115 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X) &&
00116 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X) &&
00117 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X) &&
00118 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X) &&
00119 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X) &&
00120 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y) &&
00121 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y) &&
00122 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y) &&
00123 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y) &&
00124 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y) &&
00125 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR)) {
00126
00127
00128 QString stableValue = attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE).toString();
00129
00130 setStable (stableValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
00131 setDisableX ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X).toInt());
00132 setCountX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X).toInt());
00133 setStartX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X).toDouble());
00134 setStepX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X).toDouble());
00135 setStopX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X).toDouble());
00136 setDisableY ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y).toInt());
00137 setCountY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y).toInt());
00138 setStartY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y).toDouble());
00139 setStepY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y).toDouble());
00140 setStopY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y).toDouble());
00141 setPaletteColor ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR).toInt());
00142
00143
00144 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00145 (reader.name() != DOCUMENT_SERIALIZE_GRID_DISPLAY)){
00146 loadNextFromReader(reader);
00147 if (reader.atEnd()) {
00148 success = false;
00149 break;
00150 }
00151 }
00152 }
00153
00154 if (!success) {
00155 reader.raiseError (QObject::tr ("Cannot read grid display data"));
00156 }
00157 }
00158
00159 ColorPalette DocumentModelGridDisplay::paletteColor() const
00160 {
00161 return m_paletteColor;
00162 }
00163
00164 void DocumentModelGridDisplay::printStream(QString indentation,
00165 QTextStream &str) const
00166 {
00167 str << indentation << "DocumentModelGridDisplay\n";
00168
00169 indentation += INDENTATION_DELTA;
00170
00171 str << indentation << "stable=" << (m_stable ? "true" : "false") << "\n";
00172 str << indentation << "disableX=" << m_disableX << "\n";
00173 str << indentation << "countX=" << m_countX << "\n";
00174 str << indentation << "startX=" << m_startX << "\n";
00175 str << indentation << "stepX=" << m_stepX << "\n";
00176 str << indentation << "stopX=" << m_stopX << "\n";
00177 str << indentation << "disableY=" << m_disableY << "\n";
00178 str << indentation << "countY=" << m_countY << "\n";
00179 str << indentation << "startY=" << m_startY << "\n";
00180 str << indentation << "stepY=" << m_stepY << "\n";
00181 str << indentation << "stopY=" << m_stopY << "\n";
00182 str << indentation << "color=" << colorPaletteToString (m_paletteColor) << "\n";
00183 }
00184
00185 void DocumentModelGridDisplay::saveXml(QXmlStreamWriter &writer) const
00186 {
00187 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridDisplay::saveXml";
00188
00189 writer.writeStartElement(DOCUMENT_SERIALIZE_GRID_DISPLAY);
00190 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE, m_stable ?
00191 DOCUMENT_SERIALIZE_BOOL_TRUE :
00192 DOCUMENT_SERIALIZE_BOOL_FALSE);
00193 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X, QString::number (m_disableX));
00194 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X, QString::number (m_countX));
00195 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X, QString::number (m_startX));
00196 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X, QString::number (m_stepX));
00197 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X, QString::number (m_stopX));
00198 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y, QString::number (m_disableY));
00199 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y, QString::number (m_countY));
00200 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y, QString::number (m_startY));
00201 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y, QString::number (m_stepY));
00202 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y, QString::number (m_stopY));
00203 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR, QString::number (m_paletteColor));
00204 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR_STRING, colorPaletteToString (m_paletteColor));
00205 writer.writeEndElement();
00206 }
00207
00208 void DocumentModelGridDisplay::setCountX (unsigned int countX)
00209 {
00210 m_countX = countX;
00211 }
00212
00213 void DocumentModelGridDisplay::setCountY (unsigned int countY)
00214 {
00215 m_countY = countY;
00216 }
00217
00218 void DocumentModelGridDisplay::setDisableX (GridCoordDisable disableX)
00219 {
00220 m_disableX = disableX;
00221 }
00222
00223 void DocumentModelGridDisplay::setDisableY (GridCoordDisable disableY)
00224 {
00225 m_disableY = disableY;
00226 }
00227
00228 void DocumentModelGridDisplay::setPaletteColor(ColorPalette paletteColor)
00229 {
00230 m_paletteColor = paletteColor;
00231 }
00232
00233 void DocumentModelGridDisplay::setStable(bool stable)
00234 {
00235 m_stable = stable;
00236 }
00237
00238 void DocumentModelGridDisplay::setStartX (double startX)
00239 {
00240 m_startX = startX;
00241 }
00242
00243 void DocumentModelGridDisplay::setStartY (double startY)
00244 {
00245 m_startY = startY;
00246 }
00247
00248 void DocumentModelGridDisplay::setStepX (double stepX)
00249 {
00250 m_stepX = stepX;
00251 }
00252
00253 void DocumentModelGridDisplay::setStepY (double stepY)
00254 {
00255 m_stepY = stepY;
00256 }
00257
00258 void DocumentModelGridDisplay::setStopX (double stopX)
00259 {
00260 m_stopX = stopX;
00261 }
00262
00263 void DocumentModelGridDisplay::setStopY (double stopY)
00264 {
00265 m_stopY = stopY;
00266 }
00267
00268 bool DocumentModelGridDisplay::stable() const
00269 {
00270 return m_stable;
00271 }
00272
00273 double DocumentModelGridDisplay::startX() const
00274 {
00275 return m_startX;
00276 }
00277
00278 double DocumentModelGridDisplay::startY() const
00279 {
00280 return m_startY;
00281 }
00282
00283 double DocumentModelGridDisplay::stepX() const
00284 {
00285 return m_stepX;
00286 }
00287
00288 double DocumentModelGridDisplay::stepY() const
00289 {
00290 return m_stepY;
00291 }
00292
00293 double DocumentModelGridDisplay::stopX() const
00294 {
00295 return m_stopX;
00296 }
00297
00298 double DocumentModelGridDisplay::stopY() const
00299 {
00300 return m_stopY;
00301 }