Navigation Menu

Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
[Bookmarks] Fixed drag&drop moving folders into bookmarks toolbar
Browse files Browse the repository at this point in the history
Closes #1097
  • Loading branch information
nowrep committed Dec 5, 2013
1 parent b4f0096 commit 586982e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/lib/bookmarks/bookmarksmodel.cpp
Expand Up @@ -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");
Expand All @@ -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<QImage>(imageVariant));
Expand Down
38 changes: 20 additions & 18 deletions src/lib/tools/treewidget.cpp
Expand Up @@ -123,18 +123,24 @@ QMimeData* TreeWidget::mimeData(const QList<QTreeWidgetItem*> 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 ??!!

This comment has been minimized.

Copy link
@srazi

srazi Dec 7, 2013

Member

I didn't remember ;), after a quick test I found using item causes random crashes, it seems editing items passed to mimeData() is a bad idea.

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);
Expand Down Expand Up @@ -171,15 +177,16 @@ 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);
if (stream.atEnd()) {
return false;
}

QSqlDatabase db = QSqlDatabase::database();
db.transaction();

setUpdatesEnabled(false);

while (!stream.atEnd()) {
Expand All @@ -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(),
Expand Down

0 comments on commit 586982e

Please sign in to comment.