From 09cfc76fc8af203240e3510928f75d36ba47cb0a Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 6 Oct 2018 14:02:45 +0200 Subject: bookmarks: save folder expanded state --- lib/bookmarks/bookmarkswidget.cpp | 12 ++++++++++-- lib/bookmarks/model/bookmarkmodel.cpp | 7 +++++++ lib/bookmarks/model/bookmarkmodel.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'lib/bookmarks') diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp index 1a4552a..2949b44 100644 --- a/lib/bookmarks/bookmarkswidget.cpp +++ b/lib/bookmarks/bookmarkswidget.cpp @@ -60,9 +60,17 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) connect(ui->treeView, &QTreeView::activated, this, [this](const QModelIndex &index) { if(index.column() == 1) emit openUrl(index.data(Qt::DisplayRole).toUrl()); - else { + else editBookmark(index); - } + }); + + connect(ui->treeView, &QTreeView::expanded, this, [this](const QModelIndex &index) { + model->setItemExpanded(index, true); + m_isChanged = true; + }); + connect(ui->treeView, &QTreeView::collapsed, this, [this](const QModelIndex &index) { + model->setItemExpanded(index, false); + m_isChanged = true; }); // addBookmark diff --git a/lib/bookmarks/model/bookmarkmodel.cpp b/lib/bookmarks/model/bookmarkmodel.cpp index aa8b0ac..977248c 100644 --- a/lib/bookmarks/model/bookmarkmodel.cpp +++ b/lib/bookmarks/model/bookmarkmodel.cpp @@ -104,6 +104,13 @@ bool BookmarkModel::isItemExpanded(const QModelIndex &index) const return static_cast(index.internalPointer())->isExpanded(); } +void BookmarkModel::setItemExpanded(const QModelIndex& index, bool expanded) +{ + BookmarkItem *item = getItem(index); + if(item->type() == BookmarkItem::Folder) + item->setExpanded(expanded); +} + int BookmarkModel::rowCount(const QModelIndex &index) const { if(index.column() > 0) diff --git a/lib/bookmarks/model/bookmarkmodel.h b/lib/bookmarks/model/bookmarkmodel.h index 4da2f9c..3e0f35e 100644 --- a/lib/bookmarks/model/bookmarkmodel.h +++ b/lib/bookmarks/model/bookmarkmodel.h @@ -28,6 +28,7 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const override; bool isItemExpanded(const QModelIndex &index) const; + void setItemExpanded(const QModelIndex &index, bool expanded); int rowCount(const QModelIndex &index) const override; QModelIndex appendBookmark(const QString &title, const QString &url, const QModelIndex &parent); -- cgit v1.2.1