File indexing completed on 2024-04-28 15:15:34

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Gaurav Gupta <1989.gaurav@googlemail.com>
0004 // SPDX-FileCopyrightText: 2012 Thibaut Gridel <tgridel@free.fr>
0005 //
0006 
0007 #ifndef MARBLE_BOOKMARKMANAGER_H
0008 #define MARBLE_BOOKMARKMANAGER_H
0009 
0010 #include <QObject>
0011 #include <QVector>
0012 #include "MarbleGlobal.h"
0013 
0014 class QString;
0015 
0016 namespace Marble
0017 {
0018 
0019     class BookmarkManagerPrivate;
0020     class GeoDataContainer;
0021     class GeoDataDocument;
0022     class GeoDataPlacemark;
0023     class GeoDataCoordinates;
0024     class GeoDataFolder;
0025     class GeoDataTreeModel;
0026     class StyleBuilder;
0027 /**
0028  * This class is responsible for loading the
0029  * book mark objects from the files and various
0030  * book mark operations
0031  */
0032 
0033 class MARBLE_EXPORT BookmarkManager : public QObject
0034 {
0035     Q_OBJECT
0036 
0037  public:
0038 
0039     explicit BookmarkManager( GeoDataTreeModel *treeModel, QObject *parent = nullptr );
0040 
0041     ~BookmarkManager() override;
0042 
0043     /**
0044       * @brief load bookmark file as GeoDataDocument and return true
0045       * if loaded successfully else false
0046       * @param relativeFilePath relative path of bookmark file
0047       */
0048     bool loadFile( const QString &relativeFilePath );
0049 
0050     /**
0051       * @brief return bookmark file path
0052       */
0053     QString bookmarkFile() const;
0054 
0055     /**
0056       * @brief add bookmark in a folder
0057       * @param bookmark bookmark to be added
0058       * @param folder folder to add bookmark to
0059       */
0060     void addBookmark( GeoDataContainer *folder, const GeoDataPlacemark &bookmark ) ;
0061 
0062     void updateBookmark( GeoDataPlacemark *bookmark );
0063 
0064     void removeBookmark( GeoDataPlacemark *bookmark );
0065 
0066     /**
0067       * @brief checks all the bookmarks in container recursively and returns
0068       * pointer to the one having the same coordinate as the provided
0069       */
0070     GeoDataPlacemark* bookmarkAt(GeoDataContainer *container, const GeoDataCoordinates &coordinate);
0071 
0072     GeoDataDocument * document();
0073     const GeoDataDocument * document() const;
0074 
0075     bool showBookmarks() const;
0076 
0077     /**
0078       * @brief return Vector of folders
0079       */
0080     QVector<GeoDataFolder*> folders() const;
0081 
0082     /**
0083       * @brief add a folder
0084       * @param container geodata container
0085       * @param name name of folder to be created
0086       * @return pointer to the newly added folder
0087       */
0088     GeoDataFolder* addNewBookmarkFolder( GeoDataContainer *container, const QString &name );
0089 
0090     void renameBookmarkFolder( GeoDataFolder *folder, const QString &name );
0091 
0092     void removeBookmarkFolder( GeoDataFolder *folder );
0093 
0094     /**
0095      * @brief checks that there is at least one folder
0096      */
0097 
0098     void ensureDefaultFolder();
0099 
0100     /**
0101       * @brief remove all folders and bookmarks except default folder
0102       */
0103     void removeAllBookmarks();
0104 
0105     /**
0106      * @since 0.26.0
0107      */
0108     void setStyleBuilder(const StyleBuilder* styleBuilder);
0109 
0110 public Q_SLOTS:
0111     void setShowBookmarks( bool visible );
0112 
0113 Q_SIGNALS:
0114     /** One or more bookmarks were added or removed */
0115     void bookmarksChanged();
0116 
0117  private:
0118    friend class BookmarkManagerDialog;
0119 
0120    /**
0121     * @brief updates bookmark file and return true if updated successfully
0122     */
0123     bool updateBookmarkFile();
0124 
0125     static GeoDataDocument* openFile( const QString& fileName );
0126 
0127     BookmarkManagerPrivate* const d;
0128 
0129 };
0130 
0131 }
0132 
0133 
0134 #endif