Skip to content

Commit e5d97f5

Browse files
committed
Revert d7e8ae1 and d637c67 (fixes #5407, #5409 and #5410)
1 parent aa44bfe commit e5d97f5

26 files changed

+478
-417
lines changed

python/core/qgsrasterlayer.sip

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ public:
3535
bool loadDefaultStyleFlag = true );
3636

3737
/** \brief [ data provider interface ] Constructor in provider mode */
38-
QgsRasterLayer( const QString & uri,
39-
const QString & baseName,
40-
const QString & providerKey,
41-
bool loadDefaultStyleFlag = true );
38+
QgsRasterLayer( int dummy,
39+
const QString & baseName = QString(),
40+
const QString & path = QString(),
41+
const QString & providerLib = QString(),
42+
const QStringList & layers = QStringList(),
43+
const QStringList & styles = QStringList(),
44+
const QString & format = QString(),
45+
const QString & crs = QString());
46+
4247

4348
/** \brief The destructor */
4449
~QgsRasterLayer();
@@ -190,7 +195,11 @@ public:
190195
QString redBandName();
191196

192197
/** [ data provider interface ] Set the data provider */
193-
void setDataProvider( const QString & provider );
198+
void setDataProvider( const QString & provider,
199+
const QStringList & layers,
200+
const QStringList & styles,
201+
const QString & format,
202+
const QString & crs );
194203

195204
/** \brief Mutator for drawing style */
196205
void setDrawingStyle( const DrawingStyle & theDrawingStyle );

python/gui/qgisinterface.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class QgisInterface : QObject
4646
//! Add a raster layer given a raster layer file name
4747
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
4848
//! Add a WMS layer
49-
virtual QgsRasterLayer* addRasterLayer(const QString& uri, const QString& baseName, const QString& providerKey) = 0;
49+
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;
5050

5151
//! Add a project
5252
virtual bool addProject(QString theProject)=0;

src/app/qgisapp.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ void QgisApp::dropEvent( QDropEvent *event )
746746
}
747747
else if ( u.layerType == "raster" )
748748
{
749-
addRasterLayer( u.uri, u.name, u.providerKey );
749+
addRasterLayer( u.uri, u.name, u.providerKey, QStringList(), QStringList(), QString(), QString() );
750750
}
751751
}
752752
}
@@ -2631,8 +2631,10 @@ void QgisApp::addWmsLayer()
26312631
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
26322632
return;
26332633
}
2634-
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
2635-
this , SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
2634+
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
2635+
QString const & ) ),
2636+
this , SLOT( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
2637+
QString const & ) ) );
26362638
wmss->exec();
26372639
delete wmss;
26382640
}
@@ -6803,17 +6805,22 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con
68036805

68046806
/** Add a raster layer directly without prompting user for location
68056807
The caller must provide information compatible with the provider plugin
6806-
using the uri and baseName. The provider can use these
6808+
using the rasterLayerPath and baseName. The provider can use these
68076809
parameters in any way necessary to initialize the layer. The baseName
68086810
parameter is used in the Map Legend so it should be formed in a meaningful
68096811
way.
68106812
68116813
\note Copied from the equivalent addVectorLayer function in this file
6814+
TODO Make it work for rasters specifically.
68126815
*/
68136816
QgsRasterLayer* QgisApp::addRasterLayer(
6814-
QString const &uri,
6817+
QString const &rasterLayerPath,
68156818
QString const &baseName,
6816-
QString const &providerKey )
6819+
QString const &providerKey,
6820+
QStringList const & layers,
6821+
QStringList const & styles,
6822+
QString const &format,
6823+
QString const &crs )
68176824
{
68186825
QgsDebugMsg( "about to get library for " + providerKey );
68196826

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

68256832
mMapCanvas->freeze();
68266833

6834+
// Let render() do its own cursor management
6835+
// QApplication::setOverrideCursor(Qt::WaitCursor);
6836+
68276837
// create the layer
68286838
QgsRasterLayer *layer;
6829-
QgsDebugMsg( "Creating new raster layer using " + uri
6830-
+ " with baseName of " + baseName );
6839+
/* Eliminate the need to instantiate the layer based on provider type.
6840+
The caller is responsible for cobbling together the needed information to
6841+
open the layer
6842+
*/
6843+
QgsDebugMsg( "Creating new raster layer using " + rasterLayerPath
6844+
+ " with baseName of " + baseName
6845+
+ " and layer list of " + layers.join( ", " )
6846+
+ " and style list of " + styles.join( ", " )
6847+
+ " and format of " + format
6848+
+ " and providerKey of " + providerKey
6849+
+ " and CRS of " + crs );
68316850

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

68356854
QgsDebugMsg( "Constructed new layer." );
68366855

6837-
if ( layer && layer->isValid() )
6856+
if ( layer && shouldAskUserForGDALSublayers( layer ) )
6857+
{
6858+
askUserForGDALSublayers( layer );
6859+
6860+
// The first layer loaded is not useful in that case. The user can select it in
6861+
// the list if he wants to load it.
6862+
delete layer;
6863+
}
6864+
else if ( layer && layer->isValid() )
68386865
{
68396866
addRasterLayer( layer );
68406867

68416868
statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
6869+
68426870
}
68436871
else
68446872
{
@@ -6853,6 +6881,10 @@ QgsRasterLayer* QgisApp::addRasterLayer(
68536881
mMapCanvas->refresh();
68546882

68556883
return layer;
6884+
6885+
// Let render() do its own cursor management
6886+
// QApplication::restoreOverrideCursor();
6887+
68566888
} // QgisApp::addRasterLayer
68576889

68586890

src/app/qgisapp.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,16 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
469469
virtual bool event( QEvent * event );
470470

471471
/** Open a raster layer using the Raster Data Provider.
472-
* \note added in 1.9
472+
* Note this is included to support WMS layers only at this stage,
473+
* GDAL layer support via a Provider is not yet implemented.
473474
*/
474-
QgsRasterLayer* addRasterLayer( QString const & uri, QString const & baseName, QString const & providerKey );
475+
QgsRasterLayer* addRasterLayer( QString const & rasterLayerPath,
476+
QString const & baseName,
477+
QString const & providerKey,
478+
QStringList const & layers,
479+
QStringList const & styles,
480+
QString const & format,
481+
QString const & crs );
475482

476483
void addWfsLayer( QString uri, QString typeName );
477484

@@ -1194,8 +1201,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
11941201
QString mOldScale;
11951202

11961203
#ifdef HAVE_TOUCH
1197-
bool gestureEvent( QGestureEvent *event );
1198-
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
1204+
bool gestureEvent(QGestureEvent *event);
1205+
void tapAndHoldTriggered(QTapAndHoldGesture *gesture);
11991206
#endif
12001207
};
12011208

src/app/qgisappinterface.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ QgsRasterLayer* QgisAppInterface::addRasterLayer( QString rasterLayerPath, QStri
107107
return qgis->addRasterLayer( rasterLayerPath, baseName );
108108
}
109109

110-
QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey )
110+
QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey,
111+
const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs )
111112
{
112-
return qgis->addRasterLayer( url, baseName, providerKey );
113+
return qgis->addRasterLayer( url, baseName, providerKey, layers, styles, format, crs );
113114
}
114115

