##// 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
qlopplots.cpp
153 lines | 3.2 KiB | text/x-c | CppLexer
#include "qlopplots.h"
#include <QMainWindow>
QLopPlots* QLopPlots::_self=NULL;
SocExplorerPlot* QLopPlots::m_LastPlot=NULL;
QDockWidget* QLopPlots::m_gui=NULL;
QHash<int,SocExplorerPlot*>* QLopPlots::m_plots=NULL;
toolBarContainer* QLopPlots::m_DocContainer=NULL;
#define _INIT() if(Q_UNLIKELY(_self==NULL)){init();}
QLopPlots::QLopPlots(bool noGUI,QObject *parent)
{
m_noGui = noGUI;
m_serviceName = "QLopPlots";
m_plots = new QHash<int,SocExplorerPlot*>();
}
QLopPlots::~QLopPlots()
{
}
int QLopPlots::getPlotID()
{
_INIT();
for(int i=0;i<32768;i++)
{
if(!m_plots->contains(i))
{
return i;
}
}
return -1;
}
void QLopPlots::init(bool noGUI, QObject *parent)
{
if(Q_UNLIKELY(_self==NULL))
{
_self=new QLopPlots(noGUI,parent);
}
}
QLopPlots *QLopPlots::self()
{
_INIT();
return _self;
}
SocExplorerPlot *QLopPlots::getPlot(int plotID)
{
_INIT();
if(!_self->m_noGui && (m_gui==NULL))
{
m_gui=new QDockWidget("Plots");
m_DocContainer = new toolBarContainer();
// m_SocExplorerPlot = new SocExplorerPlot();
m_gui->setWidget(m_DocContainer);
m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
if(m_plots->contains(plotID))
{
return m_plots->value(plotID);
}
if(plotID==-1)
{
return m_LastPlot;
}
return NULL;
}
int QLopPlots::addPlot()
{
_INIT();
int pid=getPlotID();
if(pid!=-1)
{
SocExplorerPlot* plot=new SocExplorerPlot();
plot->setPID(pid);
m_plots->insert(pid,plot);
QDockWidget* dock = new QDockWidget();
dock->setWidget(plot);
dock->setAllowedAreas(Qt::AllDockWidgetAreas);
m_DocContainer->addDockWidget(Qt::TopDockWidgetArea,dock);
m_LastPlot=plot;
QObject::connect(plot,SIGNAL(titleChanged(QString)),dock,SLOT(setWindowTitle(QString)));
plot->setTitle(QString("Plot %1").arg(pid));
}
return pid;
}
bool QLopPlots::removePlot(int plotID)
{
_INIT();
if(m_plots->contains(plotID))
{
SocExplorerPlot* plot=m_plots->value(plotID);
m_plots->remove(plotID);
QDockWidget* dock=(QDockWidget*)plot->parentWidget();
m_DocContainer->removeDockWidget(dock);
if(plot==m_LastPlot)
{
//TODO may cause troubles...
m_LastPlot = NULL;
}
if(dock!=NULL)
{
delete dock;
}
if(plot!=NULL)
{
delete plot;
}
}
return false;
}
QDockWidget *QLopPlots::getGUI()
{
if(!m_noGui && (m_gui==NULL))
{
m_gui=new QDockWidget("Plots");
m_DocContainer = new toolBarContainer();
// m_SocExplorerPlot = new SocExplorerPlot();
m_gui->setWidget(m_DocContainer);
m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
return m_gui;
}
const QString &QLopPlots::serviceName()
{
return m_serviceName;
}
SocExplorerPlot *QLopPlots::get_plot(int plotID)
{
return getPlot(plotID);
}
int QLopPlots::add_plot()
{
return addPlot();
}
bool QLopPlots::remove_plot(int plotID)
{
return removePlot(plotID);
}