Skip to content
Snippets Groups Projects
Commit a9e67cd3 authored by Olivier Langella's avatar Olivier Langella
Browse files

problem using proxy model

parent 2d3cc0b2
No related branches found
No related tags found
No related merge requests found
......@@ -83,9 +83,7 @@ void ProjectWindow::connectNewProteinListWindow() {
*/
#else
// Qt4 code
connect (_p_current_protein_list_window, SIGNAL(proteinMatchClicked(ProteinMatch *)), this,SLOT(doViewPeptideList(ProteinMatch *)));
connect (_p_current_protein_list_window, SIGNAL(proteinMatchDoubleClicked(ProteinMatch *)), this,SLOT(doViewProteinDetail(ProteinMatch *)));
connect (_p_current_protein_list_window, SIGNAL(identificationGroupEdited(IdentificationGroup *)), this,SLOT(doIdentificationGroupEdited(IdentificationGroup *)));
//connect (_p_current_protein_list_window, SIGNAL(proteinMatchDoubleClicked(ProteinMatch *)), this,SLOT(doViewProteinDetail(ProteinMatch *)));
connect (this, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), _p_current_protein_list_window,SLOT(doIdentificationGroupGrouped(IdentificationGroup *)));
#endif
......@@ -132,7 +130,7 @@ void ProjectWindow::connectNewPeptideListWindow() {
// Qt4 code
//connect (_p_current_peptide_list_window, SIGNAL(proteinMatchClicked(ProteinMatch *)), this,SLOT(doViewPeptideList(ProteinMatch *)));
//connect (_p_current_peptide_list_window, SIGNAL(identificationGroupEdited(IdentificationGroup *)), this,SLOT(doIdentificationGroupEdited(IdentificationGroup *)));
// connect (this, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), _p_current_peptide_list_window,SLOT(doIdentificationGroupGrouped(IdentificationGroup *)));
// connect (this, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), _p_current_peptide_list_window,SLOT(doIdentificationGroupGrouped(IdentificationGroup *)));
#endif
......@@ -140,7 +138,7 @@ void ProjectWindow::connectNewPeptideListWindow() {
}
void ProjectWindow::refreshGroup(IdentificationGroup * p_ident_group) {
qDebug() << "ProjectWindow::refreshGroup begin";
vector< MsRunIdSp > ms_run_list = p_ident_group->getMsRunIdSpList();
ui->sample_number_display->setText(QString("%1").arg(ms_run_list.size()));
......@@ -148,6 +146,7 @@ void ProjectWindow::refreshGroup(IdentificationGroup * p_ident_group) {
ui->subgroup_number_display->setText(QString("%1").arg(p_ident_group->countSubGroup()));
ui->protein_number_display->setText(QString("%1").arg(p_ident_group->countGrouped()));
emit identificationGroupGrouped(p_ident_group);
qDebug() << "ProjectWindow::refreshGroup end";
}
void ProjectWindow::doIdentificationGroupEdited(IdentificationGroup * p_ident_group) {
......@@ -212,6 +211,7 @@ void ProjectWindow::doViewProteinList(IdentificationGroup* p_identification_grou
_p_current_protein_list_window->setIdentificationGroup(p_identification_group);
_p_current_protein_list_window->show();
qDebug() << "ProjectWindow::doViewProteinList end";
}
......
......@@ -40,6 +40,7 @@ class ProjectView;
class ProjectWindow: public QMainWindow {
Q_OBJECT
friend class ProteinListWindow;
public:
explicit ProjectWindow(MainWindow * parent = 0);
......@@ -48,21 +49,24 @@ public:
public slots:
void doViewProteinList(IdentificationGroup* p_identification_group =nullptr);
void doViewPeptideList(ProteinMatch * protein_match);
void doViewProteinDetail(ProteinMatch * protein_match);
void doIdentificationGroupEdited(IdentificationGroup * p_identification_group);
void setDefaultProteinListWindow(ProteinListWindow* p_protein_list_window);
// void setColor(const QColor &color);
// void setShape(Shape shape);
signals:
void identificationGroupGrouped(IdentificationGroup * p_identification_group);
//void peptideChanged(pappso::PeptideSp peptide);
protected :
void doViewPeptideList(ProteinMatch * protein_match);
void doViewProteinDetail(ProteinMatch * protein_match);
void doIdentificationGroupEdited(IdentificationGroup * p_identification_group);
private :
void connectNewProteinListWindow();
void connectNewPeptideListWindow();
void connectNewProteinDetailWindow();
void refreshGroup(IdentificationGroup * p_ident_group);
private:
Ui::ProjectView *ui;
MainWindow * main_window;
......
......@@ -40,9 +40,9 @@ ProteinListWindow::ProteinListWindow(ProjectWindow *parent):
_p_proxy_model = new ProteinTableProxyModel(this, _protein_table_model_p);
_p_proxy_model->setSourceModel(_protein_table_model_p);
_p_proxy_model->setDynamicSortFilter(true);
ui->tableView->setModel( _p_proxy_model );
//_p_proxy_model->setSourceModel(_protein_table_model_p);
//_p_proxy_model->setDynamicSortFilter(true);
ui->tableView->setModel( _protein_table_model_p );
ui->tableView->setSortingEnabled(true);
QSettings settings;
......@@ -73,21 +73,23 @@ ProteinListWindow::ProteinListWindow(ProjectWindow *parent):
#else
// Qt4 code
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 &)));
//connect(ui->tableView, SIGNAL(doubleClicked(const QModelIndex &)), _p_proxy_model, SLOT(onTableDoubleClicked(const QModelIndex &)));
connect(ui->proteinSearchEdit, SIGNAL(textChanged(QString)), _protein_table_model_p, SLOT(onProteinSearchEdit(QString)));
connect( this, SIGNAL( focusReceived(bool) ),this, SLOT(doFocusReceived(bool)) );
//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()));
//connect(_p_proxy_model, SIGNAL(layoutChanged()),
// this, SLOT(doProxyLayoutChanged()));
//connect(_protein_table_model_p, SIGNAL(layoutChanged()), this, SLOT(updateStatusBar()));
#endif
}
void ProteinListWindow::doProxyLayoutChanged() {
updateStatusBar();
qDebug() << "ProteinListWindow::doProxyLayoutChanged begin";
//updateStatusBar();
qDebug() << "ProteinListWindow::doProxyLayoutChanged end";
}
void ProteinListWindow::showEvalueColumn(bool show) {
_display_evalue = show;
......@@ -101,12 +103,16 @@ void ProteinListWindow::showAccessionColumn(bool show) {
ui->tableView->setColumnHidden(2,!show);
}
void ProteinListWindow::clickOnproteinMatch(ProteinMatch * p_protein_match) {
emit proteinMatchClicked(p_protein_match);
void ProteinListWindow::askPeptideListView(ProteinMatch * p_protein_match) {
qDebug() << "ProteinListWindow::askPeptideListView begin";
_project_window->doViewPeptideList(p_protein_match);
qDebug() << "ProteinListWindow::askPeptideListView end";
//updateStatusBar();
}
void ProteinListWindow::doubleclickOnproteinMatch(ProteinMatch * p_protein_match) {
emit proteinMatchDoubleClicked(p_protein_match);
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) {
......@@ -120,7 +126,7 @@ void ProteinListWindow::doFocusReceived(bool has_focus) {
void ProteinListWindow::showContextMenu(const QPoint & pos) {
QMenu contextMenu(tr("Context menu"), this);
QAction accession_action("accession", this);
accession_action.setCheckable(true);
accession_action.setChecked(_display_evalue);
......@@ -147,8 +153,8 @@ ProteinListWindow::~ProteinListWindow()
void ProteinListWindow::edited() {
qDebug() << "ProteinListWindow::edited begin";
//emit dataChanged(index, index);
emit identificationGroupEdited(_p_identification_group);
updateStatusBar();
_project_window->doIdentificationGroupEdited(_p_identification_group);
//updateStatusBar();
qDebug() << "ProteinListWindow::edited end";
}
......@@ -177,24 +183,36 @@ void ProteinListWindow::doNotGroupedHide(bool hide) {
void ProteinListWindow::doIdentificationGroupGrouped(IdentificationGroup * p_identification_group) {
qDebug() << "ProteinListWindow::doIdentificationGroupGrouped begin";
if (_p_identification_group == p_identification_group) {
_p_proxy_model->setSourceModel(_protein_table_model_p);
//_p_proxy_model->setSourceModel(_protein_table_model_p);
}
qDebug() << "ProteinListWindow::doIdentificationGroupGrouped end";
}
void ProteinListWindow::setIdentificationGroup(IdentificationGroup * p_identification_group) {
qDebug() << "ProteinListWindow::setIdentificationGroup begin";
if (_p_identification_group != p_identification_group) {
_p_identification_group = p_identification_group;
_protein_table_model_p->setIdentificationGroup(p_identification_group);
_p_proxy_model->setSourceModel(_protein_table_model_p);
}
qDebug() << "ProteinListWindow::setIdentificationGroup end";
}
void ProteinListWindow::refresh() {
if (_p_identification_group == nullptr) return;
qDebug() << "ProteinListWindow::refresh begin " << _p_identification_group->getProteinMatchList().size();
//_p_proxy_model->setSourceModel(_protein_table_model_p);
qDebug() << "ProteinListWindow::refresh end ";
}
void ProteinListWindow::updateStatusBar() {
if (_p_identification_group == nullptr) {
}
else {
ui->statusbar->showMessage(tr("proteins %1 valid, %2 checked, %3 displayed").arg(_p_identification_group->countValid()).arg(_p_identification_group->countValidAndChecked()).arg(_p_proxy_model->rowCount()));
ui->statusbar->showMessage(tr("proteins %1 valid, %2 checked, %3 displayed").arg(_p_identification_group->countValid()).arg(_p_identification_group->countValidAndChecked()).arg(_p_proxy_model->rowCount()));
}
}
......@@ -38,13 +38,14 @@ class ProteinView;
class ProteinListWindow: public QMainWindow {
Q_OBJECT
friend ProteinTableModel;
friend class ProteinTableModel;
friend class ProteinTableProxyModel;
public:
explicit ProteinListWindow(ProjectWindow * parent = 0);
~ProteinListWindow();
void setIdentificationGroup(IdentificationGroup * p_identification_group);
void edited();
public slots:
......@@ -54,8 +55,6 @@ public slots:
// void setColor(const QColor &color);
// void setShape(Shape shape);
signals:
void proteinMatchClicked(ProteinMatch * p_protein_match);
void proteinMatchDoubleClicked(ProteinMatch * p_protein_match);
void identificationGroupEdited(IdentificationGroup * p_identification_group);
......@@ -67,12 +66,13 @@ protected slots:
void showContextMenu(const QPoint &);
void showEvalueColumn(bool show);
void showAccessionColumn(bool show);
protected :
protected :
void refresh();
void updateStatusBar();
void doubleclickOnproteinMatch(ProteinMatch * p_protein_match);
void clickOnproteinMatch(ProteinMatch * p_protein_match);
void askProteinDetailView(ProteinMatch * p_protein_match);
void askPeptideListView(ProteinMatch * p_protein_match);
private:
IdentificationGroup * _p_identification_group=nullptr;
......
......@@ -42,19 +42,41 @@ bool ProteinTableProxyModel::filterAcceptsRow(int source_row,
//return true;
}
void ProteinTableProxyModel::onTableClicked(const QModelIndex &index)
{
qDebug() << "ProteinTableProxyModel::onTableClicked begin " << index.row();
qDebug() << "ProteinTableProxyModel::onTableClicked begin " << this->mapToSource(index).row();
_protein_table_model_p->onTableClicked(this->mapToSource(index));
}
void ProteinTableProxyModel::onTableDoubleClicked(const QModelIndex &index)
{
qDebug() << "ProteinTableProxyModel::onTableDoubleClicked begin " << index.row();
qDebug() << "ProteinTableProxyModel::onTableDoubleClicked begin " << this->mapToSource(index).row();
_protein_table_model_p->onTableDoubleClicked(this->mapToSource(index));
//_protein_table_model_p->onTableClicked(this->mapToSource(index));
QModelIndex source_index(this->mapToSource(index));
int row = source_index.row();
int col = source_index.column();
ProteinMatch* p_protein_match = _protein_table_model_p->getIdentificationGroup()->getProteinMatchList().at(row);
if (col == 0) //add a checkbox to cell(1,0)
{
if ( p_protein_match->isChecked()) {
p_protein_match->setChecked(false);
}
else {
p_protein_match->setChecked(true);
}
_p_protein_list_window->edited();
}
else {
if ((col == 2)||(col == 3)) {
_p_protein_list_window->askProteinDetailView(p_protein_match);
}
else {
_p_protein_list_window->askPeptideListView(p_protein_match);
}
}
qDebug() << "ProteinTableProxyModel::onTableClicked end " << index.row();
}
bool ProteinTableProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const {
QVariant leftData = sourceModel()->data(left);
QVariant rightData = sourceModel()->data(right);
......@@ -92,10 +114,14 @@ QVariant ProteinTableProxyModel::headerData(int section, Qt::Orientation orienta
role);
}
IdentificationGroup * ProteinTableModel::getIdentificationGroup() {
return _p_identification_group;
}
ProteinTableModel::ProteinTableModel(ProteinListWindow * p_protein_list_window)
:QAbstractTableModel(p_protein_list_window)
{
_p_protein_list_window = p_protein_list_window;
_p_identification_group = nullptr;
//ui->tableView->show();
// QModelIndex topLeft = createIndex(0,0);
//emit a signal to make the view reread identified data
......@@ -103,11 +129,15 @@ ProteinTableModel::ProteinTableModel(ProteinListWindow * p_protein_list_window)
}
void ProteinTableModel::refresh() {
qDebug() << "ProteinTableModel::refresh begin ";
if (_p_identification_group == nullptr) return;
qDebug() << "ProteinTableModel::refresh begin " << _p_identification_group->getProteinMatchList().size();
_p_protein_list_window->refresh();
//emit layoutAboutToBeChanged();
QModelIndex topLeft = createIndex(0,0);
QModelIndex bottomRight = createIndex(rowCount(),columnCount());
qDebug() << "ProteinTableModel::refresh emit dataChanged ";
emit dataChanged(topLeft, bottomRight);
emit layoutChanged();
//emit layoutChanged();
qDebug() << "ProteinTableModel::refresh end ";
}
......@@ -117,8 +147,10 @@ void ProteinTableModel::hideNotValid(bool hide) {
}
void ProteinTableModel::hideNotChecked(bool hide) {
qDebug() << "ProteinTableModel::hideNotChecked begin ";
_hide_not_checked = hide;
refresh();
qDebug() << "ProteinTableModel::hideNotChecked end ";
}
void ProteinTableModel::hideNotGrouped(bool hide) {
_hide_not_grouped = hide;
......@@ -130,21 +162,22 @@ void ProteinTableModel::onProteinSearchEdit(QString protein_search_string) {
QModelIndex topLeft = createIndex(0,0);
QModelIndex bottomRight = createIndex(rowCount(),columnCount());
emit dataChanged(topLeft, bottomRight);
emit layoutChanged();
//emit layoutChanged();
}
void ProteinTableModel::setIdentificationGroup(IdentificationGroup * p_identification_group) {
qDebug() << "ProteinTableModel::setIdentificationGroup begin " << p_identification_group->getProteinMatchList().size();
beginResetModel();
_p_identification_group = p_identification_group;
QModelIndex topLeft = createIndex(0,0);
QModelIndex bottomRight = createIndex(rowCount(),columnCount());
emit dataChanged(topLeft, topLeft);
emit headerDataChanged(Qt::Horizontal, 0,3);
emit layoutChanged();
//emit headerDataChanged(Qt::Horizontal, 0,11);
//refresh();
endResetModel();
qDebug() << "ProteinTableModel::setIdentificationGroup end ";
}
int ProteinTableModel::rowCount(const QModelIndex &parent ) const {
qDebug() << "ProteinTableModel::rowCount begin ";
if (_p_identification_group != nullptr) {
//qDebug() << "ProteinTableModel::rowCount(const QModelIndex &parent ) " << _p_identification_group->getProteinMatchList().size();
return _p_identification_group->getProteinMatchList().size();
......@@ -152,7 +185,11 @@ int ProteinTableModel::rowCount(const QModelIndex &parent ) const {
return 0;
}
int ProteinTableModel::columnCount(const QModelIndex &parent ) const {
return 11;
qDebug() << "ProteinTableModel::columnCount begin ";
if (_p_identification_group != nullptr) {
return 11;
}
return 0;
}
QVariant ProteinTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
......@@ -280,40 +317,16 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const {
return QVariant();
}
void ProteinTableModel::onTableClicked(const QModelIndex &index)
{
int row = index.row();
int col = index.column();
if (col == 0) //add a checkbox to cell(1,0)
{
if ( _p_identification_group->getProteinMatchList().at(row)->isChecked()) {
_p_identification_group->getProteinMatchList().at(row)->setChecked(false);
}
else {
_p_identification_group->getProteinMatchList().at(row)->setChecked(true);
}
_p_protein_list_window->edited();
}
else {
_p_protein_list_window->clickOnproteinMatch(_p_identification_group->getProteinMatchList().at(row));
}
}
void ProteinTableModel::onTableDoubleClicked(const QModelIndex &index)
{
int row = index.row();
int col = index.column();
_p_protein_list_window->doubleclickOnproteinMatch(_p_identification_group->getProteinMatchList().at(row));
}
bool ProteinTableModel::acceptRow(int source_row) {
try {
ProteinMatch * protein_match = _p_identification_group->getProteinMatchList().at(source_row);
if (!_protein_search_string.isEmpty()) {
if (!protein_match->getProteinXtpSp().get()->getDescription().contains(_protein_search_string)) {
return false;
}
}
if (_hide_not_valid) {
if (! protein_match->isValid()) {
return false;
......@@ -337,12 +350,12 @@ bool ProteinTableModel::acceptRow(int source_row) {
catch (pappso::PappsoException exception_pappso) {
//QMessageBox::warning(this,
// tr("Error in ProteinTableModel::acceptRow :"), exception_pappso.qwhat());
qDebug() << "Error in ProteinTableModel::acceptRow :" << exception_pappso.qwhat();
qDebug() << "Error in ProteinTableModel::acceptRow :" << exception_pappso.qwhat();
}
catch (std::exception exception_std) {
//QMessageBox::warning(this,
// tr("Error in ProteinTableModel::acceptRow :"), exception_std.what());
qDebug() << "Error in ProteinTableModel::acceptRow :" << exception_std.what();
// tr("Error in ProteinTableModel::acceptRow :"), exception_std.what());
qDebug() << "Error in ProteinTableModel::acceptRow :" << exception_std.what();
}
return true;
......
......@@ -45,7 +45,6 @@ public:
public slots:
void onTableClicked(const QModelIndex &index);
void onTableDoubleClicked(const QModelIndex &index);
private:
ProteinTableModel* _protein_table_model_p;
ProteinListWindow * _p_protein_list_window;
......@@ -56,13 +55,14 @@ class ProteinTableModel: public QAbstractTableModel
Q_OBJECT
public:
ProteinTableModel(ProteinListWindow * p_protein_list_window);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
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;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void setIdentificationGroup(IdentificationGroup * p_identification_group);
IdentificationGroup * getIdentificationGroup();
bool acceptRow(int source_row);
void hideNotValid(bool hide);
......@@ -70,8 +70,6 @@ public:
void hideNotGrouped(bool hide);
public slots:
void onTableClicked(const QModelIndex &index);
void onTableDoubleClicked(const QModelIndex &index);
void onProteinSearchEdit(QString protein_search_string);
private :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment