From 0304a90f045f187e72427d5e8a7b51715c3a2427 Mon Sep 17 00:00:00 2001 From: ribes Date: Wed, 12 Oct 2011 08:51:31 +0000 Subject: [PATCH] Improvement of TableView Management, you can change jobs with arrows keys --- src/genericgui/BL_GenericGui.cxx | 10 +++++++++- src/genericgui/BL_GenericGui.hxx | 1 + src/genericgui/BL_JobTab.cxx | 7 +++++++ src/genericgui/BL_JobTab.hxx | 1 + src/genericgui/BL_JobsTable.cxx | 11 ++++++++++- src/genericgui/BL_JobsTable.hxx | 2 ++ src/genericgui/BL_QModelManager.cxx | 22 ---------------------- src/genericgui/BL_QModelManager.hxx | 1 - 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/genericgui/BL_GenericGui.cxx b/src/genericgui/BL_GenericGui.cxx index e8c34ff..187fcd4 100644 --- a/src/genericgui/BL_GenericGui.cxx +++ b/src/genericgui/BL_GenericGui.cxx @@ -141,7 +141,8 @@ BL::GenericGui::createCentralWidget() // TableView -> X connect(_jobs_table, SIGNAL(clicked(QModelIndex)), _job_tab, SLOT(job_selected(QModelIndex))); connect(_jobs_table, SIGNAL(clicked(QModelIndex)), this, SLOT(job_selected(QModelIndex))); - connect(_jobs_table, SIGNAL(clicked(QModelIndex)), _model_manager, SLOT(job_selected(QModelIndex))); + connect(_jobs_table, SIGNAL(activated(QModelIndex)), this, SLOT(job_activated(QModelIndex))); + connect(_jobs_table, SIGNAL(activated(QModelIndex)), _job_tab, SLOT(job_activated(QModelIndex))); // Delete Job -> X connect(this, SIGNAL(job_deleted(QString)), _job_tab, SLOT(reset(QString))); } @@ -306,6 +307,13 @@ BL::GenericGui::job_selected(const QModelIndex & index) updateButtonsStates(); } +void +BL::GenericGui::job_activated(const QModelIndex & index) +{ + DEBTRACE("BL::GenericGui::job_activated slot"); + job_selected(index); +} + void BL::GenericGui::job_state_changed(const QString & name) { diff --git a/src/genericgui/BL_GenericGui.hxx b/src/genericgui/BL_GenericGui.hxx index 9cfeceb..8b23023 100644 --- a/src/genericgui/BL_GenericGui.hxx +++ b/src/genericgui/BL_GenericGui.hxx @@ -69,6 +69,7 @@ namespace BL void stop_job(); void get_results_job(); void job_selected(const QModelIndex & index); + void job_activated(const QModelIndex & index); void job_state_changed(const QString & name); void updateButtonsStates(); diff --git a/src/genericgui/BL_JobTab.cxx b/src/genericgui/BL_JobTab.cxx index 2f577eb..0d59f8e 100644 --- a/src/genericgui/BL_JobTab.cxx +++ b/src/genericgui/BL_JobTab.cxx @@ -157,6 +157,13 @@ BL::JobTab::createJobFilesTab() insertTab(1, _files_tab, "Job Files"); } +void +BL::JobTab::job_activated(const QModelIndex & index) +{ + DEBTRACE("BL::JobTab::job_activated slot"); + job_selected(index); +} + void BL::JobTab::job_selected(const QModelIndex & index) { diff --git a/src/genericgui/BL_JobTab.hxx b/src/genericgui/BL_JobTab.hxx index dae5332..8d067f5 100644 --- a/src/genericgui/BL_JobTab.hxx +++ b/src/genericgui/BL_JobTab.hxx @@ -41,6 +41,7 @@ namespace BL public slots: void job_selected(const QModelIndex & index); + void job_activated(const QModelIndex & index); void itemChanged(QStandardItem * item); void reset(QString job_name); diff --git a/src/genericgui/BL_JobsTable.cxx b/src/genericgui/BL_JobsTable.cxx index e657e9f..e611b49 100644 --- a/src/genericgui/BL_JobsTable.cxx +++ b/src/genericgui/BL_JobsTable.cxx @@ -30,10 +30,12 @@ BL::JobsTable::JobsTable(QWidget *parent) : QTableView(parent) setShowGrid(false); setCornerButtonEnabled(false); setEditTriggers(QAbstractItemView::NoEditTriggers); - setSelectionBehavior(QAbstractItemView::SelectRows); setAlternatingRowColors(true); setSortingEnabled(true); + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::ExtendedSelection); + QHeaderView * header_view = verticalHeader(); header_view->setClickable(false); } @@ -42,3 +44,10 @@ BL::JobsTable::~JobsTable() { DEBTRACE("Destroying BL::JobsTable"); } + +void +BL::JobsTable::currentChanged(const QModelIndex & current, const QModelIndex & previous) +{ + DEBTRACE("BL::JobsTable currentChanged"); + activated(current); +} diff --git a/src/genericgui/BL_JobsTable.hxx b/src/genericgui/BL_JobsTable.hxx index 16816fb..a62dd59 100644 --- a/src/genericgui/BL_JobsTable.hxx +++ b/src/genericgui/BL_JobsTable.hxx @@ -35,6 +35,8 @@ namespace BL protected: QWidget* _parent; + protected slots: + void currentChanged(const QModelIndex & current, const QModelIndex & previous); }; } diff --git a/src/genericgui/BL_QModelManager.cxx b/src/genericgui/BL_QModelManager.cxx index f3b0ba0..88f1fd7 100644 --- a/src/genericgui/BL_QModelManager.cxx +++ b/src/genericgui/BL_QModelManager.cxx @@ -134,25 +134,3 @@ BL::QModelManager::deleteJob(const QString & name) if (list.size() > 0) _model->removeRow(list[0]->row()); } - -void -BL::QModelManager::job_selected(const QModelIndex & index) -{ - DEBTRACE("BL::QModelManager::job_selected slot"); - QStandardItem * item = _model->itemFromIndex(index); - int row = item->row(); - - // Algo un peu bourrin.... - for (int i = 0; i < _model->rowCount(); i++) - for (int j = 0; j < _model->columnCount(); j++) - { - _model->item(i,j)->setBackground(QBrush(Qt::white)); - _model->item(i,j)->setForeground(QBrush(Qt::black)); - } - - for (int j = 0; j < _model->columnCount(); j++) - { - _model->item(row,j)->setBackground(QBrush(Qt::darkBlue)); - _model->item(row,j)->setForeground(QBrush(Qt::white)); - } -} diff --git a/src/genericgui/BL_QModelManager.hxx b/src/genericgui/BL_QModelManager.hxx index 75ed8df..72b2cf7 100644 --- a/src/genericgui/BL_QModelManager.hxx +++ b/src/genericgui/BL_QModelManager.hxx @@ -43,7 +43,6 @@ namespace BL{ public slots: void new_job_added(const QString & name); void job_state_changed(const QString & name); - void job_selected(const QModelIndex & index); private: QStandardItemModel * _model; -- 2.39.2