|
|
/*------------------------------------------------------------------------------
|
|
|
-- This file is a part of the QLop Software
|
|
|
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
|
|
|
--
|
|
|
-- This program is free software; you can redistribute it and/or modify
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
|
|
-- (at your option) any later version.
|
|
|
--
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
-- GNU General Public License for more details.
|
|
|
--
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
-- along with this program; if not, write to the Free Software
|
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
-------------------------------------------------------------------------------*/
|
|
|
/*-- Author : Alexis Jeandet
|
|
|
-- Mail : alexis.jeandet@member.fsf.org
|
|
|
----------------------------------------------------------------------------*/
|
|
|
|
|
|
#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);
|
|
|
}
|
|
|
|
|
|
|