Commit 7070c406 authored by Edlira Nano's avatar Edlira Nano
Browse files

added runningBarr + thread loading msruns + discard msruns

git-svn-id: https://subversion.renater.fr/masschroq/trunk@2252 e4b6dbb4-9209-464b-83f7-6257456c460c
parent a242821b
......@@ -58,8 +58,8 @@ if (NOT CMAKE_INSTALL_PREFIX)
SET (CMAKE_INSTALL_PREFIX /usr/local)
endif (NOT CMAKE_INSTALL_PREFIX)
#SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
SET(CMAKE_BUILD_TYPE "Release")
#SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
#SET( CMAKE_BUILD_TYPE "Debug")
IF(CMAKE_BUILD_TYPE MATCHES "Release")
......
......@@ -135,19 +135,20 @@ SET(GUI_SRCS
./gui/xicProfile.cpp
./gui/xicPlot.cpp
./gui/plot.cpp
./gui/mcqThread.cpp
./gui/msrunLoaderThread.cpp
./gui/runningBarr.cpp
)
# another list, this time it includes all header files that should be treated with moc
SET(GUI_MOC_HDRS
./gui/plotStyle.h
./gui/gui_types.h
./gui/mainwindow.h
./gui/xicSelectionWidget.h
./gui/xicProfile.h
./gui/xicPlot.h
./gui/plot.h
./gui/mcqThread.h
./gui/msrunLoaderThread.h
./gui/runningBarr.h
)
set(CMAKE_MODULE_PATH ${masschroq_SOURCE_DIR}/modules)
......
......@@ -2,9 +2,9 @@
#include "mainwindow.h"
int main(int argc, char ** argv) {
QApplication app(argc, argv);
MainWindow window;
window.show();
......
......@@ -6,15 +6,13 @@
#include <QProgressDialog>
#include <QApplication>
#include <QTimer>
#include <QCloseEvent>
#include "mainwindow.h"
#include "xicSelectionWidget.h"
#include "xicProfile.h"
#include "xicPlot.h"
//#include "msrunLoaderThread.h"
MainWindow::MainWindow(QWidget *parent)
:
......@@ -28,17 +26,18 @@ MainWindow::MainWindow(QWidget *parent)
_plot_area = new Plot(this);
setCentralWidget(_plot_area);
//_plot = new XicPlot(this);
//const int margin = 4;
//d_plot->setContentsMargins( margin, margin, margin, margin);
//setCentralWidget(_plot);
setWindowTitle(tr("MassChroQ GUI"));
createActions();
createActions();
createMenus();
//createToolBars();
createStatusBar();
_msrun_loader_thread.setMaxProgress(4);
connect(&_msrun_loader_thread, SIGNAL(loadedMsrun(Msrun *)),
this, SLOT(doneLoading(Msrun *)));
}
void
......@@ -91,47 +90,72 @@ MainWindow::createActions() {
_aboutAct->setStatusTip(tr("About MassChroQ GUI"));
connect(_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
}
void
MainWindow::closeEvent(QCloseEvent * event) {
if (maybeSave()) {
discardCurrentMsrun();
event->accept();
} else {
event->ignore();
}
}
bool
MainWindow::maybeSave() {
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("MassChroQ GUI"),
tr("The xic plots have been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
return save();
else if (ret == QMessageBox::Cancel)
return false;
}
bool
MainWindow::save() {
return true;
}
void
MainWindow::loadMsrun() {
QString filename = QFileDialog::getOpenFileName(this, tr("Open Msrun File"),
QString::null,
tr("mzXML or mzML files (*.mzXML *.mzML)"));
if (!filename.isEmpty()) {
_current_msrun_file = filename;
_progressDialog = new QProgressDialog(QObject::tr("Loading MS run %1...").arg(strippedFilename(filename)), QObject::tr("Cancel"), 0, 2, this);
_progressDialog->setValue(0);
QApplication::processEvents();
connect(&_msrun_loader_thread, SIGNAL(loadedMsrun(Msrun *)),
this, SLOT(doneLoading(Msrun *)));
discardCurrentMsrun();
_current_msrun_file = filename;
QString progressTitle(QObject::tr("Loading '%1'...").arg(strippedFilename(filename)));
_runningBarr = new RunningBarr(this, &_msrun_loader_thread, progressTitle);
_runningBarr->setTimer();
// launch _msrun_loader_thread
_masschroq_gui->setMsRun(filename, &_msrun_loader_thread);
//QApplication::processEvents();
} else {
QTimer * timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateProgress()));
timer->start(1000);
}
}
void
MainWindow::updateProgress() {
if (! _msrun_loader_thread.isFinished()) {
unsigned int progress = _msrun_loader_thread.getProgressValue();
_progressDialog->setValue(progress);
}
MainWindow::discardCurrentMsrun() {
_masschroq_gui->deleteMsrun(_current_msrun_file);
_current_msrun_file.clear();
}
void
MainWindow::doneLoading(Msrun * msrun) {
QString filename = (msrun->getXmlFileInfo()).filePath();
_masschroq_gui->addMsRun(filename, msrun);
_masschroq_gui->addMsrun(filename, msrun);
this->statusBar()->showMessage(QObject::tr("MS run '%1' loaded").arg(filename), 4000);
this->setPlotAreaTitle(filename);
delete _runningBarr;
}
......
/*
*
* MassChroQ: Mass Chromatogram Quantification software.
* Copyright (C) 2010 Olivier Langella, Edlira Nano, Benoit Valot, Michel Zivy.
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope thatx 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, see <http://www.gnu.org/licenses/>.
*
*/
/**
* \file mainwindow.h
* \date November 10, 2011
* \author Edlira Nano
*/
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_ 1
#include <QMainWindow>
#include <QMenu>
#include <QToolBar>
#include <QAction>
#include <QProgressDialog>
#include "masschroq_gui.h"
#include "plot.h"
#include "runningBarr.h"
#include "msrunLoaderThread.h"
class MainWindow : public QMainWindow
......@@ -17,8 +46,8 @@ public:
MainWindow(QWidget * parent = 0);
void setPlotAreaTitle(const QString & filename);
private slots:
private slots:
void loadMsrun();
void extractXicWidget();
......@@ -27,12 +56,11 @@ private slots:
void filterXic();
void about();
void doneLoading(Msrun * msrun);
void updateProgress();
protected:
//void closeEvent(QCloseEvent *event);
void closeEvent(QCloseEvent *event);
private:
......@@ -42,6 +70,11 @@ private:
void createStatusBar();
//void createDockWindows();
//void createToolbars();
bool maybeSave();
bool save();
void discardCurrentMsrun();
QString strippedFilename(const QString & fullFilename);
......@@ -65,10 +98,12 @@ private:
QAction * _aboutAct;
QAction * _quitAct;
QProgressDialog * _progressDialog;
RunningBarr * _runningBarr;
MsrunLoaderThread _msrun_loader_thread;
QString _current_msrun_file;
std::vector<XicProfile *> _xic_profiles;
};
#endif /* MAINWINDOW_H_ */
......@@ -92,17 +92,16 @@ MasschroqGui::setMsRun(const QString & filename,
msgBox.exec();
return;
}
}
void
MasschroqGui::addMsRun(const QString & filename, Msrun * msrun) {
MasschroqGui::addMsrun(const QString & filename, Msrun * msrun) {
_msrun_map[filename] = msrun;
_current_loaded_msrun = msrun;
}
Msrun *
MasschroqGui::getMsRun(const QString & filename) const {
MasschroqGui::getMsrun(const QString & filename) const {
std::map<QString, Msrun *>::const_iterator it;
it = _msrun_map.find(filename);
if (it == _msrun_map.end()) {
......@@ -112,12 +111,22 @@ MasschroqGui::getMsRun(const QString & filename) const {
}
}
void
MasschroqGui::deleteMsrun(const QString & filename) {
std::map<QString, Msrun *>::iterator it;
it = _msrun_map.find(filename);
if (it != _msrun_map.end()) {
(it->second)->doneWithSpectra();
_msrun_map.erase(it);
}
}
void
MasschroqGui::extractXicProfile(XicProfile * xic_profile,
const QString & msrun_filename,
XicSelectionWidget * xic) {
Msrun * msrun = getMsRun(msrun_filename);
Msrun * msrun = getMsrun(msrun_filename);
if (msrun == NULL) {
QMessageBox msgBox;
......
......@@ -36,7 +36,7 @@
class XicProfile;
class XicSelectionWidget;
class MainWindow;
class QProgressDialog;
//class QProgressDialog;
class MsrunLoaderThread;
/**
......@@ -59,11 +59,13 @@ class MasschroqGui {
const QString & msrun_filename,
XicSelectionWidget * xic);
void addMsRun(const QString & filename, Msrun * msrun);
void addMsrun(const QString & filename, Msrun * msrun);
void deleteMsrun(const QString & filename);
private :
Msrun * getMsRun(const QString & filename) const;
Msrun * getMsrun(const QString & filename) const;
QString strippedFilename(const QString & fullFilename);
......
/**
* \file mcqThread.cpp
* \date December 09, 2011
* \author Edlira Nano
*/
#include "mcqThread.h"
McqThread::McqThread(QObject * parent, const unsigned int maxProgress)
:
QThread(parent)
{
setMaxProgress(maxProgress);
}
McqThread::~McqThread() {
}
void
McqThread::setMaxProgress(const unsigned int value) {
_progressMutex.lock();
_maxProgressValue = value;
_progressMutex.unlock();
}
const unsigned int
McqThread::getProgressValue() {
_progressMutex.lock();
unsigned int ret= _progressValue;
_progressMutex.unlock();
return ret;
}
void
McqThread::incrementProgressValue() {
_progressMutex.lock();
_progressValue++;
_progressMutex.unlock();
}
void
McqThread::setProgressValue(const unsigned int val) {
_progressMutex.lock();
_progressValue = val;
_progressMutex.unlock();
}
const unsigned int
McqThread::getMaxProgress() {
_progressMutex.lock();
unsigned int ret = _maxProgressValue;
_progressMutex.unlock();
return ret;
}
/*
*
* MassChroQ: Mass Chromatogram Quantification software.
* Copyright (C) 2010 Olivier Langella, Edlira Nano, Benoit Valot, Michel Zivy.
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope thatx 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, see <http://www.gnu.org/licenses/>.
*
*/
/**
* \file mcqThread.h
* \date December 19, 2011
* \author Edlira Nano
*/
#ifndef MCQ_THREAD_H_
#define MCQ_THREAD_H_ 1
#include <QThread>
#include <QMutex>
class McqThread : public QThread {
Q_OBJECT
public:
McqThread(QObject * parent = 0, const unsigned int maxProgress = 0);
~McqThread();
const unsigned int getProgressValue();
void setMaxProgress(const unsigned int value);
const unsigned int getMaxProgress();
protected :
virtual void run() = 0;
void setProgressValue(const unsigned int val);
void incrementProgressValue();
private :
QMutex _progressMutex;
unsigned int _maxProgressValue;
unsigned int _progressValue;
};
#endif /* MCQ_THREAD_H_ */
......@@ -6,23 +6,20 @@
#include "msrunLoaderThread.h"
MsrunLoaderThread::MsrunLoaderThread(QObject * parent)
MsrunLoaderThread::MsrunLoaderThread(QObject * parent, const unsigned int maxProgress)
:
QThread(parent)
McqThread(parent, maxProgress)
{
restart = false;
abort = false;
_restart = false;
_abort = false;
}
MsrunLoaderThread::~MsrunLoaderThread() {
mutex.lock();
abort = true;
condition.wakeOne();
mutex.unlock();
_mutex.lock();
_abort = true;
_condition.wakeOne();
_mutex.unlock();
wait();
}
......@@ -31,6 +28,7 @@ void
MsrunLoaderThread::loadMsrun(Msrun * msrun,
const QString & filename,
const mcq_xml_format & format) {
setProgressValue(0);
_current_msrun = msrun;
_msrun_filename = filename;
_msrun_format = format;
......@@ -38,56 +36,45 @@ MsrunLoaderThread::loadMsrun(Msrun * msrun,
if (!isRunning()) {
start();
} else {
restart = true;
condition.wakeOne();
_restart = true;
_condition.wakeOne();
}
}
const unsigned int
MsrunLoaderThread::getProgressValue() {
progressMutex.lock();
unsigned int return_value = _progressValue;
progressMutex.unlock();
return return_value;
}
void
MsrunLoaderThread::run() {
forever {
mutex.lock();
incrementProgressValue();
_mutex.lock();
Msrun * msrun = this->_current_msrun;
QString filename = this->_msrun_filename;
mcq_xml_format format = this->_msrun_format;
mutex.unlock();
if (restart) {
_mutex.unlock();
if (_restart) {
break;
}
if (abort) {
if (_abort) {
return;
}
msrun->set_from_xml(filename, format);
progressMutex.lock();
_progressValue = 1;
progressMutex.unlock();
msrun->prepareSpectraForQuantification(NULL);
progressMutex.lock();
_progressValue = 2;
progressMutex.unlock();
if (!restart)
emit loadedMsrun(msrun);
mutex.lock();
if (!restart)
condition.wait(&mutex);
restart = false;
mutex.unlock();
msrun->set_from_xml(filename, format);
incrementProgressValue();
msrun->prepareSpectraForQuantification(NULL);
setProgressValue(getMaxProgress());
if (!_restart)
emit loadedMsrun(msrun);
_mutex.lock();
if (!_restart)
_condition.wait(&_mutex);
_restart = false;
_mutex.unlock();
}
}
......@@ -27,11 +27,9 @@
#ifndef MSRUN_LOADER_THREAD_H_
#define MSRUN_LOADER_THREAD_H_ 1
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QProgressDialog>
#include "mcqThread.h"
#include "../lib/msrun/msrun.h"
/**
......@@ -39,40 +37,36 @@
* \brief The thread that loads MSrun files in the MassChroq GUI.
*/
class MsrunLoaderThread : public QThread {
class MsrunLoaderThread : public McqThread {
Q_OBJECT
public:
MsrunLoaderThread(QObject *parent = 0);
~MsrunLoaderThread();
void loadMsrun(Msrun * msrun,
const QString & filename,
const mcq_xml_format & format);
const unsigned int getProgressValue();
public:
MsrunLoaderThread(QObject * parent = 0, const unsigned int maxProgress = 0);
~MsrunLoaderThread();
void loadMsrun(Msrun * msrun,
const QString & filename,