##// END OF EJS Templates
added missing GPL headers...
added missing GPL headers fixed move/zoom issue on plot with log scale

File last commit:

r11:f1a4e3a7ca04 default
r11:f1a4e3a7ca04 default
Show More
expxmldownloader.cpp
141 lines | 3.8 KiB | text/x-c | CppLexer
/ src / Cassini / expxmldownloader.cpp
/*------------------------------------------------------------------------------
-- 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 "expxmldownloader.h"
#include <QDebug>
#include <QFile>
#include <QQueue>
#include <QDate>
#include <QDateTime>
ExpXmlDownLoader::ExpXmlDownLoader(QObject *parent) : QObject(parent)
{
this->m_doc = NULL;
}
ExpXmlDownLoader::~ExpXmlDownLoader()
{
}
bool ExpXmlDownLoader::parseXml(const QString &fileName)
{
QQueue<QString> nodes;
nodes<<"RESOURCE"<<"TABLE"<<"DATA"<<"TABLEDATA";
if(m_doc!=NULL)
delete m_doc;
m_doc = new QDomDocument(fileName);
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return false;
if (!m_doc->setContent(&file)) {
file.close();
return false;
}
file.close();
if(m_doc->isNull())
{
delete m_doc;
return false;
}
QDomElement docElem = m_doc->documentElement();
QDomNode n = docElem.firstChild();
while(!n.isNull() && !nodes.empty())
{
if(n.toElement().tagName()==nodes.head())
{
nodes.dequeue();
n=n.firstChild();
}
else
{
n = n.nextSibling();
}
}
extractIntervals(n);
makeDownloadList();
return true;
}
const QList<QDate> &ExpXmlDownLoader::daysToDownload()
{
return m_FilesToDownload;
}
void ExpXmlDownLoader::extractIntervals(QDomNode n)
{
QDomNode inter;
m_intervals.clear();
while(!n.isNull())
{
if(n.toElement().tagName()=="TR")
{
ExpXmlDownLoaderIntervals interval;
inter=n.firstChild();
if(inter.toElement().tagName()=="TD")
{
interval.start = inter.toElement().text();
}
inter=inter.nextSibling();
if(inter.toElement().tagName()=="TD")
{
interval.stop = inter.toElement().text();
}
m_intervals.append(interval);
}
n = n.nextSibling();
}
}
void ExpXmlDownLoader::makeDownloadList()
{
for(int i=0;i<m_intervals.count();i++)
{
QList<QDate> daysToDl;
QDateTime start,stop;
start=start.fromString(m_intervals[i].start,Qt::ISODate);
stop=stop.fromString(m_intervals[i].stop,Qt::ISODate);
int days=start.daysTo(stop);
daysToDl.append(start.date());
if(days)
{
for(int j=0;j<days;j++)
{
daysToDl.append(start.addDays(j+1).date());
}
}
addDaysToDownload(daysToDl);
}
qDebug()<<m_FilesToDownload.count();
}
void ExpXmlDownLoader::addDaysToDownload(QList<QDate> days)
{
for(int i=0;i<days.count();i++)
{
if(!m_FilesToDownload.contains(days.at(i)))
{
m_FilesToDownload.append(days.at(i));
}
}
}