[FEATURE] Add style options for legend layer/groups, and live refresh of all legend style options

- Based of off work from Stefan Ziegler (pull request #331)
- Options inherited by embedded groups (which are still always italic)
- Original layer name now saved to project file (instead of adjusted display name)
- Fix bug where setting capitalization, then saving/reopening would permanently set capitalization
- [API] Add originalName() to QgsMapLayer to access original (pre-adjusted name)
- [API] Add setupFont() method to legend group items
- [API] Add updateLegendItemStyles() and updateLegendItemSymbologies() to QgsLegend to allow style option changes to become active without app restart
This commit is contained in:
Larry Shaffer 2013-01-26 12:11:25 -07:00
parent 9dffa42eea
commit 94491b8479
18 changed files with 307 additions and 82 deletions

View File

@ -73,6 +73,11 @@ class QgsMapLayer : QObject
*/ */
const QString & name() const; const QString & name() const;
/** Get the original name of the layer
* @note added in 1.9
*/
const QString & originalName() const;
void setTitle( const QString& title ); void setTitle( const QString& title );
const QString& title() const; const QString& title() const;
@ -207,8 +212,8 @@ class QgsMapLayer : QObject
@note emitSignal added in 1.4 */ @note emitSignal added in 1.4 */
void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true ); void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
/** A convenience function to capitalise the layer name */ /** A convenience function to (un)capitalise the layer name */
static QString capitaliseLayerName( const QString name ); static QString capitaliseLayerName( const QString& name );
/** Retrieve the style URI for this layer /** Retrieve the style URI for this layer
* (either as a .qml file on disk or as a * (either as a .qml file on disk or as a

View File

@ -970,7 +970,8 @@ QgsLegendGroup* QgsLegend::addEmbeddedGroup( const QString& groupName, const QSt
group->setEmbedded( true ); group->setEmbedded( true );
group->setProjectPath( projectFilePath ); group->setProjectPath( projectFilePath );
QFont groupFont; // start with already set font style
QFont groupFont = group->font( 0 );
groupFont.setItalic( true ); groupFont.setItalic( true );
group->setFont( 0, groupFont ); group->setFont( 0, groupFont );
setCurrentItem( group ); setCurrentItem( group );
@ -1075,7 +1076,8 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
QgsLegendLayer* llayer = new QgsLegendLayer( layer ); QgsLegendLayer* llayer = new QgsLegendLayer( layer );
if ( !QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() ) if ( !QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() )
{ {
QFont itemFont; // start with already set font style
QFont itemFont = llayer->font( 0 );
itemFont.setItalic( true ); itemFont.setItalic( true );
llayer->setFont( 0, itemFont ); llayer->setFont( 0, itemFont );
} }
@ -1897,7 +1899,8 @@ bool QgsLegend::readXML( QgsLegendGroup *parent, const QDomNode &node )
if ( currentLayer->layer() && !QgsProject::instance()->layerIsEmbedded( currentLayer->layer()->id() ).isEmpty() ) if ( currentLayer->layer() && !QgsProject::instance()->layerIsEmbedded( currentLayer->layer()->id() ).isEmpty() )
{ {
QFont itemFont; // start with already set font style
QFont itemFont = currentLayer->font( 0 );
itemFont.setItalic( true ); itemFont.setItalic( true );
currentLayer->setFont( 0, itemFont ); currentLayer->setFont( 0, itemFont );
} }
@ -3094,3 +3097,35 @@ QList< LegendLayerAction > QgsLegend::legendLayerActions( QgsMapLayer::LayerType
{ {
return mLegendLayerActionMap.contains( type ) ? mLegendLayerActionMap.value( type ) : QList< LegendLayerAction >() ; return mLegendLayerActionMap.contains( type ) ? mLegendLayerActionMap.value( type ) : QList< LegendLayerAction >() ;
} }
void QgsLegend::updateLegendItemStyles()
{
QgsLegendGroup* lg = 0;
QgsLegendLayer* ll = 0;
for ( QTreeWidgetItem* theItem = firstItem(); theItem; theItem = nextItem( theItem ) )
{
ll = dynamic_cast<QgsLegendLayer *>( theItem );
if ( ll )
{
ll->setupFont();
// map layer name capitalize option may have changed
ll->layer()->setLayerName( ll->layer()->originalName() );
continue;
}
lg = dynamic_cast<QgsLegendGroup *>( theItem );
if ( lg )
{
lg->setupFont();
}
}
update();
}
void QgsLegend::updateLegendItemSymbologies()
{
foreach ( QgsLegendLayer* ll, legendLayers() )
{
ll->refreshSymbology( ll->layer()->id() );
}
}

View File

@ -382,6 +382,17 @@ class QgsLegend : public QTreeWidget
void removeLegendLayerActionsForLayer( QgsMapLayer* layer ); void removeLegendLayerActionsForLayer( QgsMapLayer* layer );
QList< LegendLayerAction > legendLayerActions( QgsMapLayer::LayerType type ) const; QList< LegendLayerAction > legendLayerActions( QgsMapLayer::LayerType type ) const;
/** Slot to update styles for legend items, since
* QgsLegend::item doesn't work in app stylesheet for individual legend types
* @note added in QGIS 1.9
*/
void updateLegendItemStyles();
/** Slot to update symbology for legend items
* @note added in QGIS 1.9
*/
void updateLegendItemSymbologies();
protected: protected:
/*!Event handler for mouse movements. /*!Event handler for mouse movements.

View File

@ -27,6 +27,7 @@ QgsLegendGroup::QgsLegendGroup( QTreeWidgetItem * theItem, QString theName )
setCheckState( 0, Qt::Checked ); setCheckState( 0, Qt::Checked );
QIcon myIcon = QgsApplication::getThemeIcon( "/mActionFolder.png" ); QIcon myIcon = QgsApplication::getThemeIcon( "/mActionFolder.png" );
setIcon( 0, myIcon ); setIcon( 0, myIcon );
setupFont();
mEmbedded = false; mEmbedded = false;
mDrawingOrder = -1; mDrawingOrder = -1;
} }
@ -38,6 +39,7 @@ QgsLegendGroup::QgsLegendGroup( QTreeWidget* theListView, QString theString )
setCheckState( 0, Qt::Checked ); setCheckState( 0, Qt::Checked );
QIcon myIcon = QgsApplication::getThemeIcon( "/mActionFolder.png" ); QIcon myIcon = QgsApplication::getThemeIcon( "/mActionFolder.png" );
setIcon( 0, myIcon ); setIcon( 0, myIcon );
setupFont();
mEmbedded = false; mEmbedded = false;
mDrawingOrder = -1; mDrawingOrder = -1;
} }
@ -50,6 +52,7 @@ QgsLegendGroup::QgsLegendGroup( QString name ): QgsLegendItem()
QIcon myIcon = QgsApplication::getThemeIcon( + "/mActionFolder.png" ); QIcon myIcon = QgsApplication::getThemeIcon( + "/mActionFolder.png" );
setText( 0, name ); setText( 0, name );
setIcon( 0, myIcon ); setIcon( 0, myIcon );
setupFont();
mEmbedded = false; mEmbedded = false;
mDrawingOrder = -1; mDrawingOrder = -1;
} }
@ -57,6 +60,14 @@ QgsLegendGroup::QgsLegendGroup( QString name ): QgsLegendItem()
QgsLegendGroup::~QgsLegendGroup() QgsLegendGroup::~QgsLegendGroup()
{} {}
void QgsLegendGroup::setupFont()
{
QSettings settings;
QFont myFont = font( 0 );
//visually differentiate group labels from the rest
myFont.setBold( settings.value( "/qgis/legendGroupsBold", false ).toBool() );
setFont( 0, myFont );
}
bool QgsLegendGroup::insert( QgsLegendItem* theItem ) bool QgsLegendGroup::insert( QgsLegendItem* theItem )
{ {

View File

@ -32,6 +32,13 @@ class QgsLegendGroup : public QgsLegendItem
QgsLegendGroup( QString name ); QgsLegendGroup( QString name );
~QgsLegendGroup(); ~QgsLegendGroup();
/** Helper method to set font characteristics.
* Not to be confused with setFont() which is inherited
* from the QTreeWidgetItem base class.
* @note added in QGIS 1.9
*/
void setupFont();
bool insert( QgsLegendItem* theItem ); bool insert( QgsLegendItem* theItem );
/**Returns all legend layers under this group (including those of subgroups by default)*/ /**Returns all legend layers under this group (including those of subgroups by default)*/
QList<QgsLegendLayer*> legendLayers( bool recurse = true ); QList<QgsLegendLayer*> legendLayers( bool recurse = true );

