aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/bookmarkswidget.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-12-27 16:27:25 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-12-27 16:27:25 +0100
commitab6f5290fc1582cf89257e6e5d12ec33ed428143 (patch)
tree68b5856bf7f3fdbcf5ff0ad6ec83945a8bbb60dc /lib/bookmarks/bookmarkswidget.cpp
parentRename TabWidget::deleteTab to TabWidget::removeTab (diff)
downloadsmolbote-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/bookmarkswidget.cpp')
-rw-r--r--lib/bookmarks/bookmarkswidget.cpp21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp
index 9bb29f8..045b424 100644
--- a/lib/bookmarks/bookmarkswidget.cpp
+++ b/lib/bookmarks/bookmarkswidget.cpp
@@ -7,9 +7,9 @@
*/
#include "bookmarkswidget.h"
+#include "forms/editbookmarkdialog.h"
#include "model/bookmarkitem.h"
#include "model/bookmarkmodel.h"
-#include "forms/editbookmarkdialog.h"
#include "ui_bookmarksform.h"
#include "xbel.h"
#include <QTreeView>
@@ -51,9 +51,9 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
Xbel::read(&bookmarksFile, model->root());
bookmarksFile.close();
}
+ model->resetModified();
ui->treeView->setModel(model);
-
expandChildren(ui->treeView, model, QModelIndex());
// item activated
@@ -66,11 +66,9 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
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;
});
ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -90,7 +88,6 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
const QModelIndex childIdx = model->appendBookmark(tr("Title"), QString(), idx);
ui->treeView->setCurrentIndex(childIdx);
editBookmark(childIdx);
- m_isChanged = true;
});
// addFolder
@@ -99,14 +96,12 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent)
const QModelIndex childIdx = model->appendFolder(tr("Title"), idx);
ui->treeView->setCurrentIndex(childIdx);
editBookmark(childIdx);
- m_isChanged = true;
});
// deleteItem
connect(ui->deleteItem_toolButton, &QToolButton::clicked, this, [this]() {
const QModelIndex idx = ui->treeView->currentIndex();
- if(model->removeRow(idx.row(), idx.parent()))
- m_isChanged = true;
+ model->removeRow(idx.row(), idx.parent());
});
}
@@ -115,33 +110,29 @@ BookmarksWidget::~BookmarksWidget()
delete ui;
}
-
void BookmarksWidget::editBookmark(const QModelIndex &index)
{
auto *dlg = new EditBookmarkDialog(model, index, this);
- if(dlg->exec() == QDialog::Accepted)
- m_isChanged = true;
+ dlg->exec();
}
void BookmarksWidget::save()
{
- if(!m_isChanged) {
+ if(!model->isModified())
return;
- }
QFile bookmarksFile(m_bookmarksPath);
if(bookmarksFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
Xbel::write(&bookmarksFile, model->root());
bookmarksFile.flush();
bookmarksFile.close();
- m_isChanged = false;
+ model->resetModified();
}
}
void BookmarksWidget::addBookmark(const QString &title, const QString &url)
{
model->appendBookmark(title, url, QModelIndex());
- m_isChanged = true;
}
void BookmarksWidget::search(const QString &term, std::function<void(QStringList &)> callback) const