17
17
* Free Software Foundation, Inc., *
18
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
19
***************************************************************************/
20
+
21
+ #include " qgsapplication.h"
20
22
#include " qgslegendlayer.h"
21
23
#include " qgslegendlayerfile.h"
22
24
#include " qgslegendlayerfilegroup.h"
23
25
#include " qgsmaplayer.h"
24
26
#include < iostream>
25
27
#include < QCoreApplication>
26
28
#include < QIcon>
29
+ #include < QPainter>
27
30
28
31
QgsLegendLayer::QgsLegendLayer (QTreeWidgetItem* parent,QString name)
29
32
: QgsLegendItem(parent, name)
@@ -57,7 +60,7 @@ QgsLegendLayer::~QgsLegendLayer()
57
60
58
61
void QgsLegendLayer::setLayerTypeIcon ()
59
62
{
60
- QgsMapLayer* firstLayer = firstMapLayer ();
63
+ /* QgsMapLayer* firstLayer = firstMapLayer();
61
64
if(firstLayer)
62
65
{
63
66
QFileInfo file(firstLayer->layerTypeIconPath());
@@ -66,7 +69,9 @@ void QgsLegendLayer::setLayerTypeIcon()
66
69
QIcon myIcon(file.absoluteFilePath());
67
70
setIcon(0, myIcon);
68
71
}
69
- }
72
+ }*/
73
+ QIcon myIcon (getOriginalPixmap ());
74
+ setIcon (0 , myIcon);
70
75
}
71
76
72
77
bool QgsLegendLayer::isLeafNode ()
@@ -110,7 +115,7 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayer::accept(const QgsLegendItem* li) const
110
115
return NO_ACTION;
111
116
}
112
117
113
- QgsMapLayer* QgsLegendLayer::firstMapLayer ()
118
+ QgsMapLayer* QgsLegendLayer::firstMapLayer () const
114
119
{
115
120
// first find the legend layer file group
116
121
QgsLegendLayerFileGroup* llfg = 0 ;
@@ -228,3 +233,52 @@ void QgsLegendLayer::updateCheckState()
228
233
treeWidget ()->blockSignals (false );
229
234
}
230
235
}
236
+
237
+ void QgsLegendLayer::updateIcon ()
238
+ {
239
+ QPixmap newIcon (getOriginalPixmap ());
240
+
241
+ QgsMapLayer* theLayer = firstMapLayer ();
242
+
243
+ if (mapLayers ().size () == 1 )
244
+ {
245
+
246
+ // overview
247
+ if (theLayer->showInOverviewStatus ())
248
+ {
249
+ // Overlay the overview icon on the default icon
250
+ QPixmap myPixmap (QgsApplication::themePath ()+" mIconOverview.png" );
251
+ QPainter p (&newIcon);
252
+ p.drawPixmap (0 ,0 ,myPixmap);
253
+ p.end ();
254
+ }
255
+
256
+ // editable
257
+ if (theLayer->isEditable ())
258
+ {
259
+ // Overlay the editable icon on the default icon
260
+ QPixmap myPixmap (QgsApplication::themePath ()+" mIconEditable.png" );
261
+ QPainter p (&newIcon);
262
+ p.drawPixmap (0 ,0 ,myPixmap);
263
+ p.end ();
264
+ }
265
+ }
266
+
267
+ QIcon theIcon (newIcon);
268
+ setIcon (0 , theIcon);
269
+ }
270
+
271
+ QPixmap QgsLegendLayer::getOriginalPixmap () const
272
+ {
273
+ QgsMapLayer* firstLayer = firstMapLayer ();
274
+ if (firstLayer)
275
+ {
276
+ QFileInfo file (firstLayer->layerTypeIconPath ());
277
+ if (file.exists ())
278
+ {
279
+ return QPixmap (file.absoluteFilePath ());
280
+ }
281
+ }
282
+ QPixmap emptyPixmap;
283
+ return emptyPixmap;
284
+ }
0 commit comments