Bug fixed: If you are logged in and result is sent in result dialog. If you want...
[speedfreak] / Client / categorylist.cpp
1 /*
2  * Categorylist
3  *
4  * @author     Olavi Pulkkinen <olavi.pulkkinena@fudeco.com>
5  * @copyright  (c) 2010 Speed Freak team
6  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
7  */
8
9 #include <QDebug>
10 #include "categorylist.h"
11
12 /**
13   *Constructor of this class.
14   */
15 CategoryList::CategoryList()
16 {
17     qDebug() << "__CategoryList";
18 }
19
20 /**
21   *Destructor of this class. Should be used to release all allocated resources.
22   */
23 CategoryList::~CategoryList()
24 {
25     qDebug() << "__~CategoryList";
26 }
27
28 /**
29   *This is return function.
30   *@return QStringList categoryList
31   */
32 QStringList CategoryList::getCategoryList()
33 {
34     qDebug() << "__getCategoryList" << realSizeOfCats;
35
36     if(sizeOfCategoryList() != 0) {
37         clearCategoryList();
38     }
39
40     for(int i = 0; i < realSizeOfCats; i++)
41     {
42         categoryList.append(cats[i].description);
43     }
44
45     return categoryList;
46 }
47
48 /**
49   *Append an item in the end of the categorylist.
50   *@param Item.
51   */
52 void CategoryList::appendCategoryList(QString item)
53 {
54     categoryList.append(item);
55 }
56
57 /**
58   *Input an item into the categorylist.
59   *@param Index.
60   *@param Item to be appended.
61   */
62 void CategoryList::fillCategoryList(int index, QString item)
63 {
64     categoryList.insert(index, item);
65 }
66
67 /**
68   *Show an item of the categorylist.
69   *@param Index.
70   */
71 QString CategoryList::itemOfCategoryList(int index)
72 {
73     return categoryList.at(index);
74 }
75
76 /**
77   *Clear categorylist.
78   */
79 void CategoryList::clearCategoryList()
80 {
81     categoryList.clear();
82 }
83
84 /**
85   *Read size of categorylist.
86   */
87 int CategoryList::sizeOfCategoryList()
88 {
89     return categoryList.size();
90 }
91
92 /**
93   *Append an item in the end of the categoryelementable.
94   *@param Index.
95   *@param Description of category.
96   *@param Unit.
97   *@param Category.
98   */
99 void CategoryList::appendCats(int ind, QString des, QString uni, QString cat)
100 {
101     cats[ind].description = des;
102     cats[ind].unit = uni;
103     cats[ind].category = cat;
104 }
105
106 /**
107   *Search description for an index af cats table.
108   *@param Index.
109   */
110 QString CategoryList::getRecentDescription(int ind)
111 {
112     return cats[ind].description;
113 }
114
115 /**
116   *Search category for an index af cats table.
117   *@param Index.
118   */
119 QString CategoryList::getRecentCategory(int ind)
120 {
121     return cats[ind].category;
122 }
123
124 /**
125   *Clear cats.
126   */
127 void CategoryList::clearCats()
128 {
129     for(int i = 0; i < 20; i++)
130     {
131         cats[i].description.clear();
132         cats[i].unit.clear();
133         cats[i].category.clear();
134     }
135 }
136
137 /**
138   *This function is used to get items to top list of the category that is chosen from combobox.
139   *@param QString category
140   *@param int size
141   *@todo Now there is only one (the latest top10List). Later picking up the requested category.
142   */
143 QString CategoryList::getTopList( QString category, int size)
144 {
145     qDebug() << "_getTopList";
146
147     if(!(top10List.isEmpty()))
148     {
149         return top10List;
150     }
151     else
152     {
153         QString emptyStr("");
154         qDebug() << "_getTopList: Category not found";
155         return emptyStr;
156     }
157 }
158