void YarrGui::on_exportPlotCSVButton_clicked(){ if(ui->scanPlots_tabWidget->count() == 0){return;} if(ui->plotTree->currentItem() == nullptr) { std::cerr << "Please select plot. Returning... " << std::endl; return; } if(ui->plotTree->currentItem()->childCount() > 0){ std::cerr << "Please select plot. Returning... " << std::endl; return; } QWidget * toCast = ui->scanPlots_tabWidget->currentWidget(); QCustomPlot * myPlot = dynamic_cast<QCustomPlot*>(toCast); if(myPlot == nullptr){ std::cerr << "Severe cast error. Returning... " << std::endl; return; } QCPColorMap * myColorMap = dynamic_cast<QCPColorMap*>(myPlot->plottable()); if(myColorMap == nullptr){ std::cout << "Severe cast error. Aborting... " << std::endl; return; } /* QString myFileName = ui->plotTree->currentItem()->text(0); struct tm * timeinfo; time_t rawtime; time(&rawtime); timeinfo = localtime(&rawtime); myFileName = myFileName + QString::number(1900+(timeinfo->tm_year)) + '_' + (timeinfo->tm_mon > 8 ? QString::number(1+(timeinfo->tm_mon)) : ('0' + QString::number(1+(timeinfo->tm_mon)))) + '_' + QString::number((timeinfo->tm_mday)) + '_' + QString::number((timeinfo->tm_hour)) + '_' + QString::number((timeinfo->tm_min)) + '_' + QString::number((timeinfo->tm_sec)) + ".csv"; */ QString myFileName = QFileDialog::getSaveFileName(this, "Save plot as CSV", "./", "Comma-Separated Values(*.csv)"); if(myFileName==""){return;} std::ofstream myCSVOutput(myFileName.toStdString()); for(int xCoord = 0; xCoord<80; xCoord++){ for(int yCoord = 0; yCoord<336; yCoord++) { myCSVOutput << xCoord << ",\t" << yCoord << ",\t" << myColorMap->data()->cell(xCoord, yCoord) << std::endl; } } myCSVOutput.close(); std::cout << "Saved current plot to \"" << myFileName.toStdString() << '"' << std::endl; return; }
void YarrGui::detachPlot(){ if(ui->plotTree->currentItem() == nullptr){ std::cerr << "Please select plot to detach...\n"; return; } if(ui->plotTree->currentItem()->childCount() > 0){ std::cerr << "Please select plot to detach...\n"; return; } PlotDialog * myPDiag = new PlotDialog(); QCustomPlot * plotWidget = dynamic_cast<QCustomPlot*>(ui->scanPlots_tabWidget->currentWidget()); if(plotWidget == nullptr){ std::cerr << "Severe cast error. Aborting...\n"; return; } QCustomPlot * transferPlot = dynamic_cast<QCustomPlot*>(myPDiag->childAt(10, 10)); if(transferPlot == nullptr){ std::cerr << "Severe cast error. Aborting...\n"; return; } QCPPlotTitle * widgetPT = dynamic_cast<QCPPlotTitle*>(plotWidget->plotLayout()->element(0, 0)); if(widgetPT == nullptr){ std::cerr << "Severe cast error. Aborting... \n"; return; } if(dynamic_cast<QCPColorMap*>(plotWidget->plottable(0)) != nullptr){ QCPColorMap * widgetCMap = dynamic_cast<QCPColorMap*>(plotWidget->plottable(0)); QCPColorScale * widgetCScale = dynamic_cast<QCPColorScale*>(plotWidget->plotLayout()->element(1, 1)); if(widgetCScale == nullptr) { std::cerr << "Severe cast error. Aborting... \n"; return; } transferPlot->plotLayout()->insertRow(0); transferPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(transferPlot, widgetPT->text())); QCPColorMap * transferCMap = new QCPColorMap(transferPlot->xAxis, transferPlot->yAxis); transferPlot->addPlottable(transferCMap); transferCMap->data()->setSize(80, 336); transferCMap->setData(widgetCMap->data(), true); QCPColorScale * transferCScale = new QCPColorScale(transferPlot); transferPlot->plotLayout()->addElement(1, 1, transferCScale); transferCScale->setType(QCPAxis::atRight); transferCMap->setColorScale(transferCScale); transferCMap->keyAxis()->setLabel(widgetCMap->keyAxis()->label()); transferCMap->valueAxis()->setLabel(widgetCMap->valueAxis()->label()); transferCScale->axis()->setLabel(widgetCScale->axis()->label()); transferCMap->setGradient(QCPColorGradient::gpPolar); transferCMap->rescaleDataRange(); }else if(dynamic_cast<QCPBars*>(plotWidget->plottable(0)) != nullptr){ QCPBars * widgetBars = dynamic_cast<QCPBars*>(plotWidget->plottable(0)); QCPBars * transferBars = new QCPBars(transferPlot->xAxis, transferPlot->yAxis); transferBars->setData(widgetBars->data(), true); transferBars->rescaleAxes(); transferPlot->plotLayout()->insertRow(0); transferPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(transferPlot, widgetPT->text())); transferBars->keyAxis()->setLabel(widgetBars->keyAxis()->label()); transferBars->valueAxis()->setLabel(widgetBars->valueAxis()->label()); }else{ std::cerr << "Severe cast error. Aborting... \n"; //DEBUG return; } transferPlot->rescaleAxes(); transferPlot->replot(); myPDiag->setModal(false); myPDiag->show(); removePlot(); return; }