All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SymbologyPreview.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 terralib/qt/widgets/se/SymbologyPreview.cpp
22 
23  \brief Static class used to generate preview of Symbology elements.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Polygon.h"
28 #include "../../../geometry/LinearRing.h"
29 #include "../../../geometry/Point.h"
30 #include "../../../maptools/CanvasConfigurer.h"
31 #include "../../../se/Rule.h"
32 #include "../../../se/Symbolizer.h"
33 #include "../canvas/Canvas.h"
34 #include "SymbologyPreview.h"
35 #include "Symbol.h"
36 
37 // STL
38 #include <cassert>
39 
40 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Symbolizer* symb, const QSize& size)
41 {
42  double offset = 2.0;
43 
44  te::gm::Geometry* geom = 0;
45  if(symb->getType() == "PolygonSymbolizer")
46  {
49  ring->setPoint(0, offset, offset);
50  ring->setPoint(1, size.width() - offset, offset);
51  ring->setPoint(2, size.width() - offset, size.height() - offset);
52  ring->setPoint(3, offset, size.height() - offset);
53  ring->setPoint(4, offset, offset);
54  polygon->setRingN(0, ring);
55  geom = polygon;
56  }
57  else if(symb->getType() == "LineSymbolizer")
58  {
60  line->setPoint(0, offset, size.height() * 0.5);
61  line->setPoint(1, size.width() - offset, size.height() * 0.5);
62  geom = line;
63  }
64  else if(symb->getType() == "PointSymbolizer")
65  geom = new te::gm::Point(size.width() * 0.5, size.height() * 0.5);
66 
67  QPixmap result = build(symb, geom, size);
68 
69  delete geom;
70 
71  return result;
72 }
73 
74 QPixmap te::qt::widgets::SymbologyPreview::build(const std::vector<te::se::Symbolizer*>& symbs, const QSize& size)
75 {
76  QPixmap result(size);
77  result.fill(Qt::transparent);
78 
79  // Let's draw!
80  QPainter painter(&result);
81  for(std::size_t i = 0; i < symbs.size(); ++i)
82  {
83  QPixmap pix = build(symbs[i], size);
84  painter.drawPixmap(0, 0, pix);
85  }
86 
87  return result;
88 }
89 
90 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Rule* rule, const QSize& size)
91 {
92  assert(rule);
93 
94  return build(rule->getSymbolizers(), size);
95 }
96 
97 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Symbolizer* symb, const te::gm::Geometry* geom, const QSize& size)
98 {
99  assert(symb);
100 
101  if(symb->getType() == "RasterSymbolizer")
102  return QPixmap();
103 
104  assert(geom);
105  assert(!size.isEmpty());
106 
107  // Creating a canvas...
108  te::qt::widgets::Canvas canvas(size.width(), size.height());
109  canvas.setWindow(0.0, 0.0, size.width(), size.height());
110  canvas.setBackgroundColor(te::color::RGBAColor(0, 0, 0, TE_TRANSPARENT));
111 
112  // Configuring...
113  te::map::CanvasConfigurer cc(&canvas);
114  cc.config(symb);
115 
116  // Let's draw!
117  canvas.draw(geom);
118 
119  return *canvas.getPixmap();
120 }
121 
122 QPixmap te::qt::widgets::SymbologyPreview::build(const std::vector<te::se::Symbolizer*>& symbs, const te::gm::Geometry* geom, const QSize& size)
123 {
124  QPixmap result(size);
125  result.fill(Qt::transparent);
126 
127  // Let's draw!
128  QPainter painter(&result);
129  for(std::size_t i = 0; i < symbs.size(); ++i)
130  {
131  QPixmap pix = build(symbs[i], geom, size);
132  painter.drawPixmap(0, 0, pix);
133  }
134 
135  return result;
136 }
137 
138 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Rule* rule, const te::gm::Geometry* geom, const QSize& size)
139 {
140  assert(rule);
141 
142  return build(rule->getSymbolizers(), geom, size);
143 }
144 
145 QPixmap te::qt::widgets::SymbologyPreview::build(const te::qt::widgets::Symbol* symbol, const te::gm::Geometry* geom, const QSize& size)
146 {
147  assert(symbol);
148 
149  return build(symbol->getSymbolizers(), geom, size);
150 }
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.
virtual const std::string & getType() const =0
It returns the symbolizer type.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:152
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
Definition: Config.h:46
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:78
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
A canvas built on top of Qt.
Definition: Canvas.h:54
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.
Definition: LineString.cpp:313
Static class used to generate preview of Symbology elements.
This class represents a symbol.
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
Definition: Canvas.cpp:147
const std::vector< te::se::Symbolizer * > & getSymbolizers() const
It returns the list of Symbolizers that compose the symbol.
Definition: Symbol.cpp:77