31 :
QgsDataCollectionItem( parent, name, QStringLiteral(
"favorites:" ), QStringLiteral(
"special:Favorites" ) )
36 mIconName = QStringLiteral(
"/mIconFavorites.svg" );
46 const QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ), QVariant() ).toStringList();
49 for (
const QString &favDir : favDirs )
51 const QStringList parts = favDir.split( QStringLiteral(
"|||" ) );
55 const QString dir = parts.at( 0 );
57 if ( parts.count() > 1 )
68 const QString
name = n.isEmpty() ? favDir : n;
71 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
72 favDirs.append( QStringLiteral(
"%1|||%2" ).arg( favDir,
name ) );
73 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
91 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
92 for (
int i = favDirs.count() - 1; i >= 0; --i )
94 const QStringList parts = favDirs.at( i ).split( QStringLiteral(
"|||" ) );
98 const QString dir = parts.at( 0 );
100 favDirs.removeAt( i );
102 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
107 QgsDebugMsg( QStringLiteral(
"favorites item %1 not found" ).arg( item->
path() ) );
119 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
120 for (
int i = 0; i < favDirs.count(); ++i )
122 const QStringList parts = favDirs.at( i ).split( QStringLiteral(
"|||" ) );
126 const QString dir = parts.at( 0 );
129 const QStringList newParts {
path,
name };
130 favDirs[i] = newParts.join( QLatin1String(
"|||" ) );
134 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
137 const QVector<QgsDataItem *> ch =
children();
140 if (
QgsFavoriteItem *favorite = qobject_cast< QgsFavoriteItem * >( child ) )
142 if ( favorite->dirPath() ==
path )
144 favorite->setName(
name );
158 return QStringLiteral(
" 0" );
167 children.reserve( providers.size() );
172 if (
QgsDataItem *item = provider->createDataItem( directory,
this ) )
174 item->setName(
name );
191 :
QgsDirectoryItem( parent, name, dirPath, path, QStringLiteral(
"special:Favorites" ) )
192 , mFavorites( parent )
@ Populated
Children created.
@ Rename
Item can be renamed.
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
@ Favorites
Represents a favorite item.
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
A Collection: logical collection of layers or subcollections, e.g.
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
This is the interface for those who want to add custom data items to the browser tree.
Base class for all items in the model.
static int findItem(QVector< QgsDataItem * > items, QgsDataItem *item)
Qgis::BrowserItemType mType
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
QVector< QgsDataItem * > mChildren
QVector< QgsDataItem * > children() const
Qgis::BrowserItemCapabilities mCapabilities
Qgis::BrowserItemState state() const
static QString pathComponent(const QString &component)
Create path component replacing path separators.
QString name() const
Returns the name of the item (the displayed text for the item).
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
virtual void populate(const QVector< QgsDataItem * > &children)
A directory: contains subdirectories and layers.
QString dirPath() const
Returns the full path to the directory the item represents.
A directory item showing the a single favorite directory.
QgsFavoriteItem(QgsFavoritesItem *parent, const QString &name, const QString &dirPath, const QString &path)
Constructor for QgsFavoriteItem.
bool rename(const QString &name) override
Sets a new name for the favorite.
Contains various Favorites directories.
void addDirectory(const QString &directory, const QString &name=QString())
Adds a new directory to the favorites group.
QVariant sortKey() const override
Returns the sorting key for the item.
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
static QIcon iconFavorites()
Icon for favorites group.
QVector< QgsDataItem * > createChildren() override
Create children.
QgsFavoritesItem(QgsDataItem *parent, const QString &name, const QString &path=QString())
Constructor for QgsFavoritesItem.
void renameFavorite(const QString &path, const QString &name)
Renames the stored favorite with corresponding path a new name.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.