Skip to content

Commit 7e988cb

Browse files
author
g_j_m
committedMay 11, 2006
Fix for ticket #91.
- 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@5434 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fff1b7a commit 7e988cb

File tree

6 files changed

+125
-85
lines changed

6 files changed

+125
-85
lines changed
 

‎src/gui/qgsmaplayer.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QKeyEvent>
3131
#include <QMenu>
3232
#include <QRegExp>
33+
#include <QSettings>
3334

3435
#include "qgisapp.h"
3536
#include "qgslogger.h"
@@ -65,7 +66,7 @@ QgsMapLayer::QgsMapLayer(int type,
6566
QgsDebugMsg("QgsMapLayer::QgsMapLayer - lyrname is '" + lyrname);
6667

6768
// Set the display name = internal name
68-
layerName = internalName;
69+
layerName = capitaliseLayerName(internalName);
6970

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

@@ -108,7 +109,7 @@ QString const & QgsMapLayer::getLayerID() const
108109
void QgsMapLayer::setLayerName(const QString & _newVal)
109110
{
110111
QgsDebugMsg("QgsMapLayer::setLayerName: new name is '" + _newVal);
111-
layerName = _newVal;
112+
layerName = capitaliseLayerName(_newVal);
112113
// And update the legend if one exists
113114
if (mLegend)
114115
mLegend->setName(mLegendLayerFile, layerName);
@@ -703,3 +704,19 @@ QMenu* QgsMapLayer::contextMenu()
703704
{
704705
return popMenu;
705706
}
707+
708+
QString QgsMapLayer::capitaliseLayerName(const QString name)
709+
{
710+
// Capitalise the first letter of the layer name if requested
711+
QSettings settings;
712+
bool capitaliseLayerName =
713+
settings.value("qgis/capitaliseLayerName",
714+
QVariant(false)).toBool();
715+
716+
QString layerName(name);
717+
718+
if (capitaliseLayerName)
719+
layerName = layerName.left(1).upper() + layerName.mid(1);
720+
721+
return layerName;
722+
}

‎src/gui/qgsmaplayer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,6 @@ public slots:
429429

430430
QPixmap mEditablePixmap;
431431

432-
/** Name of the layer - used for display */
433-
QString layerName;
434-
435432
/** Internal name of the layer. Derived from the datasource */
436433
QString internalName;
437434

@@ -474,6 +471,9 @@ public slots:
474471
/// QgsMapLayer not copyable
475472
QgsMapLayer & operator=( QgsMapLayer const & );
476473

474+
/// A convenience function to capitalise the layer name
475+
static QString capitaliseLayerName(const QString name);
476+
477477
/** Unique ID of this layer - used to refer to this layer in QGIS code */
478478
QString ID;
479479

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

486+
/** Name of the layer - used for display */
487+
QString layerName;
486488

487489
/** true if visible ? */
488490
bool m_visible;

‎src/gui/qgsoptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
106106
myGreen = settings.value("/qgis/default_canvas_color_green",255).toInt();
107107
myBlue = settings.value("/qgis/default_canvas_color_blue",255).toInt();
108108
pbnCanvasColor->setPaletteBackgroundColor(QColor(myRed,myGreen,myBlue));
109+
110+
capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());
109111
}
110112

