]> SALOME platform Git repositories - modules/jobmanager.git/commitdiff
Salome HOME
Multiple delete management
authorribes <ribes>
Wed, 12 Oct 2011 14:39:58 +0000 (14:39 +0000)
committerribes <ribes>
Wed, 12 Oct 2011 14:39:58 +0000 (14:39 +0000)
src/genericgui/BL_GenericGui.cxx
src/genericgui/BL_GenericGui.hxx
src/genericgui/BL_JobTab.cxx
src/genericgui/BL_JobsManager_QT.cxx
src/genericgui/BL_JobsManager_QT.hxx
src/genericgui/BL_JobsTable.cxx
src/genericgui/BL_JobsTable.hxx
src/genericgui/BL_QModelManager.cxx
src/genericgui/BL_QModelManager.hxx

index 187fcd445c84ddcf7bfa400faed4c52a3635cdad..8eb1fede294f3829bea8b76e753c9cba83a90b97 100644 (file)
@@ -24,7 +24,6 @@ BL::GenericGui::GenericGui(BL::MainWindows_Wrap * wrapper) : QObject(wrapper->ge
   DEBTRACE("Creating BL::GenericGui");
   BL_ASSERT(wrapper);
   _wrapper = wrapper;
-  _row_selected = -1;
   _job_name_selected = "";
 
   _dock_parent = _wrapper->getDockParent();
@@ -138,13 +137,12 @@ BL::GenericGui::createCentralWidget()
   /* Signals and Slots */
   // Model -> JobTab
   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)));
-  // Delete Job -> X
-  connect(this, SIGNAL(job_deleted(QString)), _job_tab, SLOT(reset(QString)));
 }
 
 void
@@ -174,7 +172,7 @@ BL::GenericGui::showDockWidgets(bool isVisible)
   if (_dw_resource_catalog) {
     _dw_resource_catalog->setVisible(isVisible);
     _dw_resource_catalog->toggleViewAction()->setVisible(isVisible);
-  }    
+  }
 }
 
 void
