mirror of
https://github.com/qgis/QGIS.git
synced 2025-05-02 00:05:04 -04:00
do not show file extension in TOC, add QqsLayerItem::layerName() for getting layer name (bug #5621)
This commit is contained in:
parent
147911b2c4
commit
04aab2938c
@ -6920,8 +6920,8 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
|
|||||||
QFileInfo myFileInfo( *myIterator );
|
QFileInfo myFileInfo( *myIterator );
|
||||||
// get the directory the .adf file was in
|
// get the directory the .adf file was in
|
||||||
QString myDirNameQString = myFileInfo.path();
|
QString myDirNameQString = myFileInfo.path();
|
||||||
//extract basename with extension
|
//extract basename
|
||||||
QString myBaseNameQString = myFileInfo.completeBaseName() + "." + myFileInfo.suffix();
|
QString myBaseNameQString = myFileInfo.completeBaseName();
|
||||||
//only allow one copy of a ai grid file to be loaded at a
|
//only allow one copy of a ai grid file to be loaded at a
|
||||||
//time to prevent the user selecting all adfs in 1 dir which
|
//time to prevent the user selecting all adfs in 1 dir which
|
||||||
//actually represent 1 coverage,
|
//actually represent 1 coverage,
|
||||||
|
@ -303,7 +303,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
|
|||||||
QgsDebugMsg( providerKey + " : " + uri );
|
QgsDebugMsg( providerKey + " : " + uri );
|
||||||
if ( type == QgsMapLayer::VectorLayer )
|
if ( type == QgsMapLayer::VectorLayer )
|
||||||
{
|
{
|
||||||
QgisApp::instance()->addVectorLayer( uri, layerItem->name(), providerKey );
|
QgisApp::instance()->addVectorLayer( uri, layerItem->layerName(), providerKey );
|
||||||
}
|
}
|
||||||
if ( type == QgsMapLayer::RasterLayer )
|
if ( type == QgsMapLayer::RasterLayer )
|
||||||
{
|
{
|
||||||
@ -333,7 +333,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
|
|||||||
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
|
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
|
||||||
QgsDebugMsg( "layers = " + layers.join( " " ) );
|
QgsDebugMsg( "layers = " + layers.join( " " ) );
|
||||||
|
|
||||||
QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
|
QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->layerName(), providerKey, layers, styles, format, crs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,8 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
|
|||||||
static const QIcon &iconTable();
|
static const QIcon &iconTable();
|
||||||
static const QIcon &iconRaster();
|
static const QIcon &iconRaster();
|
||||||
static const QIcon &iconDefault();
|
static const QIcon &iconDefault();
|
||||||
|
|
||||||
|
virtual QString layerName() const { return name(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
static const char* QGIS_URILIST_MIMETYPE = "application/x-vnd.qgis.qgis.uri";
|
static const char* QGIS_URILIST_MIMETYPE = "application/x-vnd.qgis.qgis.uri";
|
||||||
|
|
||||||
QgsMimeDataUtils::Uri::Uri( QgsLayerItem* layerItem )
|
QgsMimeDataUtils::Uri::Uri( QgsLayerItem* layerItem )
|
||||||
: providerKey( layerItem->providerKey() ), name( layerItem->name() ), uri( layerItem->uri() )
|
: providerKey( layerItem->providerKey() ), name( layerItem->layerName() ), uri( layerItem->uri() )
|
||||||
{
|
{
|
||||||
switch ( layerItem->mapLayerType() )
|
switch ( layerItem->mapLayerType() )
|
||||||
{
|
{
|
||||||
|
@ -103,6 +103,15 @@ QVector<QgsDataItem*> QgsGdalLayerItem::createChildren( )
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsGdalLayerItem::layerName() const
|
||||||
|
{
|
||||||
|
QFileInfo info( name() );
|
||||||
|
if ( info.suffix() == "gz" )
|
||||||
|
return info.baseName();
|
||||||
|
else
|
||||||
|
return info.completeBaseName();
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static QString filterString;
|
static QString filterString;
|
||||||
|
@ -34,6 +34,7 @@ class QgsGdalLayerItem : public QgsLayerItem
|
|||||||
|
|
||||||
QVector<QgsDataItem*> createChildren();
|
QVector<QgsDataItem*> createChildren();
|
||||||
|
|
||||||
|
QString layerName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,8 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
|
|||||||
// we are able to assign CRS only to shapefiles :-(
|
// we are able to assign CRS only to shapefiles :-(
|
||||||
if ( driverName == "ESRI Shapefile" )
|
if ( driverName == "ESRI Shapefile" )
|
||||||
{
|
{
|
||||||
QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
|
// QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
|
||||||
|
QString lyrName = layerName();
|
||||||
QString wkt = crs.toWkt();
|
QString wkt = crs.toWkt();
|
||||||
|
|
||||||
// save ordinary .prj file
|
// save ordinary .prj file
|
||||||
@ -86,7 +87,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
|
|||||||
OSRMorphToESRI( hSRS ); // this is the important stuff for shapefile .prj
|
OSRMorphToESRI( hSRS ); // this is the important stuff for shapefile .prj
|
||||||
char* pszOutWkt = NULL;
|
char* pszOutWkt = NULL;
|
||||||
OSRExportToWkt( hSRS, &pszOutWkt );
|
OSRExportToWkt( hSRS, &pszOutWkt );
|
||||||
QFile prjFile( layerName + ".prj" );
|
QFile prjFile( lyrName + ".prj" );
|
||||||
if ( prjFile.open( QIODevice::WriteOnly ) )
|
if ( prjFile.open( QIODevice::WriteOnly ) )
|
||||||
{
|
{
|
||||||
QTextStream prjStream( &prjFile );
|
QTextStream prjStream( &prjFile );
|
||||||
@ -95,14 +96,14 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( layerName ), tr( "OGR" ) );
|
QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( lyrName ), tr( "OGR" ) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OSRDestroySpatialReference( hSRS );
|
OSRDestroySpatialReference( hSRS );
|
||||||
CPLFree( pszOutWkt );
|
CPLFree( pszOutWkt );
|
||||||
|
|
||||||
// save qgis-specific .qpj file (maybe because of better wkt compatibility?)
|
// save qgis-specific .qpj file (maybe because of better wkt compatibility?)
|
||||||
QFile qpjFile( layerName + ".qpj" );
|
QFile qpjFile( lyrName + ".qpj" );
|
||||||
if ( qpjFile.open( QIODevice::WriteOnly ) )
|
if ( qpjFile.open( QIODevice::WriteOnly ) )
|
||||||
{
|
{
|
||||||
QTextStream qpjStream( &qpjFile );
|
QTextStream qpjStream( &qpjFile );
|
||||||
@ -111,7 +112,7 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( layerName ), tr( "OGR" ) );
|
QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( lyrName ), tr( "OGR" ) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +124,15 @@ bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsOgrLayerItem::layerName() const
|
||||||
|
{
|
||||||
|
QFileInfo info( name() );
|
||||||
|
if ( info.suffix() == "gz" )
|
||||||
|
return info.baseName();
|
||||||
|
else
|
||||||
|
return info.completeBaseName();
|
||||||
|
}
|
||||||
|
|
||||||
// -------
|
// -------
|
||||||
|
|
||||||
static QgsOgrLayerItem* dataItemForLayer( QgsDataItem* parentItem, QString name, QString path, OGRDataSourceH hDataSource, int layerId )
|
static QgsOgrLayerItem* dataItemForLayer( QgsDataItem* parentItem, QString name, QString path, OGRDataSourceH hDataSource, int layerId )
|
||||||
|
@ -28,6 +28,7 @@ class QgsOgrLayerItem : public QgsLayerItem
|
|||||||
|
|
||||||
bool setCrs( QgsCoordinateReferenceSystem crs );
|
bool setCrs( QgsCoordinateReferenceSystem crs );
|
||||||
Capability capabilities();
|
Capability capabilities();
|
||||||
|
QString layerName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QgsOgrDataCollectionItem : public QgsDataCollectionItem
|
class QgsOgrDataCollectionItem : public QgsDataCollectionItem
|
||||||
|
@ -92,7 +92,6 @@ void TestQgsDataItem::testValid()
|
|||||||
void TestQgsDataItem::testDirItemChildren()
|
void TestQgsDataItem::testDirItemChildren()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
// test scanItems setting=1 to test .vrt and .gz files are not loaded by gdal and ogr
|
|
||||||
for ( int iSetting = 0 ; iSetting <= 1 ; iSetting++ )
|
for ( int iSetting = 0 ; iSetting <= 1 ; iSetting++ )
|
||||||
{
|
{
|
||||||
settings.setValue( "/qgis/scanItemsInBrowser", iSetting );
|
settings.setValue( "/qgis/scanItemsInBrowser", iSetting );
|
||||||
@ -106,13 +105,15 @@ void TestQgsDataItem::testDirItemChildren()
|
|||||||
QgsLayerItem* layerItem = dynamic_cast<QgsLayerItem*>( dataItem );
|
QgsLayerItem* layerItem = dynamic_cast<QgsLayerItem*>( dataItem );
|
||||||
if ( ! layerItem )
|
if ( ! layerItem )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// test .vrt and .gz files are not loaded by gdal and ogr
|
||||||
QFileInfo info( layerItem->path() );
|
QFileInfo info( layerItem->path() );
|
||||||
QString lFile = info.fileName();
|
QString lFile = info.fileName();
|
||||||
QString lProvider = layerItem->providerKey();
|
QString lProvider = layerItem->providerKey();
|
||||||
QString errStr = QString( "layer #%1 - %2 provider = %3 iSetting = %4" ).arg( i ).arg( lFile ).arg( lProvider ).arg( iSetting );
|
QString errStr = QString( "layer #%1 - %2 provider = %3 iSetting = %4" ).arg( i ).arg( lFile ).arg( lProvider ).arg( iSetting );
|
||||||
const char* err = errStr.toLocal8Bit().constData();
|
const char* err = errStr.toLocal8Bit().constData();
|
||||||
|
|
||||||
QgsDebugMsg( QString( "child name=%1 provider=%2 path=%3" ).arg( layerItem->name() ).arg( lProvider ).arg( lFile ) );
|
QgsDebugMsg( QString( "testing child name=%1 provider=%2 path=%3" ).arg( layerItem->name() ).arg( lProvider ).arg( lFile ) );
|
||||||
|
|
||||||
if ( lFile == "landsat.tif" )
|
if ( lFile == "landsat.tif" )
|
||||||
{
|
{
|
||||||
@ -134,6 +135,29 @@ void TestQgsDataItem::testDirItemChildren()
|
|||||||
{
|
{
|
||||||
QVERIFY2( lProvider == "ogr", err );
|
QVERIFY2( lProvider == "ogr", err );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test layerName() does not include extension for gdal and ogr items (bug #5621)
|
||||||
|
QString lName = layerItem->layerName();
|
||||||
|
errStr = QString( "layer #%1 - %2 lName = %3 iSetting = %4" ).arg( i ).arg( lFile ).arg( lName ).arg( iSetting );
|
||||||
|
err = errStr.toLocal8Bit().constData();
|
||||||
|
|
||||||
|
if ( lFile == "landsat.tif" )
|
||||||
|
{
|
||||||
|
QVERIFY2( lName == "landsat", err );
|
||||||
|
}
|
||||||
|
else if ( lFile == "points.shp" )
|
||||||
|
{
|
||||||
|
QVERIFY2( lName == "points", err );
|
||||||
|
}
|
||||||
|
else if ( lFile == "landsat_b1.tif.gz" )
|
||||||
|
{
|
||||||
|
QVERIFY2( lName == "landsat_b1", err );
|
||||||
|
}
|
||||||
|
else if ( lFile == "points3.geojson.gz" )
|
||||||
|
{
|
||||||
|
QVERIFY2( lName == "points3", err );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ( dirItem )
|
if ( dirItem )
|
||||||
delete dirItem;
|
delete dirItem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user