20#include "agentinstancemodel.h"
22#include "agentinstance.h"
23#include "agentmanager.h"
25#include <QtCore/QStringList>
28#include <klocalizedstring.h>
35class AgentInstanceModel::Private
46 void instanceAdded(
const AgentInstance &);
47 void instanceRemoved(
const AgentInstance &);
48 void instanceChanged(
const AgentInstance &);
51void AgentInstanceModel::Private::instanceAdded(
const AgentInstance &instance)
53 mParent->beginInsertRows(QModelIndex(), mInstances.count(), mInstances.count());
54 mInstances.append(instance);
55 mParent->endInsertRows();
58void 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();
70void 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();
117int AgentInstanceModel::columnCount(
const QModelIndex &)
const
122int AgentInstanceModel::rowCount(
const QModelIndex &)
const
124 return d->mInstances.count();
127QVariant AgentInstanceModel::data(
const QModelIndex &index,
int role)
const
129 if (!index.isValid()) {
133 if (index.row() < 0 || index.row() >= d->mInstances.count()) {
137 const AgentInstance &instance = d->mInstances[index.row()];
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());
178QVariant 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");
198QModelIndex 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);
211QModelIndex AgentInstanceModel::parent(
const QModelIndex &)
const
213 return QModelIndex();
216Qt::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;
225bool AgentInstanceModel::setData(
const QModelIndex &index,
const QVariant &value,
int role)
227 if (!index.isValid()) {
231 if (index.row() < 0 || index.row() >= d->mInstances.count()) {
235 AgentInstance &instance = d->mInstances[index.row()];
240 emit dataChanged(index, index);
249#include "moc_agentinstancemodel.cpp"
@ StatusMessageRole
A textual presentation of the current status.
@ OnlineRole
The current online/offline status.
@ StatusRole
The current status (numerical) of the instance.
@ MimeTypesRole
A list of supported mimetypes.
@ InstanceRole
The agent instance itself.
@ DescriptionRole
A description of the agent type.
@ InstanceIdentifierRole
The identifier of the agent instance.
@ TypeIdentifierRole
The identifier of the agent type.
@ CapabilitiesRole
A list of supported capabilities.
@ TypeRole
The agent type itself.
@ ProgressRole
The current progress (numerical in percent) of an operation.
virtual ~AgentInstanceModel()
Destroys the agent instance model.
AgentInstanceModel(QObject *parent=0)
Creates a new agent instance model.
A representation of an agent instance.
Status status() const
Returns the status of the agent instance.
QString identifier() const
Returns the unique identifier of the agent instance.
void setIsOnline(bool online)
Sets online status of the agent instance.
AgentType type() const
Returns the agent type of this instance.
QList< AgentInstance > List
Describes a list of agent instances.
QString statusMessage() const
Returns a textual presentation of the status of the agent instance.
int progress() const
Returns the progress of the agent instance in percent, or -1 if no progress information are available...
QString name() const
Returns the user visible name of the agent instance.
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.
QString identifier() const
Returns the unique identifier of the agent type.
QStringList mimeTypes() const
Returns the list of supported mime types of the agent type.
QString description() const
Returns the description of the agent type.
QStringList capabilities() const
Returns the list of supported capabilities of the agent type.
FreeBusyManager::Singleton.