Salome HOME
463233741520d707b7a5107366fe24fffd35da49
[modules/jobmanager.git] / src / genericgui / BL_JobsTable.cxx
1 // Copyright (C) 2009-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_JobsTable.hxx"
21 #include "BL_Traces.hxx"
22 #include "BL_GenericGui.hxx"
23
24 BL::JobsTable::JobsTable(QWidget *parent) : QTableView(parent)
25 {
26   DEBTRACE("Creating BL::JobsTable");
27   BL_ASSERT(parent);
28   _parent = parent;
29   _main_gui = NULL;
30
31   // Init
32   setShowGrid(false);
33   setCornerButtonEnabled(false);
34   setEditTriggers(QAbstractItemView::NoEditTriggers);
35   setAlternatingRowColors(true);
36   setSortingEnabled(true);
37
38   setSelectionBehavior(QAbstractItemView::SelectRows);
39   setSelectionMode(QAbstractItemView::ExtendedSelection);
40
41   QHeaderView * header_view = verticalHeader();
42   header_view->setClickable(false);
43 }
44
45 BL::JobsTable::~JobsTable()
46 {
47   DEBTRACE("Destroying BL::JobsTable");
48 }
49
50 bool
51 BL::JobsTable::selectCurrent()
52 {
53   QModelIndex idx = currentIndex();
54   if (idx.row() > -1)
55     if (!isMultipleSelected())
56     {
57       DEBTRACE("SELECT CURRENT ACTIVATION !!!");
58       setCurrentIndex(idx);
59       activated(idx);
60       return true;
61     }
62   return false;
63 }
64
65 void
66 BL::JobsTable::set_main_gui(BL::GenericGui * main_gui)
67 {
68   _main_gui = main_gui;
69 }
70
71 void 
72 BL::JobsTable::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
73 {
74   QTableView::selectionChanged(selected, deselected);
75   DEBTRACE("selection changed");
76   QModelIndexList selected_rows = selectionModel()->selectedRows();
77   if (selected_rows.length() == 0)
78   {
79     _main_gui->reset_job_selection();
80   }
81   else if (selected_rows.length() == 1)
82   {
83     DEBTRACE("SELECTED CHANGED ACTIVATION !!!");
84     DEBTRACE("ROW NUMBER: " << selected_rows[0].row());
85     QModelIndex current = selected_rows[0];
86     if (!selectionModel()->isSelected(current))
87     {
88       setCurrentIndex(current);
89     }
90     activated(current);
91   }
92   DEBTRACE("Number of selected rows selection: " << selected_rows.length());
93 }
94
95 void
96 BL::JobsTable::currentChanged(const QModelIndex & current, const QModelIndex & previous)
97 {
98   QTableView::currentChanged(current, previous);
99   DEBTRACE("current changed");
100   DEBTRACE("current row: " << current.row());
101   if (current.row() > -1)
102     if (!isMultipleSelected())
103     {
104       DEBTRACE("CURRENT CHANGED ACTIVATION !!!");
105       //setCurrentIndex(current);
106       //activated(current);
107     }
108 }
109
110 bool
111 BL::JobsTable::isMultipleSelected()
112 {
113   QModelIndexList selected_rows = selectionModel()->selectedRows();
114   DEBTRACE("Number of selected rows: " << selected_rows.length());
115   if (selected_rows.length() > 1)
116     return true;
117   else
118     return false;
119 }
120
121 QModelIndexList
122 BL::JobsTable::getSelectedIndexes()
123 {
124   return selectedIndexes();
125 }