View File

@ -112,10 +112,12 @@ void QgsLegendLayer::setCheckState( int column, Qt::CheckState state )
} }
} }
void QgsLegendLayer::setupFont() //private method void QgsLegendLayer::setupFont()
{ {
QSettings settings;
QFont myFont = font( 0 ); QFont myFont = font( 0 );
myFont.setBold( true ); //visually differentiate layer labels from the rest //visually differentiate layer labels from the rest
myFont.setBold( settings.value( "/qgis/legendLayersBold", true ).toBool() );
setFont( 0, myFont ); setFont( 0, myFont );
} }

View File

@ -53,6 +53,12 @@ class QgsLegendLayer : public QgsLegendItem
/**Updates symbology of the layer and copies symbology to other layer files in the group*/ /**Updates symbology of the layer and copies symbology to other layer files in the group*/
void refreshSymbology( const QString& key, double widthScale = 1.0 ); void refreshSymbology( const QString& key, double widthScale = 1.0 );
/** Helper method to set font characteristics.
* Not to be confused with setFont() which is inherited
* from the QTreeWidgetItem base class.
*/
void setupFont();
/** called to add appropriate menu items to legend's popup menu */ /** called to add appropriate menu items to legend's popup menu */
void addToPopupMenu( QMenu& theMenu ); void addToPopupMenu( QMenu& theMenu );
@ -122,11 +128,6 @@ class QgsLegendLayer : public QgsLegendItem
QPixmap getOriginalPixmap(); QPixmap getOriginalPixmap();
private: private:
/** Helper method to make the font bold from all ctors.
* Not to be confused with setFont() which is inherited
* from the QTreeWidgetItem base class.
*/
void setupFont();
/** Label, may be layer name or layer name + [feature count] */ /** Label, may be layer name or layer name + [feature count] */
QString label(); QString label();

