Skip to content
Permalink
Browse files

[FEATURE] Add browser dock widget to QGIS main window. Layers can be …

…added to canvas by double-clicking them in the browser.
  • Loading branch information
wonder-sk committed Jul 11, 2011
1 parent ddc5b67 commit f57bef47c68f723a15568bdc024fbdab86148342
@@ -13,6 +13,7 @@ SET(QGIS_APP_SRCS
qgsattributetypeloaddialog.cpp
qgsbookmarkitem.cpp
qgsbookmarks.cpp
qgsbrowserdockwidget.cpp
qgsclipboard.cpp
qgscontinuouscolordialog.cpp
qgsconfigureshortcutsdialog.cpp
@@ -146,6 +147,7 @@ SET (QGIS_APP_MOC_HDRS
qgsattributetypedialog.h
qgsattributetypeloaddialog.h
qgsbookmarks.h
qgsbrowserdockwidget.h
qgsconfigureshortcutsdialog.h
qgscontinuouscolordialog.h
qgscustomization.h
@@ -103,6 +103,7 @@
#include "qgsattributetabledialog.h"
#include "qgsbookmarkitem.h"
#include "qgsbookmarks.h"
#include "qgsbrowserdockwidget.h"
#include "qgsclipboard.h"
#include "qgscomposer.h"
#include "qgscomposermanager.h"
@@ -446,6 +447,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mSnappingDialog = new QgsSnappingDialog( this, mMapCanvas );
mSnappingDialog->setObjectName( "SnappingOption" );

mBrowserWidget = new QgsBrowserDockWidget( this );
mBrowserWidget->setObjectName( "Browser" );
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
mBrowserWidget->hide();

mInternalClipboard = new QgsClipboard; // create clipboard
mQgisInterface = new QgisAppInterface( this ); // create the interfce

@@ -65,6 +65,7 @@ class QNetworkReply;
class QNetworkProxy;
class QAuthenticator;

class QgsBrowserDockWidget;
class QgsSnappingDialog;
class QgsGPSInformationWidget;

@@ -1049,6 +1050,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

QgsUndoWidget* mUndoWidget;

QgsBrowserDockWidget* mBrowserWidget;

QgsSnappingDialog* mSnappingDialog;

//! Persistent tile scale slider
@@ -0,0 +1,100 @@
#include "qgsbrowserdockwidget.h"

#include <QTreeView>

#include "qgsbrowsermodel.h"
#include "qgsdataitem.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"

QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
QDockWidget( parent ), mModel( NULL )
{
setWindowTitle( tr( "Browser" ) );

mBrowserView = new QTreeView( this );
setWidget( mBrowserView );

//connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
}

void QgsBrowserDockWidget::showEvent( QShowEvent * e )
{
// delayed initialization of the model
if ( mModel == NULL )
{
mModel = new QgsBrowserModel( mBrowserView );
mBrowserView->setModel( mModel );
}

QDockWidget::showEvent( e );
}


void QgsBrowserDockWidget::itemClicked( const QModelIndex& index )
{
QgsDataItem *item = mModel->dataItem( index );
if ( !item )
return;

QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( mModel->dataItem( index ) );
if ( layerItem == NULL )
return;

QString uri = layerItem->uri();
if ( uri.isEmpty() )
return;

QgsMapLayer::LayerType type = layerItem->mapLayerType();
QString providerKey = layerItem->providerKey();

QgsDebugMsg( providerKey + " : " + uri );
QgsMapLayer* layer = NULL;
if ( type == QgsMapLayer::VectorLayer )
{
layer = new QgsVectorLayer( uri, layerItem->name(), providerKey );
}
if ( type == QgsMapLayer::RasterLayer )
{
// 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( " " ) );

layer = new QgsRasterLayer( 0, rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
}

if ( !layer || !layer->isValid() )
{
qDebug( "No layer" );
delete layer;
return;
}

// add layer to the application
QgsMapLayerRegistry::instance()->addMapLayer( layer );
}
@@ -0,0 +1,29 @@
#ifndef QGSBROWSERDOCKWIDGET_H
#define QGSBROWSERDOCKWIDGET_H

#include <QDockWidget>

class QgsBrowserModel;
class QModelIndex;
class QTreeView;

class QgsBrowserDockWidget : public QDockWidget
{
Q_OBJECT
public:
explicit QgsBrowserDockWidget( QWidget *parent = 0 );

signals:

public slots:
void itemClicked( const QModelIndex& index );

protected:

void showEvent( QShowEvent * event );

QTreeView* mBrowserView;
QgsBrowserModel* mModel;
};

#endif // QGSBROWSERDOCKWIDGET_H
@@ -5,14 +5,12 @@
SET (BROWSER_SRCS
main.cpp
qgsbrowser.cpp
qgsbrowsermodel.cpp
)

SET (BROWSER_UIS qgsbrowserbase.ui)

SET (BROWSER_MOC_HDRS
qgsbrowser.h
qgsbrowsermodel.h
)

#SET (BROWSER_RCCS qgsgps_plugin.qrc)
@@ -42,6 +42,7 @@ SET(QGIS_CORE_SRCS
qgis.cpp
qgsapplication.cpp
qgsattributeaction.cpp
qgsbrowsermodel.cpp
qgscentralpointpositionmanager.cpp
qgsclipper.cpp
qgscontexthelp.cpp
@@ -220,6 +221,7 @@ ADD_BISON_FILES(QGIS_CORE_SRCS qgssearchstringparser.yy)

SET(QGIS_CORE_MOC_HDRS
qgsapplication.h
qgsbrowsermodel.h
qgscontexthelp.h
qgscoordinatetransform.h
qgsdataitem.h
File renamed without changes.
@@ -7,7 +7,7 @@

#include "qgsdataitem.h"

class QgsBrowserModel : public QAbstractItemModel
class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
{
Q_OBJECT

@@ -50,7 +50,7 @@ class QgsBrowserModel : public QAbstractItemModel

virtual QStringList mimeTypes() const;

QMimeData * mimeData(const QModelIndexList &indexes) const;
QMimeData * mimeData( const QModelIndexList &indexes ) const;

QgsDataItem *dataItem( const QModelIndex &idx ) const;

0 comments on commit f57bef4

Please sign in to comment.
You can’t perform that action at this time.