11 #include "CubePlotCurve.h"
16 #include <QApplication>
20 #include <QDataStream>
26 #include <QMouseEvent>
30 #include <qwt_legend.h>
33 #include "CubeViewport.h"
35 #include "IException.h"
37 #include "CubePlotCurveConfigureDialog.h"
71 QString expectedHeader(
"PLOT_TOOL_CURVE_V1");
72 int headerKeySize = expectedHeader.toUtf8().size();
74 if (classData.size() > headerKeySize) {
76 const char *rawClassData = classData.data();
78 QString givenKey = QString::fromUtf8(classData.data() + dataPos,
80 dataPos += headerKeySize;
81 if (givenKey != expectedHeader) {
82 IString msg =
"The given byte array does not contain the required "
87 int numSourceCubes = *(((
int *)(rawClassData + dataPos)));
88 dataPos +=
sizeof(int);
90 for (
int i = 0; i < numSourceCubes; i++) {
91 int sourceCubeSize = *(((
int *)(rawClassData + dataPos)));
92 dataPos +=
sizeof(int);
93 QString data = QString::fromUtf8(classData.data() + dataPos,
96 dataPos += sourceCubeSize;
99 int pointListSize = *(((
int *)(rawClassData + dataPos)));
100 dataPos +=
sizeof(int);
102 for (
int i = 0; i < pointListSize; i ++) {
103 int npts = *(((
int *)(rawClassData + dataPos)));
104 dataPos +=
sizeof(int);
107 for (
int pt = 0; pt < npts; pt++) {
108 double x = *((
double *)(rawClassData + dataPos));
109 dataPos +=
sizeof(double);
111 double y = *((
double *)(rawClassData + dataPos));
112 dataPos +=
sizeof(double);
114 points.append(QPointF(x, y));
119 ASSERT(dataPos == classData.size());
122 IString msg =
"The given byte array is not large enough to contain the "
140 bool blockWidgetFromEvent =
false;
143 case QEvent::MouseButtonPress: {
145 blockWidgetFromEvent =
true;
149 case QEvent::MouseButtonDblClick:
150 case QEvent::MouseButtonRelease:
151 blockWidgetFromEvent =
true;
159 return blockWidgetFromEvent;
175 customPen.setColor(pen().
color());
176 customPen.setWidth(pen().width());
178 if (pen().style() != Qt::NoPen)
179 customPen.setStyle(pen().style());
181 painter->setPen(customPen);
185 for (
int p = 1; p <= points.size(); p++) {
191 if (p != points.size()) {
192 vp->
cubeToViewport(points[p - 1].x(), points[p - 1].y(), sample1, line1);
201 painter->drawLine(QPoint(sample1, line1), QPoint(sample2, line2));
265 void CubePlotCurve::clearSource() {
280 void CubePlotCurve::addSource(CubeViewport *cvp,
QList<QPoint> screenPoints,
287 setTitle(title().text() +
" - " +
291 setTitle(title().text() +
"+" + IString(band).ToQt());
296 foreach (QPoint screenpoint, screenPoints) {
300 cvp->viewportToCube(screenpoint.x(), screenpoint.y(), sample, line);
302 points.append(QPointF(sample, line));
327 addSource(cvp, screenPoints, band);
335 for (
int i = 0; i < cvps.size(); i++) {
336 addSource(cvps.at(i), screenPoints.at(i), band.at(i));
365 QMimeData *mimeData =
new QMimeData;
366 mimeData->setData(
"application/isis3-plot-curve",
379 QByteArray classData;
381 classData.append(PlotCurve::toByteArray());
383 QString header(
"PLOT_TOOL_CURVE_V1");
384 int size = header.size();
385 classData.append(header);
388 classData.append((
char *)&size,
sizeof(
int));
390 for (
int i = 0; i < size; i++) {
391 int sourceCubeSize =
m_sourceCube.at(i).toUtf8().size();
392 classData.append((
char *)&sourceCubeSize,
sizeof(
int));
397 classData.append((
char *)&size,
sizeof(
int));
399 for (
int i = 0; i < size; i ++) {
401 int npts = points.size();
402 classData.append((
char *)&npts,
sizeof(
int));
404 for (
int pt = 0; pt < npts; pt++) {
405 QPointF data = points[pt];
409 classData.append((
char *)&x,
sizeof(
double));
410 classData.append((
char *)&y,
sizeof(
double));
426 bool deleteThisCurve =
false;
427 if (event->button() == Qt::LeftButton) {
433 QPoint newHotSpot = drag->hotSpot();
434 newHotSpot.setX(newHotSpot.x() * 2);
435 drag->setHotSpot(newHotSpot);
440 Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction,
443 if (dropAction == Qt::MoveAction) {
444 deleteThisCurve =
true;
447 else if (event->button() == Qt::RightButton) {
450 QAction *cutAct =
new QAction(QIcon::fromTheme(
"edit-cut"),
"Cut",
this);
451 contextMenu.addAction(cutAct);
452 QAction *copyAct =
new QAction(QIcon::fromTheme(
"edit-copy"),
"Copy",
455 contextMenu.addAction(copyAct);
457 contextMenu.addSeparator();
459 QAction *deleteAct =
new QAction(QIcon::fromTheme(
"edit-delete"),
"Delete",
461 contextMenu.addAction(deleteAct);
463 contextMenu.addSeparator();
465 QString configureIconFile =
468 "Configure...",
this);
469 contextMenu.addAction(configureAct);
471 QAction *chosenAct = contextMenu.exec(
474 if (chosenAct == cutAct || chosenAct == copyAct) {
477 if (chosenAct == cutAct) {
478 deleteThisCurve =
true;
483 else if (chosenAct == configureAct) {
488 else if (chosenAct == deleteAct) {
489 deleteThisCurve =
true;
493 if (deleteThisCurve) {
497 QwtPlot *plotToReplot = plot();
500 this, SLOT(deleteLater()), Qt::QueuedConnection);
502 plotToReplot, SLOT(replot()), Qt::QueuedConnection);