Skip to content
Snippets Groups Projects
proteinlistwindow.cpp 10.8 KiB
Newer Older

/*******************************************************************************
* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
*
* This file is part of XTPcpp.
*
*     XTPcpp 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.
*
*     XTPcpp 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 XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
*     Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation
******************************************************************************/

#include "proteinlistwindow.h"

#include "ui_protein_view.h"
Olivier Langella's avatar
Olivier Langella committed
#include "../mainwindow.h"
#include <QSettings>
Olivier Langella's avatar
Olivier Langella committed
ProteinListQactionColumn::ProteinListQactionColumn(ProteinListWindow * parent, ProteinListColumn column):QAction(parent) {
Olivier Langella's avatar
Olivier Langella committed
    this->setText(ProteinTableModel::getTitle(column));
Olivier Langella's avatar
Olivier Langella committed

    this->setCheckable(true);
    this->setChecked(parent->getProteinListColumnDisplay(column));
    //evalue_action.setChecked(_display_evalue);
    //connect(p_action, SIGNAL(toggled(bool)), this, SLOT(showEvalueColumn(bool)));
    _column = column;
    _p_protein_list_window = parent;

#if QT_VERSION >= 0x050000
    // Qt5 code
    /*
    connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
    connect(this, &PtSpectrumViewer::operateMsDataFile, worker, &PwizLoaderThread::doMsDataFileLoad);
    connect(worker, &PwizLoaderThread::msDataReady, this, &PtSpectrumViewer::handleMsDataFile);
    */
#else
// Qt4 code
    connect (this, SIGNAL(toggled(bool)), this,SLOT(doToggled(bool)));
#endif
Olivier Langella's avatar
Olivier Langella committed
}

