18 #include <QApplication>
19 #include <QtConcurrentMap>
20 #include <QtConcurrentRun>
22 #include <QElapsedTimer>
26 #include <QMouseEvent>
27 #include <QTreeWidget>
28 #include <QTreeWidgetItem>
33 #include <QRegularExpression>
43 #include "qgsconfig.h"
51 #define CPL_SUPRESS_CPLUSPLUS
53 #include "cpl_string.h"
146 const QString connectionName {
name() };
151 if ( md->findConnection( connectionName ) )
159 const QString databaseFilePath {
path().remove( QRegularExpression( R
"re([\aZ]{2,}://)re" ) ) };
161 if ( QFile::exists( databaseFilePath ) )
182 const QString &connectionUri,
183 const QString &providerKey,
184 const QString &schema,
185 const QString &tableName )
188 , mTableName( tableName )
189 , mConnectionUri( connectionUri )
198 mTableProperty = qgis::make_unique<QgsAbstractDatabaseProviderConnection::TableProperty>( conn->table(
schema,
tableName ) );
202 QgsDebugMsg( QStringLiteral(
"Error creating fields item: %1" ).arg( ex.
what() ) );
224 const QgsFields constFields { conn->fields( mSchema, mTableName ) };
225 for (
const auto &f : constFields )
248 return mConnectionUri;
253 std::unique_ptr<QgsVectorLayer> vl;
272 QgsDebugMsg( QStringLiteral(
"Error getting connection from %1" ).arg( mConnectionUri ) );
285 return mTableProperty.get();
304 setState( QgsDataItem::State::Populated );
315 if ( parentFields && parentFields->tableProperty() &&
316 parentFields->tableProperty()->geometryColumn() ==
mName &&
317 parentFields->tableProperty()->geometryColumnTypes().count() )
319 if ( mField.
typeName() == QLatin1String(
"raster" ) )
326 case QgsWkbTypes::GeometryType::LineGeometry:
328 case QgsWkbTypes::GeometryType::PointGeometry:
330 case QgsWkbTypes::GeometryType::PolygonGeometry:
332 case QgsWkbTypes::GeometryType::UnknownGeometry:
333 case QgsWkbTypes::GeometryType::NullGeometry:
353 return QStringLiteral(
" 0" );
366 , mCapabilities( NoCapabilities )
368 , mState( NotPopulated )
370 , mProviderKey( providerKey )
372 , mDeferredDelete( false )
373 , mFutureWatcher( nullptr )
385 child->deleteLater();
389 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
392 QgsDebugMsg( QStringLiteral(
"mFutureWatcher not finished (should not happen) -> waitForFinished()" ) );
393 mDeferredDelete =
true;
394 mFutureWatcher->waitForFinished();
397 delete mFutureWatcher;
402 return QString(
string ).replace( QRegExp(
"[\\\\/]" ), QStringLiteral(
"|" ) );
424 child->deleteLater();
428 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
430 QgsDebugMsg( QStringLiteral(
"mFutureWatcher not finished -> schedule to delete later" ) );
431 mDeferredDelete =
true;
435 QObject::deleteLater();
441 const auto constItems = items;
460 child->QObject::setParent(
nullptr );
461 child->moveToThread( targetThread );
463 QObject::moveToThread( targetThread );
474 return sPopulatingIcon->
icon();
476 if ( !
mIcon.isNull() )
495 return QVector<QgsDataItem *>();
513 if ( !mFutureWatcher )
515 mFutureWatcher =
new QFutureWatcher< QVector <QgsDataItem *> >( this );
519 mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren,
this ) );
524 QVector<QgsDataItem *> QgsDataItem::runCreateChildren(
QgsDataItem *item )
530 QgsDebugMsgLevel( QStringLiteral(
"%1 children created in %2 ms" ).arg(
children.size() ).arg( time.elapsed() ), 3 );
532 const auto constChildren =
children;
539 child->moveToThread( qApp->thread() );
547 QgsDebugMsgLevel( QStringLiteral(
"path = %1 children.size() = %2" ).arg(
path() ).arg( mFutureWatcher->result().size() ), 3 );
551 QgsDebugMsg( QStringLiteral(
"Item was scheduled to be deleted later" ) );
552 QObject::deleteLater();
558 populate( mFutureWatcher->result() );
562 refresh( mFutureWatcher->result() );
577 const auto constChildren =
children;
616 if ( !mFutureWatcher )
618 mFutureWatcher =
new QFutureWatcher< QVector <QgsDataItem *> >( this );
621 mFutureWatcher->setFuture( QtConcurrent::run( runCreateChildren,
this ) );
645 QVector<QgsDataItem *> remove;
653 remove.append( child );
655 const auto constRemove = remove;
663 const auto constChildren =
children;
676 mChildren.value( index )->refresh( child->children() );
679 child->deleteLater();
715 disconnect(
this,
nullptr,
mParent,
nullptr );
750 if (
mChildren.at( i )->mName.localeAwareCompare( child->
mName ) >= 0 )
795 for (
int i = 0; i < items.size(); i++ )
797 Q_ASSERT_X( items[i],
"findItem", QStringLiteral(
"item %1 is nullptr" ).arg( i ).toLatin1() );
799 if ( items[i]->
equal( item ) )
807 return ( metaObject()->className() == other->metaObject()->className() &&
814 return QList<QAction *>();
847 if ( !sPopulatingIcon )
871 return QList<QMenu *>();
877 const QString &uri,
LayerType layerType,
const QString &providerKey )
878 :
QgsDataItem( Layer, parent, name, path, providerKey )
880 , mLayerType( layerType )
920 switch ( layer->
type() )
924 switch ( qobject_cast< QgsVectorLayer * >( layer )->geometryType() )
963 static int enumIdx = staticMetaObject.indexOfEnumerator(
"LayerType" );
964 return staticMetaObject.enumerator( enumIdx ).valueToKey( layerType );
972 return QStringLiteral(
"/mIconPointLayer.svg" );
974 return QStringLiteral(
"/mIconLineLayer.svg" );
976 return QStringLiteral(
"/mIconPolygonLayer.svg" );
979 return QStringLiteral(
"/mIconVector.svg" );
982 return QStringLiteral(
"/mIconTableLayer.svg" );
984 return QStringLiteral(
"/mIconRaster.svg" );
986 return QStringLiteral(
"/mIconMeshLayer.svg" );
988 return QStringLiteral(
"/mIconPointCloudLayer.svg" );
990 return QStringLiteral(
"/mIconLayer.png" );
1007 const QgsLayerItem *o = qobject_cast<const QgsLayerItem *>( other );
1021 u.
layerType = QStringLiteral(
"vector" );
1050 u.
layerType = QStringLiteral(
"raster" );
1056 u.
layerType = QStringLiteral(
"vector-tile" );
1059 u.
layerType = QStringLiteral(
"pointcloud" );
1062 u.
layerType = QStringLiteral(
"plugin" );
1065 u.
layerType = QStringLiteral(
"annotation" );
1079 const QString &name,
1080 const QString &path,
1081 const QString &providerKey )
1082 :
QgsDataItem( Collection, parent, name, path, providerKey )
1085 mIconName = QStringLiteral(
"/mIconDbSchema.svg" );
1097 QgsDebugMsgLevel( QStringLiteral(
"delete child = 0x%0" ).arg(
static_cast<qlonglong
>( i ), 8, 16, QLatin1Char(
'0' ) ), 2 );
1108 , mRefreshLater( false )
1115 const QString &dirPath,
const QString &path,
1116 const QString &providerKey )
1118 , mDirPath( dirPath )
1119 , mRefreshLater( false )
1132 if (
mDirPath == QDir::homePath() )
1141 if ( fi.isDir() && fi.isSymLink() )
1162 QStringList entries = dir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
1163 const auto constEntries = entries;
1164 for (
const QString &subdir : constEntries )
1166 if ( mRefreshLater )
1172 QString subdirPath = dir.absoluteFilePath( subdir );
1174 QgsDebugMsgLevel( QStringLiteral(
"creating subdir: %1" ).arg( subdirPath ), 2 );
1180 bool handledByProvider =
false;
1183 if ( provider->handlesDirectoryPath(
path ) )
1185 handledByProvider =
true;
1189 if ( handledByProvider )
1195 item->
setSortKey( QStringLiteral(
" %1" ).arg( subdir ) );
1202 QStringList fileEntries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files, QDir::Name );
1203 const auto constFileEntries = fileEntries;
1204 for (
const QString &
name : constFileEntries )
1206 if ( mRefreshLater )
1212 QString
path = dir.absoluteFilePath(
name );
1213 QFileInfo fileInfo(
path );
1215 if ( fileInfo.suffix().compare( QLatin1String(
"zip" ), Qt::CaseInsensitive ) == 0 ||
1216 fileInfo.suffix().compare( QLatin1String(
"tar" ), Qt::CaseInsensitive ) == 0 )
1226 bool createdItem =
false;
1229 int capabilities = provider->capabilities();
1249 if ( fileInfo.suffix().compare( QLatin1String(
"qgs" ), Qt::CaseInsensitive ) == 0 ||
1250 fileInfo.suffix().compare( QLatin1String(
"qgz" ), Qt::CaseInsensitive ) == 0 )
1268 if ( !mFileSystemWatcher )
1270 mFileSystemWatcher =
new QFileSystemWatcher(
this );
1271 mFileSystemWatcher->addPath(
mDirPath );
1274 mLastScan = QDateTime::currentDateTime();
1278 if ( mFileSystemWatcher )
1280 delete mFileSystemWatcher;
1281 mFileSystemWatcher =
nullptr;
1289 if ( mLastScan.msecsTo( QDateTime::currentDateTime() ) <
QgsSettings().value( QStringLiteral(
"browser/minscaninterval" ), 10000 ).toInt() )
1296 mRefreshLater =
true;
1310 QTimer::singleShot( 100,
this, [ = ] {
refresh(); } );
1317 QStringList hiddenItems = settings.
value( QStringLiteral(
"browser/hiddenPaths" ),
1318 QStringList() ).toStringList();
1319 int idx = hiddenItems.indexOf(
path );
1320 return ( idx > -1 );
1325 QgsDebugMsgLevel( QStringLiteral(
"mRefreshLater = %1" ).arg( mRefreshLater ), 3 );
1327 if ( mRefreshLater )
1329 QgsDebugMsgLevel( QStringLiteral(
"directory changed during createChidren() -> refresh() again" ), 3 );
1330 mRefreshLater =
false;
1349 return (
path() == other->
path() );
1360 u.
layerType = QStringLiteral(
"directory" );
1367 : QTreeWidget( parent )
1369 setRootIsDecorated(
false );
1372 setColumnCount( 7 );
1374 labels << tr(
"Name" ) << tr(
"Size" ) << tr(
"Date" ) << tr(
"Permissions" ) << tr(
"Owner" ) << tr(
"Group" ) << tr(
"Type" );
1375 setHeaderLabels( labels );
1382 QList<QTreeWidgetItem *> items;
1385 QStringList entries = dir.entryList( QDir::AllEntries | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase );
1386 const auto constEntries = entries;
1387 for (
const QString &name : constEntries )
1389 QFileInfo fi( dir.absoluteFilePath( name ) );
1393 if ( fi.size() > 1024 )
1395 size = QStringLiteral(
"%1 KiB" ).arg( QString::number( fi.size() / 1024.0,
'f', 1 ) );
1397 else if ( fi.size() > 1.048576e6 )
1399 size = QStringLiteral(
"%1 MiB" ).arg( QString::number( fi.size() / 1.048576e6,
'f', 1 ) );
1403 size = QStringLiteral(
"%1 B" ).arg( fi.size() );
1406 texts << QLocale().toString( fi.lastModified(), QLocale::ShortFormat );
1408 perm += fi.permission( QFile::ReadOwner ) ?
'r' :
'-';
1409 perm += fi.permission( QFile::WriteOwner ) ?
'w' :
'-';
1410 perm += fi.permission( QFile::ExeOwner ) ?
'x' :
'-';
1412 perm += fi.permission( QFile::ReadGroup ) ?
'r' :
'-';
1413 perm += fi.permission( QFile::WriteGroup ) ?
'w' :
'-';
1414 perm += fi.permission( QFile::ExeGroup ) ?
'x' :
'-';
1415 perm += fi.permission( QFile::ReadOther ) ?
'r' :
'-';
1416 perm += fi.permission( QFile::WriteOther ) ?
'w' :
'-';
1417 perm += fi.permission( QFile::ExeOther ) ?
'x' :
'-';
1420 texts << fi.owner();
1421 texts << fi.group();
1425 if ( fi.isDir() && fi.isSymLink() )
1427 type = tr(
"folder" );
1430 else if ( fi.isDir() )
1432 type = tr(
"folder" );
1433 icon = iconDirectory;
1435 else if ( fi.isFile() && fi.isSymLink() )
1437 type = tr(
"file" );
1438 icon = iconFileLink;
1440 else if ( fi.isFile() )
1442 type = tr(
"file" );
1448 QTreeWidgetItem *item =
new QTreeWidgetItem( texts );
1449 item->setIcon( 0, icon );
1453 addTopLevelItems( items );
1457 QList<QVariant> lst = settings.
value( QStringLiteral(
"dataitem/directoryHiddenColumns" ) ).toList();
1458 const auto constLst = lst;
1459 for (
const QVariant &colVariant : constLst )
1461 setColumnHidden( colVariant.toInt(),
true );
1467 if ( event->button() == Qt::RightButton )
1473 labels << tr(
"Name" ) << tr(
"Size" ) << tr(
"Date" ) << tr(
"Permissions" ) << tr(
"Owner" ) << tr(
"Group" ) << tr(
"Type" );
1474 for (
int i = 0; i < labels.count(); i++ )
1477 action->setObjectName( QString::number( i ) );
1478 action->setCheckable(
true );
1479 action->setChecked( !isColumnHidden( i ) );
1482 popupMenu.exec( event->globalPos() );
1488 QAction *action = qobject_cast<QAction *>( sender() );
1492 int columnIndex = action->objectName().toInt();
1493 setColumnHidden( columnIndex, !isColumnHidden( columnIndex ) );
1497 QList<QVariant> lst;
1498 for (
int i = 0; i < columnCount(); i++ )
1500 if ( isColumnHidden( i ) )
1501 lst.append( QVariant( i ) );
1503 settings.
setValue( QStringLiteral(
"dataitem/directoryHiddenColumns" ), lst );
1507 const QString &path,
const QString &providerKey )
1510 mIconName = QStringLiteral(
":/images/icons/qgis_icon.svg" );
1518 u.
layerType = QStringLiteral(
"project" );
1527 mIconName = QStringLiteral(
"/mIconDelete.svg" );
1533 :
QgsDataCollectionItem( parent, name, QStringLiteral(
"favorites:" ), QStringLiteral(
"special:Favorites" ) )
1538 mIconName = QStringLiteral(
"/mIconFavorites.svg" );
1548 const QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ), QVariant() ).toStringList();
1550 for (
const QString &favDir : favDirs )
1552 QStringList parts = favDir.split( QStringLiteral(
"|||" ) );
1553 if ( parts.empty() )
1556 QString dir = parts.at( 0 );
1558 if ( parts.count() > 1 )
1559 name = parts.at( 1 );
1569 QString
name = n.isEmpty() ? favDir : n;
1572 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
1573 favDirs.append( QStringLiteral(
"%1|||%2" ).arg( favDir,
name ) );
1574 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
1579 const auto constItems = items;
1593 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
1594 for (
int i = favDirs.count() - 1; i >= 0; --i )
1596 QStringList parts = favDirs.at( i ).split( QStringLiteral(
"|||" ) );
1597 if ( parts.empty() )
1600 QString dir = parts.at( 0 );
1602 favDirs.removeAt( i );
1604 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
1609 QgsDebugMsg( QStringLiteral(
"favorites item %1 not found" ).arg( item->
path() ) );
1621 QStringList favDirs = settings.
value( QStringLiteral(
"browser/favourites" ) ).toStringList();
1622 for (
int i = 0; i < favDirs.count(); ++i )
1624 QStringList parts = favDirs.at( i ).split( QStringLiteral(
"|||" ) );
1625 if ( parts.empty() )
1628 QString dir = parts.at( 0 );
1631 favDirs[i] = QStringLiteral(
"%1|||%2" ).arg(
path,
name );
1635 settings.
setValue( QStringLiteral(
"browser/favourites" ), favDirs );
1638 const QVector<QgsDataItem *> ch =
children();
1641 if ( QgsFavoriteItem *favorite = qobject_cast< QgsFavoriteItem * >( child ) )
1643 if ( favorite->dirPath() ==
path )
1645 favorite->setName(
name );
1659 int capabilities = provider->capabilities();
1663 QgsDataItem *item = provider->createDataItem( favDir,
this );
1673 QgsFavoriteItem *item =
new QgsFavoriteItem(
this,
name, favDir,
mPath +
'/' + pathName );
1694 const QString &filePath,
const QString &path,
1695 const QString &providerKey )
1697 , mFilePath( filePath )
1702 void QgsZipItem::init()
1705 mIconName = QStringLiteral(
"/mIconZip.svg" );
1708 static std::once_flag initialized;
1709 std::call_once( initialized, [ = ]
1711 sProviderNames << QStringLiteral(
"OGR" ) << QStringLiteral(
"GDAL" );
1720 QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
1727 if ( scanZipSetting == QLatin1String(
"no" ) )
1739 for (
const QString &fileName : constMZipFileList )
1741 QFileInfo info( fileName );
1751 if ( provider->name() == QLatin1String(
"OGR" ) )
1753 if ( info.suffix().compare( QLatin1String(
"dbf" ), Qt::CaseInsensitive ) == 0 )
1755 if (
mZipFileList.indexOf( fileName.left( fileName.count() - 4 ) +
".shp" ) != -1 )
1758 if ( info.completeSuffix().compare( QLatin1String(
"shp.xml" ), Qt::CaseInsensitive ) == 0 )
1764 QgsDebugMsgLevel( QStringLiteral(
"trying to load item %1 with %2" ).arg( tmpPath, provider->name() ), 3 );
1765 QgsDataItem *item = provider->createDataItem( tmpPath,
this );
1790 QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
1791 QStringList zipFileList;
1794 bool populated =
false;
1799 if ( scanZipSetting == QLatin1String(
"no" ) )
1803 if ( (
vsiPrefix != QLatin1String(
"/vsizip/" ) &&
vsiPrefix != QLatin1String(
"/vsitar/" ) ) )
1816 if (
path.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) ||
1817 path.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) )
1822 if ( !zipFileList.isEmpty() && zipFileList.count() <= 10 )
1826 QgsDebugMsgLevel( QStringLiteral(
"Got zipItem with %1 children, path=%2, name=%3" ).arg( zipItem->
rowCount() ).arg( zipItem->
path(), zipItem->
name() ), 3 );
1830 QgsDebugMsgLevel( QStringLiteral(
"Delaying populating zipItem with path=%1, name=%2" ).arg( zipItem->
path(), zipItem->
name() ), 3 );
1835 if ( zipItem && ( !populated || zipItem->
rowCount() > 0 ) )
1851 QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
1856 if ( scanZipSetting == QLatin1String(
"no" ) )
1863 char **papszSiblingFiles = VSIReadDirRecursive( QString(
mVsiPrefix +
mFilePath ).toLocal8Bit().constData() );
1864 if ( papszSiblingFiles )
1866 for (
int i = 0; papszSiblingFiles[i]; i++ )
1868 tmpPath = papszSiblingFiles[i];
1871 if ( tmpPath.right( 1 ) != QLatin1String(
"/" ) )
1874 CSLDestroy( papszSiblingFiles );
1909 const QString connectionName {
parent()->
name() };
1931 QgsProjectHomeItem::QgsProjectHomeItem(
QgsDataItem *parent,
const QString &name,
const QString &dirPath,
const QString &path )
1932 :
QgsDirectoryItem( parent, name, dirPath, path, QStringLiteral(
"special:ProjectHome" ) )
1936 QIcon QgsProjectHomeItem::icon()
1938 if ( state() == Populating )
1943 QVariant QgsProjectHomeItem::sortKey()
const
1945 return QStringLiteral(
" 1" );
1949 QgsFavoriteItem::QgsFavoriteItem(
QgsFavoritesItem *parent,
const QString &name,
const QString &dirPath,
const QString &path )
1950 :
QgsDirectoryItem( parent, name, dirPath, path, QStringLiteral(
"special:Favorites" ) )
1951 , mFavorites( parent )
1956 bool QgsFavoriteItem::rename(
const QString &name )
1958 mFavorites->renameFavorite( dirPath(), name );
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
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.
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...
QIcon icon() const
Gets the icons representation in the current frame.
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsConnectionsRootItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsConnectionsRootItem, with the specified parent item.
A Collection: logical collection of layers or subcollections, e.g.
static QIcon openDirIcon()
Shared open directory icon.
QgsDataCollectionItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDataCollectionItem, with the specified parent item.
static QIcon homeDirIcon()
Shared home directory icon.
static QIcon iconDir()
Returns the standard browser directory icon.
~QgsDataCollectionItem() override
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
static QIcon iconDataCollection()
Returns the standard browser data collection icon.
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
QString dataProviderKey(const QString &dataItemProviderName)
Returns the (possibly blank) data provider key for a given data item provider name.
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.
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
static int findItem(QVector< QgsDataItem * > items, QgsDataItem *item)
virtual Capabilities capabilities2() const
Returns the capabilities for the data item.
virtual QList< QMenu * > menus(QWidget *parent)
Returns the list of menus available for this item.
virtual void deleteChildItem(QgsDataItem *child)
Removes and deletes a child item, emitting relevant signals to the model.
QVector< QgsDataItem * > mChildren
@ Populated
Children created.
@ Populating
Creating children in separate thread (populating or refreshing)
@ NotPopulated
Children not yet created.
Capabilities mCapabilities
virtual QVariant sortKey() const
Returns the sorting key for the item.
void setToolTip(const QString &msg)
virtual bool handleDoubleClick()
Called when a user double clicks on the item.
void dataChanged(QgsDataItem *item)
bool deferredDelete()
The item is scheduled to be deleted.
void setParent(QgsDataItem *parent)
Set item parent and connect / disconnect parent to / from item signals.
static void deleteLater(QVector< QgsDataItem * > &items)
virtual bool layerCollection() const
Returns true if the data item is a collection of layers The default implementation returns false,...
QVector< QgsDataItem * > children() const
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ Collapse
The collapse/expand status for this items children should be ignored in order to avoid undesired netw...
@ Rename
Item can be renamed.
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
void beginRemoveItems(QgsDataItem *parent, int first, int last)
QgsDataItem * parent() const
Gets item parent.
virtual void deleteLater()
Safely delete the item:
virtual QgsAbstractDatabaseProviderConnection * databaseConnection() const
For data items that represent a DB connection or one of its children, this method returns a connectio...
virtual QVector< QgsDataItem * > createChildren()
Create children.
QMap< QString, QIcon > mIconMap
virtual void childrenCreated()
virtual void setState(State state)
Set item state.
virtual QgsDataItem * removeChildItem(QgsDataItem *child)
Removes a child item and returns it without deleting it.
static QString pathComponent(const QString &component)
Create path component replacing path separators.
virtual QList< QAction * > actions(QWidget *parent)
Returns the list of actions available for this item.
@ Favorites
Represents a favorite item.
QVariant mSortKey
Custom sort key. If invalid, name() will be used for sorting instead.
void updateIcon()
Will request a repaint of this icon.
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.
void connectionsChanged(const QString &providerKey=QString())
Emitted when the connections of the provider with the specified providerKey have changed.
virtual Q_DECL_DEPRECATED QgsMimeDataUtils::Uri mimeUri() const
Returns mime URI for the data item.
QString name() const
Returns the name of the item (the displayed text for the item).
void beginInsertItems(QgsDataItem *parent, int first, int last)
virtual void refreshConnections(const QString &providerKey=QString())
Causes a data item provider to refresh all registered connections.
virtual void addChildItem(QgsDataItem *child, bool refresh=false)
Inserts a new child item.
QgsDataItem(QgsDataItem::Type type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
void setName(const QString &name)
Sets the name of the item (the displayed text for the item).
void stateChanged(QgsDataItem *item, QgsDataItem::State oldState)
void moveToThread(QThread *targetThread)
Move object and all its descendants to thread.
QString providerKey() const
Returns the provider key that created this item (e.g.
void setProviderKey(const QString &value)
Sets the provider key that created this item (e.g.
virtual void populate(const QVector< QgsDataItem * > &children)
virtual bool equal(const QgsDataItem *other)
Returns true if this item is equal to another item (by testing item type and path).
virtual QgsMimeDataUtils::UriList mimeUris() const
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
virtual void depopulate()
Remove children recursively and set as not populated. This is used when refreshing collapsed items.
~QgsDatabaseSchemaItem() override
QgsDatabaseSchemaItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDatabaseSchemaItem, with the specified parent item.
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
static QIcon iconDataCollection()
Returns the standard browser data collection icon.
A directory: contains subdirectories and layers.
void setState(State state) override
Set item state.
QVector< QgsDataItem * > createChildren() override
Create children.
Q_DECL_DEPRECATED QWidget * paramWidget() override
Returns source widget from data item for QgsBrowserPropertiesWidget.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
QString dirPath() const
Returns the full path to the directory the item represents.
void childrenCreated() override
QgsDirectoryItem(QgsDataItem *parent, const QString &name, const QString &path)
Constructor for QgsDirectoryItem, with the specified parent item.
static bool hiddenPath(const QString &path)
Check if the given path is hidden from the browser model.
Data item that can be used to report problems (e.g.
QgsErrorItem(QgsDataItem *parent, const QString &error, const QString &path)
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.
A layer field item, information about the connection URI, the schema and the table as well as the lay...
QgsFieldItem(QgsDataItem *parent, const QgsField &field)
Constructor for QgsFieldItem, with the specified parent item and field.
Encapsulate a field in an attribute table or data source.
QString typeName() const
Gets the field type.
QVariant::Type subType() const
If the field is a collection, gets its element's type.
A collection of field items with some internal logic to retrieve the fields and a the vector layer in...
QString tableName() const
Returns the table name.
QgsFieldsItem(QgsDataItem *parent, const QString &path, const QString &connectionUri, const QString &providerKey, const QString &schema, const QString &tableName)
Constructor for QgsFieldsItem, with the specified parent item.
QgsAbstractDatabaseProviderConnection::TableProperty * tableProperty() const
Returns the (possibly NULL) properties of the table this fields belong to.
QString connectionUri() const
Returns the connection URI.
QVector< QgsDataItem * > createChildren() override
Create children.
QgsVectorLayer * layer()
Creates and returns a (possibly NULL) layer from the connection URI and schema/table information.
~QgsFieldsItem() override
QString schema() const
Returns the schema name.
Container of fields for a vector layer.
static QIcon iconForFieldType(const QVariant::Type &type)
Returns an icon corresponding to a field type.
Item that represents a layer that can be opened with one of the providers.
QStringList supportedFormats() const
Returns the supported formats.
QString uri() const
Returns layer uri or empty string if layer cannot be created.
virtual Q_DECL_DEPRECATED bool deleteLayer()
Delete this layer item Use QgsDataItemGuiProvider::deleteLayer instead.
QStringList supportedCrs() const
Returns the supported CRS.
static LayerType typeFromMapLayer(QgsMapLayer *layer)
Returns the layer item type corresponding to a QgsMapLayer layer.
static QIcon iconDefault()
static QString iconName(LayerType layerType)
Returns the icon name of the given layerType.
static QString layerTypeAsString(LayerType layerType)
Returns the string representation of the given layerType.
QgsMapLayerType mapLayerType() const
Returns QgsMapLayerType.
QString providerKey() const
Returns provider key.
static QIcon iconRaster()
static QIcon iconMesh()
Returns icon for mesh layer type.
LayerType mLayerType
The layer type.
static QIcon iconForWkbType(QgsWkbTypes::Type type)
Returns the icon for a vector layer whose geometry type is provided.
static QIcon iconPolygon()
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
static QIcon iconPointCloud()
Returns icon for point cloud layer.
static QIcon iconVectorTile()
Returns icon for vector tile layer.
@ PointCloud
Added in 3.18.
@ VectorTile
Added in 3.14.
virtual QString layerName() const
QgsLayerItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey)
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
Base class for all map layer types.
QList< QgsMimeDataUtils::Uri > UriList
Data item that can be used to represent QGIS projects.
QgsMimeDataUtils::UriList mimeUris() const override
Returns mime URIs for the data item, most data providers will only return a single URI but some data ...
QgsProjectItem(QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
A data item holding a reference to a QGIS project file.
Custom exception class for provider connection related exceptions.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
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.
Represents a vector layer which manages a vector based data sets.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Type
The WKB type describes the number of dimensions a geometry has.
A zip file: contains layers, using GDAL/OGR VSIFILE mechanism.
QgsZipItem(QgsDataItem *parent, const QString &name, const QString &path)
Constructor.
QStringList getZipFileList()
static QgsDataItem * itemFromPath(QgsDataItem *parent, const QString &path, const QString &name)
Creates a new data item from the specified path.
static QString vsiPrefix(const QString &uri)
QVector< QgsDataItem * > createChildren() override
Create children.
static QStringList sProviderNames
QgsMapLayerType
Types of layers that can be added to a map.
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
#define QgsDebugMsgLevel(str, level)
The TableProperty class represents a database table or view.
QString uri
Identifier of the data source recognized by its providerKey.
QString name
Human readable name to be used e.g. in layer tree.
QString providerKey
For "vector" / "raster" type: provider id.
QgsWkbTypes::Type wkbType
WKB type, if associated with a vector layer, or QgsWkbTypes::Unknown if not yet known.
QStringList supportedFormats
QString layerType
Type of URI.