• Skip to content
  • Skip to link menu
KDE API Documentation - personactionsmodel.cpp Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • src
  • declarative
personactionsmodel.cpp
1 /*
2  Copyright (C) 2013 Martin Klapetek <mklapetek@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but 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.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "personactionsmodel_p.h"
20 #include <kpeople/persondata.h>
21 #include <kpeople/actions.h>
22 #include <QAction>
23 #include <QDebug>
24 #include <QPointer>
25 
26 namespace KPeople
27 {
28 struct PersonActionsPrivate {
29  PersonActionsPrivate()
30  : person(0)
31  {}
32 
33  QList<QAction *> actions;
34  QString id;
35  KPeople::PersonData *person;
36 };
37 }
38 
39 using namespace KPeople;
40 
41 PersonActionsModel::PersonActionsModel(QObject *parent)
42  : QAbstractListModel(parent),
43  d_ptr(new PersonActionsPrivate)
44 {
45 }
46 
47 PersonActionsModel::~PersonActionsModel()
48 {
49  delete d_ptr;
50 }
51 
52 QHash<int, QByteArray> PersonActionsModel::roleNames() const
53 {
54  QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
55  roles[IconNameRole] = "iconName";
56  roles[ActionRole] = "action";
57  return roles;
58 }
59 
60 void PersonActionsModel::setPersonUri(const QString &id)
61 {
62  Q_D(PersonActions);
63 
64  delete d->person;
65  d->person = new PersonData(id, this);
66  connect(d->person, &PersonData::dataChanged, this, &PersonActionsModel::resetActions);
67  d->id = id;
68 
69  resetActions();
70 
71  emit personChanged();
72 }
73 
74 void PersonActionsModel::resetActions()
75 {
76  Q_D(PersonActions);
77 
78  beginResetModel();
79  d->actions = KPeople::actionsForPerson(d->id, this);
80  endResetModel();
81 }
82 
83 QString PersonActionsModel::personUri() const
84 {
85  Q_D(const PersonActions);
86  return d->id;
87 }
88 
89 QVariant PersonActionsModel::data(const QModelIndex &index, int role) const
90 {
91  Q_D(const PersonActions);
92 
93  if (!index.isValid()) {
94  return QVariant();
95  }
96 
97  switch (role) {
98  case Qt::DisplayRole:
99  return d->actions[index.row()]->text();
100  case Qt::DecorationRole:
101  return d->actions[index.row()]->icon();
102  case Qt::ToolTip:
103  return d->actions[index.row()]->toolTip();
104  case IconNameRole:
105  return d->actions[index.row()]->icon().name();
106  case ActionRole:
107  return QVariant::fromValue<QObject *>(d->actions[index.row()]);
108  }
109 
110  return QVariant();
111 }
112 
113 int PersonActionsModel::rowCount(const QModelIndex &parent) const
114 {
115  Q_D(const PersonActions);
116 
117  return parent.isValid() ? 0 : d->actions.size();
118 }
119 
120 void PersonActionsModel::triggerAction(int row) const
121 {
122  Q_D(const PersonActions);
123  d->actions[row]->trigger();
124 }
125 
126 QList< QAction * > PersonActionsModel::actions() const
127 {
128  Q_D(const PersonActions);
129  return d->actions;
130 }
KPeople::actionsForPerson
QList< QAction * > actionsForPerson(const QString &contactUri, QObject *parent)
Returns a list of actions relevant to the specified contactUri.
Definition: actions.cpp:51
KPeople::PersonData
Allows to query the information about a given person.
Definition: persondata.h:44
KPeople
The KPeople namespace contains all the classes for Libkpeople.
KPeople::PersonData::dataChanged
void dataChanged()
One of the contact sources has changed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

Skip menu "KPeople"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal