SymbolEditor  1.3.0
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
Symbol.cpp
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2011 by Stephen Allewell *
3  * sallewell@users.sourceforge.net *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  ********************************************************************************/
10 
11 
26 #include "Symbol.h"
27 
28 #include <QDataStream>
29 
30 #include "Exceptions.h"
31 
32 
40  : m_filled(true),
41  m_lineWidth(0.01),
42  m_capStyle(Qt::SquareCap),
43  m_joinStyle(Qt::MiterJoin)
44 {
45 }
46 
47 
52 {
53 }
54 
55 
61 QPainterPath Symbol::path() const
62 {
63  return m_path;
64 }
65 
66 
72 bool Symbol::filled() const
73 {
74  return m_filled;
75 }
76 
77 
83 qreal Symbol::lineWidth() const
84 {
85  return m_lineWidth;
86 }
87 
88 
94 Qt::PenCapStyle Symbol::capStyle() const
95 {
96  return m_capStyle;
97 }
98 
99 
105 Qt::PenJoinStyle Symbol::joinStyle() const
106 {
107  return m_joinStyle;
108 }
109 
110 
116 void Symbol::setPath(const QPainterPath &path)
117 {
118  m_path = path;
119 }
120 
121 
127 void Symbol::setFilled(bool filled)
128 {
129  m_filled = filled;
130 }
131 
132 
138 void Symbol::setLineWidth(qreal width)
139 {
140  m_lineWidth = width;
141 }
142 
143 
149 void Symbol::setCapStyle(Qt::PenCapStyle capStyle)
150 {
152 }
153 
154 
160 void Symbol::setJoinStyle(Qt::PenJoinStyle joinStyle)
161 {
163 }
164 
165 
174 QDataStream &operator<<(QDataStream &stream, const Symbol &symbol)
175 {
176  stream << symbol.version << symbol.m_path << symbol.m_filled << symbol.m_lineWidth << static_cast<qint32>(symbol.m_capStyle) << static_cast<qint32>(symbol.m_joinStyle);
177 
178  if (stream.status() != QDataStream::Ok) {
179  throw FailedWriteLibrary(stream.status());
180  }
181 
182  return stream;
183 }
184 
185 
194 QDataStream &operator>>(QDataStream &stream, Symbol &symbol)
195 {
196  qint32 version;
197  qint32 capStyle;
198  qint32 joinStyle;
199  stream >> version;
200 
201  switch (version) {
202  case 100:
203  stream >> symbol.m_path >> symbol.m_filled >> symbol.m_lineWidth >> capStyle >> joinStyle;
204  symbol.m_capStyle = static_cast<Qt::PenCapStyle>(capStyle);
205  symbol.m_joinStyle = static_cast<Qt::PenJoinStyle>(joinStyle);
206  break;
207 
208  default:
209  throw InvalidSymbolVersion(version);
210  break;
211  }
212 
213  return stream;
214 }