Salome HOME
Merge branch 'V7_dev'
[modules/jobmanager.git] / src / genericgui / BL_JobsTable.cxx
1 // Copyright (C) 2009-2016  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 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
46   header_view->setClickable(false);
47 #else
48   header_view->setSectionsClickable(false);
49 #endif
50 }
51
52 BL::JobsTable::~JobsTable()
53 {
54   DEBTRACE("Destroying BL::JobsTable");
55 }
56
57 bool
58 BL::JobsTable::selectCurrent()
59 {
60   QModelIndex idx = currentIndex();
61   if (idx.row() > -1)
62     if (!isMultipleSelected())
63     {
64       DEBTRACE("SELECT CURRENT ACTIVATION !!!");
65       setCurrentIndex(idx);
66       activated(idx);
67       return true;
68     }
69   return false;
70 }
71
72 void
73 BL::JobsTable::set_main_gui(BL::GenericGui * main_gui)
74 {
75   _main_gui = main_gui;
76 }
77
78 void 
79 BL::JobsTable::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
80 {
81   QTableView::selectionChanged(selected, deselected);
82   DEBTRACE("selection changed");
83   QModelIndexList selected_rows = selectionModel()->selectedRows();
84   if (selected_rows.length() == 0)
85   {
86     _main_gui->reset_job_selection();
87   }
88   else if (selected_rows.length() == 1)
89   {
90     DEBTRACE("SELECTED CHANGED ACTIVATION !!!");
91     DEBTRACE("ROW NUMBER: " << selected_rows[0].row());
92     QModelIndex current = selected_rows[0];
93     if (!selectionModel()->isSelected(current))
94     {
95       setCurrentIndex(current);
96     }
97     activated(current);
98   }
99   DEBTRACE("Number of selected rows selection: " << selected_rows.length());
100 }
101
102 void
103 BL::JobsTable::currentChanged(const QModelIndex & current, const QModelIndex & previous)
104 {
105   QTableView::currentChanged(current, previous);
106   DEBTRACE("current changed");
107   DEBTRACE("current row: " << current.row());
108   if (current.row() > -1)
109     if (!isMultipleSelected())
110     {
111       DEBTRACE("CURRENT CHANGED ACTIVATION !!!");
112       //setCurrentIndex(current);
113       //activated(current);
114     }
115 }
116
117 bool
118 BL::JobsTable::isMultipleSelected()
119 {
120   QModelIndexList selected_rows = selectionModel()->selectedRows();
121   DEBTRACE("Number of selected rows: " << selected_rows.length());
122   if (selected_rows.length() > 1)
123     return true;
124   else
125     return false;
126 }
127
128 QModelIndexList
129 BL::JobsTable::getSelectedIndexes()
130 {
131   return selectedIndexes();
132 }