115116
bool QgisAppInterface::addProject( QString theProjectName )

src/app/qgisappinterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class QgisAppInterface : public QgisInterface
6464
//! Add a raster layer given its file name
6565
QgsRasterLayer* addRasterLayer( QString rasterLayerPath, QString baseName );
6666
//! Add a WMS layer
67-
QgsRasterLayer* addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey );
67+
QgsRasterLayer* addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey,
68+
const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs );
6869

6970
//! Add a project
7071
bool addProject( QString theProjectName );

src/app/qgsbrowserdockwidget.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,33 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
293293
}
294294
if ( type == QgsMapLayer::RasterLayer )
295295
{
296-
QgisApp::instance()->addRasterLayer( uri, layerItem->name(), providerKey );
296+
// This should go to WMS provider
297+
QStringList URIParts = uri.split( "|" );
298+
QString rasterLayerPath = URIParts.at( 0 );
299+
QStringList layers;
300+
QStringList styles;
301+
QString format;
302+
QString crs;
303+
for ( int i = 1 ; i < URIParts.size(); i++ )
304+
{
305+
QString part = URIParts.at( i );
306+
int pos = part.indexOf( "=" );
307+
QString field = part.left( pos );
308+
QString value = part.mid( pos + 1 );
309+
310+
if ( field == "layers" )
311+
layers = value.split( "," );
312+
if ( field == "styles" )
313+
styles = value.split( "," );
314+
if ( field == "format" )
315+
format = value;
316+
if ( field == "crs" )
317+
crs = value;
318+
}
319+
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
320+
QgsDebugMsg( "layers = " + layers.join( " " ) );
321+
322+
QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
297323
}
298324
}
299325

@@ -373,7 +399,7 @@ void QgsBrowserDockWidget::showProperties( )
373399
{
374400
QgsDebugMsg( "creating raster layer" );
375401
// should copy code from addLayer() to split uri ?
376-
QgsRasterLayer* layer = new QgsRasterLayer( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
402+
QgsRasterLayer* layer = new QgsRasterLayer( 0, layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
377403
if ( layer != NULL )
378404
{
379405
layerCrs = layer->crs();

src/browser/qgsbrowser.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,33 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )
207207
}
208208
if ( type == QgsMapLayer::RasterLayer )
209209
{
210-
mLayer = new QgsRasterLayer( uri, "", providerKey );
210+
// This should go to WMS provider
211+
QStringList URIParts = uri.split( "|" );
212+
QString rasterLayerPath = URIParts.at( 0 );
213+
QStringList layers;
214+
QStringList styles;
215+
QString format;
216+
QString crs;
217+
for ( int i = 1 ; i < URIParts.size(); i++ )
218+
{
219+
QString part = URIParts.at( i );
220+
int pos = part.indexOf( "=" );
221+
QString field = part.left( pos );
222+
QString value = part.mid( pos + 1 );
223+
224+
if ( field == "layers" )
225+
layers = value.split( "," );
226+
if ( field == "styles" )
227+
styles = value.split( "," );
228+
if ( field == "format" )
229+
format = value;
230+
if ( field == "crs" )
231+
crs = value;
232+
}
233+
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
234+
QgsDebugMsg( "layers = " + layers.join( " " ) );
235+
236+
mLayer = new QgsRasterLayer( 0, rasterLayerPath, "", providerKey, layers, styles, format, crs );
211237
}
212238
}
213239

src/core/qgsbrowsermodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
113113
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
114114
if ( ptr->type() == QgsDataItem::Layer )
115115
{
116-
flags |= Qt::ItemIsDragEnabled;
116+
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
117+
if ( layer->providerKey() != "wms" )
118+
{
119+
flags |= Qt::ItemIsDragEnabled;
120+
}
117121
}
118122
if ( ptr->acceptDrop() )
119123
flags |= Qt::ItemIsDropEnabled;
@@ -350,6 +354,7 @@ QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
350354
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
351355
if ( ptr->type() != QgsDataItem::Layer ) continue;
352356
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
357+
if ( layer->providerKey() == "wms" ) continue;
353358
lst.append( QgsMimeDataUtils::Uri( layer ) );
354359
}
355360
}

0 commit comments

Comments
 (0)