akonadi
20 #include "agentinstancemodel.h"
22 #include "agentinstance.h"
23 #include "agentmanager.h"
25 #include <QtCore/QStringList>
28 #include <klocalizedstring.h>
35 class AgentInstanceModel::Private
51 void AgentInstanceModel::Private::instanceAdded(
const AgentInstance &instance)
53 mParent->beginInsertRows(QModelIndex(), mInstances.count(), mInstances.count());
54 mInstances.append(instance);
55 mParent->endInsertRows();
58 void AgentInstanceModel::Private::instanceRemoved(
const AgentInstance &instance)
60 const int index = mInstances.indexOf(instance);
65 mParent->beginRemoveRows(QModelIndex(), index, index);
66 mInstances.removeAll(instance);
67 mParent->endRemoveRows();
70 void AgentInstanceModel::Private::instanceChanged(
const AgentInstance &instance)
72 const int numberOfInstance(mInstances.count());
73 for (
int i = 0; i < numberOfInstance; ++i) {
74 if (mInstances[i] == instance) {
75 mInstances[i] = instance;
77 const QModelIndex idx = mParent->index(i, 0);
78 emit mParent->dataChanged(idx, idx);
86 : QAbstractItemModel(parent)
87 , d(new Private(this))
91 QHash<int, QByteArray> roles = roleNames();
117 int AgentInstanceModel::columnCount(
const QModelIndex &)
const
122 int AgentInstanceModel::rowCount(
const QModelIndex &)
const
124 return d->mInstances.count();
127 QVariant AgentInstanceModel::data(
const QModelIndex &index,
int role)
const
129 if (!index.isValid()) {
133 if (index.row() < 0 || index.row() >= d->mInstances.count()) {
140 case Qt::DisplayRole:
141 return instance.
name();
142 case Qt::DecorationRole:
146 var.setValue(instance);
151 case Qt::ToolTipRole:
152 return QString::fromLatin1(
"<qt><h4>%1</h4>%2</qt>").arg(instance.
name(), instance.
type().
description());
163 var.setValue(instance.
type());
178 QVariant AgentInstanceModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
180 if (orientation == Qt::Vertical) {
184 if (role != Qt::DisplayRole) {
190 return i18nc(
"@title:column, name of a thing",
"Name");
198 QModelIndex AgentInstanceModel::index(
int row,
int column,
const QModelIndex &)
const
200 if (row < 0 || row >= d->mInstances.count()) {
201 return QModelIndex();
205 return QModelIndex();
208 return createIndex(row, column);
211 QModelIndex AgentInstanceModel::parent(
const QModelIndex &)
const
213 return QModelIndex();
216 Qt::ItemFlags AgentInstanceModel::flags(
const QModelIndex &index)
const
218 if (!index.isValid() || index.row() < 0 || index.row() >= d->mInstances.count()) {
219 return QAbstractItemModel::flags(index);
222 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
225 bool AgentInstanceModel::setData(
const QModelIndex &index,
const QVariant &value,
int role)
227 if (!index.isValid()) {
231 if (index.row() < 0 || index.row() >= d->mInstances.count()) {
240 emit dataChanged(index, index);
249 #include "moc_agentinstancemodel.cpp"
@ ProgressRole
The current progress (numerical in percent) of an operation.
QString identifier() const
Returns the unique identifier of the agent instance.
@ InstanceRole
The agent instance itself.
virtual ~AgentInstanceModel()
Destroys the agent instance model.
void setIsOnline(bool online)
Sets online status of the agent instance.
@ InstanceIdentifierRole
The identifier of the agent instance.
Status status() const
Returns the status of the agent instance.
AgentType type() const
Returns the agent type of this instance.
QString description() const
Returns the description of the agent type.
@ CapabilitiesRole
A list of supported capabilities.
@ MimeTypesRole
A list of supported mimetypes.
@ TypeRole
The agent type itself.
QStringList capabilities() const
Returns the list of supported capabilities of the agent type.
@ DescriptionRole
A description of the agent type.
@ StatusMessageRole
A textual presentation of the current status.
QList< AgentInstance > List
Describes a list of agent instances.
Provides a data model for agent instances.
QString name() const
Returns the user visible name of the agent instance.
QString identifier() const
Returns the unique identifier of the agent type.
AgentInstanceModel(QObject *parent=0)
Creates a new agent instance model.
bool isOnline() const
Returns whether the agent instance is online currently.
static AgentManager * self()
Returns the global instance of the agent manager.
AgentInstance::List instances() const
Returns the list of all available agent instances.
QIcon icon() const
Returns the icon of the agent type.
@ TypeIdentifierRole
The identifier of the agent type.
int progress() const
Returns the progress of the agent instance in percent, or -1 if no progress information are available...
@ OnlineRole
The current online/offline status.
@ StatusRole
The current status (numerical) of the instance.
QString statusMessage() const
Returns a textual presentation of the status of the agent instance.
A representation of an agent instance.
QStringList mimeTypes() const
Returns the list of supported mime types of the agent type.
FreeBusyManager::Singleton.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jan 29 2020 00:00:00 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.