7#include <qwt_plot_curve.h>
8#include <qwt_plot_marker.h>
14#include "SpecialPixel.h"
25 m_color = QColor(Qt::white);
31 PlotCurve::~PlotCurve() {
110 QwtPlotCurve::setData(data);
131 foreach (QwtPlotMarker *marker, m_valuePointMarkers) {
132 marker->setVisible(visible);
145 QString expectedHeader(
"PLOT_CURVE_V1");
146 int headerKeySize = expectedHeader.toUtf8().size();
148 if (classData.size() > headerKeySize) {
150 const char *rawClassData = classData.data();
152 QString givenKey = QString::fromUtf8(classData.data() + dataPos,
154 dataPos += headerKeySize;
155 if (givenKey != expectedHeader) {
156 IString msg =
"The given byte array does not contain the required "
161 int titleSize = *(((
int *)(rawClassData + dataPos)));
162 dataPos +=
sizeof(int);
164 setTitle(QString::fromUtf8(classData.data() + dataPos, titleSize));
165 dataPos += titleSize;
167 m_xUnits = (
Units)(*((
int *)(rawClassData + dataPos)));
168 dataPos +=
sizeof(int);
170 m_yUnits = (
Units)(*((
int *)(rawClassData + dataPos)));
171 dataPos +=
sizeof(int);
174 int penBufferSize = *(((
int *)(rawClassData + dataPos)));
175 dataPos +=
sizeof(int);
177 QByteArray penBufferBytes(rawClassData + dataPos, penBufferSize);
178 dataPos += penBufferSize;
180 QBuffer penDataBuffer(&penBufferBytes);
181 penDataBuffer.open(QIODevice::ReadWrite);
183 QDataStream penDataStream(&penDataBuffer);
185 penDataStream >> pen;
190 int colorBufferSize = *(((
int *)(rawClassData + dataPos)));
191 dataPos +=
sizeof(int);
193 QByteArray colorBufferBytes(rawClassData + dataPos, colorBufferSize);
194 dataPos += colorBufferSize;
196 QBuffer colorDataBuffer(&colorBufferBytes);
197 colorDataBuffer.open(QIODevice::ReadWrite);
199 QDataStream colorDataStream(&colorDataBuffer);
201 colorDataStream >> newColor;
205 int markerSymbolBufferSize = *(((
int *)(rawClassData + dataPos)));
206 dataPos +=
sizeof(int);
208 QByteArray markerSymbolBufferBytes(rawClassData + dataPos,
209 markerSymbolBufferSize);
210 dataPos += markerSymbolBufferSize;
212 QBuffer markerSymbolDataBuffer(&markerSymbolBufferBytes);
213 markerSymbolDataBuffer.open(QIODevice::ReadWrite);
215 QDataStream markerSymbolDataStream(&markerSymbolDataBuffer);
218 markerSymbolDataStream >> markerBrush;
222 markerSymbolDataStream >> markerPen;
226 markerSymbolDataStream >> markerSize;
230 markerSymbolDataStream >> markerStyle;
234 int plotDataSize = *((
int *)(rawClassData + dataPos));
235 dataPos +=
sizeof(int);
236 QVector<QPointF> plotDataValues;
238 for (
int i = 0; i < plotDataSize; i ++) {
239 double x = *((
double *)(rawClassData + dataPos));
240 dataPos +=
sizeof(double);
242 double y = *((
double *)(rawClassData + dataPos));
243 dataPos +=
sizeof(double);
245 plotDataValues.append(QPointF(x, y));
248 setData(
new QwtPointSeriesData(plotDataValues));
250 return classData.right(classData.size() - dataPos);
253 IString msg =
"The given byte array is not large enough to contain the "
260 QByteArray PlotCurve::toByteArray()
const {
261 QByteArray classData;
263 QString header(
"PLOT_CURVE_V1");
264 classData.append(header.toUtf8());
266 QByteArray titleArray = title().text().toUtf8();
267 int size = titleArray.size();
268 classData.append((
char *)&size,
sizeof(
int));
269 classData.append(titleArray);
271 int xUnitsInt = (int)m_xUnits;
272 int yUnitsInt = (int)m_yUnits;
273 classData.append((
char *)&xUnitsInt,
sizeof(int));
274 classData.append((
char *)&yUnitsInt,
sizeof(int));
277 QBuffer penDataBuffer;
278 penDataBuffer.open(QIODevice::ReadWrite);
280 QDataStream penDataStream(&penDataBuffer);
281 penDataStream << pen();
282 penDataBuffer.seek(0);
284 size = penDataBuffer.buffer().size();
285 classData.append((
char *)&size,
sizeof(
int));
286 classData.append(penDataBuffer.buffer());
289 QBuffer colorDataBuffer;
290 colorDataBuffer.open(QIODevice::ReadWrite);
292 QDataStream colorDataStream(&colorDataBuffer);
293 colorDataStream << m_color;
294 colorDataBuffer.seek(0);
296 size = colorDataBuffer.buffer().size();
297 classData.append((
char *)&size,
sizeof(
int));
298 classData.append(colorDataBuffer.buffer());
301 QBuffer markerSymbolDataBuffer;
302 markerSymbolDataBuffer.open(QIODevice::ReadWrite);
304 QDataStream markerSymbolDataStream(&markerSymbolDataBuffer);
309 markerSymbolDataBuffer.seek(0);
311 size = markerSymbolDataBuffer.buffer().size();
312 classData.append((
char *)&size,
sizeof(int));
313 classData.append(markerSymbolDataBuffer.buffer());
316 const QwtSeriesData<QPointF> &plotData = *data();
317 size = plotData.size();
318 classData.append((
char *)&size,
sizeof(
int));
320 for (
int i = 0; i < size; i ++) {
321 double x = plotData.sample(i).x();
322 double y = plotData.sample(i).y();
324 classData.append((
char *)&x,
sizeof(
double));
325 classData.append((
char *)&y,
sizeof(
double));
340 newPen.setColor(m_color);
342 QwtPlotCurve::setPen(newPen);
348 void PlotCurve::clearMarkers() {
349 foreach (QwtPlotMarker *marker, m_valuePointMarkers) {
354 m_valuePointMarkers.clear();
358 void PlotCurve::recreateMarkers() {
359 bool markersVisible =
true;
360 if (m_valuePointMarkers.size()) {
361 markersVisible = m_valuePointMarkers.first()->isVisible();
366 markerPen.setColor(m_color);
369 const QwtSeriesData<QPointF> &plotData = *data();
370 for(
unsigned int i = 0; i < plotData.size(); i++) {
371 QwtPlotMarker *newMarker =
new QwtPlotMarker();
372 newMarker->setValue(plotData.sample(i).x(), plotData.sample(i).y());
373 newMarker->setAxes(xAxis(), yAxis());
375 newMarker->setVisible(markersVisible);
376 newMarker->attach(plot());
377 m_valuePointMarkers.append(newMarker);
@ Programmer
This error is for when a programmer made an API call that was illegal.
Adds specific functionality to C++ strings.
void setColor(const QColor &color)
Set the color of this curve and it's markers.
QColor color() const
This method returns the color of the curve.
QwtSymbol * m_markerSymbol
Marker's styles.
void setData(QwtSeriesData< QPointF > *data)
This method sets the data for the curve, then sets the value for the markers associated with the curv...
QByteArray fromByteArray(const QByteArray &classData)
Construct the plot curve given the past results of toByteArray(...).
Units yUnits() const
Get the units of the y-axis double data.
void setMarkerSymbol(QwtSymbol::Style style)
This method sets the shape of the markers.
PlotCurve(Units xUnits, Units yUnits)
Constructs and instance of a PlotCurve with some default properties.
Units xUnits() const
Get the units of the x-axis double data.
void attachMarkers()
After attaching this curve to a plot, due to an inheritance/implementation complication with qwt the ...
Units
These are all the possible units for the x or y data in a plot curve.
void setPen(const QPen &pen)
Sets the plot pen to the passed-in pen.
QwtSymbol * markerSymbol() const
This method returns the shape of the markers.
void setMarkerVisible(bool visible)
This method sets the visibility states of the markers at each value point.
This is free and unencumbered software released into the public domain.