10 changes: 9 additions & 1 deletion images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<file>themes/default/mActionNewFolder.png</file>
<file>themes/default/mActionNewVectorLayer.png</file>
<file>themes/default/mActionNodeTool.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOpenTable.png</file>
<file>themes/default/mActionOptions.png</file>
<file>themes/default/mActionPan.png</file>
Expand Down Expand Up @@ -156,32 +156,40 @@
<file>themes/default/mActionZoomOut.png</file>
<file>themes/default/mActionZoomToLayer.png</file>
<file>themes/default/mActionZoomToSelected.png</file>
<file>themes/default/mIconConnect.png</file>
<file>themes/default/mIconDbSchema.png</file>
<file>themes/default/mIconDelete.png</file>
<file>themes/default/mIconEditable.png</file>
<file>themes/default/mIconFavourites.png</file>
<file>themes/default/mIconFirst.png</file>
<file>themes/default/mIconGeometryLayer.png</file>
<file>themes/default/mIconLast.png</file>
<file>themes/default/mIconLayer.png</file>
<file>themes/default/mIconLineLayer.png</file>
<file>themes/default/mIconLock.png</file>
<file>themes/default/mIconNew.png</file>
<file>themes/default/mIconMssql.png</file>
<file>themes/default/mIconNext.png</file>
<file>themes/default/mIconNoPyramid.png</file>
<file>themes/default/mIconPointLayer.png</file>
<file>themes/default/mIconPolygonLayer.png</file>
<file>themes/default/mIconPostgis.png</file>
<file>themes/default/mIconPrevious.png</file>
<file>themes/default/mIconProjectionDisabled.png</file>
<file>themes/default/mIconProjectionEnabled.png</file>
<file>themes/default/mIconProjectionProblem.png</file>
<file>themes/default/mIconProperties.png</file>
<file>themes/default/mIconPyramid.png</file>
<file>themes/default/mIconSpatialite.png</file>
<file>themes/default/mIconStopRendering.png</file>
<file>themes/default/mIconRaster.png</file>
<file>themes/default/mIconRenderingEnabled.png</file>
<file>themes/default/mIconRenderingDisabled.png</file>
<file>themes/default/mIconSymbology.png</file>
<file>themes/default/mIconTableLayer.png</file>
<file>themes/default/mIconUnknownLayerType.png</file>
<file>themes/default/mIconWaitingForLayerType.png</file>
<file>themes/default/mIconWfs.png</file>
<file>themes/default/mIconWms.png</file>
<file>themes/default/mIconWmsLayer.png</file>
<file>themes/default/mIconWarn.png</file>
Expand Down
Binary file added images/themes/default/mIconConnect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconDbSchema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconFavourites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconMssql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconPostgis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconRaster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconSpatialite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconWfs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 123 additions & 16 deletions src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include "qgsvectorlayer.h"
#include "qgisapp.h"

// browser layer properties dialog
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include <ui_qgsbrowserlayerpropertiesbase.h>

