Skip to content

Commit

Permalink
Fix for ticket #91.
Browse files Browse the repository at this point in the history
- Captialising the layer name is now a global, per-user settings.
- Moved the capitalise code to QgsMapLayer so that it's not repeated in
  the code for loading each layer type.



git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5434 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed May 11, 2006
1 parent 804acac commit 3e5e030
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 85 deletions.
21 changes: 19 additions & 2 deletions src/gui/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QKeyEvent>
#include <QMenu>
#include <QRegExp>
#include <QSettings>

#include "qgisapp.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ QgsMapLayer::QgsMapLayer(int type,
QgsDebugMsg("QgsMapLayer::QgsMapLayer - lyrname is '" + lyrname);

// Set the display name = internal name
layerName = internalName;
layerName = capitaliseLayerName(internalName);

QgsDebugMsg("QgsMapLayer::QgsMapLayer - layerName is '" + layerName);

Expand Down Expand Up @@ -108,7 +109,7 @@ QString const & QgsMapLayer::getLayerID() const
void QgsMapLayer::setLayerName(const QString & _newVal)
{
QgsDebugMsg("QgsMapLayer::setLayerName: new name is '" + _newVal);
layerName = _newVal;
layerName = capitaliseLayerName(_newVal);
// And update the legend if one exists
if (mLegend)
mLegend->setName(mLegendLayerFile, layerName);
Expand Down Expand Up @@ -703,3 +704,19 @@ QMenu* QgsMapLayer::contextMenu()
{
return popMenu;
}

QString QgsMapLayer::capitaliseLayerName(const QString name)
{
// Capitalise the first letter of the layer name if requested
QSettings settings;
bool capitaliseLayerName =
settings.value("qgis/capitaliseLayerName",
QVariant(false)).toBool();

QString layerName(name);

if (capitaliseLayerName)
layerName = layerName.left(1).upper() + layerName.mid(1);

return layerName;
}
8 changes: 5 additions & 3 deletions src/gui/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,6 @@ public slots:

QPixmap mEditablePixmap;

/** Name of the layer - used for display */
QString layerName;

/** Internal name of the layer. Derived from the datasource */
QString internalName;

Expand Down Expand Up @@ -474,6 +471,9 @@ public slots:
/// QgsMapLayer not copyable
QgsMapLayer & operator=( QgsMapLayer const & );

/// A convenience function to capitalise the layer name
static QString capitaliseLayerName(const QString name);

/** Unique ID of this layer - used to refer to this layer in QGIS code */
QString ID;

Expand All @@ -483,6 +483,8 @@ public slots:
//! Tag for embedding additional information
QString tag;

/** Name of the layer - used for display */
QString layerName;

/** true if visible ? */
bool m_visible;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
myGreen = settings.value("/qgis/default_canvas_color_green",255).toInt();
myBlue = settings.value("/qgis/default_canvas_color_blue",255).toInt();
pbnCanvasColor->setPaletteBackgroundColor(QColor(myRed,myGreen,myBlue));

capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());
}

//! Destructor
Expand Down Expand Up @@ -148,6 +150,8 @@ void QgsOptions::saveOptions()
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
settings.writeEntry("/qgis/new_layers_visible",chkAddedVisibility->isChecked());
settings.writeEntry("/qgis/enable_anti_aliasing",chkAntiAliasing->isChecked());
settings.setValue("qgis/capitaliseLayerName", capitaliseCheckBox->isChecked());

if(cmbTheme->currentText().length() == 0)
{
settings.writeEntry("/Themes", "default");
Expand Down
13 changes: 6 additions & 7 deletions src/gui/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2129,16 +2129,15 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )

if (providerKey == "postgres")
{
QgsDebugMsg("Beautifying layer name " + layerName);
QgsDebugMsg("Beautifying layer name " + name());
// adjust the display name for postgres layers
layerName = layerName.mid(layerName.find(".") + 1);
layerName = layerName.left(layerName.find("(") - 1); // Take one away, to avoid a trailing space
QgsDebugMsg("Beautifying layer name " + layerName);
QString lName(name());
lName = lName.mid(lName.find(".") + 1);
lName = lName.left(lName.find("(") - 1); // Take one away, to avoid a trailing space
setLayerName(lName);
QgsDebugMsg("Beautifying layer name " + name());
}

// upper case the first letter of the layer name
layerName = layerName.left(1).upper() + layerName.mid(1);

// label
mLabel = new QgsLabel ( dataProvider->fields() );
mLabelOn = false;
Expand Down
16 changes: 6 additions & 10 deletions src/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ QgsRasterLayer::QgsRasterLayer(QString const & path, QString const & baseName)