ProteinListQactionColumn::~ProteinListQactionColumn()
{
    //if (_p_ms_data_file != nullptr) delete _p_ms_data_file;
Olivier Langella's avatar
Olivier Langella committed
    qDebug() << "ProteinListQactionColumn::~ProteinListQactionColumn begin ";
Olivier Langella's avatar
Olivier Langella committed
void ProteinListQactionColumn::doToggled(bool toggled) {
    qDebug() << "ProteinListQactionColumn::doToggled begin " << toggled;
    setChecked(toggled);
    _p_protein_list_window->setProteinListColumnDisplay(_column, toggled);
    
    qDebug() << "ProteinListQactionColumn::doToggled end";
}
ProteinListWindow::ProteinListWindow(ProjectWindow *parent):
    QMainWindow(parent),
    ui(new Ui::ProteinView)
{
    _project_window = parent;
    ui->setupUi(this);
    /*
    */
Olivier Langella's avatar
Olivier Langella committed
    _protein_table_model_p = new ProteinTableModel(this);
    _p_proxy_model = new ProteinTableProxyModel(this, _protein_table_model_p);
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->setSourceModel(_protein_table_model_p);
    _p_proxy_model->setDynamicSortFilter(true);
    ui->tableView->setModel( _p_proxy_model );
Olivier Langella's avatar
Olivier Langella committed
    ui->tableView->setSortingEnabled(true);
Olivier Langella's avatar
Olivier Langella committed
    ui->tableView->setAlternatingRowColors(true);
    QSettings settings;
    bool hide = settings.value("proteinview/hidenotvalid", "true").toBool();
    if (hide) {
        ui->hideNotValidCheckBox->setCheckState(Qt::Checked);
    }
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->hideNotValid(hide);
    hide = settings.value("proteinview/hidenotchecked", "false").toBool();
    if (hide) {
        ui->hideNotCheckedCheckBox->setCheckState(Qt::Checked);
    }
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->hideNotChecked(hide);
    hide = settings.value("proteinview/hidenotgrouped", "false").toBool();
    if (hide) {
        ui->hideNotGroupedCheckBox->setCheckState(Qt::Checked);
    }
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->hideNotGrouped(hide);
Olivier Langella's avatar
Olivier Langella committed


#if QT_VERSION >= 0x050000
    // Qt5 code
    /*
    connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
    connect(this, &PtSpectrumViewer::operateMsDataFile, worker, &PwizLoaderThread::doMsDataFileLoad);
    connect(worker, &PwizLoaderThread::msDataReady, this, &PtSpectrumViewer::handleMsDataFile);
    */
#else
// Qt4 code
Olivier Langella's avatar
Olivier Langella committed
    connect (_project_window, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), this,SLOT(doIdentificationGroupGrouped(IdentificationGroup *)));

    connect (this, SIGNAL(proteinDataChanged()), _protein_table_model_p, SLOT(onProteinDataChanged()));
Olivier Langella's avatar
Olivier Langella committed
    connect(ui->tableView, SIGNAL(clicked(const QModelIndex &)), _p_proxy_model, SLOT(onTableClicked(const QModelIndex &)));
    //connect(ui->tableView, SIGNAL(doubleClicked(const QModelIndex &)), _p_proxy_model, SLOT(onTableDoubleClicked(const QModelIndex &)));
Olivier Langella's avatar
Olivier Langella committed
    //connect(ui->protein_search_edit, SIGNAL(textChanged(QString)), this, SLOT(onProteinSearchEdit(QString)));
    //connect( this, SIGNAL( focusReceived(bool) ),this, SLOT(doFocusReceived(bool)) );
    connect(ui->centralwidget, SIGNAL(customContextMenuRequested(const QPoint &)),
            this, SLOT(showContextMenu(const QPoint &)));
    //connect(_p_proxy_model, SIGNAL(layoutChanged()),
    //        this, SLOT(doProxyLayoutChanged()));
Olivier Langella's avatar
Olivier Langella committed
    connect(_protein_table_model_p, SIGNAL(layoutChanged()), this, SLOT(updateStatusBar()));
Olivier Langella's avatar
Olivier Langella committed
#endif
void ProteinListWindow::doProxyLayoutChanged() {
    qDebug() << "ProteinListWindow::doProxyLayoutChanged begin";
    //updateStatusBar();
    qDebug() << "ProteinListWindow::doProxyLayoutChanged end";
void ProteinListWindow::showEvalueColumn(bool show) {
    _display_evalue = show;

    ui->tableView->setColumnHidden(4,!show);
}

void ProteinListWindow::showAccessionColumn(bool show) {
    _display_accession = show;

    ui->tableView->setColumnHidden(2,!show);
}
void ProteinListWindow::askPeptideListView(ProteinMatch * p_protein_match) {
    qDebug() << "ProteinListWindow::askPeptideListView begin";
Olivier Langella's avatar
Olivier Langella committed
    _project_window->doViewPeptideList(_p_identification_group, p_protein_match);
    qDebug() << "ProteinListWindow::askPeptideListView end";
Olivier Langella's avatar
Olivier Langella committed
    //updateStatusBar();
void ProteinListWindow::askProteinDetailView(ProteinMatch * p_protein_match) {
    qDebug() << "ProteinListWindow::askProteinDetailView begin";
    _project_window->doViewProteinDetail(p_protein_match);
    qDebug() << "ProteinListWindow::askProteinDetailView end";
    //updateStatusBar();
}
void ProteinListWindow::doFocusReceived(bool has_focus) {
    if (has_focus ) {
        qDebug() << "ProteinListWindow::doFocusReceived begin";
        _project_window->setDefaultProteinListWindow(this);
        qDebug() << "ProteinListWindow::doFocusReceived end";

void ProteinListWindow::showContextMenu(const QPoint & pos) {
Olivier Langella's avatar
Olivier Langella committed
    if (_p_context_menu == nullptr) {
    _p_context_menu = new QMenu(tr("Context menu"), this);
Olivier Langella's avatar
Olivier Langella committed
    ProteinListQactionColumn * p_action;
    for (unsigned int i=0; i < _protein_table_model_p->columnCount(); i++) {
Olivier Langella's avatar
Olivier Langella committed
        p_action = new ProteinListQactionColumn(this,ProteinTableModel::getProteinListColumn(i));
Olivier Langella's avatar
Olivier Langella committed
        _p_context_menu->addAction(p_action);
Olivier Langella's avatar
Olivier Langella committed
    _p_context_menu->exec(mapToGlobal(pos));
    }
    _p_context_menu->show();
ProteinListWindow::~ProteinListWindow()
{
    //if (_p_ms_data_file != nullptr) delete _p_ms_data_file;
    delete ui;
Olivier Langella's avatar
Olivier Langella committed
    if (_p_context_menu != nullptr) {
        delete _p_context_menu;
    }
Olivier Langella's avatar
Olivier Langella committed
void ProteinListWindow::edited() {
    qDebug() << "ProteinListWindow::edited begin";
    //emit dataChanged(index, index);
    _project_window->doIdentificationGroupEdited(_p_identification_group);
    //updateStatusBar();
Olivier Langella's avatar
Olivier Langella committed

    qDebug() << "ProteinListWindow::edited end";
}
void ProteinListWindow::doNotValidHide(bool hide) {
    qDebug() << "ProteinListWindow::doNotValidHide begin";
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->hideNotValid(hide);
    QSettings settings;
    settings.setValue("proteinview/hidenotvalid", QString("%1").arg(hide));
Olivier Langella's avatar
Olivier Langella committed
    emit proteinDataChanged();
    qDebug() << "ProteinListWindow::doNotValidHide end";
}
void ProteinListWindow::doNotCheckedHide(bool hide) {
    qDebug() << "ProteinListWindow::doNotCheckedHide begin";
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->hideNotChecked(hide);
    QSettings settings;
    settings.setValue("proteinview/hidenotchecked", QString("%1").arg(hide));
Olivier Langella's avatar
Olivier Langella committed
    emit proteinDataChanged();
    qDebug() << "ProteinListWindow::doNotCheckedHide end";
}
void ProteinListWindow::doNotGroupedHide(bool hide) {
    qDebug() << "ProteinListWindow::doNotGroupedHide begin";
Olivier Langella's avatar
Olivier Langella committed
    _p_proxy_model->hideNotGrouped(hide);
    QSettings settings;
    settings.setValue("proteinview/hidenotgrouped", QString("%1").arg(hide));
Olivier Langella's avatar
Olivier Langella committed
    emit proteinDataChanged();
    qDebug() << "ProteinListWindow::doNotGroupedHide end";
}
Olivier Langella's avatar
Olivier Langella committed
void ProteinListWindow::doSearchOn(QString search_on) {
    qDebug() << "ProteinTableProxyModel::doSearchOn begin " << search_on;
    _p_proxy_model->setSearchOn( search_on);
    emit proteinDataChanged();
}


void ProteinListWindow::onProteinSearchEdit(QString protein_search_string) {
    qDebug() << "ProteinTableProxyModel::onProteinSearchEdit begin " << protein_search_string;
    _p_proxy_model->setProteinSearchString( protein_search_string);
    emit proteinDataChanged();
}


Olivier Langella's avatar
Olivier Langella committed
void ProteinListWindow::doIdentificationGroupGrouped(IdentificationGroup * p_identification_group) {
    qDebug() << "ProteinListWindow::doIdentificationGroupGrouped begin";
    if (_p_identification_group == p_identification_group) {
Olivier Langella's avatar
Olivier Langella committed
        //_protein_table_model_p->setIdentificationGroup(p_identification_group);
        //_p_proxy_model->setSourceModel(_protein_table_model_p);
Olivier Langella's avatar
Olivier Langella committed
        emit proteinDataChanged();
Olivier Langella's avatar
Olivier Langella committed
    }
Olivier Langella's avatar
Olivier Langella committed

Olivier Langella's avatar
Olivier Langella committed
    qDebug() << "ProteinListWindow::doIdentificationGroupGrouped end";
}
void ProteinListWindow::setIdentificationGroup(IdentificationGroup * p_identification_group) {
    qDebug() << "ProteinListWindow::setIdentificationGroup begin " ;
Olivier Langella's avatar
Olivier Langella committed
    if (p_identification_group != nullptr) {
        qDebug() << "ProteinListWindow::setIdentificationGroup not null";
        _p_identification_group = p_identification_group;
        _protein_table_model_p->setIdentificationGroup(p_identification_group);
Olivier Langella's avatar
Olivier Langella committed
        //_p_proxy_model->setSourceModel(_protein_table_model_p);
Olivier Langella's avatar
Olivier Langella committed
    }
    else {
        qDebug() << "ProteinListWindow::setIdentificationGroup  null";
Olivier Langella's avatar
Olivier Langella committed
    qDebug() << "ProteinListWindow::setIdentificationGroup end";
Olivier Langella's avatar
Olivier Langella committed
void ProteinListWindow::updateStatusBar() {
    if (_p_identification_group == nullptr) {
    }
    else {
Olivier Langella's avatar
Olivier Langella committed
        ui->statusbar->showMessage(tr("proteins all:%1 valid:%2 valid&checked:%3 grouped:%4 displayed:%5").arg(_p_identification_group->countProteinMatch(ValidationState::notValid)).arg(_p_identification_group->countProteinMatch(ValidationState::valid)).arg(_p_identification_group->countProteinMatch(ValidationState::validAndChecked)).arg(_p_identification_group->countProteinMatch(ValidationState::grouped)).arg(_p_proxy_model->rowCount()));
Olivier Langella's avatar
Olivier Langella committed

void ProteinListWindow::setProteinListColumnDisplay(ProteinListColumn column, bool toggled) {
    _p_proxy_model->setProteinListColumnDisplay(column, toggled);
}
bool ProteinListWindow::getProteinListColumnDisplay(ProteinListColumn column) const {
    return _p_proxy_model->getProteinListColumnDisplay(column);
}