QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsfavoritesitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfavoritesitem.h
3  -------------------
4  begin : 2011-04-01
5  copyright : (C) 2011 Radim Blazek
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSFAVORITESITEM_H
18 #define QGSFAVORITESITEM_H
19 
20 #include "qgis_sip.h"
21 #include "qgis_core.h"
22 
23 #include "qgis.h"
24 #include "qgsdatacollectionitem.h"
25 #include "qgsdirectoryitem.h"
26 
32 class CORE_EXPORT QgsFavoritesItem : public QgsDataCollectionItem
33 {
34  Q_OBJECT
35  public:
36 
41  QgsFavoritesItem( QgsDataItem *parent, const QString &name, const QString &path = QString() );
42 
43 #ifdef SIP_RUN
44  SIP_PYOBJECT __repr__();
45  % MethodCode
46  QString str = QStringLiteral( "<QgsFavoritesItem: \"%1\">" ).arg( sipCpp->name() );
47  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
48  % End
49 #endif
50 
51  QVector<QgsDataItem *> createChildren() override;
52 
61  void addDirectory( const QString &directory, const QString &name = QString() );
62 
67  void removeDirectory( QgsDirectoryItem *item );
68 
72  void renameFavorite( const QString &path, const QString &name );
73 
75  static QIcon iconFavorites();
76 
77  QVariant sortKey() const override;
78 
79  private:
80  QVector<QgsDataItem *> createChildren( const QString &directory, const QString &name );
81 };
82 
83 #ifndef SIP_RUN
84 
91 Q_NOWARN_DEPRECATED_PUSH // rename is deprecated
92 class CORE_EXPORT QgsFavoriteItem : public QgsDirectoryItem
93 {
94  Q_OBJECT
95 
96  public:
97 
106  QgsFavoriteItem( QgsFavoritesItem *parent, const QString &name, const QString &dirPath, const QString &path );
107 
108  // TODO QGIS 4.0 - don't remove this method when the deprecated base class virtual method is removed, but instead
109  // remove the override!
110 
114  bool rename( const QString &name ) override;
115 
116  private:
117 
118  QgsFavoritesItem *mFavorites = nullptr;
119 
120 };
122 
123 #endif
124 
125 #endif // QGSFAVORITESITEM_H
126 
127 
A Collection: logical collection of layers or subcollections, e.g.
Base class for all items in the model.
Definition: qgsdataitem.h:46
virtual QVariant sortKey() const
Returns the sorting key for the item.
Definition: qgsdataitem.cpp:95
virtual QVector< QgsDataItem * > createChildren()
Create children.
virtual Q_DECL_DEPRECATED bool rename(const QString &name)
Sets a new name for the item, and returns true if the item was successfully renamed.
A directory: contains subdirectories and layers.
A directory item showing the a single favorite directory.
Contains various Favorites directories.
#define str(x)
Definition: qgis.cpp:37
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:1080
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:1079