Skip to content

Commit 02ff1dd

Browse files
author
mhugent
committedJan 15, 2006
Legend layer now uses layer type specific icons in legend. Outline- and fillcolorlabels now are fully colored
git-svn-id: http://svn.osgeo.org/qgis/trunk@4686 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 41d1f81 commit 02ff1dd

File tree

10 files changed

+82
-11
lines changed

10 files changed

+82
-11
lines changed
 

‎src/gui/qgsmaplayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class QgsMapLayer : public QObject
273273
// also sets the contents of the r2 parameter
274274
bool projectExtent(QgsRect& extent, QgsRect& r2);
275275

276+
/**Returns the path to an icon which characterises the type of layer*/
277+
virtual QString layerTypeIconPath() = 0;
278+
276279
void setLegendSymbologyGroupParent(QgsLegendSymbologyGroup* item) {mLegendSymbologyGroupParent = item;}
277280
const QgsLegendSymbologyGroup* legendSymbologyGroupParent() {return mLegendSymbologyGroupParent;}
278281

‎src/gui/qgsvectorlayer.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <qwidget.h>
6060
#include <qglobal.h>
6161

62+
#include "qgsapplication.h"
6263
#include "qgisapp.h"
6364
#include "qgsproject.h"
6465
#include "qgsrect.h"
@@ -2815,6 +2816,24 @@ bool QgsVectorLayer::addFeatures(std::vector<QgsFeature*>* features, bool makeSe
28152816
return true;
28162817
}
28172818

