8 #include <QApplication> 12 #include <QDataStream> 18 #include <QMouseEvent> 22 #include <qwt_legend.h> 29 #include "CubePlotCurveConfigureDialog.h" 63 QString expectedHeader(
"PLOT_TOOL_CURVE_V1");
64 int headerKeySize = expectedHeader.toUtf8().size();
66 if (classData.size() > headerKeySize) {
68 const char *rawClassData = classData.data();
70 QString givenKey = QString::fromUtf8(classData.data() + dataPos,
72 dataPos += headerKeySize;
73 if (givenKey != expectedHeader) {
74 IString msg =
"The given byte array does not contain the required " 79 int numSourceCubes = *(((
int *)(rawClassData + dataPos)));
80 dataPos +=
sizeof(int);
82 for (
int i = 0; i < numSourceCubes; i++) {
83 int sourceCubeSize = *(((
int *)(rawClassData + dataPos)));
84 dataPos +=
sizeof(int);
85 QString data = QString::fromUtf8(classData.data() + dataPos,
88 dataPos += sourceCubeSize;
91 int pointListSize = *(((
int *)(rawClassData + dataPos)));
92 dataPos +=
sizeof(int);
94 for (
int i = 0; i < pointListSize; i ++) {
95 int npts = *(((
int *)(rawClassData + dataPos)));
96 dataPos +=
sizeof(int);
99 for (
int pt = 0; pt < npts; pt++) {
100 double x = *((
double *)(rawClassData + dataPos));
101 dataPos +=
sizeof(double);
103 double y = *((
double *)(rawClassData + dataPos));
104 dataPos +=
sizeof(double);
106 points.append(QPointF(x, y));
111 ASSERT(dataPos == classData.size());
114 IString msg =
"The given byte array is not large enough to contain the " 132 bool blockWidgetFromEvent =
false;
135 case QEvent::MouseButtonPress: {
137 blockWidgetFromEvent =
true;
141 case QEvent::MouseButtonDblClick:
142 case QEvent::MouseButtonRelease:
143 blockWidgetFromEvent =
true;
151 return blockWidgetFromEvent;
167 customPen.setColor(pen().
color());
168 customPen.setWidth(pen().width());
170 if (pen().style() != Qt::NoPen)
171 customPen.setStyle(pen().style());
173 painter->setPen(customPen);
177 for (
int p = 1; p <= points.size(); p++) {
183 if (p != points.size()) {
184 vp->
cubeToViewport(points[p - 1].x(), points[p - 1].y(), sample1, line1);
193 painter->drawLine(QPoint(sample1, line1), QPoint(sample2, line2));
257 void CubePlotCurve::clearSource() {
272 void CubePlotCurve::addSource(CubeViewport *cvp,
QList<QPoint> screenPoints,
279 setTitle(title().text() +
" - " +
283 setTitle(title().text() +
"+" + IString(band).ToQt());
288 foreach (QPoint screenpoint, screenPoints) {
292 cvp->viewportToCube(screenpoint.x(), screenpoint.y(), sample, line);
294 points.append(QPointF(sample, line));
319 addSource(cvp, screenPoints, band);
327 for (
int i = 0; i < cvps.size(); i++) {
328 addSource(cvps.at(i), screenPoints.at(i), band.at(i));
357 QMimeData *mimeData =
new QMimeData;
358 mimeData->setData(
"application/isis3-plot-curve",
371 QByteArray classData;
373 classData.append(PlotCurve::toByteArray());
375 QString header(
"PLOT_TOOL_CURVE_V1");
376 int size = header.size();
377 classData.append(header);
380 classData.append((
char *)&size,
sizeof(
int));
382 for (
int i = 0; i < size; i++) {
383 int sourceCubeSize =
m_sourceCube.at(i).toUtf8().size();
384 classData.append((
char *)&sourceCubeSize,
sizeof(
int));
389 classData.append((
char *)&size,
sizeof(
int));
391 for (
int i = 0; i < size; i ++) {
393 int npts = points.size();
394 classData.append((
char *)&npts,
sizeof(
int));
396 for (
int pt = 0; pt < npts; pt++) {
397 QPointF data = points[pt];
401 classData.append((
char *)&x,
sizeof(
double));
402 classData.append((
char *)&y,
sizeof(
double));
418 bool deleteThisCurve =
false;
419 if (event->button() == Qt::LeftButton) {
425 QPoint newHotSpot = drag->hotSpot();
426 newHotSpot.setX(newHotSpot.x() * 2);
427 drag->setHotSpot(newHotSpot);
432 Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction,
435 if (dropAction == Qt::MoveAction) {
436 deleteThisCurve =
true;
439 else if (event->button() == Qt::RightButton) {
442 QAction *cutAct =
new QAction(QIcon::fromTheme(
"edit-cut"),
"Cut",
this);
443 contextMenu.addAction(cutAct);
444 QAction *copyAct =
new QAction(QIcon::fromTheme(
"edit-copy"),
"Copy",
447 contextMenu.addAction(copyAct);
449 contextMenu.addSeparator();
451 QAction *deleteAct =
new QAction(QIcon::fromTheme(
"edit-delete"),
"Delete",
453 contextMenu.addAction(deleteAct);
455 contextMenu.addSeparator();
457 QString configureIconFile =
460 "Configure...",
this);
461 contextMenu.addAction(configureAct);
463 QAction *chosenAct = contextMenu.exec(
466 if (chosenAct == cutAct || chosenAct == copyAct) {
469 if (chosenAct == cutAct) {
470 deleteThisCurve =
true;
475 else if (chosenAct == configureAct) {
480 else if (chosenAct == deleteAct) {
481 deleteThisCurve =
true;
485 if (deleteThisCurve) {
489 QwtPlot *plotToReplot = plot();
492 this, SLOT(deleteLater()), Qt::QueuedConnection);
494 plotToReplot, SLOT(replot()), Qt::QueuedConnection);
bool eventFilter(QObject *o, QEvent *e)
This will start the drag & drop operation for these curves.
QStringList sourceCube() const
This method returns the cube view port associated with the curve.
QStringList m_sourceCube
The cube that the data is coming from.
void copySource(const CubePlotCurve &other)
This copies the source data from another CubePlotCurve.
File name manipulation and expansion.
void setSource(CubeViewport *cvp, QList< QPoint > screenPoints, int band=-1)
Tell this plot curve from where its data originated.
void needsRepaint()
This is emitted when the curve is modified in such a way that it would paint a viewport differently...
Widget to display Isis cubes for qt apps.
void cubeToViewport(double sample, double line, int &x, int &y) const
Turns a cube into a viewport.
QPointer< QWidget > m_legendItem
This is the widget legend item associated with this curve.
This error is for when a programmer made an API call that was illegal.
void updateLegendItemWidget(QWidget *legendItem)
This creates a legend item and overrides events from it.
void enableAutoRenaming(bool)
This enables/disables the plot curve from changing it's title when the source data changes...
QString m_originalName
This is the curve's name before any automatic renaming happened.
QMimeData * createMimeData() const
This converts the plot curve into a binary, clipboard-compatible storage format (QMimeData).
This is a plot curve with information relating it to a particular cube or region of a cube...
#define _FILEINFO_
Macro for the filename and line number.
QColor color() const
This method returns the color of the curve.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
void setColor(const QColor &color)
Set the color of this curve and it's markers.
QList< QList< QPointF > > sourceVertices() const
This method returns a list of points which are the vertices of the selected area (by the rubberband) ...
void mousePressEvent(QMouseEvent *e)
Handle various events on the legend item.
QByteArray fromByteArray(const QByteArray &classData)
Construct the plot curve given the past results of toByteArray(...).
virtual QString fileName() const
Returns the opened cube's filename.
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
bool m_renameAutomatically
This indicates if we are allowed to modify the title of this curve when the source (origin) data chan...
QList< QList< QPointF > > m_pointList
List of vertices in sample,line coordinates from the rubber band.
CubePlotCurve(Units xUnits, Units yUnits)
This constructs a CubePlotCurve...
void removing()
This is emitted just before the cube plot curve is deleted.
Units
These are all the possible units for the x or y data in a plot curve.
QByteArray toByteArray() const
Serialize this plot curve into a binary byte array.
virtual QWidget * legendItem() const
This method is necessary for getting the correct (event filter altered) legend item.
void paint(CubeViewport *vp, QPainter *painter)
Use information inside of the plot curve to paint onto a cube viewport.