##// END OF EJS Templates
Removed hack from QCustomPlot, moved to QCustomPlotVect class.
Removed hack from QCustomPlot, moved to QCustomPlotVect class.

File last commit:

r7:6e23aedd1ca8 default
r7:6e23aedd1ca8 default
Show More
cassinitools.cpp
161 lines | 4.2 KiB | text/x-c | CppLexer
#include "cassinitools.h"
#include <qlopplots.h>
#include <QPen>
#include <QAction>
CassiniTools* CassiniTools::_self=NULL;
QDockWidget* CassiniTools::m_gui=NULL;
CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL;
CassiniDataFile* CassiniTools::m_dataFile=NULL;
int CassiniTools::m_defaultPlot=-1;
Qt::GlobalColor QLopColours[]= {Qt::black,
Qt::red,
Qt::blue,
Qt::green,
Qt::darkGreen,
Qt::cyan,
Qt::darkRed,
Qt::gray,
Qt::yellow,
Qt::darkBlue,
Qt::darkCyan,
Qt::magenta,
Qt::darkMagenta,
Qt::darkYellow,
Qt::darkGray,
Qt::lightGray};
int QLopColoursCount=16;
#define _INIT() if(Q_UNLIKELY(_self==NULL)){init();}
CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent)
{
m_dataFile = new CassiniDataFile();
connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList)));
m_serviceName="CassiniTools";
m_noGui=noGUI;
}
CassiniTools::~CassiniTools()
{
delete m_dataFile;
delete m_CassiniToolsGUI;
delete m_gui;
}
void CassiniTools::makePlot()
{
m_defaultPlot = QLopPlots::addPlot();
SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot);
if(plot)
{
plot->setTitle(_self->m_serviceName + " plot");
plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
plot->setContextMenuPolicy(Qt::ActionsContextMenu);
SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self);
plot->addAction(action);
QObject::connect(action,SIGNAL(triggered()),_self,SLOT(export_view()));
}
}
void CassiniTools::init(bool noGUI, QObject *parent)
{
if(Q_UNLIKELY(_self==NULL))
{
_self=new CassiniTools(noGUI,parent);
}
}
CassiniTools *CassiniTools::self()
{
_INIT();
return _self;
}
void CassiniTools::decodeFGMData(const QString &file)
{
_INIT();
m_dataFile->parseFile(file);
}
void CassiniTools::plotFile(const QString &File)
{
if(!m_dataFile->isRunning())
{
m_dataFile->parseFile(File);
// TODO fixme
SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
if(plot==NULL)
{
makePlot();
plot = QLopPlots::getPlot(m_defaultPlot);
}
if(plot)
plot->setTitle(File);
}
}
void CassiniTools::plot_TAB_File(const QString &fileName)
{
//TODO fix: accent not accepted
plotFile(fileName);
}
void CassiniTools::export_view(int PID)
{
SocExplorerPlot* plot = QLopPlots::getPlot(PID);
if(plot==NULL)
return;
{
QString fileName = QFileDialog::getSaveFileName();
}
}
QDockWidget *CassiniTools::getGUI()
{
if(!m_noGui && (m_gui==NULL))
{
m_gui=new QDockWidget("Cassini Tools");
m_CassiniToolsGUI = new CassiniToolsGUI();
m_gui->setWidget(m_CassiniToolsGUI);
m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
return m_gui;
}
const QString &CassiniTools::serviceName()
{
_INIT();
return m_serviceName;
}
void CassiniTools::dataReady(QLopDataList data)
{
SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
if(plot==NULL)
{
makePlot();
plot = QLopPlots::getPlot(m_defaultPlot);
}
if(plot)
{
plot->removeAllGraphs();
for(int i=0;i<data.count();i++)
{
plot->addGraph();
plot->setAdaptativeSampling(i,true);
plot->setUseFastVector(i,true);
QPen pen = plot->getGraphPen(i);
pen.setColor(QLopColours[i%QLopColoursCount]);
plot->setGraphPen(i,pen);
plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")");
plot->setGraphData(i,data.at(i)->data,false);
}
plot->rescaleAxis();
plot->replot();
}
}