Commit a745dade authored by David Faure's avatar David Faure

EntityOrderProxyModel: support adding a favorite at a specific position

Summary:
If EntityTreeModel::modelIndexForCollection() doesn't find the
collection we're dropping, then insert it first (via the base class
dropMimeData) and then look for it again, to handle it as a move.

I hope this doesn't affect other EOPM users than the favorites model;
but when reordering a full ETM surely the dropped folder is somewhere in the
ETM.

Test Plan:
When using the ListView mode for the favorites, this allows to
directly drop a new folder (from the folder tree) to a specific position,
as shown by the "between items" drop indicator.

Reviewers: dvratil, mlaurent

Reviewed By: dvratil

Subscribers: #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D9417
parent 0985a2d9
...@@ -115,6 +115,45 @@ bool EntityOrderProxyModel::lessThan(const QModelIndex &left, const QModelIndex ...@@ -115,6 +115,45 @@ bool EntityOrderProxyModel::lessThan(const QModelIndex &left, const QModelIndex
return leftPosition < rightPosition; return leftPosition < rightPosition;
} }
QStringList EntityOrderProxyModel::configStringsForDroppedUrls(const QList<QUrl> &urls, const Akonadi::Collection &parentCol, bool *containsMove) const
{
QStringList droppedList;
droppedList.reserve(urls.count());
for (const QUrl &url : urls) {
Collection col = Collection::fromUrl(url);
if (!col.isValid()) {
Item item = Item::fromUrl(url);
if (!item.isValid()) {
continue;
}
const QModelIndexList list = EntityTreeModel::modelIndexesForItem(this, item);
if (list.isEmpty()) {
continue;
}
if (!*containsMove && parentCollection(list.first()).id() != parentCol.id()) {
*containsMove = true;
}
droppedList << configString(list.first());
} else {
const QModelIndex idx = EntityTreeModel::modelIndexForCollection(this, col);
if (!idx.isValid()) {
continue;
}
if (!*containsMove && parentCollection(idx).id() != parentCol.id()) {
*containsMove = true;
}
droppedList << configString(idx);
}
}
return droppedList;
}
bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{ {
Q_D(EntityOrderProxyModel); Q_D(EntityOrderProxyModel);
...@@ -134,6 +173,9 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a ...@@ -134,6 +173,9 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
bool containsMove = false; bool containsMove = false;
const QList<QUrl> urls = data->urls(); const QList<QUrl> urls = data->urls();
if (urls.isEmpty()) {
return false;
}
Collection parentCol; Collection parentCol;
...@@ -148,37 +190,14 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a ...@@ -148,37 +190,14 @@ bool EntityOrderProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction a
parentCol = parentCollection(targetIndex); parentCol = parentCollection(targetIndex);
} }
QStringList droppedList;
for (const QUrl &url : urls) {
Collection col = Collection::fromUrl(url);
if (!col.isValid()) { QStringList droppedList = configStringsForDroppedUrls(urls, parentCol, &containsMove);
Item item = Item::fromUrl(url);
if (!item.isValid()) {
continue;
}
const QModelIndexList list = EntityTreeModel::modelIndexesForItem(this, item); // Dropping new favorite folders
if (list.isEmpty()) { if (droppedList.isEmpty()) {
continue; const bool ok = KRecursiveFilterProxyModel::dropMimeData(data, action, row, column, parent);
} if (ok) {
droppedList = configStringsForDroppedUrls(urls, parentCol, &containsMove);
if (!containsMove && parentCollection(list.first()).id() != parentCol.id()) {
containsMove = true;
}
droppedList << configString(list.first());
} else {
const QModelIndex idx = EntityTreeModel::modelIndexForCollection(this, col);
if (!idx.isValid()) {
continue;
}
if (!containsMove && parentCollection(idx).id() != parentCol.id()) {
containsMove = true;
}
droppedList << configString(idx);
} }
} }
......
...@@ -96,6 +96,8 @@ protected: ...@@ -96,6 +96,8 @@ protected:
virtual Akonadi::Collection parentCollection(const QModelIndex &index) const; virtual Akonadi::Collection parentCollection(const QModelIndex &index) const;
private: private:
QStringList configStringsForDroppedUrls(const QList<QUrl> &urls, const Akonadi::Collection &parentCol, bool *containsMove) const;
//@cond PRIVATE //@cond PRIVATE
Q_DECLARE_PRIVATE(EntityOrderProxyModel) Q_DECLARE_PRIVATE(EntityOrderProxyModel)
//@endcond //@endcond
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment