diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-27 16:27:25 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-27 16:27:25 +0100 |
commit | ab6f5290fc1582cf89257e6e5d12ec33ed428143 (patch) | |
tree | 68b5856bf7f3fdbcf5ff0ad6ec83945a8bbb60dc /lib/bookmarks/model/bookmarkmodel.cpp | |
parent | Rename TabWidget::deleteTab to TabWidget::removeTab (diff) | |
download | smolbote-ab6f5290fc1582cf89257e6e5d12ec33ed428143.tar.xz |
Bookmarks: track modified state in the model rather than the widget
Dragging and dropping bookmarks is done by the QTreeView rather than
through the BookmarksWidget, so the widget could not track modification
state correctly when items were reordered.
BUG: #9 Bookmark reordering does not persist
Diffstat (limited to 'lib/bookmarks/model/bookmarkmodel.cpp')
-rw-r--r-- | lib/bookmarks/model/bookmarkmodel.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/bookmarks/model/bookmarkmodel.cpp b/lib/bookmarks/model/bookmarkmodel.cpp index 977248c..9214c24 100644 --- a/lib/bookmarks/model/bookmarkmodel.cpp +++ b/lib/bookmarks/model/bookmarkmodel.cpp @@ -72,8 +72,10 @@ bool BookmarkModel::setData(const QModelIndex &index, const QVariant &value, int success = static_cast<BookmarkItem *>(index.internalPointer())->setData(static_cast<BookmarkItem::Fields>(index.column()), value); } - if(success) + if(success) { emit dataChanged(index, index, { role }); + m_isModified = true; + } return success; } @@ -83,8 +85,10 @@ bool BookmarkModel::setData(const QModelIndex &index, const QVariant &value, Boo return false; bool success = static_cast<BookmarkItem *>(index.internalPointer())->setData(column, value); - if(success) + if(success) { emit dataChanged(index, index, { role }); + m_isModified = true; + } return success; } @@ -104,11 +108,13 @@ bool BookmarkModel::isItemExpanded(const QModelIndex &index) const return static_cast<BookmarkItem *>(index.internalPointer())->isExpanded(); } -void BookmarkModel::setItemExpanded(const QModelIndex& index, bool expanded) +void BookmarkModel::setItemExpanded(const QModelIndex &index, bool expanded) { BookmarkItem *item = getItem(index); - if(item->type() == BookmarkItem::Folder) + if(item->type() == BookmarkItem::Folder) { item->setExpanded(expanded); + m_isModified = true; + } } int BookmarkModel::rowCount(const QModelIndex &index) const @@ -129,6 +135,7 @@ QModelIndex BookmarkModel::appendBookmark(const QString &title, const QString &u parentItem->appendChild(childItem); endInsertRows(); + m_isModified = true; return createIndex(row, 0, childItem); } @@ -142,6 +149,7 @@ QModelIndex BookmarkModel::appendFolder(const QString &title, const QModelIndex parentItem->appendChild(childItem); endInsertRows(); + m_isModified = true; return createIndex(row, 0, childItem); } @@ -152,6 +160,9 @@ bool BookmarkModel::removeRows(int position, int rows, const QModelIndex &parent beginRemoveRows(parent, position, position + rows - 1); bool success = parentItem->removeChildAt(position, rows); endRemoveRows(); + + if(success) + m_isModified = true; return success; } @@ -339,5 +350,7 @@ bool BookmarkModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction actio delete fakeRoot; } + + m_isModified = true; return true; } |