111113
//! Destructor
@@ -148,6 +150,8 @@ void QgsOptions::saveOptions()
148150
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
149151
settings.writeEntry("/qgis/new_layers_visible",chkAddedVisibility->isChecked());
150152
settings.writeEntry("/qgis/enable_anti_aliasing",chkAntiAliasing->isChecked());
153+
settings.setValue("qgis/capitaliseLayerName", capitaliseCheckBox->isChecked());
154+
151155
if(cmbTheme->currentText().length() == 0)
152156
{
153157
settings.writeEntry("/Themes", "default");

‎src/gui/qgsvectorlayer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,16 +2129,15 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
21292129

21302130
if (providerKey == "postgres")
21312131
{
2132-
QgsDebugMsg("Beautifying layer name " + layerName);
2132+
QgsDebugMsg("Beautifying layer name " + name());
21332133
// adjust the display name for postgres layers
2134-
layerName = layerName.mid(layerName.find(".") + 1);
2135-
layerName = layerName.left(layerName.find("(") - 1); // Take one away, to avoid a trailing space
2136-
QgsDebugMsg("Beautifying layer name " + layerName);
2134+
QString lName(name());
2135+
lName = lName.mid(lName.find(".") + 1);
2136+
lName = lName.left(lName.find("(") - 1); // Take one away, to avoid a trailing space
2137+
setLayerName(lName);
2138+
QgsDebugMsg("Beautifying layer name " + name());
21372139
}
21382140

2139-
// upper case the first letter of the layer name
2140-
layerName = layerName.left(1).upper() + layerName.mid(1);
2141-
21422141
// label
21432142
mLabel = new QgsLabel ( dataProvider->fields() );
21442143
mLabelOn = false;

‎src/raster/qgsrasterlayer.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,7 @@ QgsRasterLayer::QgsRasterLayer(QString const & path, QString const & baseName)
470470

471471
if ( ! baseName.isEmpty() ) // XXX shouldn't this happen in parent?
472472
{
473-
QString layerTitle = baseName;
474-
layerTitle = layerTitle.left(1).upper() + layerTitle.mid(1);
475-
setLayerName(layerTitle);
473+
setLayerName(baseName);
476474
}
477475

478476
// load the file if one specified
@@ -1075,9 +1073,9 @@ bool QgsRasterLayer::draw(QPainter * theQPainter,
10751073
{
10761074
return;
10771075
}
1078-
}
1076+
}
10791077
*/
1080-
1078+
10811079
// clip raster extent to view extent
10821080
QgsRect myRasterExtent = theViewExtent->intersect(&layerExtent);
10831081
if (myRasterExtent.isEmpty())
@@ -2701,7 +2699,7 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNoInt)
27012699
return myRasterBandStats;
27022700
}
27032701
// only print message if we are actually gathering the stats
2704-
emit setStatus(QString("Retrieving stats for ")+layerName);
2702+
emit setStatus(QString("Retrieving stats for ")+name());
27052703
qApp->processEvents();
27062704
QgsDebugMsg("QgsRasterLayer::retrieve stats for band " + QString::number(theBandNoInt));
27072705
GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
@@ -2751,7 +2749,7 @@ const QgsRasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNoInt)
27512749

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

2754-
emit setStatus(QString("Calculating stats for ")+layerName);
2752+
emit setStatus(QString("Calculating stats for ")+name());
27552753
//reset the main app progress bar
27562754
emit setProgress(0,0);
27572755

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

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

49784974

49794975
//

‎src/ui/qgsoptionsbase.ui

