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
20 //#define DEBUG_SHOPPER 1
32 #include "shopperList.h"
38 ////////////////////////////////////////////////////////////////
40 int Category::id_master
= 0;
41 Category::Category(sparseCategory dummy
) : // SPARSE constructor for ListParser
47 Category::Category() :
48 id (Category::id_master
++),
53 Category::Category(QString name
) :
54 id (Category::id_master
++),
62 while (!items
.empty()) // Can't use an iterator as rm() modifies the list... <sigh>
70 void Category::dbg() {
71 DEBUG("\nCat name : " << name
<<
73 "\n wanted : " << _wanted
<<
74 "\n bought : " << _bought
<<
79 bool operator< (const Category
&a
, const Category
&b
){
82 bool cat_cmp (const Category
*a
, const Category
*b
) {
83 return (a
->id
< b
->id
);
86 // bool user_cmp (const Category &a, const Category &b)
88 // return (a.pos < b.pos);
92 int Category::get_id() const { return id
; }
93 void Category::set_id(int i
) {
99 void Category::set_name(QString n
) {
105 QString
Category::get_name() const { return name
; }
106 int Category::get_size() const { return items
.size(); }
108 void Category::setWanted(bool b
) { b
?_wanted
++:_wanted
--; emit
changed(); }
109 void Category::setBought(bool b
) { b
?_bought
++:_bought
--; emit
changed(); }
110 int Category::wanted() const { return _wanted
; }
111 int Category::bought() const { return _bought
; }
114 void Category::add(Item
&it
)
116 DEBUG("Category add item " << it
.get_desc() << "\n");
117 items
.push_back(&it
);
118 emit
item_added(&it
);
120 void Category::rm(Item
&it
)
122 DEBUG("Category remove item " << it
.get_desc() << "\n");
124 emit
item_removed(&it
);
128 Category::pItemIter
Category::itemsI() {return items
.begin();}
129 Category::pItemIter
Category::itemsEnd(){return items
.end();}
130 int Category::size() const {return items
.size();}