qlopdatabase.cpp
161 lines
| 3.7 KiB
| text/x-c
|
CppLexer
r15 | /*------------------------------------------------------------------------------ | |||
-- 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 | ||||
----------------------------------------------------------------------------*/ | ||||
r12 | #include "qlopdatabase.h" | |||
r14 | #include <qlopdatabaseviewer.h> | |||
r12 | ||||
QList<QLopData*>* QLopDataBase::m_dataBase=NULL; | ||||
QLopDataBase* QLopDataBase::_self=NULL; | ||||
r14 | QDockWidget* QLopDataBase::m_gui=NULL; | |||
r12 | ||||
#define INIT() \ | ||||
if(Q_UNLIKELY(_self==NULL))\ | ||||
{\ | ||||
init();\ | ||||
} | ||||
r14 | QLopDataBase::QLopDataBase(bool noGUI,QObject *parent) : QLopService(parent) | |||
r12 | { | |||
this->m_dataBase = new QList<QLopData*>(); | ||||
r14 | m_serviceName="QLopDataBase"; | |||
m_noGui=noGUI; | ||||
r12 | } | |||
QLopDataBase::~QLopDataBase() | ||||
{ | ||||
} | ||||
r14 | QDockWidget *QLopDataBase::getGUI() | |||
{ | ||||
if(!m_noGui && (m_gui==NULL)) | ||||
{ | ||||
m_gui=new QLopDataBaseViewer(); | ||||
m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | ||||
} | ||||
return m_gui; | ||||
} | ||||
void QLopDataBase::init(bool noGUI, QObject *parent) | ||||
r12 | { | |||
r15 | _self=new QLopDataBase(noGUI,parent); | |||
r12 | } | |||
r14 | const QString &QLopDataBase::serviceName() | |||
{ | ||||
INIT(); | ||||
return m_serviceName; | ||||
} | ||||
r12 | int QLopDataBase::addData(QLopData *data) | |||
{ | ||||
INIT(); | ||||
if(!m_dataBase->contains(data)) | ||||
{ | ||||
m_dataBase->append(data); | ||||
r14 | emit QLopDataBase::self()->DBChanged(); | |||
r12 | return 1; | |||
} | ||||
return 0; | ||||
} | ||||
int QLopDataBase::addData(const QLopDataList& data) | ||||
{ | ||||
INIT(); | ||||
int addedData=0; | ||||
for (int i = 0; i < data.count(); i++) | ||||
{ | ||||
addedData += addData(data.at(i)); | ||||
} | ||||
r14 | emit QLopDataBase::self()->DBChanged(); | |||
r12 | return addedData; | |||
} | ||||
r14 | int QLopDataBase::removeData(QLopData *data) | |||
{ | ||||
INIT(); | ||||
if(m_dataBase->contains(data)) | ||||
{ | ||||
m_dataBase->removeAll(data); | ||||
emit QLopDataBase::self()->DBChanged(); | ||||
return 1; | ||||
} | ||||
return 0; | ||||
} | ||||
int QLopDataBase::removeData(const QLopDataList &data) | ||||
{ | ||||
INIT(); | ||||
int removedData=0; | ||||
for (int i = 0; i < data.count(); i++) | ||||
{ | ||||
removedData += removeData(data.at(i)); | ||||
} | ||||
emit QLopDataBase::self()->DBChanged(); | ||||
return removedData; | ||||
} | ||||
r12 | QLopDataBase *QLopDataBase::self() | |||
{ | ||||
INIT(); | ||||
return _self; | ||||
} | ||||
int QLopDataBase::count() | ||||
{ | ||||
r14 | INIT(); | |||
r12 | return m_dataBase->count(); | |||
} | ||||
QLopData *QLopDataBase::getData(const QString &name) | ||||
{ | ||||
r14 | INIT(); | |||
r12 | for (int i = 0; i < m_dataBase->count(); i++) | |||
{ | ||||
if(Q_UNLIKELY(m_dataBase->at(i)->name==name)) | ||||
{ | ||||
return m_dataBase->at(i); | ||||
} | ||||
} | ||||
return NULL; | ||||
} | ||||
QLopData *QLopDataBase::getData(int ID) | ||||
{ | ||||
r14 | INIT(); | |||
r12 | for (int i = 0; i < m_dataBase->count(); i++) | |||
{ | ||||
if(Q_UNLIKELY(m_dataBase->at(i)->ID==ID)) | ||||
{ | ||||
return m_dataBase->at(i); | ||||
} | ||||
} | ||||
return NULL; | ||||
} | ||||
r13 | QLopData *QLopDataBase::getDataFromIdex(int index) | |||
{ | ||||
if((index>=0)&&(index<m_dataBase->count())) | ||||
return m_dataBase->at(index); | ||||
else | ||||
return NULL; | ||||
} | ||||