-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocview.cpp
More file actions
60 lines (55 loc) · 2.47 KB
/
procview.cpp
File metadata and controls
60 lines (55 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "procview.h"
ProcessView::ProcessView(QWidget * parent): QTableView(parent)
{
setMouseTracking(true); // needed to catch mouse moves
resizeColumnsToContents();
resizeRowsToContents();
verticalHeader()->hide(); // hide left side table headers
setSortingEnabled(true);
setEditTriggers(QAbstractItemView::NoEditTriggers); // set whole table as read-only
}
void ProcessView::mousePressEvent(QMouseEvent *me)
{
QModelIndex posindex = indexAt(me->pos()); // get model cell index at mouse position to obtain selected cell
int row = posindex.row();
if(model()==nullptr) std::cout<<"ERROR! no model set for view"<<std::endl; // catch lack of model for this view. This should not occur and is for debug
if(me->button()==Qt::LeftButton)
{
if (row>-1 && row<listprocmodel->rowCount())
{
listprocmodel->addproctobekilled(row); // add the selected process number to those to be killed
emit(dataChanged(listprocmodel->index(row,0),listprocmodel->index(row,listprocmodel->columnCount()-1)));
}
else
{
QTableView::mousePressEvent(me); // otherwise pass mouse event to base class
}
}
else if(me->button()==Qt::RightButton) // then undo this selection
{
if (row>-1 && row<listprocmodel->rowCount())
{
listprocmodel->removeproctobekilled(row); // remove the selected process number to those to be killed
emit(dataChanged(listprocmodel->index(row,0),listprocmodel->index(row,listprocmodel->columnCount()-1)));
}
else
{
QTableView::mousePressEvent(me); // otherwise pass mouse event to base class
}
}
else
{
QTableView::mousePressEvent(me); // otherwise pass mouse event to base class
}
}
void ProcessView::setModel(QAbstractItemModel *setmodel)
{
QTableView::setModel(setmodel); //default setting of model
listprocmodel =dynamic_cast<ListProcModel *> (model()); // set alias of the view's model
connect(listprocmodel,SIGNAL(updateviewwidth()),this,SLOT(updatecolumnwidth()));
}
void ProcessView::updatecolumnwidth() // slot to resize column widths. Typically called by the model when data changes
{
resizeRowsToContents();
resizeColumnsToContents();
}