1
/***************************************************************************
2
* Copyright (C) 2009 by Joris Guisson *
3
* joris.guisson@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "activitylistmodel.h"
22
#include "activitylistwidget.h"
23
#include <interfaces/activity.h>
27
ActivityListModel::ActivityListModel(ActivityListWidget* widget) : QStringListModel(widget),widget(widget)
31
ActivityListModel::~ActivityListModel()
35
int ActivityListModel::rowCount(const QModelIndex & parent) const
37
if (!parent.isValid())
38
return activities.count();
43
QVariant ActivityListModel::data(const QModelIndex& index, int role) const
48
Activity* act = (Activity*)index.internalPointer();
55
if (widget->displayMode() == ICONS_ONLY)
59
case Qt::DecorationRole:
60
if (widget->displayMode() == TEXT_ONLY)
63
return KIcon(act->icon());
65
return act->toolTip();
66
case Qt::TextAlignmentRole:
67
return Qt::AlignCenter;
73
void ActivityListModel::addActivity(kt::Activity* act)
75
activities.append(act);
76
insertRow(activities.count() - 1);
79
void ActivityListModel::removeActivity(kt::Activity* act)
81
int idx = activities.indexOf(act);
85
activities.removeAll(act);
89
QModelIndex ActivityListModel::index(int row, int column, const QModelIndex& parent) const
91
if (parent.isValid() || row < 0 || row >= activities.count())
94
return createIndex(row,column,activities[row]);
97
QModelIndex ActivityListModel::indexOf(Activity* act) const
99
int r = activities.indexOf(act);
101
return QModelIndex();
103
return index(r,0,QModelIndex());
106
void ActivityListModel::emitLayoutChanged()
108
emit layoutChanged();
111
void ActivityListModel::sort(int column, Qt::SortOrder order)
113
qSort(activities.begin(),activities.end(),Activity::lessThan);
b'\\ No newline at end of file'