Skip to content
Permalink
Browse files
Ensure zip items behave correctly as files in browser
Also fixes drag and drop support for zip to project

Refs #45769
  • Loading branch information
nyalldawson authored and github-actions committed Nov 2, 2021
1 parent 850ee56 commit dff5db19815b03dde835e11b7cf7fa2bcb573cf8
Showing with 25 additions and 1 deletion.
  1. +5 −0 python/core/auto_generated/browser/qgszipitem.sip.in
  2. +1 −1 src/core/browser/qgsdirectoryitem.cpp
  3. +16 −0 src/core/browser/qgszipitem.cpp
  4. +3 −0 src/core/browser/qgszipitem.h
@@ -40,6 +40,11 @@ Constructor

QStringList getZipFileList();

virtual bool hasDragEnabled() const;

virtual QgsMimeDataUtils::UriList mimeUris() const;


static QStringList sProviderNames;

static QString vsiPrefix( const QString &uri );
@@ -307,7 +307,7 @@ QVector<QgsDataItem *> QgsDirectoryItem::createChildren()
if ( fileInfo.suffix().compare( QLatin1String( "zip" ), Qt::CaseInsensitive ) == 0 ||
fileInfo.suffix().compare( QLatin1String( "tar" ), Qt::CaseInsensitive ) == 0 )
{
QgsDataItem *item = QgsZipItem::itemFromPath( this, path, name, mPath + '/' + name );
QgsDataItem *item = QgsZipItem::itemFromPath( this, path, name, path );
if ( item )
{
children.append( item );
@@ -57,13 +57,29 @@ void QgsZipItem::init()
mIconName = QStringLiteral( "/mIconZip.svg" );
mVsiPrefix = vsiPrefix( mFilePath );

setCapabilities( capabilities2() | Qgis::BrowserItemCapability::ItemRepresentsFile );

static std::once_flag initialized;
std::call_once( initialized, [ = ]
{
sProviderNames << QStringLiteral( "OGR" ) << QStringLiteral( "GDAL" );
} );
}

bool QgsZipItem::hasDragEnabled() const
{
return true;
}

QgsMimeDataUtils::UriList QgsZipItem::mimeUris() const
{
QgsMimeDataUtils::Uri u;
u.layerType = QStringLiteral( "collection" );
u.uri = path();
u.filePath = path();
return { u };
}

QVector<QgsDataItem *> QgsZipItem::createChildren()
{
QVector<QgsDataItem *> children;
@@ -53,6 +53,9 @@ class CORE_EXPORT QgsZipItem : public QgsDataCollectionItem
QVector<QgsDataItem *> createChildren() override;
QStringList getZipFileList();

bool hasDragEnabled() const override;
QgsMimeDataUtils::UriList mimeUris() const override;

//! \note not available via Python bindings
static QVector<dataItem_t *> sDataItemPtr SIP_SKIP;
static QStringList sProviderNames;

0 comments on commit dff5db1

Please sign in to comment.