Tidied up quit processing - hit bug [#3627] in Qt on Maemo
[shopper.git] / src / Item.cc
blobf10c3aff499caac3508843c1057a824938332cd2
1 /* Shopper
2 * Copyright (C) 2008 David Greaves <david@dgreaves.com>
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
20 //#define DEBUG_SHOPPER 1
22 #include "shopper.h"
24 #include <iostream>
25 #include <sstream>
26 #include <string>
27 #include <fstream>
28 #include <list>
29 #include <set>
30 #include <algorithm>
31 #include <signal.h>
32 #include "shopperList.h"
34 using namespace std;
36 namespace Shopper
38 int Item::id_master = 0;
40 Item::Item(sparseItem dummy) : // SPARSE constructor for ListParser
41 id (Item::id_master++),
42 category (0),
43 wanted (false),
44 bought (false)
45 { Q_UNUSED(dummy) }
46 Item::Item() :
47 id (Item::id_master++),
48 category (0),
49 wanted (false),
50 bought (false)
52 Item::Item(Category &c, QString d, QString n, bool w, bool b) :
53 id (Item::id_master++),
54 category (&c),
55 desc (d),
56 note (n),
57 wanted (false),
58 bought (false)
60 set_wanted (w);
61 set_bought (b);
63 DEBUG("Created an item from parts\n");
66 Item::~Item()
68 emit deleted();
71 void Item::dbg() {
72 DEBUG(
73 "\nItem desc : " << desc <<
74 "\n id : " << id <<
75 "\n note : " << note <<
76 "\n bought : " << (bought ? "true":"false") <<
77 "\n wanted : " << (wanted ? "true":"false") <<
78 "\n category : " << category->get_name() <<
79 "\n");
81 // accessors
82 int Item::get_id() const { return id; }
83 void Item::set_id(int i){ id = i; }
84 void Item::set_desc(QString d){
85 if (desc != d) {
86 desc = d;
87 emit changed();
90 QString Item::get_desc() const { return desc; }
92 void Item::set_note(QString n) {
93 if (note != n) {
94 note = n;
95 emit changed();
98 QString Item::get_note() const { return note; }
99 void Item::set_wanted(bool w) {
100 if (wanted !=w) {
101 DEBUG("Wanted\n");
102 wanted =w;
103 category->setWanted(wanted);
104 emit changed();
107 bool Item::get_wanted() const { return wanted; }
108 void Item::set_bought(bool b)
110 if (bought != b) {
111 DEBUG("Bought\n");
112 bought = b;
113 category->setBought(bought);
114 emit changed();
117 bool Item::get_bought() const { return bought; }
118 void Item::set_category(Category *c){
119 if (category != c) {
120 category->rm(*this, false);
121 category = c;
122 category->add(*this);
123 emit changed();
126 Category* Item::get_category() { return category; }