-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaffixmodel.cpp
More file actions
192 lines (183 loc) · 5.52 KB
/
Copy pathaffixmodel.cpp
File metadata and controls
192 lines (183 loc) · 5.52 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "affixmodel.h"
affixmodel::affixmodel(QList<CPrefix*> * prefixes, QObject *parent)
: QAbstractItemModel{parent}
{
m_prefixes = prefixes;
qDebug() << 7<< prefixes->count();
foreach (CPrefix* prefix, *m_prefixes){
qDebug() << 8 << prefix->get_key();
}
m_suffixes = nullptr;
QStringList labels = {tr("word"), tr("word count"), tr("prefix signatures")};
}
affixmodel::affixmodel(QList<CSuffix*> * suffixes, QObject *parent)
: QAbstractItemModel{parent}
{
m_suffixes = suffixes;
m_prefixes = nullptr;
QStringList labels = {tr("word"), tr("word count"), tr("suffix signatures")};
}
bool greaterthan_suffix_key(CSuffix* a, CSuffix* b){
return a->get_key() > b->get_key();
}
bool lessthan_suffix_key(CSuffix * a, CSuffix* b){
return a->get_key() < b->get_key();
}
bool greaterthan_prefix_key(CPrefix* a, CPrefix* b){
return a->get_key() > b->get_key();
}
bool lessthan_prefix_key(CPrefix* a, CPrefix* b){
return a->get_key() < b->get_key();
}
bool greaterthan_suffix_count(CSuffix* a, CSuffix* b){
return a->count() > b->count();
}
bool lessthan_suffix_count(CSuffix* a, CSuffix* b){
return a->count() < b->count();
}
bool greaterthan_prefix_count(CPrefix* a, CPrefix* b){
return a->get_count() > b->get_count();
}
bool lessthan_prefix_count(CPrefix* a, CPrefix* b){
return a->get_count() < b->get_count();
}
void affixmodel::sort(int column, Qt::SortOrder order){
switch(column){
case 0:{
if (m_prefixes){
if (order == Qt::AscendingOrder) {
std::sort(m_prefixes->begin(), m_prefixes->end(), lessthan_prefix_key);
}else{
std::sort(m_prefixes->begin(), m_prefixes->end(), greaterthan_prefix_key);
}
} else{
if (order == Qt::AscendingOrder) {
std::sort(m_suffixes->begin(), m_suffixes->end(), lessthan_suffix_key);
}else{
std::sort(m_suffixes->begin(), m_suffixes->end(), greaterthan_suffix_key);
}
}
break;
}
case 1: {
if (m_prefixes){
if (order == Qt::AscendingOrder) {
std::sort(m_prefixes->begin(), m_prefixes->end(), lessthan_prefix_count);
}else{
std::sort(m_prefixes->begin(), m_prefixes->end(), greaterthan_prefix_count);
}
} else{
if (order == Qt::AscendingOrder) {
std::sort(m_suffixes->begin(), m_suffixes->end(), lessthan_suffix_count);
}else{
std::sort(m_suffixes->begin(), m_suffixes->end(), greaterthan_suffix_count);
}
}
}
default:
break;
}
emit layoutChanged();
}
int affixmodel::rowCount(const QModelIndex &parent)const {
Q_UNUSED(parent);
if (m_prefixes) {
return m_prefixes->count();
}
return m_suffixes->count();
}
int affixmodel::columnCount(const QModelIndex &parent)const {
Q_UNUSED(parent);
return 3;
}
QModelIndex affixmodel::index(int row, int column, const QModelIndex &parent) const {
Q_UNUSED(parent);
return createIndex(row, column, nullptr);
}
QVariant affixmodel::data(const QModelIndex & index, int role)const {
if (!index.isValid())
return QVariant();
int row = index.row();
int column = index.column();
if (m_suffixes){
if ( row > m_suffixes->count()) {
return QVariant();
}
} else {
if ( row > m_prefixes->count()){
return QVariant();
}
}
CSuffix * suffix;
CPrefix* prefix;
if (m_suffixes){
suffix = m_suffixes->at(row);
} else{
prefix = m_prefixes->at(row);
}
switch (column) {
case 0:
if (role==Qt::DisplayRole){
if (m_suffixes){
return QVariant(suffix->get_key());
} else {
return QVariant(prefix->get_key());
}
}
break;
case 1:
if (role==Qt::DisplayRole){
if (m_suffixes){
return QVariant(suffix->get_sig_count());
} else {
return QVariant(prefix->get_sig_count());
}
}
break;
case 2:
if (role==Qt::DisplayRole){
if (m_suffixes){
return QVariant(suffix->get_word_count());
} else {
return QVariant(prefix->get_word_count());
}
}
break;
default:
return QVariant();
break;
}
return QVariant();
}
QModelIndex affixmodel::parent(const QModelIndex &index) const {
Q_UNUSED(index);
return QModelIndex();
}
QVariant affixmodel::headerData(int section, Qt::Orientation orientation, int role ) const {
if (role != Qt::DisplayRole) {return QVariant();}
if (orientation == Qt::Horizontal){
if (section == 0) return QVariant("Affix" );
if (section == 1) return QVariant("signature count");
if (section == 2) return QVariant("word count");
}
return QVariant();
}
affixSFProxymodel::affixSFProxymodel(QObject* parent ):QSortFilterProxyModel (parent){
}
bool affixSFProxymodel::lessThan(const QModelIndex & left, const QModelIndex & right) const {
int column = left.column();
QVariant leftData = sourceModel()->data(left);
QVariant rightData = sourceModel()->data(right);
switch (column){
case 0:{
return leftData.toString() < rightData.toString();
break;
}
case 1:{
return leftData.toInt() < rightData.toInt();
break;
}
default:
return true;
}
}