8 #include <qwt_legend.h>
9 #include <qwt_plot_grid.h>
10 #include <qwt_plot_spectrogram.h>
11 #include <qwt_symbol.h>
12 #include <qwt_scale_engine.h>
15 #include <QApplication>
17 #include <QFileDialog>
18 #include <QGridLayout>
24 #include <QMessageBox>
26 #include <QPrintDialog>
27 #include <QProgressDialog>
28 #include <QPushButton>
30 #include <QTableWidget>
34 #include "CubePlotCurve.h"
35 #include "CubePlotCurveConfigureDialog.h"
36 #include "CubeViewport.h"
38 #include "Interpolator.h"
39 #include "MainWindow.h"
40 #include "MdiCubeViewport.h"
41 #include "PlotWindowBestFitDialog.h"
44 #include "PvlKeyword.h"
45 #include "QHistogram.h"
47 #include "TableMainWindow.h"
78 setObjectName(
"Plot Window: " + title);
85 IString msg =
"PlotWindow cannot be instantiated with a NULL parent";
89 installEventFilter(
this);
93 setWindowTitle(title);
97 connect(QGuiApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)),
101 connect(
this, SIGNAL(requestFillTable()),
102 this, SLOT(
fillTable()), Qt::QueuedConnection);
123 setWindowFlags(Qt::Tool);
125 setWindowFlags(Qt::Dialog);
131 PlotWindow::~PlotWindow() {
148 m_plot->installEventFilter(
this);
149 m_plot->setAxisMaxMinor(QwtPlot::yLeft, 5);
150 m_plot->setAxisMaxMajor(QwtPlot::xBottom, 30);
151 m_plot->setAxisMaxMinor(QwtPlot::xBottom, 5);
152 m_plot->setAxisLabelRotation(QwtPlot::xBottom, 45);
153 m_plot->setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignRight);
157 m_legend->setDefaultItemMode(QwtLegendData::Clickable);
158 m_legend->setWhatsThis(
"Right Click on a legend item to display the context "
166 m_grid->setMajorPen(QPen(Qt::white, 1, Qt::DotLine));
167 m_grid->setMinorPen(QPen(Qt::gray, 1, Qt::DotLine));
169 m_grid->setVisible(
false);
173 m_zoomer->setRubberBandPen(QPen(Qt::lightGray));
174 m_zoomer->setTrackerPen(QPen(Qt::lightGray));
209 m_plot->setAxisTitle(axisId, title);
242 return m_plot->title().text();
290 m_plot->setCanvasBackground(c);
318 return m_plot->canvasBackground().color();
331 const QwtPlotItemList &plotItems =
m_plot->itemList();
333 for (
int itemIndex = 0; itemIndex < plotItems.size(); itemIndex++) {
336 if (item->rtti() == QwtPlotItem::Rtti_PlotCurve) {
339 if (curve && curve->
color().alpha() != 0)
340 foundCurves.append(curve);
357 const QwtPlotItemList &plotItems =
m_plot->itemList();
359 for (
int itemIndex = 0; itemIndex < plotItems.size(); itemIndex++) {
362 if (item->rtti() == QwtPlotItem::Rtti_PlotCurve) {
366 foundCurves.append(curve);
384 const QwtPlotItemList &plotItems =
m_plot->itemList();
386 for (
int itemIndex = 0; itemIndex < plotItems.size(); itemIndex++) {
389 if (item->rtti() == QwtPlotItem::Rtti_PlotSpectrogram) {
390 QwtPlotSpectrogram *spectrogram =
391 dynamic_cast<QwtPlotSpectrogram *
>(item);
394 foundSpectrograms.append(spectrogram);
398 return foundSpectrograms;
412 const QwtPlotItemList &plotItems =
m_plot->itemList();
414 for (
int itemIndex = 0; itemIndex < plotItems.size(); itemIndex++) {
417 if (item->rtti() == QwtPlotItem::Rtti_PlotSpectrogram) {
418 const QwtPlotSpectrogram *spectrogram =
419 dynamic_cast<const QwtPlotSpectrogram *
>(item);
422 foundSpectrograms.append(spectrogram);
426 return foundSpectrograms;
438 QMessageBox::warning(NULL,
"Failed to add plot curve",
439 "Can not add plot curves with x/y units that do not match the plot's "
443 QString curveTitle = pc->title().text();
445 bool titleAccepted =
false;
446 int titleTryCount = 0;
447 while (!titleAccepted) {
448 if (titleTryCount > 0) {
449 curveTitle = pc->title().text() +
" (" +
450 QString::number(titleTryCount + 1) +
")";
454 titleAccepted =
true;
456 const QwtPlotItemList &plotItems =
m_plot->itemList();
458 for (
int itemIndex = 0; itemIndex < plotItems.size(); itemIndex ++) {
461 if (item->title().text() == curveTitle)
462 titleAccepted =
false;
466 pc->setTitle(curveTitle);
473 connect(pc, SIGNAL(needsRepaint()),
475 connect(pc, SIGNAL(destroyed(
QObject *)),
512 if (curves.size() < 1) {
517 configDialog->exec();
541 const QwtPlotItemList &plotItems =
m_plot->itemList();
543 for (
int itemIndex = plotItems.size()- 1; itemIndex >= 0; itemIndex --) {
546 if (item->rtti() == QwtPlotItem::Rtti_PlotCurve ||
547 item->rtti() == QwtPlotItem::Rtti_PlotHistogram) {
561 if (
m_zoomer->trackerMode() == QwtPicker::ActiveOnly) {
562 m_zoomer->setTrackerMode(QwtPicker::AlwaysOn);
565 m_zoomer->setTrackerMode(QwtPicker::ActiveOnly);
576 static QPrinter *printer = NULL;
577 if (printer == NULL) printer =
new QPrinter;
578 printer->setPageSize(QPrinter::Letter);
579 printer->setColorMode(QPrinter::Color);
581 QPrintDialog printDialog(printer, (
QWidget *)parent());
583 if (printDialog.exec() == QDialog::Accepted) {
586 QImage img = pixmap.toImage();
588 QPainter painter(printer);
589 QRect rect = painter.viewport();
590 QSize size = img.size();
591 size.scale(rect.size(), Qt::KeepAspectRatio);
592 painter.setViewport(rect.x(), rect.y(),
593 size.width(), size.height());
594 painter.setWindow(img.rect());
595 painter.drawImage(0, 0, img);
608 QFileDialog::getSaveFileName((
QWidget *)parent(),
609 "Choose output file",
611 QString(
"Images (*.png *.jpg *.tif)"));
612 if (output.isEmpty())
return;
614 if (!output.isEmpty()) {
615 if (!output.endsWith(
".png") && !output.endsWith(
".jpg") && !output.endsWith(
".tif")) {
616 output = output +
".png";
620 QString format = QFileInfo(output).suffix();
623 std::string formatString = format.toStdString();
624 if (!pixmap.save(output, formatString.c_str())) {
625 QMessageBox::information((
QWidget *)parent(),
"Error",
"Unable to save " + output);
636 QPen *pen =
new QPen(Qt::white);
638 if (
m_plot->canvasBackground() == Qt::white) {
639 m_plot->setCanvasBackground(Qt::black);
640 m_grid->setMajorPen(QPen(Qt::white, 1, Qt::DotLine));
643 m_plot->setCanvasBackground(Qt::white);
644 pen->setColor(Qt::black);
645 m_grid->setMajorPen(QPen(Qt::black, 1, Qt::DotLine));
665 m_plot->setAxisAutoScale(QwtPlot::xBottom);
670 m_plot->setAxisScale(QwtPlot::xBottom, calculatedXRange.first,
671 calculatedXRange.second);
675 m_plot->setAxisAutoScale(QwtPlot::yLeft);
680 m_plot->setAxisScale(QwtPlot::yLeft, calculatedYRange.first,
681 calculatedYRange.second);
696 m_plot->setAxisScaleEngine(QwtPlot::xBottom,
new QwtLogScaleEngine);
700 m_plot->setAxisScaleEngine(QwtPlot::xBottom,
new QwtLinearScaleEngine);
705 m_plot->setAxisScaleEngine(QwtPlot::yLeft,
new QwtLogScaleEngine);
709 m_plot->setAxisScaleEngine(QwtPlot::yLeft,
new QwtLinearScaleEngine);
722 m_plot->setAxisScale(QwtPlot::xBottom, xMin, xMax);
730 m_plot->setAxisScale(QwtPlot::yLeft, yMin, yMax);
745 dialog->setWindowTitle(
"Set Display Range");
747 QGridLayout *dialogLayout =
new QGridLayout;
751 QLabel *autoLabel =
new QLabel(
"Auto-Scale: ");
752 dialogLayout->addWidget(autoLabel, row, 0);
761 QLabel *xLabel =
new QLabel(
"<h3>X-Axis</h3>");
762 dialogLayout->addWidget(xLabel, row, 0, 1, 2);
765 QLabel *xMinLabel =
new QLabel(
"Minimum: ");
766 dialogLayout->addWidget(xMinLabel, row, 0);
768 double xMin =
plot()->axisScaleDiv(QwtPlot::xBottom).lowerBound();
769 m_xMinEdit =
new QLineEdit(QString::number(xMin));
773 QLabel *xMaxLabel =
new QLabel(
"Maximum: ");
774 dialogLayout->addWidget(xMaxLabel, row, 0);
776 double xMax =
plot()->axisScaleDiv(QwtPlot::xBottom).upperBound();
777 m_xMaxEdit =
new QLineEdit(QString::number(xMax));
781 QLabel *xLogLabel =
new QLabel(
"Logarithmic Scale");
782 dialogLayout->addWidget(xLogLabel, row, 0);
792 QLabel *yLabel =
new QLabel(
"<h3>Y-Axis</h3>");
793 dialogLayout->addWidget(yLabel, row, 0, 1, 2);
796 QLabel *yMinLabel =
new QLabel(
"Minimum: ");
797 dialogLayout->addWidget(yMinLabel, row, 0);
799 double yMin =
plot()->axisScaleDiv(QwtPlot::yLeft).lowerBound();
800 m_yMinEdit =
new QLineEdit(QString::number(yMin));
804 QLabel *yMaxLabel =
new QLabel(
"Maximum: ");
805 dialogLayout->addWidget(yMaxLabel, row, 0);
807 double yMax =
plot()->axisScaleDiv(QwtPlot::yLeft).upperBound();
808 m_yMaxEdit =
new QLineEdit(QString::number(yMax));
812 QLabel *yLogLabel =
new QLabel(
"Logarithmic Scale");
813 dialogLayout->addWidget(yLogLabel, row, 0);
823 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
824 buttonsLayout->addStretch();
826 QPushButton *okButton =
new QPushButton(
"&Ok");
827 okButton->setIcon(QIcon::fromTheme(
"dialog-ok"));
828 connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
829 connect(dialog, SIGNAL(accepted()),
this, SLOT(
setUserValues()));
830 okButton->setShortcut(Qt::Key_Enter);
831 buttonsLayout->addWidget(okButton);
833 QPushButton *cancelButton =
new QPushButton(
"&Cancel");
834 cancelButton->setIcon(QIcon::fromTheme(
"dialog-cancel"));
835 connect(cancelButton, SIGNAL(clicked()), dialog, SLOT(reject()));
836 buttonsLayout->addWidget(cancelButton);
839 buttonsWrapper->setLayout(buttonsLayout);
840 dialogLayout->addWidget(buttonsWrapper, row, 0, 1, 2);
845 dialog->setLayout(dialogLayout);
856 dialog->setWindowTitle(
"Name Plot Labels");
858 QGridLayout *dialogLayout =
new QGridLayout;
861 QLabel *plotLabel =
new QLabel(
"Plot Title: ");
862 dialogLayout->addWidget(plotLabel, row, 0);
868 QLabel *xAxisLabel =
new QLabel(
"X-Axis Label: ");
869 dialogLayout->addWidget(xAxisLabel, row, 0);
875 QLabel *yAxisLabel =
new QLabel(
"Y-Axis Label: ");
876 dialogLayout->addWidget(yAxisLabel, row, 0);
882 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
883 buttonsLayout->addStretch();
885 QPushButton *okButton =
new QPushButton(
"&Ok");
886 okButton->setIcon(QIcon::fromTheme(
"dialog-ok"));
887 connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
888 connect(dialog, SIGNAL(accepted()),
this, SLOT(
setLabels()));
889 okButton->setShortcut(Qt::Key_Enter);
890 buttonsLayout->addWidget(okButton);
892 QPushButton *cancelButton =
new QPushButton(
"&Cancel");
893 cancelButton->setIcon(QIcon::fromTheme(
"dialog-cancel"));
894 connect(cancelButton, SIGNAL(clicked()), dialog, SLOT(reject()));
895 buttonsLayout->addWidget(cancelButton);
898 buttonsWrapper->setLayout(buttonsLayout);
899 dialogLayout->addWidget(buttonsWrapper, row, 0, 1, 2);
902 dialog->setLayout(dialogLayout);
926 if (
m_grid->isVisible()) {
942 method = &QwtPlotItem::hide;
948 method = &QwtPlotItem::show;
953 for (
int i = 0; i <
m_plot->itemList().size(); i ++) {
955 if (plotItem->rtti() == QwtPlotItem::Rtti_PlotMarker)
956 (plotItem->*method)();
970 method = &QwtPlotItem::hide;
974 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_showCurves.png").expanded()));
978 method = &QwtPlotItem::show;
982 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_hideCurves.png").expanded()));
985 for (
int i = 0; i <
m_plot->itemList().size(); i ++) {
987 if (plotItem->rtti() == QwtPlotItem::Rtti_PlotCurve)
988 (plotItem->*method)();
1001 d->setWindowTitle(
"Basic Help");
1003 QLabel *zoomLabel =
new QLabel(
"<U>Zoom Options:</U>");
1004 QLabel *zoomIn =
new
1005 QLabel(
" <b>Left click</b> on the mouse, drag, and release to select an area to zoom in on");
1006 QLabel *zoomOut =
new
1007 QLabel(
" <b>Middle click</b> on the mouse to zoom out one level");
1008 QLabel *zoomReset =
new
1009 QLabel(
" <b>Right click</b> on the mouse and select <I>Reset Scale</I> to clear the zoom and return to the original plot");
1011 QLabel *curveConfigLabel =
new QLabel(
"<br><U>Curve Configuration:</U>");
1012 QLabel *configDirections =
new
1013 QLabel(
" <b>To configure the curve properties</b> Right click on the legend and select <I>Configure</I> from <br> the menu"
1014 " or click on the configure icon in the tool bar.");
1015 QLabel *config =
new QLabel();
1016 config->setPixmap(QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_configure.png").expanded()));
1018 QLabel *tableLabel =
new QLabel(
"<br><U>Table Options:</U>");
1019 QLabel *tableDirections =
new
1020 QLabel(
" <b>To view the table</b> Click on the File menu and select <I>Show Table</I> or click on the table icon in the <br> tool bar.");
1021 QLabel *table =
new QLabel();
1022 table->setPixmap(QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_table.png").expanded()));
1024 QVBoxLayout *layout =
new QVBoxLayout();
1025 layout->addWidget(zoomLabel);
1026 layout->addWidget(zoomIn);
1027 layout->addWidget(zoomOut);
1028 layout->addWidget(zoomReset);
1029 layout->addWidget(curveConfigLabel);
1030 layout->addWidget(config);
1031 layout->addWidget(configDirections);
1032 layout->addWidget(tableLabel);
1033 layout->addWidget(table);
1034 layout->addWidget(tableDirections);
1036 d->setLayout(layout);
1059 save->setText(
"&Save Plot As");
1060 save->setIcon(QIcon::fromTheme(
"document-save-as"));
1062 "<b>Function:</b> Save the plot as a png, jpg, or tif file.";
1063 save->setWhatsThis(text);
1064 connect(save, SIGNAL(triggered()),
this, SLOT(
savePlot()));
1065 fileMenu->addAction(save);
1066 actions.push_back(save);
1071 prt->setText(
"&Print Plot");
1072 prt->setIcon(QIcon::fromTheme(
"document-print"));
1074 "<b>Function:</b> Sends the plot image to the printer";
1075 prt->setWhatsThis(text);
1076 connect(prt, SIGNAL(triggered()),
this, SLOT(
printPlot()));
1077 fileMenu->addAction(prt);
1078 actions.push_back(prt);
1083 table->setText(
"Show Table");
1085 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_table.png").expanded()));
1087 "<b>Function:</b> Activates the table which displays the data of the "
1089 table->setWhatsThis(text);
1090 connect(table, SIGNAL(triggered()),
this, SLOT(
showTable()));
1091 fileMenu->addAction(table);
1092 actions.push_back(table);
1095 QAction *close =
new QAction(QIcon::fromTheme(
"document-close"),
"&Close",
1097 connect(close, SIGNAL(triggered()),
this, SLOT(close()));
1098 fileMenu->addAction(close);
1102 track->setText(
"Show Mouse &Tracking");
1104 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/goto.png").expanded()));
1105 track->setCheckable(
true);
1107 "<b>Function:</b> Displays the x,y coordinates as the cursor moves "
1108 "around on the plot.";
1109 track->setWhatsThis(text);
1110 connect(track, SIGNAL(triggered()),
this, SLOT(
trackerEnabled()));
1111 optionsMenu->addAction(track);
1117 backgrdSwitch->setText(
"White/Black &Background");
1118 backgrdSwitch->setIcon(
1119 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_switchBackgrd.png").expanded()));
1121 "<b>Function:</b> Switch the background color between black and "
1123 backgrdSwitch->setWhatsThis(text);
1124 connect(backgrdSwitch, SIGNAL(triggered()),
1126 optionsMenu->addAction(backgrdSwitch);
1127 actions.push_back(backgrdSwitch);
1134 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_grid.png").expanded()));
1136 "<b>Function:</b> Display grid lines on the plot.";
1145 changeLabels->setText(
"Rename Plot &Labels");
1146 changeLabels->setIcon(
1147 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_renameLabels.png").expanded()));
1149 "<b>Function:</b> Edit the plot title, x and y axis labels.";
1150 changeLabels->setWhatsThis(text);
1151 connect(changeLabels, SIGNAL(triggered()),
1153 optionsMenu->addAction(changeLabels);
1154 actions.push_back(changeLabels);
1160 changeScale->setText(
"Set &Display Range");
1161 changeScale->setIcon(
1162 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_setScale.png").expanded()));
1164 "<b>Function:</b> Adjust the scale for the x and y axis on the "
1166 changeScale->setWhatsThis(text);
1167 connect(changeScale, SIGNAL(triggered()),
this, SLOT(
setDefaultRange()));
1168 optionsMenu->addAction(changeScale);
1169 actions.push_back(changeScale);
1177 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_showCurves.png").expanded()));
1179 "<b>Function:</b> Displays or hides all the curves currently "
1180 "displayed on the plot.";
1193 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_markers.png").expanded()));
1194 QString text =
"<b>Function:</b> Displays or hides a symbol for each "
1195 "data point plotted on a plot.";
1205 resetScaleButton->setText(
"Reset Scale");
1206 resetScaleButton->setIcon(
1207 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_resetscale.png").expanded()));
1209 "<b>Function:</b> Reset the plot's scale.";
1210 resetScaleButton->setWhatsThis(text);
1211 connect(resetScaleButton, SIGNAL(triggered()),
this, SLOT(
resetScale()));
1212 actions.push_back(resetScaleButton);
1217 clear->setText(
"Clear Plot");
1219 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_clear.png").expanded()));
1221 "<b>Function:</b> Removes all the curves from the plot.";
1222 clear->setWhatsThis(text);
1223 connect(clear, SIGNAL(triggered()),
this, SLOT(
clearPlot()));
1224 actions.push_back(clear);
1229 lineFit->setText(
"Create Best Fit Line");
1231 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/linefit.png").expanded()));
1232 QString text =
"<b>Function:</b> Calculates a best fit line from an "
1234 lineFit->setWhatsThis(text);
1236 optionsMenu->addAction(lineFit);
1237 actions.push_back(lineFit);
1242 configurePlot->setText(
"Configure Plot");
1243 configurePlot->setIcon(
1244 QPixmap(
FileName(
"$ISISROOT/appdata/images/icons/plot_configure.png").expanded() ) );
1245 QString text =
"<b>Function:</b> Change the name, color, style, and vertex symbol of the "
1247 configurePlot->setWhatsThis(text);
1248 connect( configurePlot, SIGNAL( triggered() ),
1250 optionsMenu->addAction(configurePlot);
1251 actions.push_back(configurePlot);
1255 basicHelp->setText(
"Basic Help");
1256 QString text =
"<b>Function:</b> Provides a basic overview on using components "
1257 "of the qview plot window";
1258 basicHelp->setWhatsThis(text);
1259 connect( basicHelp, SIGNAL( triggered() ),
1261 helpMenu->addAction(basicHelp);
1267 m_pasteAct->setShortcut(Qt::CTRL | Qt::Key_V);
1272 menu.push_back(fileMenu);
1273 menu.push_back(editMenu);
1275 if (optionsMenu->actions().size()) {
1276 menu.push_back(optionsMenu);
1283 if (helpMenu->actions().size()) {
1284 menu.push_back(helpMenu);
1307 bool userCanAdd =
false;
1310 curve->hasFormat(
"application/isis3-plot-curve")) {
1313 curve->data(
"application/isis3-plot-curve"));
1315 userCanAdd =
canAdd(testCurve);
1362 m_toolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea | Qt::TopToolBarArea);
1363 addToolBar(Qt::TopToolBarArea,
m_toolBar);
1372 for (
int i = 0; i < menu.size(); i++) {
1376 for (
int i = 0; i < actions.size(); i++) {
1400 if (!m_scheduledFillTable) {
1401 m_scheduledFillTable =
true;
1402 emit requestFillTable();
1412 m_scheduledFillTable =
false;
1421 m_plot->axisTitle(QwtPlot::xBottom).text(),
1422 m_plot->axisTitle(QwtPlot::xBottom).text());
1427 curve->title().text(),
1428 curve->title().text());
1445 QProgressDialog progress(tr(
"Re-calculating Table"), tr(
""), 0, 1000,
this);
1446 double percentPerCurve = 0.5 * 1.0 / curves.count();
1448 for (
int curveIndex = 0; curveIndex < curves.count(); curveIndex++) {
1449 progress.setValue(qRound(curveIndex * percentPerCurve * 1000.0));
1453 double percentPerDataIndex = (1.0 / curve->data()->size()) * percentPerCurve;
1457 for (
int dataIndex = (
int)curve->data()->size() - 1;
1460 double xValue = curve->data()->sample(dataIndex).x();
1461 QString xValueString =
toString(xValue);
1463 int inverseDataIndex = (curve->data()->size() - 1) - dataIndex;
1465 qRound( ((curveIndex * percentPerCurve) +
1466 (inverseDataIndex * percentPerDataIndex)) * 1000.0));
1472 qBinaryFind(xAxisPoints.begin(), xAxisPoints.end(), xValueString);
1474 if (foundPos == xAxisPoints.end()) {
1475 bool inserted =
false;
1477 for (
int searchIndex = 0;
1478 searchIndex < xAxisPoints.size() && !inserted;
1480 if (xAxisPoints[searchIndex] > xValueString) {
1482 xAxisPoints.insert(searchIndex, xValueString);
1487 xAxisPoints.append(xValueString);
1492 qSort(xAxisPoints.begin(), xAxisPoints.end(), &numericStringLessThan);
1498 for (
int i = 0; i < curves.count(); i++) {
1499 lastSuccessfulSamples.append(-1);
1505 progress.setValue(500 + qRound(row * progressPerRow * 1000.0));
1507 QString xValueString = xAxisPoints[row];
1508 double xValue =
toDouble(xValueString);
1510 QTableWidgetItem *xAxisItem =
new QTableWidgetItem(xValueString);
1522 bool tooFar =
false;
1524 for (
int dataIndex = lastSuccessfulSamples[col - 1] + 1;
1525 dataIndex < (int)curve->data()->size() && y ==
Null && !tooFar;
1528 if (
toString(curve->data()->sample(dataIndex).x()) == xValueString) {
1530 if (dataIndex > 0 &&
1531 curve->data()->sample(dataIndex - 1).x() < curve->data()->sample(dataIndex).x()) {
1532 lastSuccessfulSamples[col - 1] = dataIndex;
1534 y = curve->data()->sample(dataIndex).y();
1537 else if (dataIndex > 0 &&
1538 curve->data()->sample(dataIndex - 1).x() < curve->data()->sample(dataIndex).x() &&
1539 curve->data()->sample(dataIndex).x() > xValue) {
1544 QTableWidgetItem *item = NULL;
1547 item =
new QTableWidgetItem(QString(
"N/A"));
1549 item =
new QTableWidgetItem(
toString(y));
1591 bool blockWidgetFromEvent =
false;
1593 switch (e->type()) {
1594 case QEvent::MouseButtonPress:
1596 childAt(((QMouseEvent *)e)->pos()) !=
plot()->canvas()) {
1598 blockWidgetFromEvent =
true;
1606 bool stopHandlingEvent =
false;
1607 if (!blockWidgetFromEvent && o ==
this) {
1608 stopHandlingEvent = MainWindow::eventFilter(o, e);
1610 if (e->type() == QEvent::Close && !stopHandlingEvent) {
1615 return stopHandlingEvent || blockWidgetFromEvent;
1629 if (qobject_cast<QWidget *>(
object) &&
1630 event->button() == Qt::RightButton &&
1634 QAction *pasteAct =
new QAction(QIcon::fromTheme(
"edit-paste"),
"Paste",
1636 contextMenu.addAction(pasteAct);
1638 QAction *chosenAct = contextMenu.exec(
1639 qobject_cast<QWidget *>(
object)->mapToGlobal(event->pos()));
1641 if (chosenAct == pasteAct) {
1699 QClipboard *globalClipboard = QApplication::clipboard();
1700 const QMimeData *globalData = globalClipboard->mimeData();
1702 if (globalData->hasFormat(
"application/isis3-plot-curve")) {
1704 globalData->data(
"application/isis3-plot-curve"));
1725 bool foundDataValue =
false;
1729 for (
int dataIndex = 0; dataIndex < (int)curve->dataSize(); dataIndex++) {
1730 if (axisId == QwtPlot::xBottom) {
1731 if (!foundDataValue) {
1732 rangeMinMax.first = curve->sample(dataIndex).x();
1733 rangeMinMax.second = curve->sample(dataIndex).x();
1734 foundDataValue =
true;
1737 rangeMinMax.first = qMin(rangeMinMax.first, curve->sample(dataIndex).x());
1738 rangeMinMax.second = qMax(rangeMinMax.second, curve->sample(dataIndex).x());
1741 else if (axisId == QwtPlot::yLeft) {
1742 if (!foundDataValue) {
1743 rangeMinMax.first = curve->sample(dataIndex).y();
1744 rangeMinMax.second = curve->sample(dataIndex).y();
1745 foundDataValue =
true;
1748 rangeMinMax.first = qMin(rangeMinMax.first, curve->sample(dataIndex).y());
1749 rangeMinMax.second = qMax(rangeMinMax.second, curve->sample(dataIndex).y());
1755 if (!foundDataValue) {
1756 rangeMinMax.first = 1;
1757 rangeMinMax.second = 10;
1759 else if(rangeMinMax.first == rangeMinMax.second) {
1760 rangeMinMax.first -= 0.5;
1761 rangeMinMax.second += 0.5;
1768 bool PlotWindow::numericStringLessThan(QString left, QString right) {
1769 bool result =
false;
1774 catch (IException &) {
1789 curve->
paint(vp, painter);
1824 QObject *source =
event->source();
1826 if (source !=
m_legend->contentsWidget() &&
1828 event->acceptProposedAction();
1846 event->mimeData()->hasFormat(
"application/isis3-plot-curve")) {
1847 Qt::DropActions possibleActions =
event->possibleActions();
1848 Qt::DropAction actionToTake =
event->proposedAction();
1851 boldFont.setBold(
true);
1852 QMenu dropActionsMenu;
1855 if (possibleActions.testFlag(Qt::CopyAction)) {
1856 dropActionsMenu.addAction(copyAct);
1858 if (actionToTake == Qt::CopyAction)
1859 copyAct->setFont(boldFont);
1863 if (possibleActions.testFlag(Qt::MoveAction)) {
1864 dropActionsMenu.addAction(moveAct);
1866 if (actionToTake == Qt::MoveAction)
1867 moveAct->setFont(boldFont);
1870 if (dropActionsMenu.actions().size() > 1) {
1871 dropActionsMenu.addSeparator();
1874 dropActionsMenu.addAction(cancelAct);
1876 QAction *chosenAct = dropActionsMenu.exec(mapToGlobal(event->pos()));
1878 if (chosenAct == copyAct) {
1879 actionToTake = Qt::CopyAction;
1881 else if (chosenAct == moveAct) {
1882 actionToTake = Qt::MoveAction;
1885 actionToTake = Qt::IgnoreAction;
1889 if (actionToTake != Qt::IgnoreAction) {
1891 event->mimeData()->data(
"application/isis3-plot-curve"));
1896 event->setDropAction(actionToTake);