View File

@ -21,6 +21,7 @@
#include "qgis.h" #include "qgis.h"
#include "qgisapp.h" #include "qgisapp.h"
#include "qgisappstylesheet.h" #include "qgisappstylesheet.h"
#include "qgslegend.h"
#include "qgsmapcanvas.h" #include "qgsmapcanvas.h"
#include "qgsmaprenderer.h" #include "qgsmaprenderer.h"
#include "qgsgenericprojectionselector.h" #include "qgsgenericprojectionselector.h"
@ -504,6 +505,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
chkUseQPixmap->setChecked( !( settings.value( "/qgis/use_qimage_to_render", true ).toBool() ) ); chkUseQPixmap->setChecked( !( settings.value( "/qgis/use_qimage_to_render", true ).toBool() ) );
chkAddedVisibility->setChecked( settings.value( "/qgis/new_layers_visible", true ).toBool() ); chkAddedVisibility->setChecked( settings.value( "/qgis/new_layers_visible", true ).toBool() );
cbxLegendClassifiers->setChecked( settings.value( "/qgis/showLegendClassifiers", false ).toBool() ); cbxLegendClassifiers->setChecked( settings.value( "/qgis/showLegendClassifiers", false ).toBool() );
mLegendLayersBoldChkBx->setChecked( settings.value( "/qgis/legendLayersBold", true ).toBool() );
mLegendGroupsBoldChkBx->setChecked( settings.value( "/qgis/legendGroupsBold", false ).toBool() );
cbxHideSplash->setChecked( settings.value( "/qgis/hideSplash", false ).toBool() ); cbxHideSplash->setChecked( settings.value( "/qgis/hideSplash", false ).toBool() );
cbxShowTips->setChecked( settings.value( "/qgis/showTips", true ).toBool() ); cbxShowTips->setChecked( settings.value( "/qgis/showTips", true ).toBool() );
cbxAttributeTableDocked->setChecked( settings.value( "/qgis/dockAttributeTable", false ).toBool() ); cbxAttributeTableDocked->setChecked( settings.value( "/qgis/dockAttributeTable", false ).toBool() );
@ -562,7 +565,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
myBlue = settings.value( "/qgis/default_measure_color_blue", 180 ).toInt(); myBlue = settings.value( "/qgis/default_measure_color_blue", 180 ).toInt();
pbnMeasureColor->setColor( QColor( myRed, myGreen, myBlue ) ); pbnMeasureColor->setColor( QColor( myRed, myGreen, myBlue ) );
capitaliseCheckBox->setChecked( settings.value( "qgis/capitaliseLayerName", QVariant( false ) ).toBool() ); capitaliseCheckBox->setChecked( settings.value( "/qgis/capitaliseLayerName", QVariant( false ) ).toBool() );
chbAskToSaveProjectChanges->setChecked( settings.value( "qgis/askToSaveProjectChanges", QVariant( true ) ).toBool() ); chbAskToSaveProjectChanges->setChecked( settings.value( "qgis/askToSaveProjectChanges", QVariant( true ) ).toBool() );
chbWarnOldProjectVersion->setChecked( settings.value( "/qgis/warnOldProjectVersion", QVariant( true ) ).toBool() ); chbWarnOldProjectVersion->setChecked( settings.value( "/qgis/warnOldProjectVersion", QVariant( true ) ).toBool() );
@ -1003,7 +1006,12 @@ void QgsOptions::saveOptions()
settings.setValue( "/Map/identifyMode", cmbIdentifyMode->itemData( cmbIdentifyMode->currentIndex() ).toInt() ); settings.setValue( "/Map/identifyMode", cmbIdentifyMode->itemData( cmbIdentifyMode->currentIndex() ).toInt() );
settings.setValue( "/Map/identifyAutoFeatureForm", cbxAutoFeatureForm->isChecked() ); settings.setValue( "/Map/identifyAutoFeatureForm", cbxAutoFeatureForm->isChecked() );
settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() ); settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() );
bool showLegendClassifiers = settings.value( "/qgis/showLegendClassifiers", false ).toBool();
settings.setValue( "/qgis/showLegendClassifiers", cbxLegendClassifiers->isChecked() ); settings.setValue( "/qgis/showLegendClassifiers", cbxLegendClassifiers->isChecked() );
bool legendLayersBold = settings.value( "/qgis/legendLayersBold", true ).toBool();
settings.setValue( "/qgis/legendLayersBold", mLegendLayersBoldChkBx->isChecked() );
bool legendGroupsBold = settings.value( "/qgis/legendGroupsBold", false ).toBool();
settings.setValue( "/qgis/legendGroupsBold", mLegendGroupsBoldChkBx->isChecked() );
settings.setValue( "/qgis/hideSplash", cbxHideSplash->isChecked() ); settings.setValue( "/qgis/hideSplash", cbxHideSplash->isChecked() );
settings.setValue( "/qgis/showTips", cbxShowTips->isChecked() ); settings.setValue( "/qgis/showTips", cbxShowTips->isChecked() );
settings.setValue( "/qgis/dockAttributeTable", cbxAttributeTableDocked->isChecked() ); settings.setValue( "/qgis/dockAttributeTable", cbxAttributeTableDocked->isChecked() );
@ -1019,6 +1027,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/dockSnapping", cbxSnappingOptionsDocked->isChecked() ); settings.setValue( "/qgis/dockSnapping", cbxSnappingOptionsDocked->isChecked() );
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() ); settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
settings.setValue( "/qgis/addNewLayersToCurrentGroup", cbxAddNewLayersToCurrentGroup->isChecked() ); settings.setValue( "/qgis/addNewLayersToCurrentGroup", cbxAddNewLayersToCurrentGroup->isChecked() );
bool createRasterLegendIcons = settings.value( "/qgis/createRasterLegendIcons", true ).toBool();
settings.setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() ); settings.setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );
settings.setValue( "/qgis/copyGeometryAsWKT", cbxCopyWKTGeomFromTable->isChecked() ); settings.setValue( "/qgis/copyGeometryAsWKT", cbxCopyWKTGeomFromTable->isChecked() );
settings.setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() ); settings.setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() );
@ -1027,6 +1036,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/use_qimage_to_render", !( chkUseQPixmap->isChecked() ) ); settings.setValue( "/qgis/use_qimage_to_render", !( chkUseQPixmap->isChecked() ) );
settings.setValue( "/qgis/use_symbology_ng", chkUseSymbologyNG->isChecked() ); settings.setValue( "/qgis/use_symbology_ng", chkUseSymbologyNG->isChecked() );
settings.setValue( "/qgis/legendDoubleClickAction", cmbLegendDoubleClickAction->currentIndex() ); settings.setValue( "/qgis/legendDoubleClickAction", cmbLegendDoubleClickAction->currentIndex() );
bool legendLayersCapitalise = settings.value( "/qgis/capitaliseLayerName", false ).toBool();
settings.setValue( "/qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() ); settings.setValue( "/qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
// project // project
@ -1233,6 +1243,21 @@ void QgsOptions::saveOptions()
if ( mLoadedGdalDriverList ) if ( mLoadedGdalDriverList )
saveGdalDriverList(); saveGdalDriverList();
// refresh legend if any legend item's state is to be changed
if ( legendLayersBold != mLegendLayersBoldChkBx->isChecked()
|| legendGroupsBold != mLegendGroupsBoldChkBx->isChecked()
|| legendLayersCapitalise != capitaliseCheckBox->isChecked() )
{
QgisApp::instance()->legend()->updateLegendItemStyles();
}
// refresh symbology for any legend items, only if needed
if ( showLegendClassifiers != cbxLegendClassifiers->isChecked()
|| createRasterLegendIcons != cbxCreateRasterLegendIcons->isChecked() )
{
QgisApp::instance()->legend()->updateLegendItemSymbologies();
}
// save app stylesheet last (in case reset becomes necessary) // save app stylesheet last (in case reset becomes necessary)
if ( mStyleSheetNewOpts != mStyleSheetOldOpts ) if ( mStyleSheetNewOpts != mStyleSheetOldOpts )
{ {

View File

@ -591,6 +591,7 @@ void QgsRasterLayerProperties::sync()
//these properties (layer name and label) are provided by the qgsmaplayer superclass //these properties (layer name and label) are provided by the qgsmaplayer superclass
leLayerSource->setText( mRasterLayer->source() ); leLayerSource->setText( mRasterLayer->source() );
mLayerOrigNameLineEd->setText( mRasterLayer->originalName() );
leDisplayName->setText( mRasterLayer->name() ); leDisplayName->setText( mRasterLayer->name() );
//display the raster dimensions and no data value //display the raster dimensions and no data value
@ -749,7 +750,7 @@ void QgsRasterLayerProperties::apply()
/* /*
* General Tab * General Tab
*/ */
mRasterLayer->setLayerName( leDisplayName->text() ); mRasterLayer->setLayerName( mLayerOrigNameLineEd->text() );
// set up the scale based layer visibility stuff.... // set up the scale based layer visibility stuff....
mRasterLayer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() ); mRasterLayer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
@ -819,6 +820,11 @@ void QgsRasterLayerProperties::apply()
updatePipeList(); updatePipeList();
}//apply }//apply
void QgsRasterLayerProperties::on_mLayerOrigNameLineEd_textEdited( const QString& text )
{
leDisplayName->setText( mRasterLayer->capitaliseLayerName( text ) );
}
void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked() void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
{ {
QgsRasterDataProvider* provider = mRasterLayer->dataProvider(); QgsRasterDataProvider* provider = mRasterLayer->dataProvider();

View File

@ -56,6 +56,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
//TODO: Verify that these all need to be public //TODO: Verify that these all need to be public
/** \brief Applies the settings made in the dialog without closing the box */ /** \brief Applies the settings made in the dialog without closing the box */
void apply(); void apply();
/** \brief Slot to update layer display name as original is edited
* @note added in QGIS 1.9 */
void on_mLayerOrigNameLineEd_textEdited( const QString& text );
/** \brief this slot asks the rasterlayer to construct pyramids */ /** \brief this slot asks the rasterlayer to construct pyramids */
void on_buttonBuildPyramids_clicked(); void on_buttonBuildPyramids_clicked();
/** \brief slot executed when user presses "Add Values From Display" button on the transparency page */ /** \brief slot executed when user presses "Add Values From Display" button on the transparency page */

View File

@ -337,6 +337,7 @@ void QgsVectorLayerProperties::setDisplayField( QString name )
void QgsVectorLayerProperties::reset( void ) void QgsVectorLayerProperties::reset( void )
{ {
// populate the general information // populate the general information
mLayerOrigNameLineEdit->setText( layer->originalName() );
txtDisplayName->setText( layer->name() ); txtDisplayName->setText( layer->name() );
pbnQueryBuilder->setWhatsThis( tr( "This button opens the query " pbnQueryBuilder->setWhatsThis( tr( "This button opens the query "
"builder and allows you to create a subset of features to display on " "builder and allows you to create a subset of features to display on "
@ -468,7 +469,7 @@ void QgsVectorLayerProperties::apply()
if ( labelDialog ) if ( labelDialog )
labelDialog->apply(); labelDialog->apply();
layer->enableLabels( labelCheckBox->isChecked() ); layer->enableLabels( labelCheckBox->isChecked() );
layer->setLayerName( displayName() ); layer->setLayerName( mLayerOrigNameLineEdit->text() );
QSet<QString> excludeAttributesWMS, excludeAttributesWFS; QSet<QString> excludeAttributesWMS, excludeAttributesWFS;
@ -584,7 +585,10 @@ QString QgsVectorLayerProperties::metadata()
return layer->metadata(); return layer->metadata();
} }
void QgsVectorLayerProperties::on_mLayerOrigNameLineEdit_textEdited( const QString& text )
{
txtDisplayName->setText( layer->capitaliseLayerName( text ) );
}
void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked() void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked()
{ {

View File

@ -89,6 +89,11 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
/** Get metadata about the layer in nice formatted html */ /** Get metadata about the layer in nice formatted html */
QString metadata(); QString metadata();
/** Slot to update layer display name as original is edited
* @note added in QGIS 1.9
*/
void on_mLayerOrigNameLineEdit_textEdited( const QString& text );
/** Set transparency based on slider position */ /** Set transparency based on slider position */
void sliderTransparency_valueChanged( int theValue ); void sliderTransparency_valueChanged( int theValue );

View File

@ -47,17 +47,16 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mTransparencyLevel( 255 ), // 0 is completely transparent mTransparencyLevel( 255 ), // 0 is completely transparent
mValid( false ), // assume the layer is invalid mValid( false ), // assume the layer is invalid
mDataSource( source ), mDataSource( source ),
mLayerOrigName( lyrname ), // store the original name
mID( "" ), mID( "" ),
mLayerType( type ) mLayerType( type )
{ {
QgsDebugMsg( "lyrname is '" + lyrname + "'" );
mCRS = new QgsCoordinateReferenceSystem(); mCRS = new QgsCoordinateReferenceSystem();
// Set the display name = internal name // Set the display name = internal name
mLayerName = capitaliseLayerName( lyrname ); QgsDebugMsg( "original name: '" + mLayerOrigName + "'" );
QgsDebugMsg( "layerName is '" + mLayerName + "'" ); mLayerName = capitaliseLayerName( mLayerOrigName );
QgsDebugMsg( "display name: '" + mLayerName + "'" );
// Generate the unique ID of this layer // Generate the unique ID of this layer
QDateTime dt = QDateTime::currentDateTime(); QDateTime dt = QDateTime::currentDateTime();
@ -77,8 +76,6 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mpCacheImage = 0; mpCacheImage = 0;
} }
QgsMapLayer::~QgsMapLayer() QgsMapLayer::~QgsMapLayer()
{ {
delete mCRS; delete mCRS;
@ -102,9 +99,11 @@ QString QgsMapLayer::id() const
/** Write property of QString layerName. */ /** Write property of QString layerName. */
void QgsMapLayer::setLayerName( const QString & name ) void QgsMapLayer::setLayerName( const QString & name )
{ {
QgsDebugMsg( "new name is '" + name + "'" ); QgsDebugMsg( "new original name: '" + name + "'" );
QString newName = capitaliseLayerName( name ); QString newName = capitaliseLayerName( name );
if ( newName == mLayerName ) return; QgsDebugMsg( "new display name: '" + name + "'" );
if ( name == mLayerOrigName && newName == mLayerName ) return;
mLayerOrigName = name; // store the new original name
mLayerName = newName; mLayerName = newName;
emit layerNameChanged(); emit layerNameChanged();
} }
@ -432,7 +431,7 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
// layer name // layer name
QDomElement layerName = document.createElement( "layername" ); QDomElement layerName = document.createElement( "layername" );
QDomText layerNameText = document.createTextNode( name() ); QDomText layerNameText = document.createTextNode( originalName() );
layerName.appendChild( layerNameText ); layerName.appendChild( layerNameText );
// layer title // layer title
@ -608,12 +607,12 @@ void QgsMapLayer::setTransparency( unsigned int theInt )
mTransparencyLevel = theInt; mTransparencyLevel = theInt;
} }
QString QgsMapLayer::capitaliseLayerName( const QString name ) QString QgsMapLayer::capitaliseLayerName( const QString& name )
{ {
// Capitalise the first letter of the layer name if requested // Capitalise the first letter of the layer name if requested
QSettings settings; QSettings settings;
bool capitaliseLayerName = bool capitaliseLayerName =
settings.value( "qgis/capitaliseLayerName", QVariant( false ) ).toBool(); settings.value( "/qgis/capitaliseLayerName", QVariant( false ) ).toBool();
QString layerName( name ); QString layerName( name );

View File

@ -83,6 +83,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/ */
const QString & name() const; const QString & name() const;
/** Get the original name of the layer
* @note added in 1.9
*/
const QString & originalName() const { return mLayerOrigName; }
void setTitle( const QString& title ) { mTitle = title; } void setTitle( const QString& title ) { mTitle = title; }
const QString& title() const { return mTitle; } const QString& title() const { return mTitle; }
@ -223,8 +228,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
@note emitSignal added in 1.4 */ @note emitSignal added in 1.4 */
void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true ); void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
/** A convenience function to capitalise the layer name */ /** A convenience function to (un)capitalise the layer name */
static QString capitaliseLayerName( const QString name ); static QString capitaliseLayerName( const QString& name );
/** Retrieve the style URI for this layer /** Retrieve the style URI for this layer
* (either as a .qml file on disk or as a * (either as a .qml file on disk or as a
@ -428,6 +433,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Name of the layer - used for display */ /** Name of the layer - used for display */
QString mLayerName; QString mLayerName;
/** Original name of the layer
* @note added in 1.9
*/
QString mLayerOrigName;
QString mTitle; QString mTitle;
/**Description of the layer*/ /**Description of the layer*/

View File

@ -1543,7 +1543,7 @@ QString QgsProject::layerIsEmbedded( const QString& id ) const
return QString(); return QString();
} }
return it.value().first; return it.value().first;
}; }
bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes, bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag ) QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag )

View File

@ -807,7 +807,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>611</width> <width>654</width>
<height>808</height> <height>808</height>
</rect> </rect>
</property> </property>
@ -1137,8 +1137,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>559</width> <width>669</width>
<height>417</height> <height>490</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_27"> <layout class="QVBoxLayout" name="verticalLayout_27">
@ -1456,7 +1456,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>615</width> <width>654</width>
<height>681</height> <height>681</height>
</rect> </rect>
</property> </property>
@ -1944,8 +1944,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>498</width> <width>669</width>
<height>332</height> <height>490</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_25"> <layout class="QVBoxLayout" name="verticalLayout_25">
@ -2074,26 +2074,98 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="2">
<widget class="Line" name="line_4">
<property name="minimumSize">
<size>
<width>12</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_34">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="capitaliseCheckBox"> <widget class="QCheckBox" name="capitaliseCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Capitalise layer names</string> <string>Capitalise layer names</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="3">
<widget class="QCheckBox" name="mLegendLayersBoldChkBx">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Bold layer names</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QCheckBox" name="cbxLegendClassifiers"> <widget class="QCheckBox" name="cbxLegendClassifiers">
<property name="text"> <property name="text">
<string>Display classification attribute names</string> <string>Display classification attribute names</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="1" colspan="3">
<widget class="QCheckBox" name="cbxCreateRasterLegendIcons"> <widget class="QCheckBox" name="mLegendGroupsBoldChkBx">
<property name="text"> <property name="text">
<string>Create raster icons</string> <string>Bold group names</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1" colspan="3">
<widget class="QCheckBox" name="cbxCreateRasterLegendIcons">
<property name="text">
<string>Create raster icons (may be slow)</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_53">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Legend item styles</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QCheckBox" name="cbxAddNewLayersToCurrentGroup"> <widget class="QCheckBox" name="cbxAddNewLayersToCurrentGroup">
<property name="text"> <property name="text">

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>678</width> <width>752</width>
<height>537</height> <height>599</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -607,12 +607,26 @@
<item> <item>
<widget class="QLabel" name="lblDisplayName"> <widget class="QLabel" name="lblDisplayName">
<property name="text"> <property name="text">
<string>Display name</string> <string>Layer name</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="leDisplayName"/> <widget class="QLineEdit" name="mLayerOrigNameLineEd"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>displayed as</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leDisplayName">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -1146,7 +1160,7 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</widget> </widget>
@ -1238,9 +1252,6 @@ p, li { white-space: pre-wrap; }
<attribute name="headerStretchLastSection"> <attribute name="headerStretchLastSection">
<bool>true</bool> <bool>true</bool>
</attribute> </attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<column> <column>
<property name="text"> <property name="text">
<string notr="true">1</string> <string notr="true">1</string>

View File

@ -66,7 +66,7 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>4</number> <number>0</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -297,8 +297,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>920</width> <width>906</width>
<height>756</height> <height>720</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
@ -615,17 +615,7 @@ p, li { white-space: pre-wrap; }
<string>Display</string> <string>Display</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_19"> <layout class="QGridLayout" name="gridLayout_19">
<item row="0" column="0"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>Legend display text</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtDisplayName"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Map Tip display text</string> <string>Map Tip display text</string>
@ -751,6 +741,34 @@ p, li { white-space: pre-wrap; }
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>Layer name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mLayerOrigNameLineEdit"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>displayed as</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtDisplayName">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabWidgetPage5"> <widget class="QWidget" name="tabWidgetPage5">
@ -778,8 +796,8 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>912</width> <width>866</width>
<height>748</height> <height>688</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -890,8 +908,8 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>912</width> <width>866</width>
<height>748</height> <height>688</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_17"> <layout class="QGridLayout" name="gridLayout_17">