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
21 #ifndef SHOPPER_CATEGORY_H
22 #define SHOPPER_CATEGORY_H
34 // some forward declarations...
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
49 typedef enum sparseCategory_
{SPARSE
} sparseCategory
; // Only friends know about
50 Category(sparseCategory dummy
); // This constructor is for friends to instantiate objects
53 Category(const Category
&src
);
54 Category(QString name
);
62 void set_name(QString
);
64 void setWanted(bool b
);
66 void setBought(bool b
);
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
);
73 typedef list
<Item
*>::const_iterator pItemIter
;
78 static const Category EVERYTHING
; /* Used for filter */
80 int id
; /* The id of the item */
81 // int pos; /* Allow user defined sorting */
82 QString name
; /* The item name */
85 static int id_master
; /* Used for uniqueness */
93 void item_added(Item
*);
94 void item_removed(Item
*);
96 friend class ListParser
;
97 friend class XMLWriter
;
101 Q_DECLARE_METATYPE ( Shopper::Category
* )
103 #endif //SHOPPER_CATEGORY_H
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
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.