28#include "moc_qgsfavoritesitem.cpp"
30using namespace Qt::StringLiterals;
52 const QStringList favDirs = settings.
value( u
"browser/favourites"_s, QVariant() ).toStringList();
55 for (
const QString &favDir : favDirs )
57 const QStringList parts = favDir.split( u
"|||"_s );
61 const QString dir = parts.at( 0 );
63 if ( parts.count() > 1 )
74 const QString
name = n.isEmpty() ? favDir : n;
77 QStringList favDirs = settings.
value( u
"browser/favourites"_s ).toStringList();
78 favDirs.append( u
"%1|||%2"_s.arg( favDir,
name ) );
79 settings.
setValue( u
"browser/favourites"_s, favDirs );
97 QStringList favDirs = settings.
value( u
"browser/favourites"_s ).toStringList();
98 for (
int i = favDirs.count() - 1; i >= 0; --i )
100 const QStringList parts = favDirs.at( i ).split( u
"|||"_s );
104 const QString dir = parts.at( 0 );
106 favDirs.removeAt( i );
108 settings.
setValue( u
"browser/favourites"_s, favDirs );
125 QStringList favDirs = settings.
value( u
"browser/favourites"_s ).toStringList();
126 for (
int i = 0; i < favDirs.count(); ++i )
128 const QStringList parts = favDirs.at( i ).split( u
"|||"_s );
132 const QString dir = parts.at( 0 );
135 const QStringList newParts {
path,
name };
136 favDirs[i] = newParts.join(
"|||"_L1 );
140 settings.
setValue( u
"browser/favourites"_s, favDirs );
143 const QVector<QgsDataItem *> ch =
children();
146 if (
QgsFavoriteItem *favorite = qobject_cast< QgsFavoriteItem * >( child ) )
148 if ( favorite->dirPath() ==
path )
150 favorite->setName(
name );
173 children.reserve( providers.size() );
178 if (
QgsDataItem *item = provider->createDataItem( directory,
this ) )
180 item->setName(
name );
187 children.append(
new QgsFavoriteItem(
this,
name, directory,
mPath +
'/' + pathName ) );
@ Directories
Can provides items which corresponds to directories.
@ 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.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDataCollectionItem, with the specified parent item.
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
Interface for providers that 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
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
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.
QgsDataItem * parent() const
Gets item parent.
virtual void populate(const QVector< QgsDataItem * > &children)
A browser item for directories: contains subdirectories and layers.
QString dirPath() const
Returns the full path to the directory the item represents.
QgsDirectoryItem(QgsDataItem *parent, const QString &name, const QString &path)
Constructor for QgsDirectoryItem, with the specified parent item.
A directory item showing 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.
A browser item which 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.
Stores settings for use within QGIS.
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.
#define QgsDebugError(str)