qlopplots.cpp
175 lines
| 4.3 KiB
| text/x-c
|
CppLexer
r11 | /*------------------------------------------------------------------------------ | |||
-- 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 | ||||
----------------------------------------------------------------------------*/ | ||||
r5 | #include "qlopplots.h" | |||
r6 | #include <QMainWindow> | |||
r5 | ||||
QLopPlots* QLopPlots::_self=NULL; | ||||
r6 | SocExplorerPlot* QLopPlots::m_LastPlot=NULL; | |||
r5 | QDockWidget* QLopPlots::m_gui=NULL; | |||
r6 | QHash<int,SocExplorerPlot*>* QLopPlots::m_plots=NULL; | |||
toolBarContainer* QLopPlots::m_DocContainer=NULL; | ||||
r5 | ||||
#define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} | ||||
QLopPlots::QLopPlots(bool noGUI,QObject *parent) | ||||
{ | ||||
m_noGui = noGUI; | ||||
m_serviceName = "QLopPlots"; | ||||
r6 | m_plots = new QHash<int,SocExplorerPlot*>(); | |||
r5 | } | |||
QLopPlots::~QLopPlots() | ||||
{ | ||||
} | ||||
r6 | int QLopPlots::getPlotID() | |||
{ | ||||
_INIT(); | ||||
for(int i=0;i<32768;i++) | ||||
{ | ||||
if(!m_plots->contains(i)) | ||||
{ | ||||
return i; | ||||
} | ||||
} | ||||
return -1; | ||||
} | ||||
r5 | void QLopPlots::init(bool noGUI, QObject *parent) | |||
{ | ||||
if(Q_UNLIKELY(_self==NULL)) | ||||
{ | ||||
_self=new QLopPlots(noGUI,parent); | ||||
} | ||||
} | ||||
QLopPlots *QLopPlots::self() | ||||
{ | ||||
_INIT(); | ||||
return _self; | ||||
} | ||||
r6 | SocExplorerPlot *QLopPlots::getPlot(int plotID) | |||
r5 | { | |||
_INIT(); | ||||
if(!_self->m_noGui && (m_gui==NULL)) | ||||
{ | ||||
m_gui=new QDockWidget("Plots"); | ||||
r6 | m_DocContainer = new toolBarContainer(); | |||
// m_SocExplorerPlot = new SocExplorerPlot(); | ||||
m_gui->setWidget(m_DocContainer); | ||||
r5 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |||
} | ||||
r6 | 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(); | ||||
r7 | plot->setPID(pid); | |||
r6 | 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; | ||||
r5 | } | |||
QDockWidget *QLopPlots::getGUI() | ||||
{ | ||||
if(!m_noGui && (m_gui==NULL)) | ||||
{ | ||||
m_gui=new QDockWidget("Plots"); | ||||
r6 | m_DocContainer = new toolBarContainer(); | |||
// m_SocExplorerPlot = new SocExplorerPlot(); | ||||
m_gui->setWidget(m_DocContainer); | ||||
r5 | m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | |||
} | ||||
return m_gui; | ||||
} | ||||
const QString &QLopPlots::serviceName() | ||||
{ | ||||
return m_serviceName; | ||||
} | ||||
r6 | SocExplorerPlot *QLopPlots::get_plot(int plotID) | |||
r5 | { | |||
r6 | return getPlot(plotID); | |||
r5 | } | |||
r6 | int QLopPlots::add_plot() | |||
{ | ||||
return addPlot(); | ||||
} | ||||
bool QLopPlots::remove_plot(int plotID) | ||||
{ | ||||
return removePlot(plotID); | ||||
} | ||||