2819+
QString QgsVectorLayer::layerTypeIconPath()
2820+
{
2821+
QString myThemePath = QgsApplication::themePath();
2822+
switch(vectorType())
2823+
{
2824+
case Point:
2825+
return (myThemePath+"/mIconPointLayer.png");
2826+
break;
2827+
case Line:
2828+
return (myThemePath+"/mIconLineLayer.png");
2829+
break;
2830+
case Polygon:
2831+
return (myThemePath+"/mIconPolygonLayer.png");
2832+
default:
2833+
return (myThemePath+"/mIconLayer.png");
2834+
}
2835+
}
2836+
28182837
void QgsVectorLayer::refreshLegend()
28192838
{
28202839
if(mLegendSymbologyGroupParent && m_renderer)
@@ -2874,11 +2893,18 @@ bool QgsVectorLayer::copySymbologySettings(const QgsMapLayer& other)
28742893

28752894
bool QgsVectorLayer::isSymbologyCompatible(const QgsMapLayer& other) const
28762895
{
2877-
//vector layers are symbology compatible if they have the same sequence of numerical/ non numerical fields and the same field names
2896+
//vector layers are symbology compatible if they have the same type, the same sequence of numerical/ non numerical fields and the same field names
2897+
28782898

28792899
const QgsVectorLayer* otherVectorLayer = dynamic_cast<const QgsVectorLayer*>(&other);
28802900
if(otherVectorLayer)
28812901
{
2902+
2903+
if(otherVectorLayer->vectorType() != vectorType())
2904+
{
2905+
return false;
2906+
}
2907+
28822908
const std::vector<QgsField> fieldsThis = dataProvider->fields();
28832909
const std::vector<QgsField> fieldsOther = otherVectorLayer ->dataProvider->fields();
28842910

‎src/gui/qgsvectorlayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ const QString displayField() const { return fieldIndex; }
145145
*/
146146
bool addFeatures(std::vector<QgsFeature*>* features, bool makeSelected = TRUE);
147147

148+
/**Returns the path to an icon which characterises the type of layer*/
149+
QString layerTypeIconPath();
150+
148151
/**Fill the pixmaps and labels of the renderers into the treeview legend*/
149152
void refreshLegend();
150153

‎src/legend/qgslegend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
444444
mStateOfCheckBoxes.insert(std::make_pair(llayer, Qt::Checked)); //insert the check state into the map to query for changes later
445445
QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup(llayer,QString("Files"));
446446
QgsLegendLayerFile * llfile = new QgsLegendLayerFile(llfgroup, QgsLegendLayerFile::nameFromLayer(layer), layer);
447+
llayer->setLayerTypeIcon();
447448

448449
//set the correct check state
449450
blockSignals(true);

‎src/legend/qgslegendlayer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ QgsLegendLayer::~QgsLegendLayer()
7575
mType=LEGEND_LAYER;
7676
}
7777

78+
void QgsLegendLayer::setLayerTypeIcon()
79+
{
80+
QgsMapLayer* firstLayer = firstMapLayer();
81+
if(firstLayer)
82+
{
83+
QFileInfo file(firstLayer->layerTypeIconPath());
84+
if(file.exists())
85+
{
86+
QIcon myIcon(file.absoluteFilePath());
87+
setIcon(0, myIcon);
88+
}
89+
}
90+
}
91+
7892
bool QgsLegendLayer::isLeafNode()
7993
{
8094
return false;

‎src/legend/qgslegendlayer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
//#include <qobject.h>
2424
#include <qgslegenditem.h>
25+
#include <QFileInfo>
2526

2627
class QgsLegendLayer;
2728
class QgsLegendLayerFile;
@@ -41,6 +42,9 @@ class QgsLegendLayer : public QgsLegendItem, public QObject //for signal/ slot
4142
QgsLegendLayer(QTreeWidget* ,QString);
4243
QgsLegendLayer(QString name);
4344
~QgsLegendLayer();
45+
/**Sets an icon characterising the type of layer(s) it contains.
46+
Note: cannot be in the constructor because layers are added after creation*/
47+
void setLayerTypeIcon();
4448
bool isLeafNode();
4549
QgsLegendItem::DRAG_ACTION accept(LEGEND_ITEM_TYPE type);
4650
QgsLegendItem::DRAG_ACTION accept(const QgsLegendItem* li) const;

‎src/raster/qgsrasterlayer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5194,6 +5194,11 @@ void QgsRasterLayer::showStatusMessage(QString const & theMessage)
51945194
emit setStatus(theMessage);
51955195
}
51965196

5197+
QString QgsRasterLayer::layerTypeIconPath()
5198+
{
5199+
return (QgsApplication::themePath()+"/mIconLayer.png");
5200+
}
5201+
51975202
void QgsRasterLayer::refreshLegend()
51985203
{
51995204
if(mLegendSymbologyGroupParent)

‎src/raster/qgsrasterlayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ class QgsRasterLayer : public QgsMapLayer
742742
/** Return time stamp for given file name */
743743
static QDateTime lastModified ( QString const & name );
744744

745+
/**Returns the path to an icon which characterises the type of layer*/
746+
QString layerTypeIconPath();
747+
745748
/**Refresh the symbology part of the legend
746749
by adding a child item to mLegendSymbologyGroupParent*/
747750
void refreshLegend();

‎src/ui/qgscontcoldialogbase.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
<height>22</height>
9090
</size>
9191
</property>
92+
<property name="autoFillBackground" >
93+
<bool>true</bool>
94+
</property>
9295
<property name="frameShape" >
9396
<enum>QFrame::StyledPanel</enum>
9497
</property>
@@ -154,6 +157,9 @@
154157
<height>22</height>
155158
</size>
156159
</property>
160+
<property name="autoFillBackground" >
161+
<bool>true</bool>
162+
</property>
157163
<property name="frameShape" >
158164
<enum>QFrame::StyledPanel</enum>
159165
</property>

‎src/ui/qgssisydialogbase.ui

Lines changed: 16 additions & 10 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>330</width>
12-
<height>391</height>
11+
<width>443</width>
12+
<height>444</height>
1313
</rect>
1414
</property>
1515
<property name="sizePolicy" >
@@ -37,10 +37,10 @@
3737
</property>
3838
<layout class="QGridLayout" >
3939
<property name="margin" >
40-
<number>8</number>
40+
<number>4</number>
4141
</property>
4242
<property name="spacing" >
43-
<number>6</number>
43+
<number>4</number>
4444
</property>
4545
<item row="0" column="4" >
4646
<widget class="QToolButton" name="bdiag" >
@@ -54,8 +54,8 @@
5454
</property>
5555
<property name="minimumSize" >
5656
<size>
57-
<width>60</width>
58-
<height>23</height>
57+
<width>0</width>
58+
<height>0</height>
5959
</size>
6060
</property>
6161
<property name="maximumSize" >
@@ -87,8 +87,8 @@
8787
</property>
8888
<property name="minimumSize" >
8989
<size>
90-
<width>60</width>
91-
<height>23</height>
90+
<width>0</width>
91+
<height>0</height>
9292
</size>
9393
</property>
9494
<property name="maximumSize" >
@@ -139,8 +139,8 @@
139139
</property>
140140
<property name="minimumSize" >
141141
<size>
142-
<width>60</width>
143-
<height>23</height>
142+
<width>0</width>
143+
<height>0</height>
144144
</size>
145145
</property>
146146
<property name="maximumSize" >
@@ -602,6 +602,9 @@
602602
<height>22</height>
603603
</size>
604604
</property>
605+
<property name="autoFillBackground" >
606+
<bool>true</bool>
607+
</property>
605608
<property name="frameShape" >
606609
<enum>QFrame::StyledPanel</enum>
607610
</property>
@@ -681,6 +684,9 @@
681684
<height>22</height>
682685
</size>
683686
</property>
687+
<property name="autoFillBackground" >
688+
<bool>true</bool>
689+
</property>
684690
<property name="frameShape" >
685691
<enum>QFrame::StyledPanel</enum>
686692
</property>

0 commit comments

Comments
 (0)
Please sign in to comment.