Added showing infotext.
[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
18 }
19
20 /**
21   *Destructor of this class. Should be used to release all allocated resources.
22   */
23 CategoryList::~CategoryList()
24 {
25 }
26
27 /**
28   *This is return function.
29   *@return QStringList categoryList
30   */
31 QStringList CategoryList::getCategoryList()
32 {
33     qDebug() << "_getCategoryList" << realSizeOfCats;
34
35     if(sizeOfCategoryList() != 0) {
36         clearCategoryList();
37     }
38
39     for(int i = 0; i < realSizeOfCats; i++)
40     {
41         categoryList.append(cats[i].description);
42     }
43
44     return categoryList;
45 }
46
47 /**
48   *Append an item in the end of the categorylist.
49   *@param Item.
50   */
51 void CategoryList::appendCategoryList(QString item)
52 {
53     categoryList.append(item);
54 }
55
56 /**
57   *Input an item into the categorylist.
58   *@param Index.
59   *@param Item to be appended.
60   */
61 void CategoryList::fillCategoryList(int index, QString item)
62 {
63     categoryList.insert(index, item);
64 }
65
66 /**
67   *Show an item of the categorylist.
68   *@param Index.
69   */
70 QString CategoryList::itemOfCategoryList(int index)
71 {
72     return categoryList.at(index);
73 }
74
75 /**
76   *Clear categorylist.
77   */
78 void CategoryList::clearCategoryList()
79 {
80     categoryList.clear();
81 }
82
83 /**
84   *Read size of categorylist.
85   */
86 int CategoryList::sizeOfCategoryList()
87 {
88     return categoryList.size();
89 }
90
91 /**
92   *Append an item in the end of the categoryelementable.
93   *@param Index.
94   *@param Description of category.
95   *@param Unit.
96   *@param Category.
97   */
98 void CategoryList::appendCats(int ind, QString des, QString uni, QString cat)
99 {
100     cats[ind].description = des;
101     cats[ind].unit = uni;
102     cats[ind].category = cat;
103 }
104
105 /**
106   *Search description for an index af cats table.
107   *@param Index.
108   */
109 QString CategoryList::getRecentDescription(int ind)
110 {
111     return cats[ind].description;
112 }
113
114 /**
115   *Search category for an index af cats table.
116   *@param Index.
117   */
118 QString CategoryList::getRecentCategory(int ind)
119 {
120     return cats[ind].category;
121 }
122
123 /**
124   *Clear cats.
125   */
126 void CategoryList::clearCats()
127 {
128     for(int i = 0; i < 20; i++)
129     {
130         cats[i].description.clear();
131         cats[i].unit.clear();
132         cats[i].category.clear();
133     }
134 }
135
136 /**
137   *This function is used to get items to top list of the category that is chosen from combobox.
138   *@param QString category
139   *@param int size
140   *@todo Now there is only one (the latest top10List). Later picking up the requested category.
141   */
142 QString CategoryList::getTopList( QString category, int size)
143 {
144     qDebug() << "_getTopList";
145
146     if(!(top10List.isEmpty()))
147     {
148         return top10List;
149     }
150     else
151     {
152         QString emptyStr("");
153         qDebug() << "_getTopList: Category not found";
154         return emptyStr;
155     }
156 }
157