@@ -262,9 +260,20 @@ void
 BL::GenericGui::delete_job()
 {
   DEBTRACE("Delete Job Slot BL::GenericGui");
-  int ret = QMessageBox::warning(NULL, "Delete a job", "Do you really want to delete this job ?",
-                                 QMessageBox::Ok|QMessageBox::Cancel,
-                                 QMessageBox::Ok);
+  int ret = QMessageBox::Cancel;
+
+  if (!_jobs_table->isMultipleSelected())
+  {
+    ret = QMessageBox::warning(NULL, "Delete a job", "Do you really want to delete job " + _job_name_selected + " ? ",
+                               QMessageBox::Ok|QMessageBox::Cancel,
+                               QMessageBox::Ok);
+  }
+  else
+  {
+   ret = QMessageBox::warning(NULL, "Delete jobs", "Do you really want to delete these jobs ?",
+                              QMessageBox::Ok|QMessageBox::Cancel,
+                              QMessageBox::Ok);
+  }
   if (ret == QMessageBox::Ok)
   {
     delete_job_internal();
@@ -274,12 +283,10 @@ BL::GenericGui::delete_job()
 void
 BL::GenericGui::delete_job_external(const QString & name)
 {
+  DEBTRACE("Delete Job External");
   _jobs_manager->delete_job(name);
-  _model_manager->deleteJob(name);
-  emit job_deleted(name);
-  if (name == _job_name_selected)
+  if (!_jobs_table->selectCurrent())
   {
-    _row_selected = -1;
     _job_name_selected = "";
     updateButtonsStates();
   }
@@ -288,22 +295,44 @@ BL::GenericGui::delete_job_external(const QString & name)
 void
 BL::GenericGui::delete_job_internal()
 {
-  _jobs_manager->delete_job(_job_name_selected);
-  _model_manager->deleteJob(_row_selected);
-  emit job_deleted(_job_name_selected);
-  _row_selected = -1;
-  _job_name_selected = "";
-  updateButtonsStates();
+  if (!_jobs_table->isMultipleSelected())
+  {
+    QModelIndexList selected_list = _jobs_table->getSelectedIndexes();
+    QString job_name_to_delete    = _model->itemFromIndex(selected_list[0])->text();
+    DEBTRACE("Single Deleting job: " << job_name_to_delete.toStdString());
+    _jobs_manager->delete_job(job_name_to_delete);
+    if (!_jobs_table->selectCurrent())
+    {
+      _job_name_selected = "";
+      updateButtonsStates();
+    }
+  }
+  else
+  {
+    QModelIndexList selected_list = _jobs_table->getSelectedIndexes();
+    QString job_name = _model->itemFromIndex(selected_list[0])->text();
+    DEBTRACE("Multiple Deleting job: " << job_name.toStdString());
+    _jobs_manager->delete_job(job_name);
+    delete_job_internal(); // Recursive delete
+  }
 }
 
 void
 BL::GenericGui::job_selected(const QModelIndex & index)
 {
-  DEBTRACE("BL::GenericGui::job_selected slot");
-  QStandardItem * item = _model->itemFromIndex(index);
-  QStandardItem * item_name = _model->item(item->row());
-  _row_selected = item->row();
-  _job_name_selected = item_name->text();
+  DEBTRACE("BL::GenericGui::job_selected");
+  if (index.row() >= 0)
+  {
+    QStandardItem * item = _model->itemFromIndex(index);
+    QStandardItem * item_name = _model->item(item->row());
+    _job_name_selected = item_name->text();
+    DEBTRACE("BL::GenericGui::job_selected name is " << _job_name_selected.toStdString());
+  }
+  else
+  {
+    _job_name_selected = "";
+    DEBTRACE("BL::GenericGui::job_selected - no jobs are selected");
+  }
   updateButtonsStates();
 }
 
@@ -314,19 +343,48 @@ BL::GenericGui::job_activated(const QModelIndex & index)
   job_selected(index);
 }
 
-void 
+void
 BL::GenericGui::job_state_changed(const QString & name)
 {
   if (name == _job_name_selected)
     updateButtonsStates();
 }
+
 void
 BL::GenericGui::updateButtonsStates()
 {
-  DEBTRACE("BL::GenericGui::updateButtonsStates slot");
+  if (!_jobs_table->isMultipleSelected())
+  {
+    updateButtonsStatesSingleSelection();
+  }
+  else
+  {
+    _start_job_action->setEnabled(false);
+    _edit_clone_job_action->setEnabled(false);
+    _restart_job_action->setEnabled(false);
+    _buttons->disable_start_button();
+    _buttons->disable_edit_clone_button();
+    _buttons->disable_restart_button();
+
+    // You can always delete jobs
+    _delete_job_action->setEnabled(true);
+    _buttons->enable_delete_button();
+
+    _stop_job_action->setEnabled(false);
+    _buttons->disable_stop_button();
+
+    _get_results_job_action->setEnabled(false);
+    _buttons->disable_get_results_button();
+  }
+}
+
+void
+BL::GenericGui::updateButtonsStatesSingleSelection()
+{
+  DEBTRACE("BL::GenericGui::updateButtonsStatesSingleSelection slot");
 
   // First case: no job selected
-  if (_job_name_selected == "" and _row_selected == -1)
+  if (_job_name_selected == "")
   {
     _start_job_action->setEnabled(false);
     _delete_job_action->setEnabled(false);
@@ -341,7 +399,7 @@ BL::GenericGui::updateButtonsStates()
     _stop_job_action->setEnabled(false);
     _buttons->disable_stop_button();
   }
-  else if (_job_name_selected != "" and _row_selected != -1)
+  else if (_job_name_selected != "")
   {
     BL::Job * job = _jobs_manager->getJob(_job_name_selected.toStdString());
     BL::Job::State job_state = job->getState();
index 8b23023803a98e42f1c60a10f620f4fbc3f7fde5..3f4a33f029b3a351b00cff0c2f2c2352b5228d30 100644 (file)
@@ -72,12 +72,12 @@ namespace BL
       void job_activated(const QModelIndex & index);
       void job_state_changed(const QString & name);
       void updateButtonsStates();
+      void updateButtonsStatesSingleSelection();
 
-    signals:
-      void job_deleted(QString job_name);
+    public:
+      BL::JobTab * _job_tab;
 
     protected:
-     
       BL::MainWindows_Wrap * _wrapper;
 
       BL::SALOMEServices * _salome_services;
@@ -86,10 +86,9 @@ namespace BL
       QMainWindow * _tab_parent;
       QDockWidget * _dw_summary;
       QDockWidget * _dw_resource_catalog;
-     
+
       BL::Buttons * _buttons;
-      BL::JobsTable * _jobs_table;  
-      BL::JobTab * _job_tab;
+      BL::JobsTable * _jobs_table;
       BL::Summary * _summary;
 
       QAction * _create_job_action;
@@ -106,7 +105,6 @@ namespace BL
       QStandardItemModel * _model;
       JM::ResourceCatalog * _resource_catalog;
 
-      int _row_selected;
       QString _job_name_selected;
   };
 }
index 0d59f8e0ade094147bf7acc99155af2f44351097..d7b45d647258db062ce5fb5aa6929059152e5096 100644 (file)
@@ -293,25 +293,28 @@ BL::JobTab::itemChanged(QStandardItem * item)
 void
 BL::JobTab::reset(QString job_name)
 {
-  _job_name_label_value->setText("");
-  _job_type_label_value->setText("");
-  _job_state_label_value->setText("");
-  _job_launcher_label_value->setText("");
-  _job_resource_label_value->setText("");
-  _job_nif_label_value->setText("");
-  _job_nof_label_value->setText("");
-  _job_bd_label_value->setText("");
-  _job_rd_label_value->setText("");
-  _job_mdt_label_value->setText("");
-  _job_em_label_value->setText("");
-  _job_nop_label_value->setText("");
-  _job_jobfile_label_value->setText("");
-  _job_envfile_label_value->setText("");
-
-  _input_files_list->clear();
-  _output_files_list->clear();
-
-  _yacs_dump_state_value->setText("");
-  _batch_queue_value->setText("");
-  _ll_jobtype_value->setText("");
+  if (job_name == _job_name_label_value->text() || job_name == "")
+  {
+    _job_name_label_value->setText("");
+    _job_type_label_value->setText("");
+    _job_state_label_value->setText("");
+    _job_launcher_label_value->setText("");
+    _job_resource_label_value->setText("");
+    _job_nif_label_value->setText("");
+    _job_nof_label_value->setText("");
+    _job_bd_label_value->setText("");
+    _job_rd_label_value->setText("");
+    _job_mdt_label_value->setText("");
+    _job_em_label_value->setText("");
+    _job_nop_label_value->setText("");
+    _job_jobfile_label_value->setText("");
+    _job_envfile_label_value->setText("");
+
+    _input_files_list->clear();
+    _output_files_list->clear();
+
+    _yacs_dump_state_value->setText("");
+    _batch_queue_value->setText("");
+    _ll_jobtype_value->setText("");
+  }
 }
index b9f9bf649a01a628bbd3db8596b57243b262beb1..5ceb46028444a75c726a64c3781fea8b551fe774 100644 (file)
@@ -39,7 +39,7 @@ BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui,
   DEBTRACE("Creating BL::JobsManager_QT");
   _main_gui = main_gui;
   setObserver(this);
-  _model = NULL;
+  _model_manager = NULL;
 
   // Widget Part
 
@@ -96,9 +96,9 @@ BL::JobsManager_QT::~JobsManager_QT()
 }
 
 void
-BL::JobsManager_QT::set_model(QStandardItemModel * model)
+BL::JobsManager_QT::set_model_manager(BL::QModelManager * model_manager)
 {
-  _model = model;
+  _model_manager = model_manager;
 }
 
 void
@@ -313,6 +313,8 @@ void
 BL::JobsManager_QT::delete_job(QString job_name)
 {
   BL::JobsManager::removeJob(job_name.toStdString());
+  _model_manager->delete_job(job_name);
+  _main_gui->_job_tab->reset(job_name);
 }
 
 void 
index c85a6ae38ed019981d546ae03d01c926c16388e7..18f3a26c668042d9058d94e3472eeceb541f0658 100644 (file)
@@ -25,6 +25,8 @@
 #include "BL_Traces.hxx"
 #include "BL_JobsManager.hxx"
 #include "BL_CreateJobWizard.hxx"
+#include "BL_JobsManager.hxx"
+#include "BL_QModelManager.hxx"
 
 #include <string>
 
@@ -72,7 +74,7 @@ namespace BL{
       void write_normal_text(const QString & text);
       void write_error_text(const QString & text);
 
-      void set_model(QStandardItemModel * model);
+      void set_model_manager(BL::QModelManager * model_manager);
 
     protected:
       void create_job_with_wizard(BL::CreateJobWizard & wizard);
@@ -100,7 +102,7 @@ namespace BL{
       QTimer * _timer;
       QTextEdit * _log;
       BL::GenericGui * _main_gui;
-      QStandardItemModel * _model;
+      BL::QModelManager * _model_manager;
   };
 
 }
index e611b49a4ffdf129c3aed9d7e530b7c8229d6955..60eba5b053289d1045e61f295194cfecd22cd4ca 100644 (file)
@@ -45,9 +45,50 @@ BL::JobsTable::~JobsTable()
   DEBTRACE("Destroying BL::JobsTable");
 }
 
