Skip to content
Permalink
Browse files
add simple layer properties dialog to browser dock (source, provider …
…and metadata) ; ui tweaks in raster properties dialog

Signed-off-by: Tim Sutton <tim@linfiniti.com>
  • Loading branch information
etiennesky authored and timlinux committed Mar 31, 2012
1 parent 7b8bc5a commit c7f3af07e58bb7856db720025df129972f78cfdf
Showing with 249 additions and 10 deletions.
  1. +90 −0 src/app/qgsbrowserdockwidget.cpp
  2. +2 −0 src/app/qgsbrowserdockwidget.h
  3. +153 −0 src/ui/qgsbrowserlayerpropertiesbase.ui
  4. +4 −10 src/ui/qgsrasterlayerpropertiesbase.ui
@@ -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.
@@ -166,6 +171,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
{
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();
@@ -352,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();
}
}
}
@@ -25,8 +25,10 @@ class QgsBrowserDockWidget : public QDockWidget

void refresh();

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

protected:

@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsBrowserLayerPropertiesBase</class>
<widget class="QDialog" name="QgsBrowserLayerPropertiesBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>617</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Display Name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Layer Source</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leName">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leSource">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Provider</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leProvider">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Metadata</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="txtbMetadata"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="lblNotice">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsBrowserLayerPropertiesBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsBrowserLayerPropertiesBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -952,9 +952,6 @@
<string>Colormap</string>
</attribute>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="grpGenerateColorMap">
<property name="title">
@@ -1494,9 +1491,6 @@
<string>General</string>
</attribute>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lblDisplayName">
<property name="text">
@@ -1517,7 +1511,10 @@
<item row="1" column="2" colspan="4">
<widget class="QLineEdit" name="leLayerSource">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
@@ -1857,9 +1854,6 @@
<string>Pyramids</string>
</attribute>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="3" colspan="2">
<widget class="QLabel" name="textLabel5">
<property name="text">

0 comments on commit c7f3af0

Please sign in to comment.