mainwindow.cpp
215 lines
| 6.7 KiB
| text/x-c
|
CppLexer
/ src / mainwindow.cpp
r0 | /*------------------------------------------------------------------------------ | |||
-- 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" | ||||
r4 | #include "filedownloader_old.h" | |||
r0 | #include <omp.h> | |||
r4 | #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; | ||||
r0 | ||||
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())); | ||||
r4 | connect(&this->fileReader,SIGNAL(dataReady(QListOfDataVector)),this,SLOT(dataReady(QListOfDataVector))); | |||
connect(this->ui->actionIndex_Viewer,SIGNAL(triggered()),this,SLOT(showThemisIndexViewer())); | ||||
r0 | 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); | ||||
r1 | progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); | |||
r0 | 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(); | ||||
r1 | this->progressThreadIds[i] = -1; | |||
r0 | } | |||
this->progressWidget->setWindowTitle("Loading File"); | ||||
r4 | 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"); | ||||
r0 | } | |||
MainWindow::~MainWindow() | ||||
{ | ||||
delete ui; | ||||
} | ||||
r1 | 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 ""; | ||||
} | ||||
r0 | ||||
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); | ||||
r2 | this->ui->Plot->setTitle(File); | |||
r0 | } | |||
} | ||||
r4 | void MainWindow::dataReady(QListOfDataVector data) | |||
r3 | { | |||
for(int i=0;i<OMP_THREADS;i++) | ||||
{ | ||||
progressThreadIds[i]=-1; | ||||
} | ||||
this->progressWidget->hide(); | ||||
r4 | 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); | ||||
} | ||||
r3 | this->ui->Plot->rescaleAxis(); | |||
this->ui->Plot->replot(); | ||||
} | ||||
r0 | ||||
void MainWindow::updateProgress(int threadId, int percentProgress) | ||||
{ | ||||
r1 | bool updated=false; | |||
for(int i=0;i<OMP_THREADS;i++) | ||||
{ | ||||
if(progressThreadIds[i]==threadId) | ||||
{ | ||||
r2 | if(threadId<this->progress.count()) | |||
{ | ||||
r4 | this->progress.at(i)->setValue(percentProgress); | |||
r2 | updated=true; | |||
} | ||||
r1 | } | |||
} | ||||
if(Q_UNLIKELY(updated==false)) | ||||
{ | ||||
for(int i=0;i<OMP_THREADS;i++) | ||||
{ | ||||
if(progressThreadIds[i]==-1) | ||||
{ | ||||
progressThreadIds[i] = threadId; | ||||
updateProgress(threadId,percentProgress); | ||||
r4 | return; | |||
r1 | } | |||
} | ||||
} | ||||
r0 | } | |||
void MainWindow::addFolderView() | ||||
{ | ||||
r1 | this->folderViews.append(new FolderView(this)); | |||
r0 | this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last()); | |||
r1 | this->folderViews.last()->setWindowTitle( QString("Folder View %1").arg(this->folderViews.length())); | |||
r0 | this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas); | |||
connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString))); | ||||
r1 | ||||
r0 | } | |||
r1 | void MainWindow::askGlobalRescan() | |||
{ | ||||
for(int i=0;i<this->folderViews.count();i++) | ||||
{ | ||||
this->folderViews.at(i)->refreshFolder(); | ||||
r4 | } | |||
} | ||||
void MainWindow::showThemisIndexViewer() | ||||
{ | ||||
this->themisIndexFileViewer->show(); | ||||
r1 | } | |||
r0 | void MainWindow::changeEvent(QEvent *e) | |||
{ | ||||
QMainWindow::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
ui->retranslateUi(this); | ||||
break; | ||||
default: | ||||
break; | ||||
} | ||||
} | ||||