From d6c82efee54d9547256dba8e119bca10a181d484 Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Sun, 9 Jul 2017 07:53:51 +0200 Subject: [PATCH] column resize in protein list --- .../peptide_list_view/peptidelistwindow.cpp | 4 ++ src/gui/peptide_list_view/peptidelistwindow.h | 1 + .../protein_list_view/proteinlistwindow.cpp | 31 ++++++--------- src/gui/protein_list_view/proteinlistwindow.h | 3 +- .../protein_list_view/proteintablemodel.cpp | 38 +++++++++++++++++-- src/gui/protein_list_view/proteintablemodel.h | 2 +- 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/gui/peptide_list_view/peptidelistwindow.cpp b/src/gui/peptide_list_view/peptidelistwindow.cpp index a47a4bbe..3834b0d4 100644 --- a/src/gui/peptide_list_view/peptidelistwindow.cpp +++ b/src/gui/peptide_list_view/peptidelistwindow.cpp @@ -184,3 +184,7 @@ void PeptideListWindow::updateStatusBar() { ui->statusbar->showMessage(tr("peptides all:%1 valid:%2 valid&checked:%3 displayed:%4").arg(_p_protein_match->countPeptideMatch(ValidationState::notValid)).arg(_p_protein_match->countPeptideMatch(ValidationState::valid)).arg(_p_protein_match->countPeptideMatch(ValidationState::validAndChecked)).arg(_p_proxy_model->rowCount())); } } + +void PeptideListWindow::resizeColumnsToContents() { + ui->tableView->resizeColumnsToContents(); +} diff --git a/src/gui/peptide_list_view/peptidelistwindow.h b/src/gui/peptide_list_view/peptidelistwindow.h index fd3ce5b9..d6d291e8 100644 --- a/src/gui/peptide_list_view/peptidelistwindow.h +++ b/src/gui/peptide_list_view/peptidelistwindow.h @@ -47,6 +47,7 @@ public: explicit PeptideListWindow(ProjectWindow * parent = 0); ~PeptideListWindow(); void setProteinMatch(IdentificationGroup * p_identification_group, ProteinMatch * p_protein_match); + void resizeColumnsToContents(); void edited(); ProjectWindow * getProjectWindow(); diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp index 263dc250..7471e5ec 100644 --- a/src/gui/protein_list_view/proteinlistwindow.cpp +++ b/src/gui/protein_list_view/proteinlistwindow.cpp @@ -61,7 +61,7 @@ void ProteinListQactionColumn::doToggled(bool toggled) { qDebug() << "ProteinListQactionColumn::doToggled begin " << toggled; setChecked(toggled); _p_protein_list_window->setProteinListColumnDisplay(_column, toggled); - + qDebug() << "ProteinListQactionColumn::doToggled end"; } @@ -132,17 +132,6 @@ void ProteinListWindow::doProxyLayoutChanged() { //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"; @@ -167,16 +156,16 @@ void ProteinListWindow::doFocusReceived(bool has_focus) { void ProteinListWindow::showContextMenu(const QPoint & pos) { if (_p_context_menu == nullptr) { - _p_context_menu = new QMenu(tr("Context menu"), this); + _p_context_menu = new QMenu(tr("Context menu"), this); - ProteinListQactionColumn * p_action; - for (unsigned int i=0; i < _protein_table_model_p->columnCount(); i++) { - p_action = new ProteinListQactionColumn(this,ProteinTableModel::getProteinListColumn(i)); - _p_context_menu->addAction(p_action); - } + ProteinListQactionColumn * p_action; + for (unsigned int i=0; i < _protein_table_model_p->columnCount(); i++) { + p_action = new ProteinListQactionColumn(this,ProteinTableModel::getProteinListColumn(i)); + _p_context_menu->addAction(p_action); + } - _p_context_menu->exec(mapToGlobal(pos)); + _p_context_menu->exec(mapToGlobal(pos)); } _p_context_menu->show(); } @@ -276,10 +265,12 @@ void ProteinListWindow::updateStatusBar() { } } - 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); } +void ProteinListWindow::resizeColumnsToContents() { + ui->tableView->resizeColumnsToContents(); +} diff --git a/src/gui/protein_list_view/proteinlistwindow.h b/src/gui/protein_list_view/proteinlistwindow.h index 79dee349..0b30860f 100644 --- a/src/gui/protein_list_view/proteinlistwindow.h +++ b/src/gui/protein_list_view/proteinlistwindow.h @@ -66,6 +66,7 @@ public: void setIdentificationGroup(IdentificationGroup * p_identification_group); void setProteinListColumnDisplay(ProteinListColumn column, bool toggled); bool getProteinListColumnDisplay(ProteinListColumn column) const; + void resizeColumnsToContents(); void edited(); @@ -86,8 +87,6 @@ protected slots: void doNotGroupedHide(bool hide); void doProxyLayoutChanged(); void showContextMenu(const QPoint &); - void showEvalueColumn(bool show); - void showAccessionColumn(bool show); void updateStatusBar(); void onProteinSearchEdit(QString protein_search_string); void doSearchOn(QString search_on); diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp index 8d7eb2fc..b495df5f 100644 --- a/src/gui/protein_list_view/proteintablemodel.cpp +++ b/src/gui/protein_list_view/proteintablemodel.cpp @@ -49,6 +49,8 @@ void ProteinTableModel::setIdentificationGroup(IdentificationGroup * p_identific //refresh(); qDebug() << "ProteinTableModel::setIdentificationGroup end "; endResetModel(); + + _p_protein_list_window->resizeColumnsToContents(); } @@ -79,7 +81,7 @@ const QString ProteinTableModel::getDescription(ProteinListColumn column) { } const QString ProteinTableModel::getTitle(std::int8_t column) { - + qDebug() << "ProteinTableModel::getTitle begin " << column; switch (column) { @@ -128,7 +130,7 @@ const QString ProteinTableModel::getTitle(std::int8_t column) { } const QString ProteinTableModel::getDescription(std::int8_t column) { - + qDebug() << "ProteinTableModel::getDescription begin " << column; switch (column) { @@ -187,13 +189,37 @@ QVariant ProteinTableModel::headerData(int section, Qt::Orientation orientation, case Qt::ToolTipRole : return QVariant(getDescription(section)); break; - + case Qt::SizeHintRole : + //qDebug() << "ProteinTableModel::headerData " << ProteinTableModel::getColumnWidth(section); + return QSize( ProteinTableModel::getColumnWidth(section), 40 ); + break; } } return QVariant(); } -ProteinListColumn ProteinTableModel::getProteinListColumn(std::int8_t column){ +int ProteinTableModel::getColumnWidth(int column) { + qDebug() << "ProteinTableModel::getColumnWidth " << column; + switch (column) { + + case (int) ProteinListColumn::checked: + break; + + case (int) ProteinListColumn::protein_grouping_id: + return 120; + break; + case (int) ProteinListColumn::accession: + qDebug() << "ProteinTableModel::getColumnWidth accession " << column; + return 250; + break; + case (int) ProteinListColumn::description: + return 400; + break; + } + return 100; +} + +ProteinListColumn ProteinTableModel::getProteinListColumn(std::int8_t column) { return static_cast<ProteinListColumn>(column); } @@ -218,6 +244,10 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const { } } break; + case Qt::SizeHintRole : + //qDebug() << "ProteinTableModel::headerData " << ProteinTableModel::getColumnWidth(section); + return QSize( ProteinTableModel::getColumnWidth(col), 30 ); + break; case Qt::BackgroundRole: if (_p_identification_group->getProteinMatchList().at(row)->isValid() == false) { diff --git a/src/gui/protein_list_view/proteintablemodel.h b/src/gui/protein_list_view/proteintablemodel.h index 2c0924d4..99642418 100644 --- a/src/gui/protein_list_view/proteintablemodel.h +++ b/src/gui/protein_list_view/proteintablemodel.h @@ -73,11 +73,11 @@ public slots: void onProteinDataChanged(); private : + static int getColumnWidth(int column); void refresh(); private : IdentificationGroup * _p_identification_group = nullptr; ProteinListWindow * _p_protein_list_window; - QStringList _columns; }; #endif // PROTEINTABLEMODEL_H -- GitLab