-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsafelistview.cpp
41 lines (36 loc) · 1.2 KB
/
safelistview.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
#include "safelistview.h"
#include "supportfunctions.h"
#include <QStringListModel>
SafeListView::SafeListView(QWidget *parent) :
QListView(parent)
{
}
void SafeListView::setCurrentIndex(const QModelIndex &idx)
{
curridx = idx ;
if (hasFocus()) {
QListView::setCurrentIndex(curridx) ;
selectionModel()->select(curridx, QItemSelectionModel::Select);
dbg(QString("hasfocus, curridx.row=%1").arg(curridx.row())) ;
emit selectionChanged(curridx);
} else {
dbg(QString("does not have focus, caching curridx.row=%1").arg(curridx.row())) ;
}
}
void SafeListView::focusInEvent(QFocusEvent * e)
{
QListView::focusInEvent(e) ;
if (curridx.isValid()) {
QListView::setCurrentIndex(curridx) ;
selectionModel()->select(curridx, QItemSelectionModel::Select);
dbg(QString("gained focus, curridx.row=%1").arg(curridx.row())) ;
emit selectionChanged(curridx) ;
}
}
void SafeListView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint hint)
{
curridx = index ;
dbg(QString("Changed Index Position, curridx.row=%1").arg(curridx.row())) ;
QListView::scrollTo(index, hint) ;
emit selectionChanged(index) ;
}