-
Notifications
You must be signed in to change notification settings - Fork 5
/
parsemodel.cpp
86 lines (83 loc) · 2.62 KB
/
parsemodel.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
#include "parsemodel.h"
#include "cparse.h"
parsemodel::parsemodel(QMap<QString, CParse*> * parses, QObject * parent): QAbstractItemModel {parent} {
m_parses = new QList<CParse*>;
foreach (CParse* parse, parses->values()){
m_parses->append(parse);
}
}
int parsemodel::rowCount(const QModelIndex &parent )const{
return m_parses->count();
}
int parsemodel::columnCount (const QModelIndex & parent) const{
return 3;
}
QVariant parsemodel::data(const QModelIndex & index, int role)const{
if (!index.isValid())
return QVariant();
int row = index.row();
int column = index.column();
if (row > m_parses->count()){ return QVariant();}
if (column == 0){
return QVariant(m_parses->at(row)->get_stem());
}
if (column == 1){
return QVariant(m_parses->at(row)->get_affix());
}
return QVariant();
}
QModelIndex parsemodel::index(int row, int column, const QModelIndex &parent) const {
Q_UNUSED(parent);
return createIndex(row, column, nullptr);
}
QModelIndex parsemodel::parent(const QModelIndex &index) const {
Q_UNUSED(index);
return QModelIndex();
}
QVariant parsemodel::headerData(int section, Qt::Orientation orientation, int role ) const {
if (role != Qt::DisplayRole) {return QVariant();}
if (orientation == Qt::Horizontal){
if (section == 0) return QVariant("Stem" );
if (section == 1) return QVariant("Affix");
if (section == 2) return QVariant("Affix side");
}else{if(orientation==Qt::Vertical){
return QVariant(section);
}
}
return QVariant();
}
bool lessthan_stem(CParse* parse1, CParse* parse2){
return parse1->get_stem() < parse2->get_stem();
}
bool greaterthan_stem(CParse* parse1, CParse* parse2){
return parse1->get_stem() > parse2->get_stem();
}
bool lessthan_affix(CParse* parse1, CParse* parse2){
return parse1->get_affix() < parse2->get_affix();
}
bool greaterthan_affix(CParse* parse1, CParse* parse2){
return parse1->get_affix() > parse2->get_affix();
}
/*
void parsemodel::sort(int column, Qt::SortOrder order){
switch(column){
case 0:{if (order == Qt::AscendingOrder) {
std::sort(m_parses->begin(), m_parses->end(), lessthan_stem);
}else{
std::sort(m_parses->begin(), m_parses->end(), greaterthan_stem);
}
break;
}
case 1:{if (order == Qt::AscendingOrder) {
std::sort(m_parses->begin(), m_parses->end(), lessthan_affix);
}else{
std::sort(m_parses->begin(), m_parses->end(), greaterthan_affix);
}
break;
}
default:
break;
}
emit layoutChanged();
}
*/