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();
67 int CollectionModel::columnCount(
const QModelIndex &parent)
const 69 if (parent.isValid() && parent.column() != 0) {
75 QVariant 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);
111 QModelIndex 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()));
137 QModelIndex 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()));
164 int CollectionModel::rowCount(
const QModelIndex &parent)
const 167 QVector<Collection::Id> list;
168 if (parent.isValid()) {
169 list = d->childCollections.value(parent.internalId());
177 QVariant 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);
187 bool 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();
199 bool 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);
216 Qt::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;
252 Qt::DropActions CollectionModel::supportedDropActions()
const 254 return Qt::CopyAction | Qt::MoveAction;
257 QStringList CollectionModel::mimeTypes()
const 259 return QStringList() << QLatin1String(
"text/uri-list");
262 QMimeData *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);
278 bool 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" Job that modifies a collection in the Akonadi storage.
void fetchCollectionStatistics(bool enable)
Enables automatic fetching of changed collection statistics information from the Akonadi storage.
QString displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() other...
Rights rights() const
Returns the rights the user has on the collection.
Collection parentCollection() const
Returns the parent collection of this object.
Represents a collection of PIM items.
KJob * paste(const QMimeData *mimeData, const Collection &collection, bool copy=true, Session *session=0)
Paste/drop the given mime data into the given collection.
qint64 Id
Describes the unique id type.
Collection collectionForId(Collection::Id id) const
Returns the collection for a given collection id.
Can create new subcollections in this collection.
void setName(const QString &name)
Sets the i18n'ed name of the collection.
The actual collection object. For binary compatibility to <4.3.
void fetchCollectionStatistics(bool enable)
Sets whether collection statistics information shall be provided by the model.
bool hasAttribute(const QByteArray &name) const
Returns true if the entity has an attribute of the given type name, false otherwise.
Can create new items in this collection.
Id id() const
Returns the unique identifier of the entity.
static Collection root()
Returns the root collection.
Can delete this collection.
void includeUnsubscribed(bool include=true)
Sets whether unsubscribed collections shall be listed in the model.
virtual ~CollectionModel()
Destroys the collection model.
The actual collection object.
Attribute * attribute(const QByteArray &name) const
Returns the attribute of the given type name if available, 0 otherwise.
CollectionModel(QObject *parent=0)
Creates a new collection model.
FreeBusyManager::Singleton.
The collection identifier. For binary compatibility to <4.3.
The collection identifier.
Attribute that stores the properties that are used to display an entity.
Can change this collection.
bool isValid() const
Returns whether the entity is valid.