~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/legend/qgslegendlayerfile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 by Tim Sutton   *
3
 
 *   aps02ts@macbuntu   *
4
 
 *                                                                         *
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.                                   *
9
 
 *                                                                         *
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.                          *
14
 
 *                                                                         *
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>
26
 
#include <QPainter>
27
 
 
28
 
QgsLegendLayerFile::QgsLegendLayerFile(QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer)
29
 
    : QgsLegendItem(theLegendItem, theString), mLayer(theLayer)
30
 
{
31
 
  mType = LEGEND_LAYER_FILE;
32
 
  QPixmap originalPixmap = getOriginalPixmap();
33
 
  //ensure the overview glasses is painted if necessary
34
 
  if(mLayer->showInOverviewStatus())
35
 
  {
36
 
      QPixmap inOverviewPixmap(QgsApplication::themePath()+"/mActionInOverview.png");
37
 
      QPainter p(&originalPixmap);
38
 
      p.drawPixmap(0,0,inOverviewPixmap);
39
 
  }
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);
45
 
}
46
 
 
47
 
QgsLegendLayerFile::QgsLegendLayerFile(QString theString, QgsMapLayer* theLayer)
48
 
    : QgsLegendItem(), mLayer(theLayer)
49
 
{
50
 
  mType = LEGEND_LAYER_FILE;
51
 
  QPixmap originalPixmap = getOriginalPixmap();
52
 
  //ensure the overview glasses is painted if necessary
53
 
  if(mLayer->showInOverviewStatus())
54
 
  {
55
 
    QPixmap inOverviewPixmap(QgsApplication::themePath()+"/mActionInOverview.png");
56
 
    QPainter p(&originalPixmap);
57
 
    p.drawPixmap(0,0,inOverviewPixmap);
58
 
  }
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);
64
 
}
65
 
 
66
 
 
67
 
QgsLegendLayerFile::~QgsLegendLayerFile()
68
 
{
69
 
}
70
 
 
71
 
QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(LEGEND_ITEM_TYPE type)
72
 
{
73
 
  return NO_ACTION;
74
 
}
75
 
 
76
 
QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(const QgsLegendItem* li) const
77
 
{
78
 
  if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE)
79
 
    {
80
 
      if(li->parent() == this->parent())
81
 
        {
82
 
          return REORDER;
83
 
        }
84
 
    }
85
 
  return NO_ACTION;
86
 
}
87
 
 
88
 
QPixmap QgsLegendLayerFile::getOriginalPixmap() const
89
 
{
90
 
    QPixmap myPixmap(QgsApplication::themePath()+"mActionFileSmall.png");
91
 
    return myPixmap;
92
 
}
93
 
 
94
 
void QgsLegendLayerFile::setLegendPixmap(const QPixmap& pix)
95
 
{
96
 
  QIcon theIcon(pix);
97
 
  setIcon(0, theIcon);
98
 
}
99
 
 
100
 
void QgsLegendLayerFile::setIconAppearance(bool inOverview,
101
 
                                           bool editable)
102
 
{
103
 
  QPixmap newIcon(getOriginalPixmap());
104
 
 
105
 
  if (inOverview)
106
 
  {
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);
111
 
    p.end();
112
 
  }
113
 
  
114
 
  if (editable)
115
 
  {
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);
120
 
    p.end();
121
 
  }
122
 
 
123
 
  QIcon theIcon(newIcon);
124
 
  setIcon(0, theIcon);
125
 
 
126
 
  //also update the icon of the legend layer
127
 
  ((QgsLegendLayer*)(parent()->parent()))->updateIcon();
128
 
}
129
 
 
130
 
void QgsLegendLayerFile::toggleCheckBox(bool state)
131
 
{
132
 
  //todo
133
 
}
134
 
 
135
 
QString QgsLegendLayerFile::nameFromLayer(QgsMapLayer* layer)
136
 
{
137
 
  QString sourcename = layer->source(); //todo: move this duplicated code into a new function
138
 
  if(sourcename.startsWith("host", false))
139
 
    {
140
 
      //this layer is a database layer
141
 
      //modify source string such that password is not visible
142
 
      sourcename = layer->name();
143
 
    }
144
 
  else
145
 
    {
146
 
      //modify source name such that only the file is visible
147
 
      sourcename = layer->source().section('/',-1,-1);
148
 
    }
149
 
  return sourcename;
150
 
}
151