All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GridPlanarItem.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 GridPlanarItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "GridPlanarItem.h"
30 #include "../../core/pattern/mvc/ItemController.h"
31 #include "../../core/AbstractScene.h"
32 #include "../../core/pattern/mvc/Observable.h"
33 #include "../../../color/RGBAColor.h"
34 #include "../../../qt/widgets/Utils.h"
35 #include "../../../geometry/Envelope.h"
36 #include "../../../common/STLUtils.h"
37 #include "../../item/GridMapModel.h"
38 #include "MapItem.h"
39 
40 //Qt
41 #include <QStyleOptionGraphicsItem>
42 #include "../../core/WorldTransformer.h"
43 
45  GridMapItem(controller, o)
46 {
47  m_nameClass = std::string(this->metaObject()->className());
48 }
49 
51 {
52 
53 }
54 
55 void te::layout::GridPlanarItem::drawGrid( QPainter* painter )
56 {
57  GridMapModel* model = dynamic_cast<GridMapModel*>(m_model);
58  if(!model)
59  {
60  return;
61  }
62 
63  painter->save();
64 
65  QRectF parentBound = boundingRect();
66 
67  if(parentItem())
68  {
69  parentBound = parentItem()->boundingRect();
70  }
71 
72  QPainterPath gridMapPath;
73  gridMapPath.setFillRule(Qt::WindingFill);
74 
75  int heightRect = (int)parentBound.height();
76  int widgetRect = (int)parentBound.width();
77 
78  te::color::RGBAColor rgbColor = model->getLineColor();
79  QColor cLine(rgbColor.getRed(), rgbColor.getGreen(), rgbColor.getBlue(), rgbColor.getAlpha());
80 
81  painter->setPen(QPen(cLine, 0, Qt::SolidLine));
82 
83  QFont ft(model->getFontFamily().c_str(), model->getTextPointSize());
84 
85  painter->setFont(ft);
86 
87  m_maxHeigthTextMM = m_onePointMM * ft.pointSize();
88 
89  QString text = "A";
90 
91  for (int i = 0; i <= heightRect; i+=10)
92  {
93  QLineF lineOne = QLineF(parentBound.topLeft().x(), parentBound.topLeft().y() + i, parentBound.topRight().x(), parentBound.topRight().y() + i);
94 
95  QPointF pointInit(parentBound.topLeft().x() - (heightRect*.01), parentBound.topLeft().y() + i - (m_maxHeigthTextMM/2)); //esquerda
96  drawText(pointInit, painter, text.toStdString(), true);
97  QPointF pointFinal(parentBound.topRight().x() + (heightRect*.01), parentBound.topRight().y() + i - (m_maxHeigthTextMM/2)); //direita
98  drawText(pointFinal, painter, text.toStdString());
99 
100  painter->drawLine(lineOne);
101 
102  for (int j = 0; j <= widgetRect; j+=10)
103  {
104  QLineF lineTwo = QLineF(parentBound.topLeft().x() + j, parentBound.topLeft().y(), parentBound.bottomLeft().x() + j, parentBound.bottomLeft().y());
105 
106  QPointF pointInit(parentBound.topLeft().x() + j + (m_maxWidthTextMM/2), boundingRect().topLeft().y() /*- (widgetRect*.01)*/); //inferior
107  drawText(pointInit, painter, text.toStdString(), true);
108  QPointF pointFinal(parentBound.bottomLeft().x() + j - (m_maxWidthTextMM/2), parentBound.bottomLeft().y() + (widgetRect*.01)); //superior
109  drawText(pointFinal, painter, text.toStdString());
110 
111  painter->drawLine(lineTwo);
112  }
113  }
114 
115  painter->restore();
116 }
117 
118 
119 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
virtual te::color::RGBAColor getLineColor()
virtual int getTextPointSize()
Class that represents a "Model" part of GridMap MVC component. Its coordinate system is the same of s...
Definition: GridMapModel.h:67
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
virtual void drawGrid(QPainter *painter)
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:305
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:300
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
virtual ~GridPlanarItem()
Destructor.
GridPlanarItem(ItemController *controller, Observable *o)
Constructor.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310
std::string m_nameClass
Class name.
Definition: ItemObserver.h:201
Class that represents a graphic GridMap. Its coordinate system is the same of scene (millimeters)...
Definition: GridMapItem.h:52
Class that represents a graphic GridMap. Its coordinate system is the same of scene (millimeters)...
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
virtual std::string getFontFamily()