]> SALOME platform Git repositories - modules/jobmanager.git/commitdiff
Salome HOME
Finaly a correct management of selection in TableView
authorribes <ribes>
Wed, 12 Oct 2011 16:29:41 +0000 (16:29 +0000)
committerribes <ribes>
Wed, 12 Oct 2011 16:29:41 +0000 (16:29 +0000)
src/genericgui/BL_GenericGui.cxx
src/genericgui/BL_GenericGui.hxx
src/genericgui/BL_JobTab.cxx
src/genericgui/BL_JobTab.hxx
src/genericgui/BL_JobsTable.cxx
src/genericgui/BL_JobsTable.hxx

index 8eb1fede294f3829bea8b76e753c9cba83a90b97..85603c1abe8cfe92cc29665e8e2ac7267115c9c5 100644 (file)
@@ -112,6 +112,7 @@ BL::GenericGui::createCentralWidget()
   /* Jobs Table */
   _jobs_table = new BL::JobsTable(_tab_parent);
   _jobs_table->setModel(_model);
+  _jobs_table->set_main_gui(this);
 
   /* Job Tab */
   _job_tab = new BL::JobTab(_tab_parent, _jobs_manager);
@@ -139,10 +140,8 @@ BL::GenericGui::createCentralWidget()
   connect(_model, SIGNAL(itemChanged(QStandardItem*)), _job_tab, SLOT(itemChanged(QStandardItem*)));
 
   // 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(activated(QModelIndex)), this, SLOT(job_activated(QModelIndex)));
-  connect(_jobs_table, SIGNAL(activated(QModelIndex)), _job_tab, SLOT(job_activated(QModelIndex)));
 }
 
 void
@@ -317,20 +316,36 @@ BL::GenericGui::delete_job_internal()
   }
 }
 
