The class declaration should be the first header in the cc file for
[shopper.git] / src / Category.h
blobd3a526588f68dd236cdc7336f5ee932e1fd368fb
1 /* Shopper
2 * Copyright (C) 2008 David Greaves
4 * This software is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1 of
7 * the License, or (at your option) any later version.
9 * This software is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this software; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA
21 #ifndef SHOPPER_CATEGORY_H
22 #define SHOPPER_CATEGORY_H
24 #include <QObject>
25 #include <QMetaType>
26 #include <iostream>
27 #include <list>
28 #include <set>
29 #include <map>
30 using namespace std;
32 namespace Shopper
34 // some forward declarations...
35 class List;
36 class Category;
37 class Item;
39 // normal functions
40 bool operator< (const Category &a, const Category &b);
41 bool cat_cmp (const Category *a, const Category *b);
43 ////////////////////////////////////////////////////////////////
44 class Category : public QObject
46 Q_OBJECT;
48 private:
49 typedef enum sparseCategory_ {SPARSE} sparseCategory; // Only friends know about
50 Category(sparseCategory dummy); // This constructor is for friends to instantiate objects
51 public:
52 Category();
53 Category(const Category &src);
54 Category(QString name);
55 ~Category();
57 void dbg();
58 // accessors
59 QString print_id();
60 int get_id() const;
61 void set_id(int);
62 void set_name(QString);
63 int get_size() const;
64 void setWanted(bool b);
65 int wanted() const;
66 void setBought(bool b);
67 int bought() const;
68 QString get_name() const;
69 friend bool operator< (const Category &a, const Category &b);
70 friend bool cat_cmp (const Category *a, const Category *b);
71 void add(Item &it);
72 void rm(Item &it);
73 typedef list<Item*>::const_iterator pItemIter;
74 pItemIter itemsI();
75 pItemIter itemsEnd();
76 int size() const;
78 static const Category EVERYTHING; /* Used for filter */
79 private:
80 int id; /* The id of the item */
81 // int pos; /* Allow user defined sorting */
82 QString name; /* The item name */
83 int _wanted;
84 int _bought;
85 static int id_master; /* Used for uniqueness */
87 // Items in list
88 list<Item*> items;
90 signals:
91 void changed();
92 void deleted();
93 void item_added(Item*);
94 void item_removed(Item*);
96 friend class ListParser;
97 friend class XMLWriter;
98 friend class List;
101 Q_DECLARE_METATYPE ( Shopper::Category* )
103 #endif //SHOPPER_CATEGORY_H
107 // Ordering
109 // This needs 2 functions: re-sequence and re-order
111 // re-sequence iterates the list in the current list order and sets
112 // 'id' incrementally
114 // re-order causes the list to examine all the member id's and
115 // re-order itself
117 // Each category has a sort position - 'id'.
118 // On load this is used to insert into the <list>
119 // post-load the list is re-sequenced
121 // On 'add' the category is inserted according to a probably duplicate id
122 // Then the list is re-sequenced.
124 // To re-order the list, the id's are swapped and the list is re-ordered.