-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeProxyModel.cpp
More file actions
executable file
·77 lines (64 loc) · 1.91 KB
/
TreeProxyModel.cpp
File metadata and controls
executable file
·77 lines (64 loc) · 1.91 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "TreeProxyModel.h"
#include <QRect>
#include <QTextStream>
#include <QDebug>
#include "Win.h"
#include "TreeEnums.h"
TreeProxyModel::TreeProxyModel()
{
}
QVariant TreeProxyModel::data(const QModelIndex& index, int role) const
{
if(role == Qt::EditRole || role != Qt::DisplayRole)
{
return QIdentityProxyModel::data(index, role);
}
const QModelIndex sourceIndex = mapToSource(index);
const QVariant originalData = sourceModel()->data(sourceIndex, Qt::DisplayRole);
if(originalData.userType() == qMetaTypeId<QRect>()) {
QRect rect = qvariant_cast<QRect>(originalData);
QString text;
QTextStream out(&text);
out << "Pos: ";
out << rect.x() << ", " << rect.y();
out << "\n";
out << "Size: ";
out << rect.width() << ", " << rect.height();
return text;
}
else if(originalData.userType() == qMetaTypeId<Axis>()) {
Axis axis = qvariant_cast<Axis>(originalData);
switch(axis)
{
case Axis::A_None:
return "None";
case Axis::A_Horizontal:
return "Horizontal";
case Axis::A_Vertical:
return "Vertical";
}
}
else if(originalData.userType() == qMetaTypeId<Layout>()) {
Layout layout = qvariant_cast<Layout>(originalData);
switch(layout)
{
case Layout::L_None:
return "None";
case Layout::L_Tabbed:
return "Tabbed";
case Layout::L_Split:
return "Split";
}
}
else if(originalData.userType() == qMetaTypeId<HWND>()) {
HWND hwnd = qvariant_cast<HWND>(originalData);
return "0x" + QString("%1").arg((quint64)hwnd, 0, 16);
}
return QIdentityProxyModel::data(index, role);
}
bool TreeProxyModel::moveRows(const QModelIndex& sourceParent, int sourceRow, int count, const QModelIndex& destinationParent, int destinationChild)
{
const QModelIndex sourceIndex = mapToSource(sourceParent);
const QModelIndex destinationIndex = mapToSource(destinationParent);
return sourceModel()->moveRows(sourceIndex, sourceRow, count, destinationIndex, destinationChild);
}