if ( ! baseName.isEmpty() ) // XXX shouldn't this happen in parent?
{
QString layerTitle = baseName;
layerTitle = layerTitle.left(1).upper() + layerTitle.mid(1);
setLayerName(layerTitle);
setLayerName(baseName);
}

// load the file if one specified
Expand Down Expand Up @@ -1075,9 +1073,9 @@ bool QgsRasterLayer::draw(QPainter * theQPainter,
{
return;
}
}
}
*/

// clip raster extent to view extent
QgsRect myRasterExtent = theViewExtent->intersect(&layerExtent);
if (myRasterExtent.isEmpty())
Expand Down Expand Up @@ -2701,7 +2699,7 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNoInt)
return myRasterBandStats;
}
// only print message if we are actually gathering the stats
emit setStatus(QString("Retrieving stats for ")+layerName);
emit setStatus(QString("Retrieving stats for ")+name());
qApp->processEvents();
QgsDebugMsg("QgsRasterLayer::retrieve stats for band " + QString::number(theBandNoInt));
GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
Expand Down Expand Up @@ -2751,7 +2749,7 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNoInt)

myRasterBandStats.elementCountInt = 0; // because we'll be counting only VALID pixels later

emit setStatus(QString("Calculating stats for ")+layerName);
emit setStatus(QString("Calculating stats for ")+name());
//reset the main app progress bar
emit setProgress(0,0);

Expand Down Expand Up @@ -4971,9 +4969,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
layerExtent.setYmax(mbr->yMax());
layerExtent.setYmin(mbr->yMin());

// upper case the first letter of the layer name
layerName = layerName.left(1).upper() + layerName.mid(1);
QgsDebugMsg("QgsRasterLayer::setDataProvider: layerName: " + layerName);
QgsDebugMsg("QgsRasterLayer::setDataProvider: layerName: " + name());


//
Expand Down
148 changes: 85 additions & 63 deletions src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>517</width>
<height>413</height>
<width>554</width>
<height>434</height>
</rect>
</property>
<property name="windowTitle" >
Expand All @@ -21,43 +21,30 @@
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<item>
<widget class="QTabWidget" name="tabWidget" >
<widget class="QWidget" name="tabAppearance" >
<attribute name="title" >
<string>&amp;Appearance</string>
</attribute>
<layout class="QGridLayout" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="3" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" >
<widget class="QGroupBox" name="groupBox_9" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Default Map Appearance (Overridden by project properties)</string>
<string>&amp;Splash screen</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
Expand All @@ -66,50 +53,17 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="2" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Background Color:</string>
</property>
<property name="buddy" >
<cstring>pbnCanvasColor</cstring>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QToolButton" name="pbnCanvasColor" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QToolButton" name="pbnSelectionColour" >
<property name="minimumSize" >
<size>
<width>10</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="textLabel1_9" >
<widget class="QCheckBox" name="cbxHideSplash" >
<property name="text" >
<string>Selection Color:</string>
</property>
<property name="buddy" >
<cstring>pbnSelectionColour</cstring>
<string>Hide splash screen at startup</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" >
<item>
<widget class="QGroupBox" name="groupBox_2" >
<property name="title" >
<string>&amp;Icon Theme</string>
Expand Down Expand Up @@ -177,10 +131,10 @@
</layout>
</widget>
</item>
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox" >
<item>
<widget class="QGroupBox" name="groupBox_9" >
<property name="title" >
<string>&amp;Splash screen</string>
<string>Default Map Appearance (Overridden by project properties)</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
Expand All @@ -189,16 +143,84 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="2" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Background Color:</string>
</property>
<property name="buddy" >
<cstring>pbnCanvasColor</cstring>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QToolButton" name="pbnCanvasColor" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QToolButton" name="pbnSelectionColour" >
<property name="minimumSize" >
<size>
<width>10</width>
<height>22</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QCheckBox" name="cbxHideSplash" >
<widget class="QLabel" name="textLabel1_9" >
<property name="text" >
<string>Hide splash screen at startup</string>
<string>Selection Color:</string>
</property>
<property name="buddy" >
<cstring>pbnSelectionColour</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3" >
<property name="title" >
<string>Appearance</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="capitaliseCheckBox" >
<property name="text" >
<string>Capitalise layer name</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="TabPage" >
Expand Down Expand Up @@ -609,7 +631,7 @@ identifying features without zooming in very close.
</widget>
</widget>
</item>
<item row="1" column="0" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
Expand Down

0 comments on commit 3e5e030

Please sign in to comment.