8 #include <qwt_plot_curve.h>
9 #include <qwt_plot_marker.h>
10 #include <qwt_symbol.h>
15 #include "SpecialPixel.h"
26 m_color = QColor(Qt::white);
32 PlotCurve::~PlotCurve() {
111 QwtPlotCurve::setData(data);
132 foreach (QwtPlotMarker *marker, m_valuePointMarkers) {
133 marker->setVisible(visible);
146 QString expectedHeader(
"PLOT_CURVE_V1");
147 int headerKeySize = expectedHeader.toUtf8().size();
149 if (classData.size() > headerKeySize) {
151 const char *rawClassData = classData.data();
153 QString givenKey = QString::fromUtf8(classData.data() + dataPos,
155 dataPos += headerKeySize;
156 if (givenKey != expectedHeader) {
157 IString msg =
"The given byte array does not contain the required "
162 int titleSize = *(((
int *)(rawClassData + dataPos)));
163 dataPos +=
sizeof(int);
165 setTitle(QString::fromUtf8(classData.data() + dataPos, titleSize));
166 dataPos += titleSize;
168 m_xUnits = (
Units)(*((
int *)(rawClassData + dataPos)));
169 dataPos +=
sizeof(int);
171 m_yUnits = (
Units)(*((
int *)(rawClassData + dataPos)));
172 dataPos +=
sizeof(int);
175 int penBufferSize = *(((
int *)(rawClassData + dataPos)));
176 dataPos +=
sizeof(int);
178 QByteArray penBufferBytes(rawClassData + dataPos, penBufferSize);
179 dataPos += penBufferSize;
181 QBuffer penDataBuffer(&penBufferBytes);
182 penDataBuffer.open(QIODevice::ReadWrite);
184 QDataStream penDataStream(&penDataBuffer);
186 penDataStream >> pen;
191 int colorBufferSize = *(((
int *)(rawClassData + dataPos)));
192 dataPos +=
sizeof(int);
194 QByteArray colorBufferBytes(rawClassData + dataPos, colorBufferSize);
195 dataPos += colorBufferSize;
197 QBuffer colorDataBuffer(&colorBufferBytes);
198 colorDataBuffer.open(QIODevice::ReadWrite);
200 QDataStream colorDataStream(&colorDataBuffer);
202 colorDataStream >> newColor;
206 int markerSymbolBufferSize = *(((
int *)(rawClassData + dataPos)));
207 dataPos +=
sizeof(int);
209 QByteArray markerSymbolBufferBytes(rawClassData + dataPos,
210 markerSymbolBufferSize);
211 dataPos += markerSymbolBufferSize;
213 QBuffer markerSymbolDataBuffer(&markerSymbolBufferBytes);
214 markerSymbolDataBuffer.open(QIODevice::ReadWrite);
216 QDataStream markerSymbolDataStream(&markerSymbolDataBuffer);
219 markerSymbolDataStream >> markerBrush;
223 markerSymbolDataStream >> markerPen;
227 markerSymbolDataStream >> markerSize;
231 markerSymbolDataStream >> markerStyle;
235 int plotDataSize = *((
int *)(rawClassData + dataPos));
236 dataPos +=
sizeof(int);
239 for (
int i = 0; i < plotDataSize; i ++) {
240 double x = *((
double *)(rawClassData + dataPos));
241 dataPos +=
sizeof(double);
243 double y = *((
double *)(rawClassData + dataPos));
244 dataPos +=
sizeof(double);
246 plotDataValues.append(QPointF(x, y));
249 setData(
new QwtPointSeriesData(plotDataValues));
250 ASSERT(dataPos <= classData.size());
252 return classData.right(classData.size() - dataPos);
255 IString msg =
"The given byte array is not large enough to contain the "
262 QByteArray PlotCurve::toByteArray()
const {
263 QByteArray classData;
265 QString header(
"PLOT_CURVE_V1");
266 classData.append(header.toUtf8());
268 QByteArray titleArray = title().text().toUtf8();
269 int size = titleArray.size();
270 classData.append((
char *)&size,
sizeof(
int));
271 classData.append(titleArray);
273 int xUnitsInt = (int)m_xUnits;
274 int yUnitsInt = (int)m_yUnits;
275 classData.append((
char *)&xUnitsInt,
sizeof(int));
276 classData.append((
char *)&yUnitsInt,
sizeof(int));
279 QBuffer penDataBuffer;
280 penDataBuffer.open(QIODevice::ReadWrite);
282 QDataStream penDataStream(&penDataBuffer);
283 penDataStream << pen();
284 penDataBuffer.seek(0);
286 size = penDataBuffer.buffer().size();
287 classData.append((
char *)&size,
sizeof(
int));
288 classData.append(penDataBuffer.buffer());
291 QBuffer colorDataBuffer;
292 colorDataBuffer.open(QIODevice::ReadWrite);
294 QDataStream colorDataStream(&colorDataBuffer);
295 colorDataStream << m_color;
296 colorDataBuffer.seek(0);
298 size = colorDataBuffer.buffer().size();
299 classData.append((
char *)&size,
sizeof(
int));
300 classData.append(colorDataBuffer.buffer());
303 QBuffer markerSymbolDataBuffer;
304 markerSymbolDataBuffer.open(QIODevice::ReadWrite);
306 QDataStream markerSymbolDataStream(&markerSymbolDataBuffer);
311 markerSymbolDataBuffer.seek(0);
313 size = markerSymbolDataBuffer.buffer().size();
314 classData.append((
char *)&size,
sizeof(int));
315 classData.append(markerSymbolDataBuffer.buffer());
318 const QwtSeriesData<QPointF> &plotData = *data();
319 size = plotData.size();
320 classData.append((
char *)&size,
sizeof(
int));
322 for (
int i = 0; i < size; i ++) {
323 double x = plotData.sample(i).x();
324 double y = plotData.sample(i).y();
326 classData.append((
char *)&x,
sizeof(
double));
327 classData.append((
char *)&y,
sizeof(
double));
342 newPen.setColor(m_color);
344 QwtPlotCurve::setPen(newPen);
350 void PlotCurve::clearMarkers() {
351 foreach (QwtPlotMarker *marker, m_valuePointMarkers) {
356 m_valuePointMarkers.clear();
360 void PlotCurve::recreateMarkers() {
361 bool markersVisible =
true;
362 if (m_valuePointMarkers.size()) {
363 markersVisible = m_valuePointMarkers.first()->isVisible();
368 markerPen.setColor(m_color);
371 const QwtSeriesData<QPointF> &plotData = *data();
372 for(
unsigned int i = 0; i < plotData.size(); i++) {
373 QwtPlotMarker *newMarker =
new QwtPlotMarker();
374 newMarker->setValue(plotData.sample(i).x(), plotData.sample(i).y());
375 newMarker->setAxes(xAxis(), yAxis());
377 newMarker->setVisible(markersVisible);
378 newMarker->attach(plot());
379 m_valuePointMarkers.append(newMarker);