+bool
+BL::JobsTable::selectCurrent()
+{
+  QModelIndex idx = currentIndex();
+  if (idx.row() > -1)
+    if (!isMultipleSelected())
+    {
+      DEBTRACE("SELECT CURRENT ACTIVATION !!!");
+      setCurrentIndex(idx);
+      activated(idx);
+      return true;
+    }
+  return false;
+}
+
 void
 BL::JobsTable::currentChanged(const QModelIndex & current, const QModelIndex & previous)
 {
-  DEBTRACE("BL::JobsTable currentChanged");
-  activated(current);
+  DEBTRACE("current changed");
+  DEBTRACE("current row: " << current.row());
+  if (current.row() > -1)
+    if (!isMultipleSelected())
+    {
+      DEBTRACE("CURRENT CHANGED ACTIVATION !!!");
+      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)
+    return true;
+  else
+    return false;
+}
+
+QModelIndexList
+BL::JobsTable::getSelectedIndexes()
+{
+  return selectedIndexes();
 }
index a62dd59eba8dba972ab9ba5d83b8c1c6febdd0cb..9d485578370ceced6d3e08152353a019ea29738b 100644 (file)
@@ -32,6 +32,10 @@ namespace BL
       JobsTable(QWidget *parent);
       virtual ~JobsTable();
 
