1 change: 1 addition & 0 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
}

chkMergeLines->setEnabled( layer->geometryType() == QGis::Line );
chkAddDirectionSymbol->setEnabled( layer->geometryType() == QGis::Line );
label_19->setEnabled( layer->geometryType() != QGis::Point );
mMinSizeSpinBox->setEnabled( layer->geometryType() != QGis::Point );

Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
{
return item->name();
}
else if ( role == Qt::ToolTipRole )
{
return item->toolTip();
}
else if ( role == Qt::DecorationRole && index.column() == 0 )
{
return item->icon();
Expand Down
22 changes: 22 additions & 0 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ const QIcon &QgsLayerItem::iconTable()
return icon;
}

const QIcon &QgsLayerItem::iconRaster()
{
static QIcon icon;

if ( icon.isNull() )
icon = QIcon( getThemePixmap( "/mIconRaster.png" ) );

return icon;
}

const QIcon &QgsLayerItem::iconDefault()
{
static QIcon icon;
Expand All @@ -86,6 +96,16 @@ const QIcon &QgsLayerItem::iconDefault()
return icon;
}

const QIcon &QgsDataCollectionItem::iconDataCollection()
{
static QIcon icon;

if ( icon.isNull() )
icon = QIcon( getThemePixmap( "/mIconDbSchema.png" ) );

return icon;
}

const QIcon &QgsDataCollectionItem::iconDir()
{
static QIcon icon;
Expand Down Expand Up @@ -277,6 +297,7 @@ QgsLayerItem::QgsLayerItem( QgsDataItem* parent, QString name, QString path, QSt
case Line: mIcon = iconLine(); break;
case Polygon: mIcon = iconPolygon(); break;
case TableLayer: mIcon = iconTable(); break;
case Raster: mIcon = iconRaster(); break;
default: mIcon = iconDefault(); break;
}
}
Expand Down Expand Up @@ -304,6 +325,7 @@ bool QgsLayerItem::equal( const QgsDataItem *other )
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path )
: QgsDataItem( Collection, parent, name, path )
{
mIcon = iconDataCollection();
}

QgsDataCollectionItem::~QgsDataCollectionItem()
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsdataitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class CORE_EXPORT QgsDataItem : public QObject

void setIcon( QIcon icon ) { mIcon = icon; }

void setToolTip( QString msg ) { mToolTip = msg; }
QString toolTip() const { return mToolTip; }

protected:

Type mType;
Expand All @@ -120,6 +123,7 @@ class CORE_EXPORT QgsDataItem : public QObject
bool mPopulated;
QString mName;
QString mPath; // it is also used to identify item in tree
QString mToolTip;
QIcon mIcon;

public slots:
Expand Down Expand Up @@ -180,6 +184,7 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
static const QIcon &iconLine();
static const QIcon &iconPolygon();
static const QIcon &iconTable();
static const QIcon &iconRaster();
static const QIcon &iconDefault();
};

Expand All @@ -196,6 +201,7 @@ class CORE_EXPORT QgsDataCollectionItem : public QgsDataItem
void addChild( QgsDataItem *item ) { mChildren.append( item ); }

static const QIcon &iconDir(); // shared icon: open/closed directory
static const QIcon &iconDataCollection(); // default icon for data collection
};

/** A directory: contains subdirectories and layers */
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SET(GDAL_SRCS qgsgdalprovider.cpp)
SET(GDAL_SRCS qgsgdalprovider.cpp qgsgdaldataitems.cpp)
SET(GDAL_MOC_HDRS qgsgdalprovider.h)

INCLUDE_DIRECTORIES (
Expand Down
116 changes: 116 additions & 0 deletions src/providers/gdal/qgsgdaldataitems.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "qgsgdaldataitems.h"
#include "qgsgdalprovider.h"
#include "qgslogger.h"

#include <QFileInfo>

// defined in qgsgdalprovider.cpp
void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString, QStringList & theExtensions, QStringList & theWildcards );


QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem* parent,
QString name, QString path, QString uri )
: QgsLayerItem( parent, name, path, uri, QgsLayerItem::Raster, "gdal" )
{
mToolTip = uri;
mPopulated = true; // children are not expected
}

QgsGdalLayerItem::~QgsGdalLayerItem()
{
}

QgsLayerItem::Capability QgsGdalLayerItem::capabilities()
{
// Check if data sour can be opened for update
QgsDebugMsg( "mPath = " + mPath );
GDALAllRegister();
GDALDatasetH hDS = GDALOpen( TO8F( mPath ), GA_Update );

if ( !hDS )
return NoCapabilities;

return SetCrs;
}

bool QgsGdalLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
{
QgsDebugMsg( "mPath = " + mPath );
GDALAllRegister();
GDALDatasetH hDS = GDALOpen( TO8F( mPath ), GA_Update );

if ( !hDS )
return false;

QString wkt = crs.toWkt();
if ( GDALSetProjection( hDS, wkt.toLocal8Bit().data() ) != CE_None )
{
QgsDebugMsg( "Could not set CRS" );
return false;
}
GDALClose( hDS );
return true;
}


// ---------------------------------------------------------------------------

static QStringList extensions = QStringList();
static QStringList wildcards = QStringList();

QGISEXTERN int dataCapabilities()
{
return QgsDataProvider::File | QgsDataProvider::Dir;
}

QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
{
if ( thePath.isEmpty() )
return 0;

QFileInfo info( thePath );
if ( info.isFile() )
{
// Filter files by extension
if ( extensions.isEmpty() )
{
QString filterString;
buildSupportedRasterFileFilterAndExtensions( filterString, extensions, wildcards );
QgsDebugMsg( "extensions: " + extensions.join( " " ) );
QgsDebugMsg( "wildcards: " + wildcards.join( " " ) );
}
if ( extensions.indexOf( info.suffix().toLower() ) < 0 )
{
bool matches = false;
foreach( QString wildcard, wildcards )
{
QRegExp rx( wildcard, Qt::CaseInsensitive, QRegExp::Wildcard );
if ( rx.exactMatch( info.fileName() ) )
{
matches = true;
break;
}
}
if ( !matches )
return 0;
}

GDALAllRegister();
GDALDatasetH hDS = GDALOpen( TO8F( thePath ), GA_ReadOnly );

if ( !hDS )
return 0;

GDALClose( hDS );

QgsDebugMsg( "GdalDataset opened " + thePath );

QString name = info.completeBaseName();
QString uri = thePath;

QgsLayerItem * item = new QgsGdalLayerItem( parentItem, name, thePath, uri );
return item;
}
return 0;
}

18 changes: 18 additions & 0 deletions src/providers/gdal/qgsgdaldataitems.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef QGSGDALDATAITEMS_H
#define QGSGDALDATAITEMS_H

#include "qgsdataitem.h"

class QgsGdalLayerItem : public QgsLayerItem
{
public:
QgsGdalLayerItem( QgsDataItem* parent,
QString name, QString path, QString uri );
~QgsGdalLayerItem();

bool setCrs( QgsCoordinateReferenceSystem crs );
Capability capabilities();
};


#endif // QGSGDALDATAITEMS_H
109 changes: 0 additions & 109 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
#include "cpl_conv.h"
#include "cpl_string.h"

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif


static QString PROVIDER_KEY = "gdal";
static QString PROVIDER_DESCRIPTION = "GDAL provider";
Expand Down Expand Up @@ -1929,106 +1923,3 @@ QGISEXTERN void buildSupportedRasterFileFilter( QString & theFileFiltersString )
QStringList wildcards;
buildSupportedRasterFileFilterAndExtensions( theFileFiltersString, exts, wildcards );
}

QGISEXTERN int dataCapabilities()
{
return QgsDataProvider::File | QgsDataProvider::Dir;
}


QgsGdalLayerItem::QgsGdalLayerItem( QgsDataItem* parent,
QString name, QString path, QString uri )
: QgsLayerItem( parent, name, path, uri, QgsLayerItem::Raster, "gdal" )
{
}

QgsGdalLayerItem::~QgsGdalLayerItem()
{
}

QgsLayerItem::Capability QgsGdalLayerItem::capabilities()
{
// Check if data sour can be opened for update
QgsDebugMsg( "mPath = " + mPath );
GDALAllRegister();
GDALDatasetH hDS = GDALOpen( TO8F( mPath ), GA_Update );

if ( !hDS )
return NoCapabilities;

return SetCrs;
}

bool QgsGdalLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
{
QgsDebugMsg( "mPath = " + mPath );
GDALAllRegister();
GDALDatasetH hDS = GDALOpen( TO8F( mPath ), GA_Update );

if ( !hDS )
return false;

QString wkt = crs.toWkt();
if ( GDALSetProjection( hDS, wkt.toLocal8Bit().data() ) != CE_None )
{
QgsDebugMsg( "Could not set CRS" );
return false;
}
GDALClose( hDS );
return true;
}

static QStringList extensions = QStringList();
static QStringList wildcards = QStringList();

QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
{
if ( thePath.isEmpty() )
return 0;

QFileInfo info( thePath );
if ( info.isFile() )
{
// Filter files by extension
if ( extensions.isEmpty() )
{
QString filterString;
buildSupportedRasterFileFilterAndExtensions( filterString, extensions, wildcards );
QgsDebugMsg( "extensions: " + extensions.join( " " ) );
QgsDebugMsg( "wildcards: " + wildcards.join( " " ) );
}
if ( extensions.indexOf( info.suffix().toLower() ) < 0 )
{
bool matches = false;
foreach( QString wildcard, wildcards )
{
QRegExp rx( wildcard, Qt::CaseInsensitive, QRegExp::Wildcard );
if ( rx.exactMatch( info.fileName() ) )
{
matches = true;
break;
}
}
if ( !matches )
return 0;
}

GDALAllRegister();
GDALDatasetH hDS = GDALOpen( TO8F( thePath ), GA_ReadOnly );

if ( !hDS )
return 0;

GDALClose( hDS );

QgsDebugMsg( "GdalDataset opened " + thePath );

QString name = info.fileName();
QString uri = thePath;

QgsLayerItem * item = new QgsGdalLayerItem( parentItem, name, thePath, uri );
return item;
}
return 0;
}

18 changes: 7 additions & 11 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class QgsRasterPyramid;
#define CPL_SUPRESS_CPLUSPLUS
#include <gdal.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif


/** \ingroup core
* A call back function for showing progress of gdal operations.
*/
Expand Down Expand Up @@ -296,16 +303,5 @@ class QgsGdalProvider : public QgsRasterDataProvider

};

class QgsGdalLayerItem : public QgsLayerItem
{
public:
QgsGdalLayerItem( QgsDataItem* parent,
QString name, QString path, QString uri );
~QgsGdalLayerItem();

bool setCrs( QgsCoordinateReferenceSystem crs );
Capability capabilities();
};

#endif

Loading