Lines changed: 85 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<rect>
99
<x>0</x>
1010
<y>0</y>
11-
<width>517</width>
12-
<height>413</height>
11+
<width>554</width>
12+
<height>434</height>
1313
</rect>
1414
</property>
1515
<property name="windowTitle" >
@@ -21,43 +21,30 @@
2121
<property name="sizeGripEnabled" >
2222
<bool>true</bool>
2323
</property>
24-
<layout class="QGridLayout" >
24+
<layout class="QVBoxLayout" >
2525
<property name="margin" >
2626
<number>9</number>
2727
</property>
2828
<property name="spacing" >
2929
<number>6</number>
3030
</property>
31-
<item row="0" column="0" >
31+
<item>
3232
<widget class="QTabWidget" name="tabWidget" >
3333
<widget class="QWidget" name="tabAppearance" >
3434
<attribute name="title" >
3535
<string>&amp;Appearance</string>
3636
</attribute>
37-
<layout class="QGridLayout" >
37+
<layout class="QVBoxLayout" >
3838
<property name="margin" >
3939
<number>9</number>
4040
</property>
4141
<property name="spacing" >
4242
<number>6</number>
4343
</property>
44-
<item row="3" column="0" >
45-
<spacer>
46-
<property name="orientation" >
47-
<enum>Qt::Vertical</enum>
48-
</property>
49-
<property name="sizeHint" >
50-
<size>
51-
<width>20</width>
52-
<height>40</height>
53-
</size>
54-
</property>
55-
</spacer>
56-
</item>
57-
<item row="2" column="0" >
58-
<widget class="QGroupBox" name="groupBox_9" >
44+
<item>
45+
<widget class="QGroupBox" name="groupBox" >
5946
<property name="title" >
60-
<string>Default Map Appearance (Overridden by project properties)</string>
47+
<string>&amp;Splash screen</string>
6148
</property>
6249
<layout class="QGridLayout" >
6350
<property name="margin" >
@@ -66,50 +53,17 @@
6653
<property name="spacing" >
6754
<number>6</number>
6855
</property>
69-
<item row="0" column="2" >
70-
<widget class="QLabel" name="label" >
71-
<property name="text" >
72-
<string>Background Color:</string>
73-
</property>
74-
<property name="buddy" >
75-
<cstring>pbnCanvasColor</cstring>
76-
</property>
77-
</widget>
78-
</item>
79-
<item row="0" column="3" >
80-
<widget class="QToolButton" name="pbnCanvasColor" >
81-
<property name="text" >
82-
<string/>
83-
</property>
84-
</widget>
85-
</item>
86-
<item row="0" column="1" >
87-
<widget class="QToolButton" name="pbnSelectionColour" >
88-
<property name="minimumSize" >
89-
<size>
90-
<width>10</width>
91-
<height>22</height>
92-
</size>
93-
</property>
94-
<property name="text" >
95-
<string/>
96-
</property>
97-
</widget>
98-
</item>
9956
<item row="0" column="0" >
100-
<widget class="QLabel" name="textLabel1_9" >
57+
<widget class="QCheckBox" name="cbxHideSplash" >
10158
<property name="text" >
102-
<string>Selection Color:</string>
103-
</property>
104-
<property name="buddy" >
105-
<cstring>pbnSelectionColour</cstring>
59+
<string>Hide splash screen at startup</string>
10660
</property>
10761
</widget>
10862
</item>
10963
</layout>
11064
</widget>
11165
</item>
112-
<item row="1" column="0" >
66+
<item>
11367
<widget class="QGroupBox" name="groupBox_2" >
11468
<property name="title" >
11569
<string>&amp;Icon Theme</string>
@@ -177,10 +131,10 @@
177131
</layout>
178132
</widget>
179133
</item>
180-
<item row="0" column="0" >
181-
<widget class="QGroupBox" name="groupBox" >
134+
<item>
135+
<widget class="QGroupBox" name="groupBox_9" >
182136
<property name="title" >
183-
<string>&amp;Splash screen</string>
137+
<string>Default Map Appearance (Overridden by project properties)</string>
184138
</property>
185139
<layout class="QGridLayout" >
186140
<property name="margin" >
@@ -189,16 +143,84 @@
189143
<property name="spacing" >
190144
<number>6</number>
191145
</property>
146+
<item row="0" column="2" >
147+
<widget class="QLabel" name="label" >
148+
<property name="text" >
149+
<string>Background Color:</string>
150+
</property>
151+
<property name="buddy" >
152+
<cstring>pbnCanvasColor</cstring>
153+
</property>
154+
</widget>
155+
</item>
156+
<item row="0" column="3" >
157+
<widget class="QToolButton" name="pbnCanvasColor" >
158+
<property name="text" >
159+
<string/>
160+
</property>
161+
</widget>
162+
</item>
163+
<item row="0" column="1" >
164+
<widget class="QToolButton" name="pbnSelectionColour" >
165+
<property name="minimumSize" >
166+
<size>
167+
<width>10</width>
168+
<height>22</height>
169+
</size>
170+
</property>
171+
<property name="text" >
172+
<string/>
173+
</property>
174+
</widget>
175+
</item>
192176
<item row="0" column="0" >
193-
<widget class="QCheckBox" name="cbxHideSplash" >
177+
<widget class="QLabel" name="textLabel1_9" >
194178
<property name="text" >
195-
<string>Hide splash screen at startup</string>
179+
<string>Selection Color:</string>
180+
</property>
181+
<property name="buddy" >
182+
<cstring>pbnSelectionColour</cstring>
183+
</property>
184+
</widget>
185+
</item>
186+
</layout>
187+
</widget>
188+
</item>
189+
<item>
190+
<widget class="QGroupBox" name="groupBox_3" >
191+
<property name="title" >
192+
<string>Appearance</string>
193+
</property>
194+
<layout class="QVBoxLayout" >
195+
<property name="margin" >
196+
<number>9</number>
197+
</property>
198+
<property name="spacing" >
199+
<number>6</number>
200+
</property>
201+
<item>
202+
<widget class="QCheckBox" name="capitaliseCheckBox" >
203+
<property name="text" >
204+
<string>Capitalise layer name</string>
196205
</property>
197206
</widget>
198207
</item>
199208
</layout>
200209
</widget>
201210
</item>
211+
<item>
212+
<spacer>
213+
<property name="orientation" >
214+
<enum>Qt::Vertical</enum>
215+
</property>
216+
<property name="sizeHint" >
217+
<size>
218+
<width>20</width>
219+
<height>40</height>
220+
</size>
221+
</property>
222+
</spacer>
223+
</item>
202224
</layout>
203225
</widget>
204226
<widget class="QWidget" name="TabPage" >
@@ -609,7 +631,7 @@ identifying features without zooming in very close.
609631
</widget>
610632
</widget>
611633
</item>
612-
<item row="1" column="0" >
634+
<item>
613635
<layout class="QHBoxLayout" >
614636
<property name="margin" >
615637
<number>0</number>

0 commit comments

Comments
 (0)
Please sign in to comment.