QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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 )
A Collection: logical collection of layers or subcollections, e.g. GRASS location/mapset,...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void renameFavorite(const QString &path, const QString &name)
Renames the stored favorite with corresponding path a new name.
static QIcon iconFavorites()
Icon for favorites group.
Qgis::BrowserItemState state() const
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
QString name() const
Returns the name of the item (the displayed text for the item).
This class is a composition of two QSettings instances:
Qgis::BrowserItemCapabilities mCapabilities
void addDirectory(const QString &directory, const QString &name=QString())
Adds a new directory to the favorites group.
QVector< QgsDataItem * > createChildren() override
Create children.
static QString pathComponent(const QString &component)
Create path component replacing path separators.
QString dirPath() const
Returns the full path to the directory the item represents.
Qgis::BrowserItemType mType
bool rename(const QString &name) override
Sets a new name for the favorite.
A directory: contains subdirectories and layers.
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.
@ Populated
Children created.
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
@ Favorites
Represents a favorite item.
A directory item showing the a single favorite directory.
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
QgsFavoritesItem(QgsDataItem *parent, const QString &name, const QString &path=QString())
Constructor for QgsFavoritesItem.
virtual void populate(const QVector< QgsDataItem * > &children)
QVector< QgsDataItem * > mChildren
QVector< QgsDataItem * > children() const
@ Rename
Item can be renamed.
static int findItem(QVector< QgsDataItem * > items, QgsDataItem *item)
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Contains various Favorites directories.
QVariant sortKey() const override
Returns the sorting key for the item.
Base class for all items in the model.
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
QgsFavoriteItem(QgsFavoritesItem *parent, const QString &name, const QString &dirPath, const QString &path)
Constructor for QgsFavoriteItem.