From fedb7ddf4f02ba5b4dfa9d40315981546cbd663d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dutkiewicz?= Date: Sat, 23 Nov 2019 22:30:55 +0100 Subject: [PATCH] Add helper method to access parent Bookmark --- src/core/BookmarksImporter.cpp | 4 ++-- src/core/BookmarksImporter.h | 2 +- src/core/BookmarksModel.cpp | 12 ++++++++++++ src/core/BookmarksModel.h | 1 + src/modules/importers/opera/OperaNotesImporter.cpp | 2 +- .../windows/bookmarks/BookmarksContentsWidget.cpp | 2 +- src/modules/windows/notes/NotesContentsWidget.cpp | 2 +- src/ui/BookmarkPropertiesDialog.cpp | 4 ++-- src/ui/BookmarkPropertiesDialog.h | 2 +- 9 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/core/BookmarksImporter.cpp b/src/core/BookmarksImporter.cpp index 3f4b98db37..d911d0ba1a 100644 --- a/src/core/BookmarksImporter.cpp +++ b/src/core/BookmarksImporter.cpp @@ -1,7 +1,7 @@ /************************************************************************** * Otter Browser: Web browser controlled by the user, not vice-versa. * Copyright (C) 2014 Piotr Wójcik -* Copyright (C) 2014 - 2018 Michal Dutkiewicz aka Emdek +* Copyright (C) 2014 - 2019 Michal Dutkiewicz aka Emdek * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,7 +41,7 @@ void BookmarksImporter::goToParent() if (m_currentFolder) { - m_currentFolder = static_cast(m_currentFolder->parent()); + m_currentFolder = m_currentFolder->getParent(); } if (!m_currentFolder) diff --git a/src/core/BookmarksImporter.h b/src/core/BookmarksImporter.h index 646960104a..95a704b7ad 100644 --- a/src/core/BookmarksImporter.h +++ b/src/core/BookmarksImporter.h @@ -1,7 +1,7 @@ /************************************************************************** * Otter Browser: Web browser controlled by the user, not vice-versa. * Copyright (C) 2014 Piotr Wójcik -* Copyright (C) 2014 - 2018 Michal Dutkiewicz aka Emdek +* Copyright (C) 2014 - 2019 Michal Dutkiewicz aka Emdek * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/core/BookmarksModel.cpp b/src/core/BookmarksModel.cpp index 63877a26f6..e26d143355 100644 --- a/src/core/BookmarksModel.cpp +++ b/src/core/BookmarksModel.cpp @@ -83,6 +83,18 @@ QStandardItem* BookmarksModel::Bookmark::clone() const return bookmark; } +BookmarksModel::Bookmark* BookmarksModel::Bookmark::getParent() const +{ + BookmarksModel *model(qobject_cast(this->model())); + + if (model) + { + return model->getBookmark(index().parent()); + } + + return nullptr; +} + BookmarksModel::Bookmark* BookmarksModel::Bookmark::getChild(int index) const { BookmarksModel *model(qobject_cast(this->model())); diff --git a/src/core/BookmarksModel.h b/src/core/BookmarksModel.h index 4682551a2d..bda1ddd676 100644 --- a/src/core/BookmarksModel.h +++ b/src/core/BookmarksModel.h @@ -76,6 +76,7 @@ class BookmarksModel final : public QStandardItemModel void setData(const QVariant &value, int role) override; void setItemData(const QVariant &value, int role); QStandardItem* clone() const override; + Bookmark* getParent() const; Bookmark* getChild(int index) const; QString getTitle() const; QString getDescription() const; diff --git a/src/modules/importers/opera/OperaNotesImporter.cpp b/src/modules/importers/opera/OperaNotesImporter.cpp index 65ae5a1e2b..e640d4a22d 100644 --- a/src/modules/importers/opera/OperaNotesImporter.cpp +++ b/src/modules/importers/opera/OperaNotesImporter.cpp @@ -188,7 +188,7 @@ bool OperaNotesImporter::import(const QString &path) { if (m_currentFolder) { - m_currentFolder = static_cast(m_currentFolder->parent()); + m_currentFolder = m_currentFolder->getParent(); } if (!m_currentFolder) diff --git a/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp b/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp index ae0b0d0931..3396b99cbd 100644 --- a/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp +++ b/src/modules/windows/bookmarks/BookmarksContentsWidget.cpp @@ -311,7 +311,7 @@ BookmarksContentsWidget::BookmarkLocation BookmarksContentsWidget::getBookmarkCr const BookmarksModel::BookmarkType type(item->getType()); - location.folder = ((type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark) ? item : static_cast(item->parent())); + location.folder = ((type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark) ? item : item->getParent()); location.row = ((location.folder && location.folder->index() == index) ? -1 : (index.row() + 1)); return location; diff --git a/src/modules/windows/notes/NotesContentsWidget.cpp b/src/modules/windows/notes/NotesContentsWidget.cpp index 375e11dbdf..19e710a0ef 100644 --- a/src/modules/windows/notes/NotesContentsWidget.cpp +++ b/src/modules/windows/notes/NotesContentsWidget.cpp @@ -322,7 +322,7 @@ BookmarksModel::Bookmark* NotesContentsWidget::findFolder(const QModelIndex &ind const BookmarksModel::BookmarkType type(item->getType()); - return ((type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark) ? item : static_cast(item->parent())); + return ((type == BookmarksModel::RootBookmark || type == BookmarksModel::FolderBookmark) ? item : item->getParent()); } QString NotesContentsWidget::getTitle() const diff --git a/src/ui/BookmarkPropertiesDialog.cpp b/src/ui/BookmarkPropertiesDialog.cpp index dc3083498b..ca04c98419 100644 --- a/src/ui/BookmarkPropertiesDialog.cpp +++ b/src/ui/BookmarkPropertiesDialog.cpp @@ -1,6 +1,6 @@ /************************************************************************** * Otter Browser: Web browser controlled by the user, not vice-versa. -* Copyright (C) 2013 - 2018 Michal Dutkiewicz aka Emdek +* Copyright (C) 2013 - 2019 Michal Dutkiewicz aka Emdek * Copyright (C) 2014 Piotr Wójcik * * This program is free software: you can redistribute it and/or modify @@ -40,7 +40,7 @@ BookmarkPropertiesDialog::BookmarkPropertiesDialog(BookmarksModel::Bookmark *boo const bool isUrl(type == BookmarksModel::FeedBookmark || type == BookmarksModel::UrlBookmark); m_ui->setupUi(this); - m_ui->folderComboBox->setCurrentFolder(static_cast(bookmark->parent())); + m_ui->folderComboBox->setCurrentFolder(bookmark->getParent()); m_ui->titleLineEditWidget->setText(m_bookmark->getTitle()); m_ui->addressLineEditWidget->setText(m_bookmark->getUrl().toDisplayString()); m_ui->addressLineEditWidget->setVisible(isUrl); diff --git a/src/ui/BookmarkPropertiesDialog.h b/src/ui/BookmarkPropertiesDialog.h index 17f5cc358a..ed7a81a486 100644 --- a/src/ui/BookmarkPropertiesDialog.h +++ b/src/ui/BookmarkPropertiesDialog.h @@ -1,6 +1,6 @@ /************************************************************************** * Otter Browser: Web browser controlled by the user, not vice-versa. -* Copyright (C) 2013 - 2018 Michal Dutkiewicz aka Emdek +* Copyright (C) 2013 - 2019 Michal Dutkiewicz aka Emdek * Copyright (C) 2014 Piotr Wójcik * * This program is free software: you can redistribute it and/or modify