00001
00002
00003
00004
00005
00006
00007 #include "CmdMediator.h"
00008 #include "DocumentModelSegments.h"
00009 #include "DocumentSerialize.h"
00010 #include "Logger.h"
00011 #include <QObject>
00012 #include <QTextStream>
00013 #include <QXmlStreamWriter>
00014 #include "Xml.h"
00015
00016 const double DEFAULT_POINT_SEPARATION = 25;
00017 const double DEFAULT_MIN_LENGTH = 2;
00018 const double DEFAULT_LINE_WIDTH = 4;
00019 const ColorPalette DEFAULT_LINE_COLOR (COLOR_PALETTE_GREEN);
00020
00021 DocumentModelSegments::DocumentModelSegments() :
00022 m_pointSeparation (DEFAULT_POINT_SEPARATION),
00023 m_minLength (DEFAULT_MIN_LENGTH),
00024 m_fillCorners (false),
00025 m_lineWidth (DEFAULT_LINE_WIDTH),
00026 m_lineColor (DEFAULT_LINE_COLOR)
00027 {
00028 }
00029
00030 DocumentModelSegments::DocumentModelSegments(const Document &document) :
00031 m_pointSeparation (document.modelSegments().pointSeparation()),
00032 m_minLength (document.modelSegments().minLength()),
00033 m_fillCorners (document.modelSegments().fillCorners()),
00034 m_lineWidth (document.modelSegments().lineWidth()),
00035 m_lineColor (document.modelSegments().lineColor())
00036 {
00037 }
00038
00039 DocumentModelSegments::DocumentModelSegments(const DocumentModelSegments &other) :
00040 m_pointSeparation (other.pointSeparation()),
00041 m_minLength (other.minLength()),
00042 m_fillCorners (other.fillCorners ()),
00043 m_lineWidth (other.lineWidth()),
00044 m_lineColor (other.lineColor())
00045 {
00046 }
00047
00048 DocumentModelSegments &DocumentModelSegments::operator=(const DocumentModelSegments &other)
00049 {
00050 m_pointSeparation = other.pointSeparation();
00051 m_minLength = other.minLength();
00052 m_fillCorners = other.fillCorners ();
00053 m_lineWidth = other.lineWidth();
00054 m_lineColor = other.lineColor();
00055
00056 return *this;
00057 }
00058
00059 bool DocumentModelSegments::fillCorners () const
00060 {
00061 return m_fillCorners;
00062 }
00063
00064 ColorPalette DocumentModelSegments::lineColor() const
00065 {
00066 return m_lineColor;
00067 }
00068
00069 double DocumentModelSegments::lineWidth() const
00070 {
00071 return m_lineWidth;
00072 }
00073
00074 void DocumentModelSegments::loadXml(QXmlStreamReader &reader)
00075 {
00076 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::loadXml";
00077
00078 bool success = true;
00079
00080
00081 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
00082 (reader.name() != DOCUMENT_SERIALIZE_SEGMENTS)){
00083 loadNextFromReader(reader);
00084 if (reader.atEnd()) {
00085 success = false;
00086 break;
00087 }
00088 }
00089
00090 if (!success) {
00091 reader.raiseError(QObject::tr ("Cannot read segment data"));
00092 }
00093 }
00094
00095 double DocumentModelSegments::minLength() const
00096 {
00097 return m_minLength;
00098 }
00099
00100 double DocumentModelSegments::pointSeparation() const
00101 {
00102 return m_pointSeparation;
00103 }
00104
00105 void DocumentModelSegments::printStream(QString indentation,
00106 QTextStream &str) const
00107 {
00108 str << indentation << "DocumentModelSegments\n";
00109
00110 indentation += INDENTATION_DELTA;
00111
00112 str << indentation << "pointSeparation=" << m_pointSeparation << "\n";
00113 str << indentation << "minLength=" << m_minLength << "\n";
00114 str << indentation << "fillCorners=" << (m_fillCorners ? "true" : "false") << "\n";
00115 str << indentation << "lineWidth=" << m_lineWidth << "\n";
00116 str << indentation << "lineColor=" << colorPaletteToString (m_lineColor) << "\n";
00117 }
00118
00119 void DocumentModelSegments::saveXml(QXmlStreamWriter &writer) const
00120 {
00121 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelSegments::saveXml";
00122
00123 writer.writeStartElement(DOCUMENT_SERIALIZE_SEGMENTS);
00124 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_POINT_SEPARATION, QString::number (m_pointSeparation));
00125 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_MIN_LENGTH, QString::number (m_minLength));
00126 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_FILL_CORNERS, m_fillCorners ?
00127 DOCUMENT_SERIALIZE_BOOL_TRUE :
00128 DOCUMENT_SERIALIZE_BOOL_FALSE);
00129 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_WIDTH, QString::number (m_lineWidth));
00130 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR, QString::number (m_lineColor));
00131 writer.writeAttribute(DOCUMENT_SERIALIZE_SEGMENTS_LINE_COLOR_STRING, colorPaletteToString (m_lineColor));
00132 writer.writeEndElement();
00133 }
00134
00135 void DocumentModelSegments::setFillCorners (bool fillCorners)
00136 {
00137 m_fillCorners = fillCorners;
00138 }
00139
00140 void DocumentModelSegments::setLineColor(ColorPalette lineColor)
00141 {
00142 m_lineColor = lineColor;
00143 }
00144
00145 void DocumentModelSegments::setLineWidth(double lineWidth)
00146 {
00147 m_lineWidth = lineWidth;
00148 }
00149
00150 void DocumentModelSegments::setMinLength(double minLength)
00151 {
00152 m_minLength = minLength;
00153 }
00154
00155 void DocumentModelSegments::setPointSeparation(double pointSeparation)
00156 {
00157 m_pointSeparation = pointSeparation;
00158 }