Skip to content

Commit

Permalink
Revert d7e8ae1 and d637c67 (fixes #5407, #5409 and #5410)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Apr 18, 2012
1 parent aa44bfe commit e5d97f5
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 417 deletions.
19 changes: 14 additions & 5 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -35,10 +35,15 @@ public:
bool loadDefaultStyleFlag = true );

/** \brief [ data provider interface ] Constructor in provider mode */
QgsRasterLayer( const QString & uri,
const QString & baseName,
const QString & providerKey,
bool loadDefaultStyleFlag = true );
QgsRasterLayer( int dummy,
const QString & baseName = QString(),
const QString & path = QString(),
const QString & providerLib = QString(),
const QStringList & layers = QStringList(),
const QStringList & styles = QStringList(),
const QString & format = QString(),
const QString & crs = QString());


/** \brief The destructor */
~QgsRasterLayer();
Expand Down Expand Up @@ -190,7 +195,11 @@ public:
QString redBandName();

/** [ data provider interface ] Set the data provider */
void setDataProvider( const QString & provider );
void setDataProvider( const QString & provider,
const QStringList & layers,
const QStringList & styles,
const QString & format,
const QString & crs );

/** \brief Mutator for drawing style */
void setDrawingStyle( const DrawingStyle & theDrawingStyle );
Expand Down
2 changes: 1 addition & 1 deletion python/gui/qgisinterface.sip
Expand Up @@ -46,7 +46,7 @@ class QgisInterface : QObject
//! Add a raster layer given a raster layer file name
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
//! Add a WMS layer
virtual QgsRasterLayer* addRasterLayer(const QString& uri, const QString& baseName, const QString& providerKey) = 0;
virtual QgsRasterLayer* addRasterLayer(const QString& url, const QString& layerName, const QString& providerKey, const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs) = 0;

//! Add a project
virtual bool addProject(QString theProject)=0;
Expand Down
52 changes: 42 additions & 10 deletions src/app/qgisapp.cpp
Expand Up @@ -746,7 +746,7 @@ void QgisApp::dropEvent( QDropEvent *event )
}
else if ( u.layerType == "raster" )
{
addRasterLayer( u.uri, u.name, u.providerKey );
addRasterLayer( u.uri, u.name, u.providerKey, QStringList(), QStringList(), QString(), QString() );
}
}
}
Expand Down Expand Up @@ -2631,8 +2631,10 @@ void QgisApp::addWmsLayer()
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
return;
}
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this , SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
QString const & ) ),
this , SLOT( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
QString const & ) ) );
wmss->exec();
delete wmss;
}
Expand Down Expand Up @@ -6803,17 +6805,22 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con

/** Add a raster layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
using the uri and baseName. The provider can use these
using the rasterLayerPath and baseName. The provider can use these
parameters in any way necessary to initialize the layer. The baseName
parameter is used in the Map Legend so it should be formed in a meaningful
way.
\note Copied from the equivalent addVectorLayer function in this file
TODO Make it work for rasters specifically.
*/
QgsRasterLayer* QgisApp::addRasterLayer(
QString const &uri,
QString const &rasterLayerPath,
QString const &baseName,
QString const &providerKey )
QString const &providerKey,
QStringList const & layers,
QStringList const & styles,
QString const &format,
QString const &crs )
{
QgsDebugMsg( "about to get library for " + providerKey );

Expand All @@ -6824,21 +6831,42 @@ QgsRasterLayer* QgisApp::addRasterLayer(

mMapCanvas->freeze();

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

// create the layer
QgsRasterLayer *layer;
QgsDebugMsg( "Creating new raster layer using " + uri
+ " with baseName of " + baseName );
/* Eliminate the need to instantiate the layer based on provider type.
The caller is responsible for cobbling together the needed information to
open the layer
*/
QgsDebugMsg( "Creating new raster layer using " + rasterLayerPath
+ " with baseName of " + baseName
+ " and layer list of " + layers.join( ", " )
+ " and style list of " + styles.join( ", " )
+ " and format of " + format
+ " and providerKey of " + providerKey
+ " and CRS of " + crs );

// TODO: Remove the 0 when the raster layer becomes a full provider gateway.
layer = new QgsRasterLayer( uri, baseName, providerKey );
layer = new QgsRasterLayer( 0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs );

QgsDebugMsg( "Constructed new layer." );

if ( layer && layer->isValid() )
if ( layer && shouldAskUserForGDALSublayers( layer ) )
{
askUserForGDALSublayers( layer );

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
delete layer;
}
else if ( layer && layer->isValid() )
{
addRasterLayer( layer );

statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );

}
else
{
Expand All @@ -6853,6 +6881,10 @@ QgsRasterLayer* QgisApp::addRasterLayer(
mMapCanvas->refresh();

return layer;

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addRasterLayer


Expand Down
15 changes: 11 additions & 4 deletions src/app/qgisapp.h
Expand Up @@ -469,9 +469,16 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
virtual bool event( QEvent * event );

/** Open a raster layer using the Raster Data Provider.
* \note added in 1.9
* Note this is included to support WMS layers only at this stage,
* GDAL layer support via a Provider is not yet implemented.
*/
QgsRasterLayer* addRasterLayer( QString const & uri, QString const & baseName, QString const & providerKey );
QgsRasterLayer* addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs );

void addWfsLayer( QString uri, QString typeName );

Expand Down Expand Up @@ -1194,8 +1201,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QString mOldScale;

#ifdef HAVE_TOUCH
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
bool gestureEvent(QGestureEvent *event);
void tapAndHoldTriggered(QTapAndHoldGesture *gesture);
#endif
};

Expand Down
5 changes: 3 additions & 2 deletions src/app/qgisappinterface.cpp
Expand Up @@ -107,9 +107,10 @@ QgsRasterLayer* QgisAppInterface::addRasterLayer( QString rasterLayerPath, QStri
return qgis->addRasterLayer( rasterLayerPath, baseName );
}

QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey )
QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey,
const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs )
{
return qgis->addRasterLayer( url, baseName, providerKey );
return qgis->addRasterLayer( url, baseName, providerKey, layers, styles, format, crs );
}

