1 // Implementation of CPrefixListViewItem, CSuffixListViewItem methods
2 // Copyright © 2009 The University of Chicago
3 #ifndef AFFIX_LIST_VIEW_ITEM_TCC
4 #define AFFIX_LIST_VIEW_ITEM_TCC
7 #include <Q3ListViewItem>
9 #include "StringSurrogate.h"
11 #include "CompareFunc.h"
13 namespace linguistica {
15 template<class Affix> affix_list_view_item<Affix>::affix_list_view_item(
16 Q3ListView* parent, QString text, Affix* affix,
17 QMap<QString, QString>* filter, int char_count)
18 : Q3ListViewItem(parent, text),
21 m_char_count(char_count) { }
23 template<class Affix> affix_list_view_item<Affix>::affix_list_view_item(
24 Q3ListViewItem* parent, QString text, Affix* affix,
25 QMap<QString, QString>* filter, int char_count)
26 : Q3ListViewItem(parent, text),
29 m_char_count(char_count) { }
31 template<class Affix> QString affix_list_view_item<Affix>::text(int col) const
37 return QString::number(m_affix->ComputeDL(m_char_count));
41 return QString::number(m_affix->GetLengthOfPointerToMe());
45 return QString::number(m_affix->GetCorpusCount());
47 for (affix_list_view_item* child =
48 static_cast<affix_list_view_item*>(
51 child = static_cast<affix_list_view_item*>(
52 child->nextSibling()))
53 if (Affix* affix = child->m_affix)
54 count += affix->GetCorpusCount();
55 return QString::number(count);
60 return QString::number(m_affix->GetUseCount());
62 for (affix_list_view_item* child =
63 static_cast<affix_list_view_item*>(
66 child = static_cast<affix_list_view_item*>(
67 child->nextSibling()))
68 if (Affix* affix = child->m_affix)
69 count += affix->GetUseCount();
70 return QString::number(count);
76 CParse& stem_str = *m_affix->GetStemString();
78 if (stem_str.Size() == 0)
80 QString stem_string = stem_str.GetPiece(1).Display(m_filter);
81 for (int i = 2; i <= stem_str.Size(); ++i) {
83 stem_string += stem_str.GetPiece(i).Display(m_filter);
88 return Q3ListViewItem::text(col);
92 template<class Affix> int affix_list_view_item<Affix>::compare(
93 Q3ListViewItem* other, int col, bool asc) const
95 Affix& this_affix = *m_affix;
96 Affix& other_affix = *static_cast<affix_list_view_item*>(
101 return MakeComparable(this_affix.ComputeDL(),
102 other_affix.ComputeDL());
104 return MakeComparable(this_affix.GetLengthOfPointerToMe(),
105 other_affix.GetLengthOfPointerToMe());
107 return MakeComparable(this_affix.GetCorpusCount(),
108 other_affix.GetCorpusCount());
110 return MakeComparable(this_affix.GetUseCount(),
111 other_affix.GetUseCount());
113 return Q3ListViewItem::compare(other, col, asc);
117 template<class Affix> QString affix_list_view_item<Affix>::key(
118 int col, bool asc) const
124 return QString("%1").arg(static_cast<int>(
125 1000 * m_affix->ComputeDL(m_char_count)), 15);
129 return QString("%1").arg(static_cast<int>(
130 1000 * m_affix->GetLengthOfPointerToMe()), 15);
134 return QString("%1").arg(m_affix->GetCorpusCount(), 15);
136 for (affix_list_view_item* child =
137 static_cast<affix_list_view_item*>(
140 child = static_cast<affix_list_view_item*>(
141 child->nextSibling()))
142 if (Affix* affix = child->m_affix)
143 count += affix->GetCorpusCount();
144 return QString("%1").arg(count, 15);
149 return QString("%1").arg(m_affix->GetUseCount(), 15);
151 for (affix_list_view_item* child =
152 static_cast<affix_list_view_item*>(
155 child = static_cast<affix_list_view_item*>(
156 child->nextSibling()))
157 if (Affix* affix = child->m_affix)
158 count += affix->GetUseCount();
159 return QString("%1").arg(count, 15);
165 CParse& stem_str = *m_affix->GetStemString();
167 if (stem_str.Size() == 0)
169 QString stem_string = stem_str.GetPiece(1).Display(m_filter);
170 for (int i = 2; i <= stem_str.Size(); ++i) {
172 stem_string += stem_str.GetPiece(i).Display(m_filter);
177 return Q3ListViewItem::key(col, asc);
181 } // namespace linguistica
183 #endif // AFFIX_LIST_VIEW_ITEM_TCC