RuleItem.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/RuleItem.cpp
22 */
23 
24 #include "RuleItem.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/RasterSymbolizer.h"
36 #include "../../../../se/Rule.h"
37 #include "../../../../se/Symbolizer.h"
38 #include "ColorMapItem.h"
39 
40 // Qt
41 #include <QObject>
42 
43 
45 {
46  if(s->getType() == "PointSymbolizer")
47  return new te::gm::Point(10, 10);
48 
49  if(s->getType() == "LineSymbolizer")
50  {
52 
53  gm->setPoint(0, 0, 15);
54  gm->setPoint(1, 6, 6);
55  gm->setPoint(2, 12, 15);
56  gm->setPoint(3, 18, 6);
57 
58  return gm;
59  }
60 
63 
64  ring->setPoint(0, 2, 18);
65  ring->setPoint(1, 2, 2);
66  ring->setPoint(2, 18, 2);
67  ring->setPoint(3, 18, 18);
68  ring->setPoint(4, 2, 18);
69 
70  gm->setRingN(0, ring);
71 
72  return gm;
73 }
74 
75 QIcon GetRuleIcon(const std::vector<te::se::Symbolizer*>& symbolizers)
76 {
77  te::qt::widgets::Canvas canvas(20, 20);
78 
79  // create a canvas configurer
80  te::map::CanvasConfigurer cc(&canvas);
81 
82  // number of rules defined on feature type style
83  std::size_t nSymbolizers = symbolizers.size();
84 
85  for(std::size_t j = 0; j < nSymbolizers; ++j) // for each <Symbolizer>
86  {
87  // the current symbolizer
88  te::se::Symbolizer* symb = symbolizers[j];
89 
90  // let's config de canvas based on the current symbolizer
91  cc.config(symb);
92 
93  if(symb->getType() == "RasterSymbolizer")
94  return QIcon::fromTheme("raster-symbolizer");
95 
96  std::unique_ptr<te::gm::Geometry> gm(GetRuleGeometry(symb));
97 
98  canvas.draw(gm.get());
99  } // end for each <Symbolizer>
100 
101  return QIcon(*canvas.getPixmap());
102 }
103 
104 QIcon GetRuleIcon(const te::se::Rule* rule)
105 {
106  return GetRuleIcon(rule->getSymbolizers());
107 }
108 
110 TreeItem("RULE"),
111 m_rule(rule)
112 {
113  m_icon = GetRuleIcon(rule);
114 
115  if(rule->getName())
116  m_label = *rule->getName();
117  else
118  m_label = QObject::tr("Default Rule").toUtf8().data();
119 
120  const std::vector<te::se::Symbolizer*>& symbolizers = m_rule->getSymbolizers();
121 
122  if (!symbolizers.empty())
123  {
124  // for while, consider one raster symbolizer
125  te::se::RasterSymbolizer* rasterSymbolizer = dynamic_cast<te::se::RasterSymbolizer*>(symbolizers[0]);
126 
127  if (rasterSymbolizer && rasterSymbolizer->getColorMap())
128  addChild(new ColorMapItem(rasterSymbolizer->getColorMap()));
129  }
130 }
131 
133 
135 {
136  return m_label;
137 }
138 
140 {
141  return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
142 }
143 
145 {
146  return m_icon;
147 }
148 
150 {
151  VISIBLE visible = TOTALLY;
152 
153  if (m_rule && m_rule->getMaxScaleDenominator() == 0.)
154  visible = NONE;
155 
156  return visible;
157 }
158 
159 void te::qt::widgets::RuleItem::setVisible(const VISIBLE& visible, const bool&, const bool&)
160 {
161  if (visible == TOTALLY)
162  {
164  m_rule->setMaxScaleDenominator(std::numeric_limits<double>::infinity());
165  }
166  else
167  {
170  }
171 }
172 
174 {
175  std::string toolTip;
176 
177  if (m_rule && m_rule->getDescription())
178  toolTip = m_rule->getDescription()->getTitle();
179 
180  return toolTip;
181 }
182 
184 {
185  return m_rule;
186 }
187 
189 {
190  m_icon = GetRuleIcon(rule);
191 }
192 
193 void te::qt::widgets::RuleItem::updateSymbol(const std::vector<te::se::Symbolizer*>& symbolizers)
194 {
195  m_icon = GetRuleIcon(symbolizers);
196 }
QIcon GetRuleIcon(const std::vector< te::se::Symbolizer * > &symbolizers)
Definition: RuleItem.cpp:75
te::se::Rule * getRule()
Definition: RuleItem.cpp:183
VISIBLE isVisible() const
Returns the visibilty state of the item.
Definition: RuleItem.cpp:149
std::string getAsString() const
Returns the label of the item to be presented in a Qt view.
Definition: RuleItem.cpp:134
const std::string & getTitle() const
Definition: Description.cpp:38
std::string getToolTip() const
Returns the item tooltip (for information purposes).
Definition: RuleItem.cpp:173
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
Definition: RuleItem.cpp:159
void updateSymbol(const te::se::Rule *rule)
updateSymbol
Definition: RuleItem.cpp:188
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
void setMaxScaleDenominator(const double &maxScaleDenominator)
Definition: Rule.cpp:128
Defines a hierarchical structure.
QIcon getIcon() const
Returns the image of the style as an icon.
Definition: RuleItem.cpp:144
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.
void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
std::string m_label
Label for presenting in the Qt view.
Definition: RuleItem.h:112
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
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
VISIBLE
Defines the visibility of an item.
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.
Defines a rule item.
Represents a color map of rastersymbolizer of a layer in a LayerItemModel.
Definition: ColorMapItem.h:51
virtual const std::string & getType() const =0
It returns the symbolizer type.
te::se::Rule * m_rule
Rule being used.
Definition: RuleItem.h:114
void setMinScaleDenominator(const double &minScaleDenominator)
Definition: Rule.cpp:118
const double & getMaxScaleDenominator() const
Definition: Rule.cpp:133
te::se::ColorMap * getColorMap() const
RuleItem(te::se::Rule *rule)
Constructor.
Definition: RuleItem.cpp:109
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
QIcon m_icon
Item icon.
Definition: RuleItem.h:113
const Description * getDescription() const
Definition: Rule.cpp:75
te::gm::Geometry * GetRuleGeometry(const te::se::Symbolizer *s)
Definition: RuleItem.cpp:44
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
A class that represents a color map of rastersymbolizer of a layer in a LayerItemModel.
Qt::ItemFlags flags()
Returns the flags to be used by the model.
Definition: RuleItem.cpp:139
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
const std::string * getName() const
Definition: Rule.cpp:64