-
Notifications
You must be signed in to change notification settings - Fork 38
/
filteringlistview.cpp
118 lines (101 loc) · 2.76 KB
/
filteringlistview.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "filteringlistview.h"
#include "wrench.h"
#include "filteringmodel.h"
FilteringListView::FilteringListView(QWidget *parent) :
QListView(parent)
{
}
void FilteringListView::nextEntry()
{
changeSelection(1);
}
void FilteringListView::changeSelection(int how)
{
QModelIndexList ml = selectedIndexes();
int selected = -1;
if (!ml.isEmpty()) {
selected = ml[0].row();
}
selected = selected + how;
if (selected < 0) {
selected = 0;
} else if (selected >= model()->rowCount()) {
selected = model()->rowCount() - 1;
}
if (selected >= 0 && selected < model()->rowCount()) {
this->clearSelection();
selectionModel()->select(model()->index(selected, 0), QItemSelectionModel::Select);
scrollTo(model()->index(selected, 0));
}
}
void FilteringListView::prevEntry()
{
changeSelection(-1);
}
void FilteringListView::firstEntry()
{
changeSelection(-model()->rowCount());
}
void FilteringListView::lastEntry()
{
changeSelection(model()->rowCount());
}
void FilteringListView::nextPageOfEntries()
{
changeSelection(this->height() / 50);
}
void FilteringListView::prevPageOfEntries()
{
changeSelection(this->height() / -50);
}
void FilteringListView::dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles)
{
QListView::dataChanged(topLeft, bottomRight, roles);
this->clearSelection();
selectionModel()->select(model()->index(0, 0), QItemSelectionModel::Select);
}
void FilteringListView::selectedCurrentEntryWithText(const QString& input)
{
QModelIndexList ml = selectedIndexes();
int selected = -1;
if (!ml.isEmpty()) {
selected = ml[0].row();
}
if (selected < 0) {
emit selectedCurrentText(input);
} else {
emit selectedCurrentEntry(model()->index(selected, 0));
}
return;
}
void FilteringListView::selectAllEntries()
{
for (int i = 0; i < model()->rowCount(); i++) {
emit selectedCurrentEntryNoHistory(model()->index(i, 0));
}
}
void FilteringListView::getCurrentEntryForEdit()
{
FilteringModel* myModel = (FilteringModel*) model();
QModelIndexList ml = selectedIndexes();
int selected = -1;
if (!ml.isEmpty()) {
selected = ml[0].row();
}
if (selected >= 0) {
emit sendCurrentEntryToEdit(myModel->getSelectedDisplayText(selected));
}
}
void FilteringListView::shiftSelectCurrentEntry()
{
FilteringModel* myModel = (FilteringModel*) model();
QModelIndexList ml = selectedIndexes();
int selected = -1;
if (!ml.isEmpty()) {
selected = ml[0].row();
}
if (selected >= 0) {
QMap<QString, QString> rawData = myModel->getSelectedRawData(selected);
emit selectRawData(rawData);
}
}