18 #include <QApplication> 19 #include <QtConcurrentMap> 20 #include <QtConcurrentRun> 25 #include <QMouseEvent> 26 #include <QTreeWidget> 27 #include <QTreeWidgetItem> 30 #include <QDesktopServices> 31 #include <QFileDialog> 32 #include <QInputDialog> 33 #include <QMessageBox> 44 #include "qgsconfig.h" 50 #define CPL_SUPRESS_CPLUSPLUS //#spellok 52 #include "cpl_string.h" 117 return QStringLiteral(
" 0" );
135 , mDeferredDelete( false )
136 , mFutureWatcher( nullptr )
151 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
154 QgsDebugMsg( QStringLiteral(
"mFutureWatcher not finished (should not happen) -> waitForFinished()" ) );
155 mDeferredDelete =
true;
156 mFutureWatcher->waitForFinished();
159 delete mFutureWatcher;
164 return QString(
string ).replace( QRegExp(
"[\\\\/]" ), QStringLiteral(
"|" ) );
189 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
191 QgsDebugMsg( QStringLiteral(
"mFutureWatcher not finished -> schedule to delete later" ) );
192 mDeferredDelete =
true;
196 QObject::deleteLater();
219 child->QObject::setParent(
nullptr );
222 QObject::moveToThread( targetThread );
228 return sPopulatingIcon->
icon();
230 if ( !
mIcon.isNull() )
249 return QVector<QgsDataItem *>();
267 if ( !mFutureWatcher )
269 mFutureWatcher =
new QFutureWatcher< QVector <QgsDataItem *> >( this );
273 mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren,
this ) );
278 QVector<QgsDataItem *> QgsDataItem::runCreateChildren(
QgsDataItem *item )
284 QgsDebugMsgLevel( QStringLiteral(
"%1 children created in %2 ms" ).arg( children.size() ).arg( time.elapsed() ), 3 );
294 QgsDebugMsgLevel( QStringLiteral(
"finished path %1: %2 children" ).arg( item->
path() ).arg( children.size() ), 3 );
300 QgsDebugMsgLevel( QStringLiteral(
"path = %1 children.size() = %2" ).arg(
path() ).arg( mFutureWatcher->result().size() ), 3 );
304 QgsDebugMsg( QStringLiteral(
"Item was scheduled to be deleted later" ) );
305 QObject::deleteLater();
311 populate( mFutureWatcher->result() );
315 refresh( mFutureWatcher->result() );
367 if ( !mFutureWatcher )
369 mFutureWatcher =
new QFutureWatcher< QVector <QgsDataItem *> >( this );
372 mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren,
this ) );
395 QVector<QgsDataItem *>
remove;
400 if (
findItem( children, child ) >= 0 )
402 remove.append( child );
447 disconnect(
this,
nullptr,
mParent,
nullptr );
482 if (
mChildren.at( i )->mName.localeAwareCompare( child->
mName ) >= 0 )
527 for (
int i = 0; i < items.size(); i++ )
529 Q_ASSERT_X( items[i],
"findItem", QString(
"item %1 is nullptr" ).arg( i ).toLatin1() );
531 if ( items[i]->
equal( item ) )
539 return ( metaObject()->className() == other->metaObject()->className() &&
546 return QList<QAction *>();
574 if ( !sPopulatingIcon )
598 return QList<QMenu *>();
605 , mProviderKey( providerKey )
607 , mLayerType( layerType )
641 static int enumIdx = staticMetaObject.indexOfEnumerator(
"LayerType" );
642 return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
650 return QStringLiteral(
"/mIconPointLayer.svg" );
652 return QStringLiteral(
"/mIconLineLayer.svg" );
654 return QStringLiteral(
"/mIconPolygonLayer.svg" );
657 return QStringLiteral(
"/mIconVector.svg" );
660 return QStringLiteral(
"/mIconTableLayer.svg" );
662 return QStringLiteral(
"/mIconRaster.svg" );
664 return QStringLiteral(
"/mIconMeshLayer.svg" );
666 return QStringLiteral(
"/mIconLayer.png" );
692 u.
layerType = QStringLiteral(
"vector" );
695 u.
layerType = QStringLiteral(
"raster" );
701 u.
layerType = QStringLiteral(
"plugin" );
718 mIconName = QStringLiteral(
"/mIconDbSchema.svg" );
729 QgsDebugMsgLevel( QStringLiteral(
"delete child = 0x%0" ).arg( static_cast<qlonglong>( i ), 8, 16, QLatin1Char(
'0' ) ), 2 );
740 , mRefreshLater( false )
749 , mRefreshLater( false )
771 if ( fi.isDir() && fi.isSymLink() )
792 QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
793 Q_FOREACH (
const QString &subdir, entries )
801 QString subdirPath = dir.absoluteFilePath( subdir );
803 QgsDebugMsgLevel( QStringLiteral(
"creating subdir: %1" ).arg( subdirPath ), 2 );
809 bool handledByProvider =
false;
812 if ( provider->handlesDirectoryPath( path ) )
814 handledByProvider =
true;
818 if ( handledByProvider )
824 item->
setSortKey( QStringLiteral(
" %1" ).arg( subdir ) );
828 children.append( item );
831 QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
832 Q_FOREACH (
const QString &
name, fileEntries )
840 QString
path = dir.absoluteFilePath( name );
841 QFileInfo fileInfo( path );
843 if ( fileInfo.suffix().compare( QLatin1String(
"qgs" ), Qt::CaseInsensitive ) == 0 ||
844 fileInfo.suffix().compare( QLatin1String(
"qgz" ), Qt::CaseInsensitive ) == 0 )
847 children.append( item );
851 if ( fileInfo.suffix().compare( QLatin1String(
"zip" ), Qt::CaseInsensitive ) == 0 ||
852 fileInfo.suffix().compare( QLatin1String(
"tar" ), Qt::CaseInsensitive ) == 0 )
857 children.append( item );
864 int capabilities = provider->capabilities();
872 QgsDataItem *item = provider->createDataItem( path,
this );
875 children.append( item );
889 if ( !mFileSystemWatcher )
891 mFileSystemWatcher =
new QFileSystemWatcher(
this );
892 mFileSystemWatcher->addPath(
mDirPath );
895 mLastScan = QDateTime::currentDateTime();
899 if ( mFileSystemWatcher )
901 delete mFileSystemWatcher;
902 mFileSystemWatcher =
nullptr;
910 if ( mLastScan.msecsTo( QDateTime::currentDateTime() ) <
QgsSettings().
value( QStringLiteral(
"browser/minscaninterval" ), 10000 ).toInt() )
917 mRefreshLater =
true;
931 QTimer::singleShot( 100,
this, SLOT(
refresh() ) );
938 QStringList hiddenItems = settings.
value( QStringLiteral(
"browser/hiddenPaths" ),
939 QStringList() ).toStringList();
940 int idx = hiddenItems.indexOf( path );
946 QList<QAction *> result;
948 QAction *createFolder =
new QAction( tr(
"New Directory…" ), parent );
949 connect( createFolder, &QAction::triggered,
this, [ = ]
953 QWidget *parentWindow =
parent;
954 while ( parentWindow->parentWidget() )
955 parentWindow = parentWindow->parentWidget();
957 const QString
name = QInputDialog::getText( parentWindow, tr(
"Create Directory" ), tr(
"Directory name" ), QLineEdit::Normal, QString(), &ok );
958 if ( ok && !name.isEmpty() )
961 if ( QFileInfo::exists( dir.absoluteFilePath( name ) ) )
963 QMessageBox::critical( parentWindow, tr(
"Create Directory" ), tr(
"The path “%1” already exists." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ) );
965 else if ( !dir.mkdir( name ) )
967 QMessageBox::critical( parentWindow, tr(
"Create Directory" ), tr(
"Could not create directory “%1”." ).arg( QDir::toNativeSeparators( dir.absoluteFilePath( name ) ) ) );
975 result << createFolder;
977 QAction *sep =
new QAction( parent );
978 sep->setSeparator(
true );
981 QAction *openFolder =
new QAction( tr(
"Open Directory…" ), parent );
982 connect( openFolder, &QAction::triggered,
this, [ = ]
984 QDesktopServices::openUrl( QUrl::fromLocalFile(
mDirPath ) );
986 result << openFolder;
993 QgsDebugMsgLevel( QStringLiteral(
"mRefreshLater = %1" ).arg( mRefreshLater ), 3 );
997 QgsDebugMsgLevel( QStringLiteral(
"directory changed during createChidren() -> refresh() again" ), 3 );
998 mRefreshLater =
false;
1017 return (
path() == other->
path() );
1026 : QTreeWidget( parent )
1028 setRootIsDecorated(
false );
1031 setColumnCount( 7 );
1033 labels << tr(
"Name" ) << tr(
"Size" ) << tr(
"Date" ) << tr(
"Permissions" ) << tr(
"Owner" ) << tr(
"Group" ) << tr(
"Type" );
1034 setHeaderLabels( labels );
1041 QList<QTreeWidgetItem *> items;
1044 QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
1045 Q_FOREACH (
const QString &name, entries )
1047 QFileInfo fi( dir.absoluteFilePath( name ) );
1051 if ( fi.size() > 1024 )
1053 size = size.sprintf(
"%.1f KiB", fi.size() / 1024.0 );
1055 else if ( fi.size() > 1.048576e6 )
1057 size = size.sprintf(
"%.1f MiB", fi.size() / 1.048576e6 );
1061 size = QStringLiteral(
"%1 B" ).arg( fi.size() );
1064 texts << fi.lastModified().toString( Qt::SystemLocaleShortDate );
1066 perm += fi.permission( QFile::ReadOwner ) ?
'r' :
'-';
1067 perm += fi.permission( QFile::WriteOwner ) ?
'w' :
'-';
1068 perm += fi.permission( QFile::ExeOwner ) ?
'x' :
'-';
1070 perm += fi.permission( QFile::ReadGroup ) ?
'r' :
'-';
1071 perm += fi.permission( QFile::WriteGroup ) ?
'w' :
'-';
1072 perm += fi.permission( QFile::ExeGroup ) ?
'x' :
'-';
1073 perm += fi.permission( QFile::ReadOther ) ?
'r' :
'-';
1074 perm += fi.permission( QFile::WriteOther ) ?
'w' :
'-';
1075 perm += fi.permission( QFile::ExeOther ) ?
'x' :
'-';
1078 texts << fi.owner();
1079 texts << fi.group();
1083 if ( fi.isDir() && fi.isSymLink() )
1085 type = tr(
"folder" );
1088 else if ( fi.isDir() )
1090 type = tr(
"folder" );
1091 icon = iconDirectory;
1093 else if ( fi.isFile() && fi.isSymLink() )
1095 type = tr(
"file" );
1096 icon = iconFileLink;
1098 else if ( fi.isFile() )
1100 type = tr(
"file" );
1106 QTreeWidgetItem *item =
new QTreeWidgetItem( texts );
1107 item->setIcon( 0, icon );
1111 addTopLevelItems( items );
1115 QList<QVariant> lst = settings.
value( QStringLiteral(
"dataitem/directoryHiddenColumns" ) ).toList();
1116 Q_FOREACH (
const QVariant &colVariant, lst )
1118 setColumnHidden( colVariant.toInt(), true );
1124 if ( event->button() == Qt::RightButton )
1130 labels << tr(
"Name" ) << tr(
"Size" ) << tr(
"Date" ) << tr(
"Permissions" ) << tr(
"Owner" ) << tr(
"Group" ) << tr(
"Type" );
1131 for (
int i = 0; i < labels.count(); i++ )
1133 QAction *action = popupMenu.addAction( labels[i],
this, SLOT(
showHideColumn() ) );
1134 action->setObjectName( QString::number( i ) );
1135 action->setCheckable(
true );
1136 action->setChecked( !isColumnHidden( i ) );
1139 popupMenu.exec( event->globalPos() );
1145 QAction *action = qobject_cast<QAction *>( sender() );
1149 int columnIndex = action->objectName().toInt();
1150 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
1154 QList<QVariant> lst;
1155 for (
int i = 0; i < columnCount(); i++ )
1157 if ( isColumnHidden( i ) )
1158 lst.append( QVariant( i ) );
1160 settings.
setValue( QStringLiteral(
"dataitem/directoryHiddenColumns" ), lst );
1166 mIconName = QStringLiteral(
":/images/icons/qgis_icon.svg" );
1167 setToolTip( QDir::toNativeSeparators( path ) );
1174 u.
layerType = QStringLiteral(
"project" );
1183 mIconName = QStringLiteral(
"/mIconDelete.svg" );
1194 mIconName = QStringLiteral(
"/mIconFavourites.svg" );
1203 const QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ), QVariant() ).toStringList();
1205 for (
const QString &favDir : favDirs )
1207 QStringList parts = favDir.split( QStringLiteral(
"|||" ) );
1208 if ( parts.empty() )
1211 QString dir = parts.at( 0 );
1213 if ( parts.count() > 1 )
1214 name = parts.at( 1 );
1224 QString
name = n.isEmpty() ? favDir : n;
1227 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
1228 favDirs.append( QStringLiteral(
"%1|||%2" ).arg( favDir, name ) );
1229 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
1247 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
1248 for (
int i = favDirs.count() - 1; i >= 0; --i )
1250 QStringList parts = favDirs.at( i ).split( QStringLiteral(
"|||" ) );
1251 if ( parts.empty() )
1254 QString dir = parts.at( 0 );
1256 favDirs.removeAt( i );
1258 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
1263 QgsDebugMsg( QStringLiteral(
"favorites item %1 not found" ).arg( item->
path() ) );
1275 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
1276 for (
int i = 0; i < favDirs.count(); ++i )
1278 QStringList parts = favDirs.at( i ).split( QStringLiteral(
"|||" ) );
1279 if ( parts.empty() )
1282 QString dir = parts.at( 0 );
1285 favDirs[i] = QStringLiteral(
"%1|||%2" ).arg( path, name );
1289 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
1292 const QVector<QgsDataItem *> ch =
children();
1295 if ( QgsFavoriteItem *favorite = qobject_cast< QgsFavoriteItem * >( child ) )
1297 if ( favorite->dirPath() ==
path )
1299 favorite->setName( name );
1320 children.append( item );
1324 if ( children.isEmpty() )
1326 QgsFavoriteItem *item =
new QgsFavoriteItem(
this, name, favDir,
mPath +
'/' + pathName );
1329 children.append( item );
1353 void QgsZipItem::init()
1356 mIconName = QStringLiteral(
"/mIconZip.svg" );
1359 static std::once_flag initialized;
1360 std::call_once( initialized, [ = ]
1362 sProviderNames << QStringLiteral(
"OGR" ) << QStringLiteral(
"GDAL" );
1371 QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
1378 if ( scanZipSetting == QLatin1String(
"no" ) )
1391 QFileInfo info( fileName );
1401 if ( provider->name() == QStringLiteral(
"OGR" ) )
1403 if ( info.suffix().compare( QLatin1String(
"dbf" ), Qt::CaseInsensitive ) == 0 )
1405 if (
mZipFileList.indexOf( fileName.left( fileName.count() - 4 ) +
".shp" ) != -1 )
1408 if ( info.completeSuffix().compare( QLatin1String(
"shp.xml" ), Qt::CaseInsensitive ) == 0 )
1414 QgsDebugMsgLevel( QStringLiteral(
"trying to load item %1 with %2" ).arg( tmpPath, provider->name() ), 3 );
1415 QgsDataItem *item = provider->createDataItem( tmpPath,
this );
1420 children.append( item );
1440 QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
1441 QStringList zipFileList;
1444 bool populated =
false;
1446 QgsDebugMsgLevel( QStringLiteral(
"path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path, name, scanZipSetting, vsiPrefix ), 3 );
1449 if ( scanZipSetting == QLatin1String(
"no" ) )
1453 if ( ( vsiPrefix != QLatin1String(
"/vsizip/" ) && vsiPrefix != QLatin1String(
"/vsitar/" ) ) )
1456 zipItem =
new QgsZipItem( parent, name, filePath, path );
1466 if ( path.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) ||
1467 path.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) )
1472 if ( !zipFileList.isEmpty() && zipFileList.count() <= 10 )
1476 QgsDebugMsgLevel( QStringLiteral(
"Got zipItem with %1 children, path=%2, name=%3" ).arg( zipItem->
rowCount() ).arg( zipItem->
path(), zipItem->
name() ), 3 );
1480 QgsDebugMsgLevel( QStringLiteral(
"Delaying populating zipItem with path=%1, name=%2" ).arg( zipItem->
path(), zipItem->
name() ), 3 );
1485 if ( zipItem && ( !populated || zipItem->
rowCount() > 0 ) )
1501 QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
1506 if ( scanZipSetting == QLatin1String(
"no" ) )
1513 char **papszSiblingFiles = VSIReadDirRecursive( QString(
mVsiPrefix +
mFilePath ).toLocal8Bit().constData() );
1514 if ( papszSiblingFiles )
1516 for (
int i = 0; papszSiblingFiles[i]; i++ )
1518 tmpPath = papszSiblingFiles[i];
1521 if ( tmpPath.right( 1 ) != QLatin1String(
"/" ) )
1524 CSLDestroy( papszSiblingFiles );
1536 QgsProjectHomeItem::QgsProjectHomeItem(
QgsDataItem *
parent,
const QString &
name,
const QString &dirPath,
const QString &
path )
1541 QIcon QgsProjectHomeItem::icon()
1548 QVariant QgsProjectHomeItem::sortKey()
const 1550 return QStringLiteral(
" 1" );
1553 QList<QAction *> QgsProjectHomeItem::actions( QWidget *parent )
1556 QAction *separator =
new QAction( parent );
1557 separator->setSeparator(
true );
1558 lst.append( separator );
1560 QAction *setHome =
new QAction( tr(
"Set Project Home…" ), parent );
1561 connect( setHome, &QAction::triggered,
this, [ = ]
1563 QWidget *parentWindow =
parent;
1564 while ( parentWindow->parentWidget() )
1565 parentWindow = parentWindow->parentWidget();
1568 QString newPath = QFileDialog::getExistingDirectory( parentWindow, tr(
"Select Project Home Directory" ), oldHome );
1569 if ( !newPath.isEmpty() )
1579 QgsFavoriteItem::QgsFavoriteItem(
QgsFavoritesItem *parent,
const QString &
name,
const QString &dirPath,
const QString &
path )
1581 , mFavorites( parent )
1586 bool QgsFavoriteItem::rename(
const QString &
name )
1588 mFavorites->renameFavorite( dirPath(), name );
A Collection: logical collection of layers or subcollections, e.g.
QString layerType
Type of URI. Recognized types: "vector" / "raster" / "mesh" / "plugin" / "custom" / "project"...
virtual QList< QMenu * > menus(QWidget *parent)
Returns the list of menus available for this item.
~QgsDataCollectionItem() override
static QIcon iconRaster()
void beginInsertItems(QgsDataItem *parent, int first, int last)
bool disconnectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Convenience function to disconnect the same style that the frame change connection was established...
QgsFavoritesItem(QgsDataItem *parent, const QString &name, const QString &path=QString())
Constructor for QgsFavoritesItem.
virtual void childrenCreated()
void childrenCreated() override
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
QgsErrorItem(QgsDataItem *parent, const QString &error, const QString &path)
void dataChanged(QgsDataItem *item)
static void deleteLater(QVector< QgsDataItem * > &items)
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
QString name() const
Returns the name of the item (the displayed text for the item).
QVariant mSortKey
Custom sort key. If invalid, name() will be used for sorting instead.
virtual Capabilities capabilities2() const
Returns the capabilities for the data item.
This class is a composition of two QSettings instances:
virtual QgsDataItem * createDataItem(const QString &path, QgsDataItem *parentItem)=0
Create a new instance of QgsDataItem (or null) for given path and parent item.
QgsDataItem * parent() const
Gets item parent.
QList< QgsDataItemProvider * > providers() const
Gets list of available providers.
QIcon icon() const
Gets the icons representation in the current frame.
void connectionsChanged()
Emitted when the provider's connections of the child items have changed This signal is normally forwa...
QString mProviderKey
The provider key.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString())
QString name
Human readable name to be used e.g. in layer tree.
static QString pathComponent(const QString &component)
Create path component replacing path separators.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
void setState(State state) override
Set item state.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QStringList supportedFormats
virtual bool rename(const QString &name)
Sets a new name for the item, and returns true if the item was successfully renamed.
virtual void depopulate()
Remove children recursively and set as not populated. This is used when refreshing collapsed items...
QVariant sortKey() const override
Returns the sorting key for the item.
void setToolTip(const QString &msg)
static QIcon iconDefault()
QVector< QgsDataItem * > children() const
QgsDirectoryItem(QgsDataItem *parent, const QString &name, const QString &path)
A zip file: contains layers, using GDAL/OGR VSIFILE mechanism.
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
QgsMimeDataUtils::Uri mimeUri() const override
Returns mime URI for the data item.
static QIcon iconPolygon()
void beginRemoveItems(QgsDataItem *parent, int first, int last)
#define QgsDebugMsgLevel(str, level)
LayerType
Types of layers that can be added to a map.
QgsZipItem(QgsDataItem *parent, const QString &name, const QString &path)
virtual bool handleDoubleClick()
Called when a user double clicks on the item.
static QgsDataItem * itemFromPath(QgsDataItem *parent, const QString &path, const QString &name)
Creates a new data item from the specified path.
Children not yet created.
Creating children in separate thread (populating or refreshing)
void updateIcon()
Will request a repaint of this icon.
virtual void refreshConnections()
Refresh connections: update GUI and emit signal.
virtual int capabilities()=0
Returns combination of flags from QgsDataProvider::DataCapabilities.
static bool hiddenPath(const QString &path)
Check if the given path is hidden from the browser model.
QString providerKey() const
Returns provider key.
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
static QIcon openDirIcon()
Shared open directory icon.
QgsDataItem(QgsDataItem::Type type, QgsDataItem *parent, const QString &name, const QString &path)
Create new data item.
A directory: contains subdirectories and layers.
static QStringList sProviderNames
Base class for all items in the model.
virtual QVariant sortKey() const
Returns the sorting key for the item.
QgsMapLayer::LayerType mapLayerType() const
Returns QgsMapLayer::LayerType.
Capabilities mCapabilities
virtual void setState(State state)
Set item state.
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
void setName(const QString &name)
Sets the name of the item (the displayed text for the item).
Can create children. Even items without this capability may have children, but cannot create them...
void setPresetHomePath(const QString &path)
Sets the project's home path.
QVector< QgsDataItem * > createChildren() override
Create children.
static int findItem(QVector< QgsDataItem * > items, QgsDataItem *item)
void moveToThread(QThread *targetThread)
Move object and all its descendants to thread.
QString uri() const
Returns layer uri or empty string if layer cannot be created.
virtual void populate(const QVector< QgsDataItem * > &children)
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Contains various Favorites directories.
QVector< QgsDataItem * > createChildren() override
Create children.
QStringList supportedCrs() const
Returns the supported CRS.
void removeDirectory(QgsDirectoryItem *item)
Removes an existing directory from the favorites group.
QgsMimeDataUtils::Uri mimeUri() const override
Returns mime URI for the data item.
static QString layerTypeAsString(LayerType layerType)
Returns the string representation of the given layerType.
void addDirectory(const QString &directory, const QString &name=QString())
Adds a new directory to the favorites group.
virtual QString layerName() const
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setParent(QgsDataItem *parent)
Set item parent and connect / disconnect parent to / from item signals.
void renameFavorite(const QString &path, const QString &name)
Renames the stored favorite with corresponding path a new name.
Animated icon is keeping an animation running if there are listeners connected to frameChanged...
virtual QList< QAction * > actions(QWidget *parent)
Returns the list of actions available for this item.
bool deferredDelete()
The item is scheduled to be deleted.
static QIcon homeDirIcon()
Shared home directory icon.
static QIcon iconFavorites()
Icon for favorites group.
QString providerKey
For "vector" / "raster" type: provider id.
QString uri
Identifier of the data source recognized by its providerKey.
virtual QVector< QgsDataItem * > createChildren()
Create children.
static QIcon iconDataCollection()
QVector< QgsDataItem * > createChildren() override
Create children.
Item that represents a layer that can be opened with one of the providers.
QgsProjectItem(QgsDataItem *parent, const QString &name, const QString &path)
A data item holding a reference to a QGIS project file.
virtual QgsDataItem * removeChildItem(QgsDataItem *child)
Removes a child item and returns it without deleting it.
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
QList< QAction * > actions(QWidget *parent) override
Returns the list of actions available for this item.
QgsLayerItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey)
Data item that can be used to represent QGIS projects.
LayerType mLayerType
The layer type.
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
QStringList supportedFormats() const
Returns the supported formats.
static QIcon iconMesh()
Returns icon for mesh layer type.
QVector< QgsDataItem * > mChildren
QStringList getZipFileList()
virtual void deleteLater()
Safely delete the item:
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
QWidget * paramWidget() override
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms...
bool connectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Connect a slot that will be notified repeatedly whenever a frame changes and which should request the...
Represents a favorite item.
This is the interface for those who want to add custom data items to the browser tree.
void stateChanged(QgsDataItem *item, QgsDataItem::State oldState)
static QString vsiPrefix(const QString &uri)
QMap< QString, QIcon > mIconMap
static QString iconName(LayerType layerType)
Returns the icon name of the given layerType.