From: ribes Date: Wed, 12 Oct 2011 14:39:58 +0000 (+0000) Subject: Multiple delete management X-Git-Tag: V6_4_0a1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=06c552e0faa405fa705a7b124dc6995b301e5071;p=modules%2Fjobmanager.git Multiple delete management --- diff --git a/src/genericgui/BL_GenericGui.cxx b/src/genericgui/BL_GenericGui.cxx index 187fcd4..8eb1fed 100644 --- a/src/genericgui/BL_GenericGui.cxx +++ b/src/genericgui/BL_GenericGui.cxx @@ -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(); diff --git a/src/genericgui/BL_GenericGui.hxx b/src/genericgui/BL_GenericGui.hxx index 8b23023..3f4a33f 100644 --- a/src/genericgui/BL_GenericGui.hxx +++ b/src/genericgui/BL_GenericGui.hxx @@ -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; }; } diff --git a/src/genericgui/BL_JobTab.cxx b/src/genericgui/BL_JobTab.cxx index 0d59f8e..d7b45d6 100644 --- a/src/genericgui/BL_JobTab.cxx +++ b/src/genericgui/BL_JobTab.cxx @@ -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(""); + } } diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index b9f9bf6..5ceb460 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -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 diff --git a/src/genericgui/BL_JobsManager_QT.hxx b/src/genericgui/BL_JobsManager_QT.hxx index c85a6ae..18f3a26 100644 --- a/src/genericgui/BL_JobsManager_QT.hxx +++ b/src/genericgui/BL_JobsManager_QT.hxx @@ -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 @@ -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; }; } diff --git a/src/genericgui/BL_JobsTable.cxx b/src/genericgui/BL_JobsTable.cxx index e611b49..60eba5b 100644 --- a/src/genericgui/BL_JobsTable.cxx +++ b/src/genericgui/BL_JobsTable.cxx @@ -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(); } diff --git a/src/genericgui/BL_JobsTable.hxx b/src/genericgui/BL_JobsTable.hxx index a62dd59..9d48557 100644 --- a/src/genericgui/BL_JobsTable.hxx +++ b/src/genericgui/BL_JobsTable.hxx @@ -32,6 +32,10 @@ namespace BL JobsTable(QWidget *parent); virtual ~JobsTable(); + bool selectCurrent(); + bool isMultipleSelected(); + QModelIndexList getSelectedIndexes(); + protected: QWidget* _parent; diff --git a/src/genericgui/BL_QModelManager.cxx b/src/genericgui/BL_QModelManager.cxx index 88f1fd7..d46199b 100644 --- a/src/genericgui/BL_QModelManager.cxx +++ b/src/genericgui/BL_QModelManager.cxx @@ -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 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()); diff --git a/src/genericgui/BL_QModelManager.hxx b/src/genericgui/BL_QModelManager.hxx index 72b2cf7..8bfd7f7 100644 --- a/src/genericgui/BL_QModelManager.hxx +++ b/src/genericgui/BL_QModelManager.hxx @@ -23,10 +23,10 @@ #include #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);