Category dialog draws, moves, deletes - still needs popups to handle deleting items
[shopper.git] / src / CatListModel.cc
blob1b006a17348148d401a04747e7326570870c95fa
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 #define DEBUG_SHOPPER 1
22 #include "shopper.h" // automake, i8n, gettext
23 #include "CatListModel.h"
25 namespace Shopper
27 CatListModel::CatListModel(Shopper::List &l) :
28 mylist(&l)
30 // FIX::This needs to find the current category and populate currIndex
31 currIndex = 0;
33 // Probably move to Qt collections and use a Vector instead of a list...
35 int CatListModel::rowCount(const QModelIndex & parent) const
37 return mylist->categories.size();
39 int CatListModel::columnCount(const QModelIndex & parent) const
41 return 2;
44 QVariant CatListModel::headerData(int section, Qt::Orientation orientation, int role)
49 int CatListModel::currentIndex(){
50 return currIndex;
53 QVariant CatListModel::data ( const QModelIndex & index, int role ) const
55 if (role != Qt::DisplayRole) exit(1);
56 int i = index.row();
57 if (i == 0) { // 0 = Everything
58 if (index.column() == ptrIndex)
59 return QVariant::fromValue(NULL);
60 else
61 return new QVariant(tr("Everything"));
63 Shopper::List::pCategoryIter c;
64 // Ugh... ??? unless we reimpliment Shopper::List
65 for (c = mylist->categoriesI(); --i; c++)
68 if (index.column() == ptrIndex)
69 return QVariant::fromValue(*c);
70 else
71 return new QVariant((*c)->get_name());
74 // Use like this:
75 Category *c;
76 if (v.canConvert<Category*>())
77 c = v.value<Category*>();