19#include "moc_qgszipitem.cpp"
29#include <cpl_string.h>
50 const QString &filePath,
const QString &path,
51 const QString &providerKey )
53 , mFilePath( filePath )
58void QgsZipItem::init()
61 mIconName = QStringLiteral(
"/mIconZip.svg" );
66 static std::once_flag initialized;
67 std::call_once( initialized, [ = ]
81 u.
layerType = QStringLiteral(
"collection" );
97 const QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
104 if ( scanZipSetting == QLatin1String(
"no" ) )
116 for (
const QString &fileName : constMZipFileList )
118 const QFileInfo info( fileName );
128 if ( provider->name() == QLatin1String(
"OGR" ) )
130 if ( info.suffix().compare( QLatin1String(
"dbf" ), Qt::CaseInsensitive ) == 0 )
132 if (
mZipFileList.indexOf( fileName.left( fileName.count() - 4 ) +
".shp" ) != -1 )
135 if ( info.completeSuffix().compare( QLatin1String(
"shp.xml" ), Qt::CaseInsensitive ) == 0 )
141 QgsDebugMsgLevel( QStringLiteral(
"trying to load item %1 with %2" ).arg( tmpPath, provider->name() ), 3 );
142 QgsDataItem *item = provider->createDataItem( tmpPath,
this );
167 const QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
168 QStringList zipFileList;
170 bool populated =
false;
175 if ( scanZipSetting == QLatin1String(
"no" ) )
182 auto zipItem = std::make_unique< QgsZipItem >(
parent,
name, filePath,
path );
189 if (
path.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) ||
190 path.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) )
192 zipFileList = zipItem->getZipFileList();
195 if ( !zipFileList.isEmpty() && zipFileList.count() <= 10 )
197 zipItem->populate( zipItem->createChildren() );
199 QgsDebugMsgLevel( QStringLiteral(
"Got zipItem with %1 children, path=%2, name=%3" ).arg( zipItem->rowCount() ).arg( zipItem->path(), zipItem->name() ), 3 );
203 QgsDebugMsgLevel( QStringLiteral(
"Delaying populating zipItem with path=%1, name=%2" ).arg( zipItem->path(), zipItem->name() ), 3 );
207 if ( !populated || zipItem->rowCount() > 0 )
210 return zipItem.release();
223 const QString scanZipSetting = settings.
value( QStringLiteral(
"qgis/scanZipInBrowser2" ),
"basic" ).toString();
228 if ( scanZipSetting == QLatin1String(
"no" ) )
235 char **papszSiblingFiles = VSIReadDirRecursive( QString(
mVsiPrefix +
mFilePath ).toUtf8().constData() );
236 if ( papszSiblingFiles )
238 for (
int i = 0; papszSiblingFiles[i]; i++ )
240 tmpPath = papszSiblingFiles[i];
243 if ( tmpPath.right( 1 ) != QLatin1String(
"/" ) )
246 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.
A browser item for collections of data.
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.
Qgis::BrowserItemType mType
QVector< QgsDataItem * > children() const
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.
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.