+      bool selectCurrent();
+      bool isMultipleSelected();
+      QModelIndexList getSelectedIndexes();
+
     protected:
       QWidget* _parent;
 
index 88f1fd7c777a81dfb99ffc9861d8c28f2230d1c6..d46199bc2ae1dad3727d72fc5f89c64f6e0e0b54 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "BL_QModelManager.hxx"
+#include "BL_JobsManager_QT.hxx"
 
 BL::QModelManager::QModelManager(QObject * parent, BL::JobsManager_QT * jobs_manager) : QObject(parent)
 {
@@ -26,7 +27,7 @@ BL::QModelManager::QModelManager(QObject * parent, BL::JobsManager_QT * jobs_man
   _jobs_manager = jobs_manager;
 
   _model = new QStandardItemModel(this);
-  jobs_manager->set_model(_model);
+  jobs_manager->set_model_manager(this);
   QStringList headers;
   headers << "Job Name" << "Type" << "State" << "Resource" << "Launcher Id";
   _model->setHorizontalHeaderLabels(headers);
@@ -118,18 +119,13 @@ BL::QModelManager::job_state_changed(const QString & name)
 }
 
 void
-BL::QModelManager::deleteJob(int row)
-{
-  _model->removeRow(row);
-}
-
-void
-BL::QModelManager::deleteJob(const QString & name)
+BL::QModelManager::delete_job(const QString & name)
 {
   QList<QStandardItem *> list = _model->findItems(name);
   if (list.size() != 1)
   {
-    DEBMSG("WARNING LIST IS NOT ONLY ONE !");
+    DEBMSG("LIST SIZE IS :" << list.size());
+    DEBMSG("FOR NAME :" << name.toStdString());
   }
   if (list.size() > 0)
     _model->removeRow(list[0]->row());
index 72b2cf70d94cd2137d9248b51a34eccc0a26fbd5..8bfd7f7f6d5f8ba318f1cd9788dd71cd73b24557 100644 (file)
 #include <QtGui>
 
 #include "BL_Job.hxx"
-#include "BL_JobsManager_QT.hxx"
 
 namespace BL{
 
+  class JobsManager_QT;
   class QModelManager: virtual public QObject
   {
     Q_OBJECT
@@ -37,8 +37,7 @@ namespace BL{
       
       QStandardItemModel * getModel();
 
-      void deleteJob(int row);
-      void deleteJob(const QString & name);
+      void delete_job(const QString & name);
 
     public slots:
       void new_job_added(const QString & name);