Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Nov 2, 2021
1 parent 06a2329 commit 14bd167
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions python/core/auto_generated/browser/qgszipitem.sip.in
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/browser/qgsdirectoryitem.cpp
Expand Up @@ -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 );
Expand Down
16 changes: 16 additions & 0 deletions src/core/browser/qgszipitem.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/browser/qgszipitem.h
Expand Up @@ -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;
Expand Down

0 comments on commit 14bd167

Please sign in to comment.