msidentificationlistwindow.cpp 4.53 KB
Newer Older
1
2

/*******************************************************************************
Renne Thomas's avatar
Renne Thomas committed
3
 * Copyright (c) 2019 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * 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:
Renne Thomas's avatar
Renne Thomas committed
21
 *    Thomas Renne <thomas.renne@u-psud.fr>. - initial API and
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 *implementation
 ******************************************************************************/

#include "ui_ms_identification_run_view.h"
#include "msidentificationlistwindow.h"

#include "../../mainwindow.h"
#include <QSettings>
#include <odsstream/odsdocwriter.h>
#include <odsstream/qtablewriter.h>

MsIdentificationListWindow::MsIdentificationListWindow(ProjectWindow *parent)
  : QMainWindow(parent), ui(new Ui::MsIdentificationView)
{
  m_project_window = parent;
  ui->setupUi(this);
  setWindowIcon(QIcon(":/xtpcpp_icon/resources/xtandempipeline_icon.svg"));

  m_msid_table_model_p = new MsIdentificationTableModel(this);


Renne Thomas's avatar
Renne Thomas committed
43
44
  m_proxy_model =
    new MsIdentificationTableProxyModel(this, m_msid_table_model_p);
45
46
47
48
49
50
  m_proxy_model->setSourceModel(m_msid_table_model_p);
  m_proxy_model->setDynamicSortFilter(true);

  ui->tableView->setModel(m_proxy_model);
  ui->tableView->setSortingEnabled(true);
  ui->tableView->setAlternatingRowColors(true);
Renne Thomas's avatar
Renne Thomas committed
51

52
53
  m_proxy_model->resteItemDelegates();

Renne Thomas's avatar
Renne Thomas committed
54
55
56
57
58
59
  connect(this,
          &MsIdentificationListWindow::MsIdentificationDataChanged,
          m_msid_table_model_p,
          &MsIdentificationTableModel::onMsIdentificationDataChanged);
  connect(m_msid_table_model_p,
          &MsIdentificationTableModel::layoutChanged,
60
          this,
Renne Thomas's avatar
Renne Thomas committed
61
          &MsIdentificationListWindow::updateStatusBar);
62
63
64
65
  connect(ui->tableView,
          &QTableView::clicked,
          m_proxy_model,
          &MsIdentificationTableProxyModel::onTableClicked);
66
67
68
}

void
Renne Thomas's avatar
Renne Thomas committed
69
MsIdentificationListWindow::resizeColumnsToContents()
70
{
Renne Thomas's avatar
Renne Thomas committed
71
  ui->tableView->resizeColumnsToContents();
72
73
74
}

void
Renne Thomas's avatar
Renne Thomas committed
75
MsIdentificationListWindow::doSearchOn(QString search_on)
76
{
Renne Thomas's avatar
Renne Thomas committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  qDebug() << "ProteinTableProxyModel::doSearchOn begin " << search_on;
  m_proxy_model->setSearchOn(search_on);
  emit MsIdentificationDataChanged();
}

void
MsIdentificationListWindow::onMsIdentificationSearchEdit(
  QString ms_id_search_string)
{
  qDebug()
    << "MsIdentificationTableProxyModel::onMsIdentificationSearchEdit begin "
    << ms_id_search_string;
  m_proxy_model->setMsIdentificationSearchString(ms_id_search_string);
  emit MsIdentificationDataChanged();
91
92
93
94
95
96
}

MsIdentificationListWindow::~MsIdentificationListWindow()
{
}

Renne Thomas's avatar
Renne Thomas committed
97
98
99
100
101
102
103
104
105
void
MsIdentificationListWindow::updateStatusBar()
{
  ui->statusbar->showMessage(
    tr("Ms identification all:%1 displayed:%5")
      .arg(m_msid_table_model_p->getIdentificationDataSourceSpList().size())
      .arg(m_proxy_model->rowCount()));
}

106
void
Renne Thomas's avatar
Renne Thomas committed
107
108
MsIdentificationListWindow::setIdentificationDataSourceSpList(
  std::vector<IdentificationDataSourceSp> &identificationDataSourceSpList)
109
110
111
{
  qDebug() << "MsIdentificationListWindow::setIdentificationGroup begin ";

Renne Thomas's avatar
Renne Thomas committed
112
113
  m_msid_table_model_p->setIdentificationDataSourceSpList(
    identificationDataSourceSpList);
114
115
116
117
118

  qDebug() << "MsIdentificationListWindow::setIdentificationGroup end";
}

void
119
MsIdentificationListWindow::doExportAsOdsFile()
120
{
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  QSettings settings;
  QString default_location = settings.value("path/export_ods", "").toString();

  QString filename;
  filename = QFileDialog::getSaveFileName(
    this,
    tr("Save ODS file"),
    QString("%1/untitled.ods").arg(default_location),
    tr("Open Document Spreadsheet (*.ods)"));

  if(!filename.isEmpty())
    {
      CalcWriterInterface *p_writer            = new OdsDocWriter(filename);
      const QAbstractProxyModel *p_table_model = m_proxy_model;

      QtableWriter table_writer(p_writer, p_table_model);

      table_writer.setFormatPercentForColumn(m_msid_table_model_p->index(
        0, (int)msIdentificationListColumn::percent_assign));

      table_writer.writeSheet("Ms Identification list");

      p_writer->close();
      delete p_writer;
    }
146
}