20#include <cpl_string.h>
33#include "moc_qgszipitem.cpp"
35using namespace Qt::StringLiterals;
55 const QString &filePath,
const QString &
path,
63void QgsZipItem::init()
71 static std::once_flag initialized;
72 std::call_once( initialized, []
102 const QString scanZipSetting = settings.
value( u
"qgis/scanZipInBrowser2"_s,
"basic" ).toString();
109 if ( scanZipSetting ==
"no"_L1 )
121 for (
const QString &fileName : constMZipFileList )
123 const QFileInfo info( fileName );
133 if ( provider->name() ==
"OGR"_L1 )
135 if ( info.suffix().compare(
"dbf"_L1, Qt::CaseInsensitive ) == 0 )
137 if (
mZipFileList.indexOf( fileName.left( fileName.count() - 4 ) +
".shp" ) != -1 )
140 if ( info.completeSuffix().compare(
"shp.xml"_L1, Qt::CaseInsensitive ) == 0 )
146 QgsDebugMsgLevel( u
"trying to load item %1 with %2"_s.arg( tmpPath, provider->name() ), 3 );
147 QgsDataItem *item = provider->createDataItem( tmpPath,
this );
172 const QString scanZipSetting = settings.
value( u
"qgis/scanZipInBrowser2"_s,
"basic" ).toString();
173 QStringList zipFileList;
175 bool populated =
false;
180 if ( scanZipSetting ==
"no"_L1 )
187 auto zipItem = std::make_unique< QgsZipItem >(
parent,
name, filePath,
path );
194 if (
path.endsWith(
".zip"_L1, Qt::CaseInsensitive ) ||
195 path.endsWith(
".tar"_L1, Qt::CaseInsensitive ) )
197 zipFileList = zipItem->getZipFileList();
200 if ( !zipFileList.isEmpty() && zipFileList.count() <= 10 )
202 zipItem->populate( zipItem->createChildren() );
204 QgsDebugMsgLevel( u
"Got zipItem with %1 children, path=%2, name=%3"_s.arg( zipItem->rowCount() ).arg( zipItem->path(), zipItem->name() ), 3 );
208 QgsDebugMsgLevel( u
"Delaying populating zipItem with path=%1, name=%2"_s.arg( zipItem->path(), zipItem->name() ), 3 );
212 if ( !populated || zipItem->rowCount() > 0 )
215 return zipItem.release();
228 const QString scanZipSetting = settings.
value( u
"qgis/scanZipInBrowser2"_s,
"basic" ).toString();
233 if ( scanZipSetting ==
"no"_L1 )
240 char **papszSiblingFiles = VSIReadDirRecursive( QString(
mVsiPrefix +
mFilePath ).toUtf8().constData() );
241 if ( papszSiblingFiles )
243 for (
int i = 0; papszSiblingFiles[i]; i++ )
245 tmpPath = papszSiblingFiles[i];
248 if ( tmpPath.right( 1 ) !=
"/"_L1 )
251 CSLDestroy( papszSiblingFiles );
@ ItemRepresentsFile
Item's path() directly represents a file on disk.
@ Collection
A collection of items.
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.
Qgis::BrowserItemType mType
QVector< QgsDataItem * > children() const
QgsDataItem(Qgis::BrowserItemType type, QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey=QString())
Constructor for QgsDataItem, with the specified parent item.
QString name() const
Returns the name of the item (the displayed text for the item).
virtual void setCapabilities(Qgis::BrowserItemCapabilities capabilities)
Sets the capabilities for the data item.
void setName(const QString &name)
Sets the name of the item (the displayed text for the item).
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
virtual Qgis::BrowserItemCapabilities capabilities2() const
Returns the capabilities for the data item.
static QString vsiPrefixForPath(const QString &path)
Returns a the vsi prefix which corresponds to a file path, or an empty string if the path is not asso...
static bool isVsiArchivePrefix(const QString &prefix)
Returns true if prefix is a supported archive style container prefix (e.g.
QList< QgsMimeDataUtils::Uri > UriList
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.
static Q_DECL_DEPRECATED QString vsiPrefix(const QString &uri)
QgsZipItem(QgsDataItem *parent, const QString &name, const QString &path)
Constructor.
QStringList getZipFileList()
bool hasDragEnabled() const override
Returns true if the item may be dragged.
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 QgsDataItem * itemFromPath(QgsDataItem *parent, const QString &path, const QString &name)
Creates a new data item from the specified path.
QVector< QgsDataItem * > createChildren() override
Create children.
static QStringList sProviderNames
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QString filePath
Path to file, if uri is associated with a file.
QString uri
Identifier of the data source recognized by its providerKey.
QString layerType
Type of URI.