All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SymbologyPreview.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 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 // Qt
38 #include <QIcon>
39 
40 // STL
41 #include <cassert>
42 
43 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Symbolizer* symb, const QSize& size)
44 {
45  double offset = 2.0;
46 
47  te::gm::Geometry* geom = 0;
48  if(symb->getType() == "PolygonSymbolizer")
49  {
52  ring->setPoint(0, offset, offset);
53  ring->setPoint(1, size.width() - offset, offset);
54  ring->setPoint(2, size.width() - offset, size.height() - offset);
55  ring->setPoint(3, offset, size.height() - offset);
56  ring->setPoint(4, offset, offset);
57  polygon->setRingN(0, ring);
58  geom = polygon;
59  }
60  else if(symb->getType() == "LineSymbolizer")
61  {
63  line->setPoint(0, offset, size.height() * 0.5);
64  line->setPoint(1, size.width() - offset, size.height() * 0.5);
65  geom = line;
66  }
67  else if(symb->getType() == "PointSymbolizer")
68  {
69  geom = new te::gm::Point(size.width() * 0.5, size.height() * 0.5);
70  }
71  else if(symb->getType() == "RasterSymbolizer")
72  {
73  QIcon raster = QIcon::fromTheme("raster-symbolizer");
74  return raster.pixmap(size);
75  }
76 
77  QPixmap result = build(symb, geom, size);
78 
79  delete geom;
80 
81  return result;
82 }
83 
84 QPixmap te::qt::widgets::SymbologyPreview::build(const std::vector<te::se::Symbolizer*>& symbs, const QSize& size)
85 {
86  QPixmap result(size);
87  result.fill(Qt::transparent);
88 
89  // Let's draw!
90  QPainter painter(&result);
91  for(std::size_t i = 0; i < symbs.size(); ++i)
92  {
93  QPixmap pix = build(symbs[i], size);
94  painter.drawPixmap(0, 0, pix);
95  }
96 
97  return result;
98 }
99 
100 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Rule* rule, const QSize& size)
101 {
102  assert(rule);
103 
104  return build(rule->getSymbolizers(), size);
105 }
106 
107 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Symbolizer* symb, const te::gm::Geometry* geom, const QSize& size)
108 {
109  assert(symb);
110 
111  if(symb->getType() == "RasterSymbolizer")
112  return QPixmap();
113 
114  assert(geom);
115  assert(!size.isEmpty());
116 
117  // Creating a canvas...
118  te::qt::widgets::Canvas canvas(size.width(), size.height());
119  canvas.setWindow(0.0, 0.0, size.width(), size.height());
120  canvas.setBackgroundColor(te::color::RGBAColor(0, 0, 0, TE_TRANSPARENT));
121 
122  // Configuring...
123  te::map::CanvasConfigurer cc(&canvas);
124  cc.config(symb);
125 
126  // Let's draw!
127  canvas.draw(geom);
128 
129  return *canvas.getPixmap();
130 }
131 
132 QPixmap te::qt::widgets::SymbologyPreview::build(const std::vector<te::se::Symbolizer*>& symbs, const te::gm::Geometry* geom, const QSize& size)
133 {
134  QPixmap result(size);
135  result.fill(Qt::transparent);
136 
137  // Let's draw!
138  QPainter painter(&result);
139  for(std::size_t i = 0; i < symbs.size(); ++i)
140  {
141  QPixmap pix = build(symbs[i], geom, size);
142  painter.drawPixmap(0, 0, pix);
143  }
144 
145  return result;
146 }
147 
148 QPixmap te::qt::widgets::SymbologyPreview::build(const te::se::Rule* rule, const te::gm::Geometry* geom, const QSize& size)
149 {
150  assert(rule);
151 
152  return build(rule->getSymbolizers(), geom, size);
153 }
154 
155 QPixmap te::qt::widgets::SymbologyPreview::build(const te::qt::widgets::Symbol* symbol, const te::gm::Geometry* geom, const QSize& size)
156 {
157  assert(symbol);
158 
159  return build(symbol->getSymbolizers(), geom, size);
160 }
This class represents a symbol.
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
Static class used to generate preview of Symbology elements.
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
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
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.
Definition: LineString.cpp:353
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:158
A canvas built on top of Qt.
Definition: Canvas.h:54
const std::vector< te::se::Symbolizer * > & getSymbolizers() const
It returns the list of Symbolizers that compose the symbol.
Definition: Symbol.cpp:77
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:78
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
Definition: Config.h:46
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
virtual const std::string & getType() const =0
It returns the symbolizer type.
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.
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...