1
/***************************************************************************
2
* Copyright (C) 2005 by Tim Sutton *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#include "qgsapplication.h"
21
#include "qgslegend.h"
22
#include "qgslegendlayer.h"
23
#include "qgslegendlayerfile.h"
24
#include "qgsmaplayer.h"
25
#include <QCoreApplication>
28
QgsLegendLayerFile::QgsLegendLayerFile(QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer)
29
: QgsLegendItem(theLegendItem, theString), mLayer(theLayer)
31
mType = LEGEND_LAYER_FILE;
32
QPixmap originalPixmap = getOriginalPixmap();
33
//ensure the overview glasses is painted if necessary
34
if(mLayer->showInOverviewStatus())
36
QPixmap inOverviewPixmap(QgsApplication::themePath()+"/mActionInOverview.png");
37
QPainter p(&originalPixmap);
38
p.drawPixmap(0,0,inOverviewPixmap);
40
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
41
QIcon originalIcon(originalPixmap);
42
setCheckState (0, Qt::Checked );
43
setText(0, theString);
44
setIcon(0, originalIcon);
47
QgsLegendLayerFile::QgsLegendLayerFile(QString theString, QgsMapLayer* theLayer)
48
: QgsLegendItem(), mLayer(theLayer)
50
mType = LEGEND_LAYER_FILE;
51
QPixmap originalPixmap = getOriginalPixmap();
52
//ensure the overview glasses is painted if necessary
53
if(mLayer->showInOverviewStatus())
55
QPixmap inOverviewPixmap(QgsApplication::themePath()+"/mActionInOverview.png");
56
QPainter p(&originalPixmap);
57
p.drawPixmap(0,0,inOverviewPixmap);
59
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
60
QIcon originalIcon(originalPixmap);
61
setCheckState (0, Qt::Checked );
62
setText(0, theString);
63
setIcon(0, originalIcon);
67
QgsLegendLayerFile::~QgsLegendLayerFile()
71
QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(LEGEND_ITEM_TYPE type)
76
QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(const QgsLegendItem* li) const
78
if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE)
80
if(li->parent() == this->parent())
88
QPixmap QgsLegendLayerFile::getOriginalPixmap() const
90
QPixmap myPixmap(QgsApplication::themePath()+"mActionFileSmall.png");
94
void QgsLegendLayerFile::setLegendPixmap(const QPixmap& pix)
100
void QgsLegendLayerFile::setIconAppearance(bool inOverview,
103
QPixmap newIcon(getOriginalPixmap());
107
// Overlay the overview icon on the default icon
108
QPixmap myPixmap(QgsApplication::themePath()+"mIconOverview.png");
109
QPainter p(&newIcon);
110
p.drawPixmap(0,0,myPixmap);
116
// Overlay the editable icon on the default icon
117
QPixmap myPixmap(QgsApplication::themePath()+"mIconEditable.png");
118
QPainter p(&newIcon);
119
p.drawPixmap(0,0,myPixmap);
123
QIcon theIcon(newIcon);
126
//also update the icon of the legend layer
127
((QgsLegendLayer*)(parent()->parent()))->updateIcon();
130
void QgsLegendLayerFile::toggleCheckBox(bool state)
135
QString QgsLegendLayerFile::nameFromLayer(QgsMapLayer* layer)
137
QString sourcename = layer->source(); //todo: move this duplicated code into a new function
138
if(sourcename.startsWith("host", false))
140
//this layer is a database layer
141
//modify source string such that password is not visible
142
sourcename = layer->name();
146
//modify source name such that only the file is visible
147
sourcename = layer->source().section('/',-1,-1);