20#include "collectionmodel.h"
21#include "collectionmodel_p.h"
23#include "collectionutils_p.h"
24#include "collectionmodifyjob.h"
25#include "entitydisplayattribute.h"
27#include "pastehelper_p.h"
34#include <QtCore/QMimeData>
39 : QAbstractItemModel(parent)
48 : QAbstractItemModel(parent)
58 d->childCollections.clear();
59 d->collections.clear();
67int CollectionModel::columnCount(
const QModelIndex &parent)
const
69 if (parent.isValid() && parent.column() != 0) {
75QVariant CollectionModel::data(
const QModelIndex &index,
int role)
const
78 if (!index.isValid()) {
82 const Collection col = d->collections.value(index.internalId());
87 if (index.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole)) {
92 case Qt::DecorationRole:
93 if (index.column() == 0) {
98 return KIcon(CollectionUtils::defaultIconName(col));
106 return QVariant::fromValue(col);
111QModelIndex CollectionModel::index(
int row,
int column,
const QModelIndex &parent)
const
114 if (column >= columnCount() || column < 0) {
115 return QModelIndex();
118 QVector<Collection::Id> list;
119 if (!parent.isValid()) {
122 if (parent.column() > 0) {
123 return QModelIndex();
125 list = d->childCollections.value(parent.internalId());
128 if (row < 0 || row >= list.size()) {
129 return QModelIndex();
131 if (!d->collections.contains(list.at(row))) {
132 return QModelIndex();
134 return createIndex(row, column,
reinterpret_cast<void *
>(d->collections.value(list.at(row)).id()));
137QModelIndex CollectionModel::parent(
const QModelIndex &index)
const
140 if (!index.isValid()) {
141 return QModelIndex();
144 const Collection col = d->collections.value(index.internalId());
146 return QModelIndex();
151 return QModelIndex();
153 QVector<Collection::Id> list;
156 int parentRow = list.indexOf(parentCol.
id());
158 return QModelIndex();
161 return createIndex(parentRow, 0,
reinterpret_cast<void *
>(parentCol.
id()));
164int CollectionModel::rowCount(
const QModelIndex &parent)
const
167 QVector<Collection::Id> list;
168 if (parent.isValid()) {
169 list = d->childCollections.value(parent.internalId());
177QVariant CollectionModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
181 if (section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole) {
182 return d->headerContent;
184 return QAbstractItemModel::headerData(section, orientation, role);
187bool CollectionModel::setHeaderData(
int section, Qt::Orientation orientation,
const QVariant &value,
int role)
191 if (section == 0 && orientation == Qt::Horizontal && role == Qt::EditRole) {
192 d->headerContent = value.toString();
199bool CollectionModel::setData(
const QModelIndex &index,
const QVariant &value,
int role)
202 if (index.column() == 0 && role == Qt::EditRole) {
204 Collection col = d->collections.value(index.internalId());
205 if (!col.
isValid() || value.toString().isEmpty()) {
210 connect(job, SIGNAL(result(KJob*)), SLOT(editDone(KJob*)));
213 return QAbstractItemModel::setData(index, value, role);
216Qt::ItemFlags CollectionModel::flags(
const QModelIndex &index)
const
221 if (!index.isValid()) {
225 Qt::ItemFlags flags = QAbstractItemModel::flags(index);
227 flags = flags | Qt::ItemIsDragEnabled;
230 if (index.isValid()) {
231 col = d->collections.value(index.internalId());
234 return flags | Qt::ItemIsDropEnabled;
242 if (index.column() == 0) {
243 flags = flags | Qt::ItemIsEditable;
245 flags = flags | Qt::ItemIsDropEnabled;
252Qt::DropActions CollectionModel::supportedDropActions()
const
254 return Qt::CopyAction | Qt::MoveAction;
257QStringList CollectionModel::mimeTypes()
const
259 return QStringList() << QLatin1String(
"text/uri-list");
262QMimeData *CollectionModel::mimeData(
const QModelIndexList &indexes)
const
264 QMimeData *data =
new QMimeData();
266 foreach (
const QModelIndex &index, indexes) {
267 if (index.column() != 0) {
273 urls.populateMimeData(data);
278bool CollectionModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent)
281 if (!(action & supportedDropActions())) {
287 if (row >= 0 && column >= 0) {
288 idx = index(row, column, parent);
293 if (!idx.isValid()) {
297 const Collection parentCol = d->collections.value(idx.internalId());
303 connect(job, SIGNAL(result(KJob*)), SLOT(dropResult(KJob*)));
310 return d->collections.value(
id);
316 d->fetchStatistics = enable;
323 d->unsubscribed = include;
326#include "moc_collectionmodel.cpp"
@ CollectionIdRole
The collection identifier.
@ CollectionRole
The actual collection object.
@ OldCollectionIdRole
The collection identifier. For binary compatibility to <4.3.
@ OldCollectionRole
The actual collection object. For binary compatibility to <4.3.
void includeUnsubscribed(bool include=true)
Sets whether unsubscribed collections shall be listed in the model.
virtual ~CollectionModel()
Destroys the collection model.
void fetchCollectionStatistics(bool enable)
Sets whether collection statistics information shall be provided by the model.
CollectionModel(QObject *parent=0)
Creates a new collection model.
Collection collectionForId(Collection::Id id) const
Returns the collection for a given collection id.
Job that modifies a collection in the Akonadi storage.
Represents a collection of PIM items.
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
static Collection root()
Returns the root collection.
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Rights rights() const
Returns the rights the user has on the collection.
@ CanDeleteCollection
Can delete this collection.
@ CanChangeCollection
Can change this collection.
@ CanCreateItem
Can create new items in this collection.
@ CanCreateCollection
Can create new subcollections in this collection.
KUrl url() const
Returns the url of the collection.
Attribute that stores the properties that are used to display an entity.
QString iconName() const
Returns the icon name of the icon returned by icon().
Collection parentCollection() const
Returns the parent collection of this object.
bool isValid() const
Returns whether the entity is valid.
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Id id() const
Returns the unique identifier of the entity.
qint64 Id
Describes the unique id type.
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
void fetchCollectionStatistics(bool enable)
Enables automatic fetching of changed collection statistics information from the Akonadi storage.
KJob * paste(const QMimeData *mimeData, const Collection &collection, bool copy=true, Session *session=0)
Paste/drop the given mime data into the given collection.
FreeBusyManager::Singleton.