aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/bookmarksmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bookmarks/bookmarksmodel.cpp')
-rw-r--r--lib/bookmarks/bookmarksmodel.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/lib/bookmarks/bookmarksmodel.cpp b/lib/bookmarks/bookmarksmodel.cpp
index e67668f..5cf343f 100644
--- a/lib/bookmarks/bookmarksmodel.cpp
+++ b/lib/bookmarks/bookmarksmodel.cpp
@@ -7,7 +7,6 @@
*/
#include "bookmarksmodel.h"
-#include <QStyle>
BookmarksModel::BookmarksModel(QStyle *style, QObject *parent)
: QAbstractItemModel(parent)
@@ -27,12 +26,25 @@ BookmarksModel::~BookmarksModel()
delete m_rootItem;
}
-void BookmarksModel::setRoot(BookmarkItem *root)
+bool BookmarksModel::isModified() const
{
- Q_CHECK_PTR(root);
+ return modified;
+}
- delete m_rootItem;
- m_rootItem = root;
+bool BookmarksModel::read(Xbel *xbel)
+{
+ Q_CHECK_PTR(xbel);
+ // if there are items in the bookmark list, we're adding to them, so the model becomes modified
+ if(m_rootItem->childCount() != 0) {
+ modified = true;
+ }
+ return xbel->read(m_rootItem);
+}
+
+bool BookmarksModel::write(Xbel *xbel)
+{
+ Q_CHECK_PTR(xbel);
+ return xbel->write(m_rootItem);
}
QVariant BookmarksModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -220,6 +232,7 @@ bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, in
case BookmarkItem::Folder:
if(index.column() == 0) {
node->title = value.toString();
+ modified = true;
emit dataChanged(index, index);
return true;
}
@@ -228,10 +241,12 @@ bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, in
case BookmarkItem::Bookmark:
if(index.column() == 0) {
node->title = value.toString();
+ modified = true;
emit dataChanged(index, index);
return true;
} else if(index.column() == 1) {
node->href = value.toString();
+ modified = true;
emit dataChanged(index, index);
return true;
}
@@ -275,3 +290,23 @@ QModelIndexList BookmarksModel::match(const QModelIndex &start, int role, const
return list;
}
+
+void BookmarksModel::expandItems(QTreeView *view, BookmarkItem *root)
+{
+ if(root == nullptr)
+ root = m_rootItem;
+
+ // iterate through children
+ for(int i = 0; i < root->childCount(); ++i) {
+ BookmarkItem *childNode = root->child(i);
+
+ // and if it's a folder
+ if(childNode->type() == BookmarkItem::Folder) {
+ QModelIndex idx = index(childNode);
+ view->setExpanded(idx, !childNode->folded);
+
+ // only folders have children, so go through them
+ expandItems(view, childNode);
+ }
+ }
+}