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 #define DEBUG_SHOPPER 1
22 #include "shopper.h" // automake, i8n, gettext
23 #include "CatListModel.h"
27 CatListModel::CatListModel(Shopper::List
&l
) :
30 // FIX::This needs to find the current category and populate currIndex
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
44 QVariant CatListModel::headerData(int section, Qt::Orientation orientation, int role)
49 int CatListModel::currentIndex(){
53 QVariant
CatListModel::data ( const QModelIndex
& index
, int role
) const
55 if (role
!= Qt::DisplayRole
) exit(1);
57 if (i
== 0) { // 0 = Everything
58 if (index
.column() == ptrIndex
)
59 return QVariant::fromValue(NULL
);
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
);
71 return new QVariant((*c
)->get_name());
76 if (v.canConvert<Category*>())
77 c = v.value<Category*>();