+void
+BL::GenericGui::reset_job_selection()
+{
+  _job_name_selected = "";
+  _job_tab->reset("");
+  updateButtonsStates();
+}
+
 void
 BL::GenericGui::job_selected(const QModelIndex & index)
 {
   DEBTRACE("BL::GenericGui::job_selected");
-  if (index.row() >= 0)
+
+  //Find if a job is selected (ignore index)
+  //If Multiple job are selected, take first job
+  QItemSelectionModel * selection_model = _jobs_table->selectionModel();
+  QModelIndexList selected_rows = selection_model->selectedRows();
+  if (selected_rows.length() >= 1)
   {
-    QStandardItem * item = _model->itemFromIndex(index);
+    QModelIndex idx = selected_rows[0];
+    QStandardItem * item = _model->itemFromIndex(idx);
     QStandardItem * item_name = _model->item(item->row());
     _job_name_selected = item_name->text();
+    _job_tab->job_selected(idx);
     DEBTRACE("BL::GenericGui::job_selected name is " << _job_name_selected.toStdString());
   }
   else
   {
     _job_name_selected = "";
+    _job_tab->reset("");
     DEBTRACE("BL::GenericGui::job_selected - no jobs are selected");
   }
   updateButtonsStates();
@@ -370,8 +385,31 @@ BL::GenericGui::updateButtonsStates()
     _delete_job_action->setEnabled(true);
     _buttons->enable_delete_button();
 
-    _stop_job_action->setEnabled(false);
-    _buttons->disable_stop_button();
+    // Enable stop ?
+    bool enable_stop = true;
+    QModelIndexList selected_rows = _jobs_table->selectionModel()->selectedRows();
+    for (int i = 0; i < selected_rows.length(); ++i)
+    {
+      QString job_name = _model->itemFromIndex(selected_rows[i])->text();
+      DEBTRACE(job_name.toStdString());
+
+      BL::Job * job = _jobs_manager->getJob(job_name.toStdString());
+      BL::Job::State job_state = job->getState();
+      if (job_state != BL::Job::QUEUED  &&
+          job_state != BL::Job::RUNNING &&
+          job_state != BL::Job::PAUSED)
+        enable_stop = false;
+    }
+    if (enable_stop)
+    {
+      _stop_job_action->setEnabled(true);
+      _buttons->enable_stop_button();
+    }
+    else
+    {
+      _stop_job_action->setEnabled(false);
+      _buttons->disable_stop_button();
+    }
 
     _get_results_job_action->setEnabled(false);
     _buttons->disable_get_results_button();
index 3f4a33f029b3a351b00cff0c2f2c2352b5228d30..a30882835254302279daf3e397686614c06c8115 100644 (file)
@@ -58,6 +58,8 @@ namespace BL
       void deleteDockWidget();
       void delete_job_external(const QString & name);
 
+      void reset_job_selection();
+
 
     public slots:
       void create_job();
index d7b45d647258db062ce5fb5aa6929059152e5096..9b1baed15dd1067fdc24b3bad58b8dc5c0fef963 100644 (file)
@@ -157,13 +157,6 @@ 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)
 {
index 8d067f55fa5d538a87cc7490b238d67e123ef153..7587d2f2d02d63b79c7a3f46120e2c726d1fd289 100644 (file)
@@ -38,10 +38,9 @@ namespace BL
 
       void createJobSummaryTab();
       void createJobFilesTab();
+      void job_selected(const QModelIndex & index);
 
     public slots:
-      void job_selected(const QModelIndex & index);
-      void job_activated(const QModelIndex & index);
       void itemChanged(QStandardItem * item);
       void reset(QString job_name);
 
index 60eba5b053289d1045e61f295194cfecd22cd4ca..5782465aa45a67e20830b2eb9b34c1d060648d79 100644 (file)
 
 #include "BL_JobsTable.hxx"
 #include "BL_Traces.hxx"
+#include "BL_GenericGui.hxx"
 
 BL::JobsTable::JobsTable(QWidget *parent) : QTableView(parent)
 {
   DEBTRACE("Creating BL::JobsTable");
   BL_ASSERT(parent);
   _parent = parent;
+  _main_gui = NULL;
 
   // Init
   setShowGrid(false);
@@ -60,28 +62,57 @@ BL::JobsTable::selectCurrent()
   return false;
 }
 
+void
+BL::JobsTable::set_main_gui(BL::GenericGui * main_gui)
+{
+  _main_gui = main_gui;
+}
+
+void 
+BL::JobsTable::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
+{
+  QTableView::selectionChanged(selected, deselected);
+  DEBTRACE("selection changed");
+  QModelIndexList selected_rows = selectionModel()->selectedRows();
+  if (selected_rows.length() == 0)
+  {
+    _main_gui->reset_job_selection();
+  }
+  else if (selected_rows.length() == 1)
+  {
+    DEBTRACE("SELECTED CHANGED ACTIVATION !!!");
+    DEBTRACE("ROW NUMBER: " << selected_rows[0].row());
+    QModelIndex current = selected_rows[0];
+    if (!selectionModel()->isSelected(current))
+    {
+      setCurrentIndex(current);
+    }
+    activated(current);
+  }
+  DEBTRACE("Number of selected rows selection: " << selected_rows.length());
+}
+
 void
 BL::JobsTable::currentChanged(const QModelIndex & current, const QModelIndex & previous)
 {
+  QTableView::currentChanged(current, previous);
   DEBTRACE("current changed");
   DEBTRACE("current row: " << current.row());
   if (current.row() > -1)
     if (!isMultipleSelected())
     {
       DEBTRACE("CURRENT CHANGED ACTIVATION !!!");
-      setCurrentIndex(current);
-      activated(current);
+      //setCurrentIndex(current);
+      //activated(current);
     }
 }
 
 bool
 BL::JobsTable::isMultipleSelected()
 {
-  QModelIndexList list_of_selected = selectedIndexes();
-  int length = list_of_selected.length();
-  length = length / model()->columnCount();
-  DEBTRACE("Number of selected rows: " << length);
-  if (length > 1)
+  QModelIndexList selected_rows = selectionModel()->selectedRows();
+  DEBTRACE("Number of selected rows: " << selected_rows.length());
+  if (selected_rows.length() > 1)
     return true;
   else
     return false;
index 9d485578370ceced6d3e08152353a019ea29738b..2f850bf112810e4f63fadda32d89d5b4f6c7c71c 100644 (file)
@@ -22,8 +22,9 @@
 
 #include <QtGui>
 
-namespace BL 
+namespace BL
 {
+  class GenericGui;
   class JobsTable: public QTableView
   {
     Q_OBJECT
@@ -35,12 +36,17 @@ namespace BL
       bool selectCurrent();
       bool isMultipleSelected();
       QModelIndexList getSelectedIndexes();
+      void set_main_gui(BL::GenericGui * main_gui);
 
     protected:
       QWidget* _parent;
 
     protected slots:
+      void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected );
       void currentChanged(const QModelIndex & current, const QModelIndex & previous);
+
+    private:
+      BL::GenericGui * _main_gui;
   };
 }