From eea675e1f33d29550c9f3e90eb6b6b2402e5ef37 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 28 Jan 2020 14:59:23 +0200 Subject: Add bookmarks toolbar Bookmarks Toolbar displays the contents of the top-level "Bookmarks Toolbar" folder. --- lib/bookmarks/bookmarkformat.cpp | 12 ++++++------ lib/bookmarks/bookmarkformat.h | 35 +++-------------------------------- lib/bookmarks/bookmarkitem.cpp | 5 +++++ lib/bookmarks/bookmarkitem.h | 1 + lib/bookmarks/bookmarkmodel.h | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 48 insertions(+), 39 deletions(-) (limited to 'lib') diff --git a/lib/bookmarks/bookmarkformat.cpp b/lib/bookmarks/bookmarkformat.cpp index 87b816c..491d69a 100644 --- a/lib/bookmarks/bookmarkformat.cpp +++ b/lib/bookmarks/bookmarkformat.cpp @@ -7,25 +7,25 @@ */ #include "bookmarkformat.h" -#include "formats/xbel.h" +#include "bookmarkitem.h" #include "formats/ffjson.h" +#include "formats/xbel.h" #include -template<> +template <> void BookmarkFormat::read(BookmarkItem *root) const { Xbel::read(m_device, root); } -template<> -void BookmarkFormat::write(BookmarkItem *root) +template <> +void BookmarkFormat::write(const BookmarkItem *root) { Xbel::write(m_device, root); } -template<> +template <> void BookmarkFormat::read(BookmarkItem *root) const { FFJson::read(m_device, root); } - diff --git a/lib/bookmarks/bookmarkformat.h b/lib/bookmarks/bookmarkformat.h index c886546..cdae24e 100644 --- a/lib/bookmarks/bookmarkformat.h +++ b/lib/bookmarks/bookmarkformat.h @@ -9,57 +9,28 @@ #ifndef BOOKMARKFORMAT_H #define BOOKMARKFORMAT_H -#include "bookmarkmodel.h" - class QIODevice; +class BookmarkItem; enum BookmarkFormats { XbelFormat, FirefoxJsonFormat }; -template +template class BookmarkFormat { public: explicit BookmarkFormat(QIODevice *device) { - Q_CHECK_PTR(device); m_device = device; } void read(BookmarkItem *root) const; - void write(BookmarkItem *root); + void write(const BookmarkItem *root); protected: QIODevice *m_device; }; -template -void operator<<(BookmarkModel *model, const BookmarkFormat &format) -{ - format.read(model->root()); -} - -template -void operator>>(const BookmarkFormat &format, BookmarkModel *model) -{ - format.read(model->root()); -} - -template -void operator<<(BookmarkFormat &format, BookmarkModel *model) -{ - format.write(model->root()); - model->resetModified(); -} - -template -void operator>>(BookmarkModel *model, BookmarkFormat &format) -{ - format.write(model->root()); - model->resetModified(); -} - #endif // BOOKMARKSFORMAT_H - diff --git a/lib/bookmarks/bookmarkitem.cpp b/lib/bookmarks/bookmarkitem.cpp index d361e26..242ab57 100644 --- a/lib/bookmarks/bookmarkitem.cpp +++ b/lib/bookmarks/bookmarkitem.cpp @@ -109,6 +109,11 @@ QIcon BookmarkItem::icon() return m_icon; } +QIcon BookmarkItem::icon() const +{ + return m_icon; +} + bool BookmarkItem::isExpanded() const { return m_isExpanded; diff --git a/lib/bookmarks/bookmarkitem.h b/lib/bookmarks/bookmarkitem.h index 97d3e89..310d263 100644 --- a/lib/bookmarks/bookmarkitem.h +++ b/lib/bookmarks/bookmarkitem.h @@ -49,6 +49,7 @@ public: bool setData(Fields column, const QVariant &data); QIcon icon(); + QIcon icon() const; bool isExpanded() const; void setExpanded(bool expanded); diff --git a/lib/bookmarks/bookmarkmodel.h b/lib/bookmarks/bookmarkmodel.h index 300b724..1ddab1e 100644 --- a/lib/bookmarks/bookmarkmodel.h +++ b/lib/bookmarks/bookmarkmodel.h @@ -9,6 +9,7 @@ #ifndef SMOLBOTE_BOOKMARKMODEL_H #define SMOLBOTE_BOOKMARKMODEL_H +#include "bookmarkformat.h" #include "bookmarkitem.h" #include @@ -16,6 +17,11 @@ class BookmarkModel : public QAbstractItemModel { Q_OBJECT + template + friend void operator<<(BookmarkModel *model, const BookmarkFormat &format); + template + friend void operator>>(const BookmarkFormat &format, BookmarkModel *model); + public: explicit BookmarkModel(QObject *parent = nullptr); ~BookmarkModel() override; @@ -45,7 +51,7 @@ public: QModelIndex parent(const QModelIndex &index) const override; QModelIndex parentFolder(const QModelIndex &index) const; - BookmarkItem *root() + const BookmarkItem *root() const { return rootItem; } @@ -70,4 +76,30 @@ private: bool m_isModified = false; }; +template +void operator<<(BookmarkModel *model, const BookmarkFormat &format) +{ + format.read(model->rootItem); +} + +template +void operator>>(const BookmarkFormat &format, BookmarkModel *model) +{ + format.read(model->rootItem); +} + +template +void operator<<(BookmarkFormat &format, BookmarkModel *model) +{ + format.write(model->root()); + model->resetModified(); +} + +template +void operator>>(BookmarkModel *model, BookmarkFormat &format) +{ + format.write(model->root()); + model->resetModified(); +} + #endif // SMOLBOTE_BOOKMARKMODEL_H -- cgit v1.2.1