]> SALOME platform Git repositories - modules/jobmanager.git/blob - src/genericgui/BL_JobsTable.cxx
Salome HOME
c5e9b4c82924a91b9b7c1d88083a4a09f56ce535
[modules/jobmanager.git] / src / genericgui / BL_JobsTable.cxx
1 // Copyright (C) 2009-2015  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 #include <QHeaderView>
25 #include <QMainWindow>
26
27 BL::JobsTable::JobsTable(QWidget *parent) : QTableView(parent)
28 {
29   DEBTRACE("Creating BL::JobsTable");
30   BL_ASSERT(parent);
31   _parent = parent;
32   _main_gui = NULL;
33
34   // Init
35   setShowGrid(false);
36   setCornerButtonEnabled(false);
37   setEditTriggers(QAbstractItemView::NoEditTriggers);
38   setAlternatingRowColors(true);
39   setSortingEnabled(true);
40
41   setSelectionBehavior(QAbstractItemView::SelectRows);
42   setSelectionMode(QAbstractItemView::ExtendedSelection);
43
44   QHeaderView * header_view = verticalHeader();
45   header_view->setClickable(false);
46 }
47
48 BL::JobsTable::~JobsTable()
49 {
50   DEBTRACE("Destroying BL::JobsTable");
51 }
52
53 bool
54 BL::JobsTable::selectCurrent()
55 {
56   QModelIndex idx = currentIndex();
57   if (idx.row() > -1)
58     if (!isMultipleSelected())
59     {
60       DEBTRACE("SELECT CURRENT ACTIVATION !!!");
61       setCurrentIndex(idx);
62       activated(idx);
63       return true;
64     }
65   return false;
66 }
67
68 void
69 BL::JobsTable::set_main_gui(BL::GenericGui * main_gui)
70 {
71   _main_gui = main_gui;
72 }
73
74 void 
75 BL::JobsTable::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
76 {
77   QTableView::selectionChanged(selected, deselected);
78   DEBTRACE("selection changed");
79   QModelIndexList selected_rows = selectionModel()->selectedRows();
80   if (selected_rows.length() == 0)
81   {
82     _main_gui->reset_job_selection();
83   }
84   else if (selected_rows.length() == 1)
85   {
86     DEBTRACE("SELECTED CHANGED ACTIVATION !!!");
87     DEBTRACE("ROW NUMBER: " << selected_rows[0].row());
88     QModelIndex current = selected_rows[0];
89     if (!selectionModel()->isSelected(current))
90     {
91       setCurrentIndex(current);
92     }
93     activated(current);
94   }
95   DEBTRACE("Number of selected rows selection: " << selected_rows.length());
96 }
97
98 void
99 BL::JobsTable::currentChanged(const QModelIndex & current, const QModelIndex & previous)
100 {
101   QTableView::currentChanged(current, previous);
102   DEBTRACE("current changed");
103   DEBTRACE("current row: " << current.row());
104   if (current.row() > -1)
105     if (!isMultipleSelected())
106     {
107       DEBTRACE("CURRENT CHANGED ACTIVATION !!!");
108       //setCurrentIndex(current);
109       //activated(current);
110     }
111 }
112
113 bool
114 BL::JobsTable::isMultipleSelected()
115 {
116   QModelIndexList selected_rows = selectionModel()->selectedRows();
117   DEBTRACE("Number of selected rows: " << selected_rows.length());
118   if (selected_rows.length() > 1)
119     return true;
120   else
121     return false;
122 }
123
124 QModelIndexList
125 BL::JobsTable::getSelectedIndexes()
126 {
127   return selectedIndexes();
128 }