From 494a5dab15be99f02a2ed94640a23588037dede0 Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Tue, 23 Aug 2016 21:39:36 +0200 Subject: [PATCH] first protein table view --- src/core/project.cpp | 7 ++++- src/core/project.h | 7 +++-- src/files/xpipfile.cpp | 6 +++++ src/files/xpipfile.h | 2 ++ src/gui/main.ui | 24 +++++++++++++++-- src/gui/mainwindow.cpp | 26 +++++++++++++++++++ src/gui/mainwindow.h | 13 +++++++--- .../protein_list_view/proteinlistwindow.cpp | 12 ++++++--- src/gui/protein_list_view/proteinlistwindow.h | 3 +++ .../protein_list_view/proteintablemodel.cpp | 20 +++++++++++++- src/gui/protein_list_view/proteintablemodel.h | 7 +++++ src/input/xpipsaxhandler.cpp | 11 +++++--- 12 files changed, 120 insertions(+), 18 deletions(-) diff --git a/src/core/project.cpp b/src/core/project.cpp index 2d848022..af17bcbd 100644 --- a/src/core/project.cpp +++ b/src/core/project.cpp @@ -78,5 +78,10 @@ void Project::readXpipFile(QFileInfo xpip_fileinfo) { } -void Project::addProteinSp(pappso::ProteinSp makeProteinSp) { +void Project::addProteinSp(pappso::ProteinSp protein_sp) { + _protein_list.push_back(protein_sp); } + + std::vector<pappso::ProteinSp> & Project::getProteinList() { + return _protein_list; + } \ No newline at end of file diff --git a/src/core/project.h b/src/core/project.h index 49338ace..07ea7a3a 100644 --- a/src/core/project.h +++ b/src/core/project.h @@ -39,9 +39,12 @@ public: ProjectSp makeProjectSp() const; void readXpipFile(QFileInfo xpip_source); - void addProteinSp(pappso::ProteinSp makeProteinSp); + void addProteinSp(pappso::ProteinSp protein_sp); + std::vector<pappso::ProteinSp> & getProteinList(); - pappso::GrpExperiment * _p_grp_experiment= nullptr; + pappso::GrpExperiment * _p_grp_experiment= nullptr; +private : + std::vector<pappso::ProteinSp> _protein_list; }; #endif // PROJECT_H diff --git a/src/files/xpipfile.cpp b/src/files/xpipfile.cpp index e5e55f04..d3aa2cea 100644 --- a/src/files/xpipfile.cpp +++ b/src/files/xpipfile.cpp @@ -24,6 +24,12 @@ XpipFile::XpipFile(const QUrl & xpip_source) : _xpip_source(xpip_source) { +} + + + XpipFile::XpipFile(const QFileInfo & xpip_source): _xpip_source(xpip_source.absoluteFilePath()) +{ + } XpipFile::~XpipFile() diff --git a/src/files/xpipfile.h b/src/files/xpipfile.h index 86d162f2..666be151 100644 --- a/src/files/xpipfile.h +++ b/src/files/xpipfile.h @@ -23,12 +23,14 @@ #define XPIPFILE_H #include <QUrl> +#include <QFileInfo> #include "../core/project.h" class XpipFile { public: XpipFile(const QUrl & xpip_source); + XpipFile(const QFileInfo & xpip_source); ~XpipFile(); ProjectSp getProjectSp() const; diff --git a/src/gui/main.ui b/src/gui/main.ui index c9ed6bdc..960706c9 100644 --- a/src/gui/main.ui +++ b/src/gui/main.ui @@ -20,7 +20,7 @@ <x>0</x> <y>0</y> <width>286</width> - <height>22</height> + <height>19</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -39,5 +39,25 @@ </action> </widget> <resources/> - <connections/> + <connections> + <connection> + <sender>actionLoad</sender> + <signal>triggered()</signal> + <receiver>Main</receiver> + <slot>selectXpipFile()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>142</x> + <y>185</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>selectXpipFile()</slot> + </slots> </ui> diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index e368dee9..1bf9b7dd 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -22,9 +22,12 @@ ******************************************************************************/ #include <QDockWidget> +#include <QSettings> +#include <QFileDialog> #include "mainwindow.h" #include "ui_main.h" +#include "files/xpipfile.h" MainWindow::MainWindow(QWidget *parent): @@ -69,3 +72,26 @@ MainWindow::~MainWindow() delete ui; } + + +void MainWindow::selectXpipFile() { + + QSettings settings; + QString default_location = settings.value("path/xpipfile", "").toString(); + + QString filename = QFileDialog::getOpenFileName(this, + tr("Open XPIP File"), default_location, + tr("xpip files (*.xpip);;all files (*)")); + + if (filename.isEmpty()) { + return; + } + QFileInfo new_xpip_file; + new_xpip_file.setFile(filename); + + XpipFile xpip_file(new_xpip_file); + + _project_sp = xpip_file.getProjectSp(); + _protein_list_window->setProject(_project_sp.get()); + +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index eeb5495c..4603e576 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -34,6 +34,7 @@ #include <pwiz/data/msdata/MSDataFile.hpp> #include "../utils/readspectrum.h" #include "protein_list_view/proteinlistwindow.h" +#include "core/project.h" @@ -45,7 +46,7 @@ class Main; class PwizLoaderThread : public QObject { Q_OBJECT - public: +public: public slots: void doMsDataFileLoad(const QString & parameter) { @@ -58,7 +59,7 @@ signals: void msDataReady(pwiz::msdata::MSDataFile * p_ms_data_file); }; -class MainWindow: public QMainWindow { +class MainWindow: public QMainWindow { Q_OBJECT QThread workerThread; @@ -68,6 +69,7 @@ public: ~MainWindow(); public slots: + void selectXpipFile(); //void peptideEdited(QString peptideStr); // void setColor(const QColor &color); // void setShape(Shape shape); @@ -76,10 +78,13 @@ signals: private: Ui::Main *ui; - - + + ProteinListWindow * _protein_list_window=nullptr; +private : + ProjectSp _project_sp=nullptr; + }; #endif // MAINWINDOW_H diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp index 7c646b25..55f272bc 100644 --- a/src/gui/protein_list_view/proteinlistwindow.cpp +++ b/src/gui/protein_list_view/proteinlistwindow.cpp @@ -24,7 +24,6 @@ #include "proteinlistwindow.h" #include "ui_protein_view.h" -#include "proteintablemodel.h" ProteinListWindow::ProteinListWindow(QWidget *parent): @@ -51,8 +50,8 @@ ProteinListWindow::ProteinListWindow(QWidget *parent): /* */ - ProteinTableModel * p_myModel = new ProteinTableModel(0); - ui->tableView->setModel( p_myModel ); + _protein_table_model_p = new ProteinTableModel(0); + ui->tableView->setModel( _protein_table_model_p ); } ProteinListWindow::~ProteinListWindow() @@ -60,4 +59,9 @@ ProteinListWindow::~ProteinListWindow() //if (_p_ms_data_file != nullptr) delete _p_ms_data_file; delete ui; -} \ No newline at end of file +} + + + void ProteinListWindow::setProject(Project* project_p) { + _protein_table_model_p->setProject(project_p); + } \ No newline at end of file diff --git a/src/gui/protein_list_view/proteinlistwindow.h b/src/gui/protein_list_view/proteinlistwindow.h index 19213454..826d7a2b 100644 --- a/src/gui/protein_list_view/proteinlistwindow.h +++ b/src/gui/protein_list_view/proteinlistwindow.h @@ -26,6 +26,7 @@ #include <QMainWindow> +#include "proteintablemodel.h" //http://doc.qt.io/qt-4.8/qt-itemviews-chart-mainwindow-cpp.html namespace Ui { @@ -39,6 +40,7 @@ public: explicit ProteinListWindow(QWidget * parent = 0); ~ProteinListWindow(); + void setProject(Project* project_p); public slots: //void peptideEdited(QString peptideStr); @@ -49,6 +51,7 @@ signals: private: Ui::ProteinView *ui; + ProteinTableModel * _protein_table_model_p = nullptr; }; diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp index 7ef7e8e9..5ec0ff14 100644 --- a/src/gui/protein_list_view/proteintablemodel.cpp +++ b/src/gui/protein_list_view/proteintablemodel.cpp @@ -35,8 +35,21 @@ ProteinTableModel::ProteinTableModel(QObject *parent) //emit dataChanged(topLeft, topLeft); } + +void ProteinTableModel::setProject(Project * p_project) { + qDebug() << "ProteinTableModel::setProject begin " << p_project->getProteinList().size(); + _p_project = p_project; + + QModelIndex topLeft = createIndex(0,0); + emit headerDataChanged(Qt::Horizontal, 0,3); + emit dataChanged(topLeft, topLeft); +} + int ProteinTableModel::rowCount(const QModelIndex &parent ) const { - return 2; + if (_p_project != nullptr) { + return _p_project->getProteinList().size(); + } + return 0; } int ProteinTableModel::columnCount(const QModelIndex &parent ) const { return 3; @@ -67,6 +80,11 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const { .arg(row).arg(col).arg(role); if (role == Qt::DisplayRole) { + if (col == 2) { + if (_p_project != nullptr) { + return _p_project->getProteinList().at(row).get()->getDescription(); + } + } return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); diff --git a/src/gui/protein_list_view/proteintablemodel.h b/src/gui/protein_list_view/proteintablemodel.h index 473e630f..3d80ff26 100644 --- a/src/gui/protein_list_view/proteintablemodel.h +++ b/src/gui/protein_list_view/proteintablemodel.h @@ -25,6 +25,7 @@ #define PROTEINTABLEMODEL_H #include <QAbstractTableModel> +#include "../../core/project.h" class ProteinTableModel: public QAbstractTableModel { @@ -35,6 +36,12 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + + void setProject(Project * p_project); + +private : + Project * _p_project = nullptr; }; #endif // PROTEINTABLEMODEL_H diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp index 38d82c6d..f05a2dd4 100644 --- a/src/input/xpipsaxhandler.cpp +++ b/src/input/xpipsaxhandler.cpp @@ -41,9 +41,9 @@ bool XpipSaxHandler::startElement(const QString & namespaceURI, const QString & try { //startElement_group - if (qName == "group") + if (qName == "protein") { - //is_ok = startElement_group(attributes); + is_ok = startElement_protein(attributes); } _current_text.clear(); } @@ -64,10 +64,13 @@ bool XpipSaxHandler::endElement(const QString & namespaceURI, const QString & lo bool is_ok = true; // endElement_peptide_list try { - if (qName == "group") + if (qName == "protein") { - //is_ok = endElement_group(); + is_ok = endElement_protein(); } + else if (qName == "sequence") { + is_ok = endElement_sequence(); + } // end of detection_moulon // else if ((_tag_stack.size() > 1) && -- GitLab