LegendItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9 
10 TerraLib 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 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21 * \file layer/explorer/LegendItem.cpp
22 */
23 
24 #include "LegendItem.h"
25 
26 // TerraLib
27 #include "../../canvas/Canvas.h"
28 #include "../../canvas/MapDisplay.h"
29 #include "../../../../geometry/LineString.h"
30 #include "../../../../geometry/Point.h"
31 #include "../../../../geometry/Polygon.h"
32 #include "../../../../maptools/CanvasConfigurer.h"
33 #include "../../../../se/Description.h"
34 #include "../../../../se/FeatureTypeStyle.h"
35 #include "../../../../se/Rule.h"
36 #include "../../../../se/Symbolizer.h"
37 
38 // Qt
39 #include <QObject>
40 
41 
43 {
44  if(s->getType() == "PointSymbolizer")
45  return new te::gm::Point(10, 10);
46 
47  if(s->getType() == "LineSymbolizer")
48  {
50 
51  gm->setPoint(0, 0, 15);
52  gm->setPoint(1, 6, 6);
53  gm->setPoint(2, 12, 15);
54  gm->setPoint(3, 18, 6);
55 
56  return gm;
57  }
58 
61 
62  ring->setPoint(0, 2, 18);
63  ring->setPoint(1, 2, 2);
64  ring->setPoint(2, 18, 2);
65  ring->setPoint(3, 18, 18);
66  ring->setPoint(4, 2, 18);
67 
68  gm->setRingN(0, ring);
69 
70  return gm;
71 }
72 
73 QIcon GetIcon(const std::vector<te::se::Symbolizer*>& symbolizers)
74 {
75  te::qt::widgets::Canvas canvas(20, 20);
76 
77  // create a canvas configurer
78  te::map::CanvasConfigurer cc(&canvas);
79 
80  // number of rules defined on feature type style
81  std::size_t nSymbolizers = symbolizers.size();
82 
83  for(std::size_t j = 0; j < nSymbolizers; ++j) // for each <Symbolizer>
84  {
85  // the current symbolizer
86  te::se::Symbolizer* symb = symbolizers[j];
87 
88  // let's config de canvas based on the current symbolizer
89  cc.config(symb);
90 
91  if(symb->getType() == "RasterSymbolizer")
92  return QIcon::fromTheme("raster-symbolizer");
93 
94  std::unique_ptr<te::gm::Geometry> gm(GetGeometry(symb));
95 
96  canvas.draw(gm.get());
97  } // end for each <Symbolizer>
98 
99  return QIcon(*canvas.getPixmap());
100 }
101 
102 QIcon GetIcon(const te::se::Rule* rule)
103 {
104  return GetIcon(rule->getSymbolizers());
105 }
106 
108 TreeItem("LEGEND")
109 {
110  m_icon = GetIcon(rule);
111 
112  if(rule->getDescription())
113  m_label = rule->getDescription()->getTitle();
114 
115  if(rule->getName())
116  m_label = *rule->getName();
117 
118  m_label = QObject::tr("Style").toUtf8().data();
119 }
120 
121 te::qt::widgets::LegendItem::LegendItem(const std::string& label, const std::vector<te::se::Symbolizer*>& symbolizers):
122 TreeItem("LEGEND"),
123 m_label(label)
124 {
125  m_icon = GetIcon(symbolizers);
126 }
127 
129 
131 {
132  return m_label;
133 }
134 
136 {
137  return Qt::ItemIsDropEnabled | Qt::ItemIsEnabled;
138 }
139 
141 {
142  return m_icon;
143 }
144 
146 {
147  m_icon = GetIcon(rule);
148 }
149 
150 void te::qt::widgets::LegendItem::updateSymbol(const std::vector<te::se::Symbolizer*>& symbolizers)
151 {
152  m_icon = GetIcon(symbolizers);
153 }
void updateSymbol(const te::se::Rule *rule)
updateSymbol
Definition: LegendItem.cpp:145
const std::string & getTitle() const
Definition: Description.cpp:38
Qt::ItemFlags flags()
Returns the flags to be used by the model.
Definition: LegendItem.cpp:135
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
Defines a legend item.
QIcon getIcon() const
Returns the image of the style as an icon.
Definition: LegendItem.cpp:140
std::string getAsString() const
Returns the label of the item to be presented in a Qt view.
Definition: LegendItem.cpp:130
LegendItem(const te::se::Rule *rule)
Constructor.
Definition: LegendItem.cpp:107
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
Defines a hierarchical structure.
std::string m_label
Label for presenting in the Qt view.
Definition: LegendItem.h:113
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
A point with x and y coordinate values.
Definition: Point.h:50
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:158
QIcon m_icon
Item icon.
Definition: LegendItem.h:114
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
QPixmap * getPixmap() const
It returns the internal pixmap used to draw geographical objects.
virtual const std::string & getType() const =0
It returns the symbolizer type.
te::gm::Geometry * GetGeometry(const te::se::Symbolizer *s)
Definition: LegendItem.cpp:42
QIcon GetIcon(const std::vector< te::se::Symbolizer * > &symbolizers)
Definition: LegendItem.cpp:73
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
const Description * getDescription() const
Definition: Rule.cpp:75
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
const std::string * getName() const
Definition: Rule.cpp:64