bool QgisAppInterface::addProject( QString theProjectName )
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisappinterface.h
Expand Up @@ -64,7 +64,8 @@ class QgisAppInterface : public QgisInterface
//! Add a raster layer given its file name
QgsRasterLayer* addRasterLayer( QString rasterLayerPath, QString baseName );
//! Add a WMS layer
QgsRasterLayer* addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey );
QgsRasterLayer* addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey,
const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs );

//! Add a project
bool addProject( QString theProjectName );
Expand Down
30 changes: 28 additions & 2 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -293,7 +293,33 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
}
if ( type == QgsMapLayer::RasterLayer )
{
QgisApp::instance()->addRasterLayer( uri, layerItem->name(), providerKey );
// This should go to WMS provider
QStringList URIParts = uri.split( "|" );
QString rasterLayerPath = URIParts.at( 0 );
QStringList layers;
QStringList styles;
QString format;
QString crs;
for ( int i = 1 ; i < URIParts.size(); i++ )
{
QString part = URIParts.at( i );
int pos = part.indexOf( "=" );
QString field = part.left( pos );
QString value = part.mid( pos + 1 );

if ( field == "layers" )
layers = value.split( "," );
if ( field == "styles" )
styles = value.split( "," );
if ( field == "format" )
format = value;
if ( field == "crs" )
crs = value;
}
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
QgsDebugMsg( "layers = " + layers.join( " " ) );

QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
}
}

Expand Down Expand Up @@ -373,7 +399,7 @@ void QgsBrowserDockWidget::showProperties( )
{
QgsDebugMsg( "creating raster layer" );
// should copy code from addLayer() to split uri ?
QgsRasterLayer* layer = new QgsRasterLayer( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
QgsRasterLayer* layer = new QgsRasterLayer( 0, layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
if ( layer != NULL )
{
layerCrs = layer->crs();
Expand Down
28 changes: 27 additions & 1 deletion src/browser/qgsbrowser.cpp
Expand Up @@ -207,7 +207,33 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )
}
if ( type == QgsMapLayer::RasterLayer )
{
mLayer = new QgsRasterLayer( uri, "", providerKey );
// This should go to WMS provider
QStringList URIParts = uri.split( "|" );
QString rasterLayerPath = URIParts.at( 0 );
QStringList layers;
QStringList styles;
QString format;
QString crs;
for ( int i = 1 ; i < URIParts.size(); i++ )
{
QString part = URIParts.at( i );
int pos = part.indexOf( "=" );
QString field = part.left( pos );
QString value = part.mid( pos + 1 );

if ( field == "layers" )
layers = value.split( "," );
if ( field == "styles" )
styles = value.split( "," );
if ( field == "format" )
format = value;
if ( field == "crs" )
crs = value;
}
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
QgsDebugMsg( "layers = " + layers.join( " " ) );

mLayer = new QgsRasterLayer( 0, rasterLayerPath, "", providerKey, layers, styles, format, crs );
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsbrowsermodel.cpp
Expand Up @@ -113,7 +113,11 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() == QgsDataItem::Layer )
{
flags |= Qt::ItemIsDragEnabled;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
if ( layer->providerKey() != "wms" )
{
flags |= Qt::ItemIsDragEnabled;
}
}
if ( ptr->acceptDrop() )
flags |= Qt::ItemIsDropEnabled;
Expand Down Expand Up @@ -350,6 +354,7 @@ QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() != QgsDataItem::Layer ) continue;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
if ( layer->providerKey() == "wms" ) continue;
lst.append( QgsMimeDataUtils::Uri( layer ) );
}
}
Expand Down

0 comments on commit e5d97f5

Please sign in to comment.