#include <QDragEnterEvent>
/**
Utility class for correct drag&drop handling.
Expand Down Expand Up @@ -86,6 +91,12 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
addLayersButton->setAutoRaise( true );
connect( addLayersButton, SIGNAL( clicked() ), this, SLOT( addSelectedLayers() ) );

QToolButton* collapseButton = new QToolButton( this );
collapseButton->setIcon( QgisApp::instance()->getThemeIcon( "mActionCollapseTree.png" ) );
collapseButton->setToolTip( tr( "Collapse All" ) );
collapseButton->setAutoRaise( true );
connect( collapseButton, SIGNAL( clicked() ), mBrowserView, SLOT( collapseAll() ) );

QVBoxLayout* layout = new QVBoxLayout();
QHBoxLayout* hlayout = new QHBoxLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
Expand All @@ -94,8 +105,12 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
hlayout->setSpacing( 5 );
hlayout->setAlignment( Qt::AlignLeft );

hlayout->addSpacing( 5 );
hlayout->addWidget( refreshButton );
hlayout->addSpacing( 5 );
hlayout->addWidget( addLayersButton );
hlayout->addStretch( );
hlayout->addWidget( collapseButton );
layout->addLayout( hlayout );
layout->addWidget( mBrowserView );

Expand All @@ -104,8 +119,7 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
setWidget( innerWidget );

connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
//connect( mBrowserView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( itemClicked( const QModelIndex& ) ) );
connect( mBrowserView, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( addLayerAtIndex( const QModelIndex& ) ) );

}

Expand All @@ -126,19 +140,6 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
QDockWidget::showEvent( e );
}


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

if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer )
{
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( dataItem );
if ( layerItem != NULL )
addLayer( layerItem );
}
}

void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
{
QModelIndex idx = mBrowserView->indexAt( pt );
Expand Down Expand Up @@ -168,8 +169,9 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )

else if ( item->type() == QgsDataItem::Layer )
{
menu->addAction( tr( "Add Layer" ), this, SLOT( itemClicked( idx ) ) );
menu->addAction( tr( "Add Layer" ), this, SLOT( addCurrentLayer( ) ) );
menu->addAction( tr( "Add Selected Layers" ), this, SLOT( addSelectedLayers() ) );
menu->addAction( tr( "Properties" ), this, SLOT( showProperties( ) ) );
}

QList<QAction*> actions = item->actions();
Expand Down Expand Up @@ -312,6 +314,27 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
}
}

void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
{
QgsDataItem *dataItem = mModel->dataItem( index );

if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer )
{
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( dataItem );
if ( layerItem != NULL )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
addLayer( layerItem );
QApplication::restoreOverrideCursor();
}
}
}

void QgsBrowserDockWidget::addCurrentLayer( )
{
addLayerAtIndex( mBrowserView->currentIndex() );
}

void QgsBrowserDockWidget::addSelectedLayers()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
Expand All @@ -335,3 +358,87 @@ void QgsBrowserDockWidget::addSelectedLayers()

QApplication::restoreOverrideCursor();
}

void QgsBrowserDockWidget::showProperties( )
{
QgsDebugMsg( "Entered" );
QgsDataItem* dataItem = mModel->dataItem( mBrowserView->currentIndex() );

if ( dataItem != NULL && dataItem->type() == QgsDataItem::Layer )
{
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( dataItem );
if ( layerItem != NULL )
{
QgsMapLayer::LayerType type = layerItem->mapLayerType();
QString layerMetadata = tr( "Error" );
QgsCoordinateReferenceSystem layerCrs;
QString notice;

// temporarily override /Projections/defaultBehaviour to avoid dialog prompt
QSettings settings;
QString defaultProjectionOption = settings.value( "/Projections/defaultBehaviour", "prompt" ).toString();
if ( settings.value( "/Projections/defaultBehaviour", "prompt" ).toString() == "prompt" )
{
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
}

// find root item
// we need to create a temporary layer to get metadata
// we could use a provider but the metadata is not as complete and "pretty" and this is easier
QgsDebugMsg( QString( "creating temporary layer using path %1" ).arg( layerItem->path() ) );
if ( type == QgsMapLayer::RasterLayer )
{
QgsDebugMsg( "creating raster layer" );
// should copy code from addLayer() to split uri ?
QgsRasterLayer* layer = new QgsRasterLayer( 0, layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
if ( layer != NULL )
{
layerCrs = layer->crs();
layerMetadata = layer->metadata();
delete layer;
}
}
else if ( type == QgsMapLayer::VectorLayer )
{
QgsDebugMsg( "creating vector layer" );
QgsVectorLayer* layer = new QgsVectorLayer( layerItem->uri(), layerItem->name(), layerItem->providerKey() );
if ( layer != NULL )
{
layerCrs = layer->crs();
layerMetadata = layer->metadata();
delete layer;
}
}

// restore /Projections/defaultBehaviour
if ( defaultProjectionOption == "prompt" )
{
settings.setValue( "/Projections/defaultBehaviour", defaultProjectionOption );
}

// initialize dialog
QDialog *dialog = new QDialog( this );
Ui::QgsBrowserLayerPropertiesBase ui;
ui.setupUi( dialog );

dialog->setWindowTitle( tr( "Layer Properties" ) );
ui.leName->setText( layerItem->name() );
ui.leSource->setText( layerItem->path() );
ui.leProvider->setText( layerItem->providerKey() );
QString myStyle = QgsApplication::reportStyleSheet();
ui.txtbMetadata->document()->setDefaultStyleSheet( myStyle );
ui.txtbMetadata->setHtml( layerMetadata );

// report if layer was set to to project crs without prompt (may give a false positive)
if ( defaultProjectionOption == "prompt" )
{
QgsCoordinateReferenceSystem defaultCrs =
QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs();
if ( layerCrs == defaultCrs )
ui.lblNotice->setText( "NOTICE: Layer srs set from project (" + defaultCrs.authid() + ")" );
}

dialog->show();
}
}
}
5 changes: 4 additions & 1 deletion src/app/qgsbrowserdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ class QgsBrowserDockWidget : public QDockWidget
signals:

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

void addFavourite();
void removeFavourite();

void refresh();

// layer menu items
void addCurrentLayer();
void addSelectedLayers();
void showProperties();

protected:

Expand Down
30 changes: 25 additions & 5 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,29 @@ void QgsBrowserModel::addRootItems()
// add favourite directories
QSettings settings;
QStringList favDirs = settings.value( "/browser/favourites", QVariant() ).toStringList();
foreach( QString favDir, favDirs )
// if there are 5 or more items, create a "Favourites" Root item
// perhaps this should be the default?
if ( favDirs.count() >= 5 )
{
QgsDirectoryItem *item = new QgsDirectoryItem( NULL, favDir, favDir );
connectItem( item );
mRootItems << item;
QgsFavouritesItem *item = new QgsFavouritesItem( NULL, tr( "Favourites" ), "" );
if ( item )
{
connectItem( item );
mRootItems << item;
}
}
else
{
foreach( QString favDir, favDirs )
{
item = new QgsDirectoryItem( NULL, favDir, favDir );
if ( item )
{
item->setIcon( QgsFavouritesItem::iconFavourites() );
mRootItems << item;
connectItem( item );
}
}
}

foreach( QFileInfo drive, QDir::drives() )
Expand All @@ -54,7 +72,9 @@ void QgsBrowserModel::addRootItems()
}

// Add non file top level items
foreach( QString key, QgsProviderRegistry::instance()->providerList() )
QStringList providersList = QgsProviderRegistry::instance()->providerList();
providersList.sort();
foreach( QString key, providersList )
{
QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( key );
if ( !library )
Expand Down
Loading