HowManyAreAnalyzed(): use status_user_agent to report progress
[linguistica.git] / affix_list_view_item.tcc
blob0f91985a4d78a68a22ceb71c2ccd3b679f057c85
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
6 #include "Affix.h"
7 #include <Q3ListViewItem>
8 #include <QString>
9 #include "StringSurrogate.h"
10 #include "Parse.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),
19         m_affix(affix),
20         m_filter(filter),
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),
27         m_affix(affix),
28         m_filter(filter),
29         m_char_count(char_count) { }
31 template<class Affix> QString affix_list_view_item<Affix>::text(int col) const
33         switch (col) {
34         case 1:
35                 if (m_affix == 0)
36                         return QString();
37                 return QString::number(m_affix->ComputeDL(m_char_count));
38         case 2:
39                 if (m_affix == 0)
40                         return QString();
41                 return QString::number(m_affix->GetLengthOfPointerToMe());
42         case 3:
43         {
44                 if (m_affix != 0)
45                         return QString::number(m_affix->GetCorpusCount());
46                 int count = 0;
47                 for (affix_list_view_item* child =
48                                         static_cast<affix_list_view_item*>(
49                                         firstChild());
50                                 child != 0;
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);
56         }
57         case 4:
58         {
59                 if (m_affix != 0)
60                         return QString::number(m_affix->GetUseCount());
61                 int count = 0;
62                 for (affix_list_view_item* child =
63                                         static_cast<affix_list_view_item*>(
64                                         firstChild());
65                                 child != 0;
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);
71         }
72         case 5:
73         {
74                 if (m_affix == 0)
75                         return QString();
76                 CParse& stem_str = *m_affix->GetStemString();
78                 if (stem_str.Size() == 0)
79                         return QString();
80                 QString stem_string = stem_str.GetPiece(1).Display(m_filter);
81                 for (int i = 2; i <= stem_str.Size(); ++i) {
82                         stem_string += ", ";
83                         stem_string += stem_str.GetPiece(i).Display(m_filter);
84                 }
85                 return stem_string;
86         }
87         default:
88                 return Q3ListViewItem::text(col);
89         }
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*>(
97                         other)->m_affix;
99         switch (col) {
100         case 1:
101                 return MakeComparable(this_affix.ComputeDL(),
102                         other_affix.ComputeDL());
103         case 2:
104                 return MakeComparable(this_affix.GetLengthOfPointerToMe(),
105                         other_affix.GetLengthOfPointerToMe());
106         case 3:
107                 return MakeComparable(this_affix.GetCorpusCount(),
108                         other_affix.GetCorpusCount());
109         case 4:
110                 return MakeComparable(this_affix.GetUseCount(),
111                         other_affix.GetUseCount());
112         default:
113                 return Q3ListViewItem::compare(other, col, asc);
114         }
117 template<class Affix> QString affix_list_view_item<Affix>::key(
118         int col, bool asc) const
120         switch (col) {
121         case 1:
122                 if (m_affix == 0)
123                         return QString();
124                 return QString("%1").arg(static_cast<int>(
125                         1000 * m_affix->ComputeDL(m_char_count)), 15);
126         case 2:
127                 if (m_affix == 0)
128                         return QString();
129                 return QString("%1").arg(static_cast<int>(
130                         1000 * m_affix->GetLengthOfPointerToMe()), 15);
131         case 3:
132         {
133                 if (m_affix != 0)
134                         return QString("%1").arg(m_affix->GetCorpusCount(), 15);
135                 int count = 0;
136                 for (affix_list_view_item* child =
137                                         static_cast<affix_list_view_item*>(
138                                         firstChild());
139                                 child != 0;
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);
145         }
146         case 4:
147         {
148                 if (m_affix != 0)
149                         return QString("%1").arg(m_affix->GetUseCount(), 15);
150                 int count = 0;
151                 for (affix_list_view_item* child =
152                                         static_cast<affix_list_view_item*>(
153                                         firstChild());
154                                 child != 0;
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);
160         }
161         case 5:
162         {
163                 if (m_affix == 0)
164                         return QString();
165                 CParse& stem_str = *m_affix->GetStemString();
167                 if (stem_str.Size() == 0)
168                         return QString();
169                 QString stem_string = stem_str.GetPiece(1).Display(m_filter);
170                 for (int i = 2; i <= stem_str.Size(); ++i) {
171                         stem_string += ", ";
172                         stem_string += stem_str.GetPiece(i).Display(m_filter);
173                 }
174                 return stem_string;
175         }
176         default:
177                 return Q3ListViewItem::key(col, asc);
178         }
181 } // namespace linguistica
183 #endif // AFFIX_LIST_VIEW_ITEM_TCC