Skip to content

Commit

Permalink
Legend layer now uses layer type specific icons in legend. Outline- a…
Browse files Browse the repository at this point in the history
…nd fillcolorlabels now are fully colored

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4686 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 15, 2006
1 parent f1aa8d8 commit d1a0bf8
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/gui/qgsmaplayer.h
Expand Up @@ -273,6 +273,9 @@ class QgsMapLayer : public QObject
// also sets the contents of the r2 parameter
bool projectExtent(QgsRect& extent, QgsRect& r2);

/**Returns the path to an icon which characterises the type of layer*/
virtual QString layerTypeIconPath() = 0;

void setLegendSymbologyGroupParent(QgsLegendSymbologyGroup* item) {mLegendSymbologyGroupParent = item;}
const QgsLegendSymbologyGroup* legendSymbologyGroupParent() {return mLegendSymbologyGroupParent;}

Expand Down
28 changes: 27 additions & 1 deletion src/gui/qgsvectorlayer.cpp
Expand Up @@ -59,6 +59,7 @@
#include <qwidget.h>
#include <qglobal.h>

#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgsproject.h"
#include "qgsrect.h"
Expand Down Expand Up @@ -2815,6 +2816,24 @@ bool QgsVectorLayer::addFeatures(std::vector<QgsFeature*>* features, bool makeSe
return true;
}

QString QgsVectorLayer::layerTypeIconPath()
{
QString myThemePath = QgsApplication::themePath();
switch(vectorType())
{
case Point:
return (myThemePath+"/mIconPointLayer.png");
break;
case Line:
return (myThemePath+"/mIconLineLayer.png");
break;
case Polygon:
return (myThemePath+"/mIconPolygonLayer.png");
default:
return (myThemePath+"/mIconLayer.png");
}
}

void QgsVectorLayer::refreshLegend()
{
if(mLegendSymbologyGroupParent && m_renderer)
Expand Down Expand Up @@ -2874,11 +2893,18 @@ bool QgsVectorLayer::copySymbologySettings(const QgsMapLayer& other)

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


const QgsVectorLayer* otherVectorLayer = dynamic_cast<const QgsVectorLayer*>(&other);
if(otherVectorLayer)
{

if(otherVectorLayer->vectorType() != vectorType())
{
return false;
}

const std::vector<QgsField> fieldsThis = dataProvider->fields();
const std::vector<QgsField> fieldsOther = otherVectorLayer ->dataProvider->fields();

Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsvectorlayer.h
Expand Up @@ -145,6 +145,9 @@ const QString displayField() const { return fieldIndex; }
*/
bool addFeatures(std::vector<QgsFeature*>* features, bool makeSelected = TRUE);

/**Returns the path to an icon which characterises the type of layer*/
QString layerTypeIconPath();

/**Fill the pixmaps and labels of the renderers into the treeview legend*/
void refreshLegend();

Expand Down
1 change: 1 addition & 0 deletions src/legend/qgslegend.cpp
Expand Up @@ -444,6 +444,7 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
mStateOfCheckBoxes.insert(std::make_pair(llayer, Qt::Checked)); //insert the check state into the map to query for changes later
QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup(llayer,QString("Files"));
QgsLegendLayerFile * llfile = new QgsLegendLayerFile(llfgroup, QgsLegendLayerFile::nameFromLayer(layer), layer);
llayer->setLayerTypeIcon();

//set the correct check state
blockSignals(true);
Expand Down
14 changes: 14 additions & 0 deletions src/legend/qgslegendlayer.cpp
Expand Up @@ -75,6 +75,20 @@ QgsLegendLayer::~QgsLegendLayer()
mType=LEGEND_LAYER;
}

void QgsLegendLayer::setLayerTypeIcon()
{
QgsMapLayer* firstLayer = firstMapLayer();
if(firstLayer)
{
QFileInfo file(firstLayer->layerTypeIconPath());
if(file.exists())
{
QIcon myIcon(file.absoluteFilePath());
setIcon(0, myIcon);
}
}
}

bool QgsLegendLayer::isLeafNode()
{
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/legend/qgslegendlayer.h
Expand Up @@ -22,6 +22,7 @@

//#include <qobject.h>
#include <qgslegenditem.h>
#include <QFileInfo>

class QgsLegendLayer;
class QgsLegendLayerFile;
Expand All @@ -41,6 +42,9 @@ class QgsLegendLayer : public QgsLegendItem, public QObject //for signal/ slot
QgsLegendLayer(QTreeWidget* ,QString);
QgsLegendLayer(QString name);
~QgsLegendLayer();
/**Sets an icon characterising the type of layer(s) it contains.
Note: cannot be in the constructor because layers are added after creation*/
void setLayerTypeIcon();
bool isLeafNode();
QgsLegendItem::DRAG_ACTION accept(LEGEND_ITEM_TYPE type);
QgsLegendItem::DRAG_ACTION accept(const QgsLegendItem* li) const;
Expand Down
5 changes: 5 additions & 0 deletions src/raster/qgsrasterlayer.cpp
Expand Up @@ -5194,6 +5194,11 @@ void QgsRasterLayer::showStatusMessage(QString const & theMessage)
emit setStatus(theMessage);
}

QString QgsRasterLayer::layerTypeIconPath()
{
return (QgsApplication::themePath()+"/mIconLayer.png");
}

void QgsRasterLayer::refreshLegend()
{
if(mLegendSymbologyGroupParent)
Expand Down
3 changes: 3 additions & 0 deletions src/raster/qgsrasterlayer.h
Expand Up @@ -742,6 +742,9 @@ class QgsRasterLayer : public QgsMapLayer
/** Return time stamp for given file name */
static QDateTime lastModified ( QString const & name );

/**Returns the path to an icon which characterises the type of layer*/
QString layerTypeIconPath();

/**Refresh the symbology part of the legend
by adding a child item to mLegendSymbologyGroupParent*/
void refreshLegend();
Expand Down
6 changes: 6 additions & 0 deletions src/ui/qgscontcoldialogbase.ui
Expand Up @@ -89,6 +89,9 @@
<height>22</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -154,6 +157,9 @@
<height>22</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down
26 changes: 16 additions & 10 deletions src/ui/qgssisydialogbase.ui
Expand Up @@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>330</width>
<height>391</height>
<width>443</width>
<height>444</height>
</rect>
</property>
<property name="sizePolicy" >
Expand Down Expand Up @@ -37,10 +37,10 @@
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>8</number>
<number>4</number>
</property>
<property name="spacing" >
<number>6</number>
<number>4</number>
</property>
<item row="0" column="4" >
<widget class="QToolButton" name="bdiag" >
Expand All @@ -54,8 +54,8 @@
</property>
<property name="minimumSize" >
<size>
<width>60</width>
<height>23</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize" >
Expand Down Expand Up @@ -87,8 +87,8 @@
</property>
<property name="minimumSize" >
<size>
<width>60</width>
<height>23</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize" >
Expand Down Expand Up @@ -139,8 +139,8 @@
</property>
<property name="minimumSize" >
<size>
<width>60</width>
<height>23</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize" >
Expand Down Expand Up @@ -602,6 +602,9 @@
<height>22</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down Expand Up @@ -681,6 +684,9 @@
<height>22</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
Expand Down

0 comments on commit d1a0bf8

Please sign in to comment.