##// END OF EJS Templates
A lot of cleaning.
A lot of cleaning.

File last commit:

r4:b41a5ed0a855 default
r4:b41a5ed0a855 default
Show More
mainwindow.cpp
215 lines | 6.7 KiB | text/x-c | CppLexer
/*------------------------------------------------------------------------------
-- 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 "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDir>
#include "qcustomplot.h"
#include "filedownloader_old.h"
#include <omp.h>
#include <QAction>
#include <downloadhistory.h>
#include <QDateTime>
#include <QDate>
#include <filedownloader.h>
#include <themisdatadownloader.h>
Qt::GlobalColor QLopColours[]= {Qt::black,
Qt::red,
Qt::blue,
Qt::green,
Qt::darkGreen,
Qt::cyan,
Qt::darkRed,
Qt::gray,
Qt::yellow,
Qt::darkBlue,
Qt::darkCyan,
Qt::magenta,
Qt::darkMagenta,
Qt::darkYellow,
Qt::darkGray,
Qt::lightGray};
int QLopColoursCount=16;
MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
this->OMP_THREADS = OMP_THREADS;
ui->setupUi(this);
connect(this->ui->addViewerQpb,SIGNAL(clicked()),this,SLOT(addFolderView()));
connect(&this->fileReader,SIGNAL(dataReady(QListOfDataVector)),this,SLOT(dataReady(QListOfDataVector)));
connect(this->ui->actionIndex_Viewer,SIGNAL(triggered()),this,SLOT(showThemisIndexViewer()));
this->ui->Plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
this->ui->Plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
this->progressWidget = new QWidget();
this->progressLayout = new QVBoxLayout(this->progressWidget);
this->progressWidget->setLayout(this->progressLayout);
this->progressWidget->setWindowModality(Qt::WindowModal);
progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
for(int i=0;i<OMP_THREADS;i++)
{
this->progress.append(new QProgressBar(this->progressWidget));
this->progress.last()->setMinimum(0);
this->progress.last()->setMaximum(100);
connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int)));
this->progressLayout->addWidget(this->progress.last());
this->progressWidget->hide();
this->progressThreadIds[i] = -1;
}
this->progressWidget->setWindowTitle("Loading File");
this->themisIndexFileViewer = new ThemisIndexFileViewer();
this->ui->tabWidget->addTab(this->themisIndexFileViewer,"Themis Index Viewer");
this->downLoadHistory = FileDownloader::self()->getGUI();
qDebug()<<FileDownloader::self()->serviceName();
this->ui->tabWidget->addTab(new ThemisDataDownloader(),"Themis data downloader");
this->ui->tabWidget->addTab(this->downLoadHistory,"Download History");
}
MainWindow::~MainWindow()
{
delete ui;
}
QString MainWindow::getFilePath(const QString &name)
{
for(int i=0;i<this->folderViews.count();i++)
{
if(folderViews.at(i)->isDraging(name))
return folderViews.at(i)->currentFolder();
}
return "";
}
void MainWindow::itemDoubleClicked(QListWidgetItem* item)
{
if(item)
{
plotFile(item->text());
}
}
void MainWindow::plotFile(const QString &File)
{
if(!fileReader.isRunning())
{
for(int i=0;i<OMP_THREADS;i++)
{
this->progress.at(i)->setValue(0);
}
this->progressWidget->show();
fileReader.parseFile(File);
this->ui->Plot->setTitle(File);
}
}
void MainWindow::dataReady(QListOfDataVector data)
{
for(int i=0;i<OMP_THREADS;i++)
{
progressThreadIds[i]=-1;
}
this->progressWidget->hide();
this->ui->Plot->removeAllGraphs();
for(int i=0;i<data.count();i++)
{
this->ui->Plot->addGraph();
this->ui->Plot->setAdaptativeSampling(i,true);
this->ui->Plot->setUseFastVector(i,true);
QPen pen = this->ui->Plot->getGraphPen(i);
pen.setColor(QLopColours[i%QLopColoursCount]);
this->ui->Plot->setGraphPen(i,pen);
this->ui->Plot->setGraphName(i,data.at(i).name+"("+data.at(i).unit+")");
this->ui->Plot->setGraphData(i,data.at(i).data,false);
}
this->ui->Plot->rescaleAxis();
this->ui->Plot->replot();
}
void MainWindow::updateProgress(int threadId, int percentProgress)
{
bool updated=false;
for(int i=0;i<OMP_THREADS;i++)
{
if(progressThreadIds[i]==threadId)
{
if(threadId<this->progress.count())
{
this->progress.at(i)->setValue(percentProgress);
updated=true;
}
}
}
if(Q_UNLIKELY(updated==false))
{
for(int i=0;i<OMP_THREADS;i++)
{
if(progressThreadIds[i]==-1)
{
progressThreadIds[i] = threadId;
updateProgress(threadId,percentProgress);
return;
}
}
}
}
void MainWindow::addFolderView()
{
this->folderViews.append(new FolderView(this));
this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last());
this->folderViews.last()->setWindowTitle( QString("Folder View %1").arg(this->folderViews.length()));
this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas);
connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString)));
}
void MainWindow::askGlobalRescan()
{
for(int i=0;i<this->folderViews.count();i++)
{
this->folderViews.at(i)->refreshFolder();
}
}
void MainWindow::showThemisIndexViewer()
{
this->themisIndexFileViewer->show();
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}