From 586982e47302a962299f224384b8b32577615fd5 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 5 Dec 2013 21:13:58 +0100 Subject: [PATCH] [Bookmarks] Fixed drag&drop moving folders into bookmarks toolbar Closes #1097 --- CHANGELOG | 1 + src/lib/bookmarks/bookmarksmodel.cpp | 5 +++- src/lib/tools/treewidget.cpp | 38 +++++++++++++++------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b017cc85c..75a4c7c4f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,6 +30,7 @@ Version 1.5.0 * fixed: enabling disabled rules in AdBlock now works everytime * fixed: parsing OpenSearch files with XML declaration * fixed: don't show urls multiple times in url completer + * fixed: drag & drop moving folders under bookmarks toolbar Version 1.4.4 * released 1 September 2013 diff --git a/src/lib/bookmarks/bookmarksmodel.cpp b/src/lib/bookmarks/bookmarksmodel.cpp index cf54374e5..b147eb0f3 100644 --- a/src/lib/bookmarks/bookmarksmodel.cpp +++ b/src/lib/bookmarks/bookmarksmodel.cpp @@ -593,6 +593,10 @@ void BookmarksModel::changeBookmarkParent(int id, const QString &newParent, cons void BookmarksModel::changeFolderParent(const QString &name, bool isSubfolder, bool* ok) { + if (name.isEmpty()) { + return; + } + QSqlQuery query; query.prepare("UPDATE folders SET subfolder=? WHERE name=?"); query.bindValue(0, isSubfolder ? "yes" : "no"); @@ -612,7 +616,6 @@ void BookmarksModel::changeFolderParent(const QString &name, bool isSubfolder, b } } - void BookmarksModel::bookmarkDropedLink(const QUrl &url, const QString &title, const QVariant &imageVariant, const QString &folder, bool* ok) { QIcon icon = qIconProvider->iconFromImage(qvariant_cast(imageVariant)); diff --git a/src/lib/tools/treewidget.cpp b/src/lib/tools/treewidget.cpp index 758728f21..1bdb99194 100644 --- a/src/lib/tools/treewidget.cpp +++ b/src/lib/tools/treewidget.cpp @@ -123,18 +123,24 @@ QMimeData* TreeWidget::mimeData(const QList items) const QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); + foreach (const QTreeWidgetItem* item, items) { - if (item) { - QTreeWidgetItem* clonedItem = item->clone(); - bool parentIsRoot = false; - if (!item->parent() || item->parent() == invisibleRootItem()) { - parentIsRoot = true; - } - clonedItem->setData(0, ITEM_IS_TOPLEVEL, parentIsRoot); - clonedItem->setData(0, ITEM_PARENT_TITLE, (parentIsRoot ? QString() : item->parent()->text(0))) ; - clonedItem->write(stream); - delete clonedItem; + if (!item) { + continue; } + + // Why not just pass pointers ??!! + QTreeWidgetItem* clonedItem = item->clone(); + + // #1097 Clearing icon will properly write this item into stream ... + clonedItem->setIcon(0, QIcon()); + + bool parentIsRoot = !item->parent() || item->parent() == invisibleRootItem(); + + clonedItem->setData(0, ITEM_IS_TOPLEVEL, parentIsRoot); + clonedItem->setData(0, ITEM_PARENT_TITLE, (parentIsRoot ? QString() : item->parent()->text(0))) ; + clonedItem->write(stream); + delete clonedItem; } data->setData(m_mimeType, encodedData); @@ -171,8 +177,6 @@ bool TreeWidget::dropMimeData(QTreeWidgetItem* parent, int, } QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - QSqlDatabase db = QSqlDatabase::database(); - db.transaction(); QByteArray ba = data->data(m_mimeType); QDataStream stream(&ba, QIODevice::ReadOnly); @@ -180,6 +184,9 @@ bool TreeWidget::dropMimeData(QTreeWidgetItem* parent, int, return false; } + QSqlDatabase db = QSqlDatabase::database(); + db.transaction(); + setUpdatesEnabled(false); while (!stream.atEnd()) { @@ -202,12 +209,7 @@ bool TreeWidget::dropMimeData(QTreeWidgetItem* parent, int, } if (isFolder) { - if (parent->text(0) == _bookmarksToolbar) { - emit folderParentChanged(item->text(0), true, &ok); - } - else { - emit folderParentChanged(item->text(0), false, &ok); - } + emit folderParentChanged(item->text(0), parent->text(0) == _bookmarksToolbar, &ok); } else { emit bookmarkParentChanged(item->data(0, Qt::UserRole + 10).toInt(),