All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LineItem.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 LineItemItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "LineItem.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/LineModel.h"
38 
39 // STL
40 #include <vector>
41 
42 // Qt
43 #include <QPointF>
44 #include <QGraphicsSceneMouseEvent>
45 #include <QStyleOptionGraphicsItem>
46 #include <QObject>
47 
49  ObjectItem(controller, o)
50 {
51  m_nameClass = std::string(this->metaObject()->className());
52 }
53 
55 {
56 
57 }
58 
60 {
62 
63  LineModel* model = dynamic_cast<LineModel*>(m_model);
64  if(!model)
65  {
66  return;
67  }
68 
69  if(!m_poly.empty())
70  return;
71 
72  std::vector<te::gm::Point*> coords = model->getCoords();
73 
74  if (coords.empty())
75  return;
76 
77  for (unsigned int i = 0; i < coords.size(); ++i)
78  {
79  QPointF pt(coords[i]->getX(), coords[i]->getY());
80 
81  QPointF mlocal = mapFromScene(pt);
82  m_poly.push_back(mlocal);
83  }
84 }
85 
86 void te::layout::LineItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0 */ )
87 {
88  Q_UNUSED( option );
89  Q_UNUSED( widget );
90  if ( !painter )
91  {
92  return;
93  }
94 
95  drawBackground(painter);
96 
97  drawLine(painter);
98 
99  drawBorder(painter);
100 
101  //Draw Selection
102  if (option->state & QStyle::State_Selected)
103  {
104  drawSelection(painter);
105  }
106 }
107 
108 void te::layout::LineItem::drawLine( QPainter * painter )
109 {
110  LineModel* model = dynamic_cast<LineModel*>(m_model);
111  if(!model)
112  {
113  return;
114  }
115 
116  if(m_poly.empty())
117  return;
118 
119  te::color::RGBAColor clrLne = model->getLineColor();
120 
121  QColor cpen;
122  cpen.setRed(clrLne.getRed());
123  cpen.setGreen(clrLne.getGreen());
124  cpen.setBlue(clrLne.getBlue());
125  cpen.setAlpha(clrLne.getAlpha());
126 
127  QPainterPath path (m_poly[0]);
128 
129  for(int i = 0; i < m_poly.size() ; ++i)
130  {
131  path.lineTo(m_poly[i]);
132  }
133 
134  QPen pn(cpen, 0, Qt::SolidLine);
135  painter->setPen(pn);
136 
137  painter->save();
138  painter->drawPath(path);
139  painter->restore();
140 }
141 
142 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
virtual void updateObserver(te::layout::ContextItem context)
Reimplemented from ItemObserver.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
LineItem(ItemController *controller, Observable *o)
Definition: LineItem.cpp:48
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
Definition: LineItem.cpp:86
virtual ~LineItem()
Definition: LineItem.cpp:54
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 void updateObserver(ContextItem context)
Reimplemented from ItemObserver.
Definition: LineItem.cpp:59
virtual void drawLine(QPainter *painter)
Definition: LineItem.cpp:108
Abstract class that represents a graphic item. This object is of type QGraphicsObject.
Definition: ObjectItem.h:61
virtual te::color::RGBAColor getLineColor()
Definition: LineModel.cpp:125
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
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
virtual std::vector< te::gm::Point * > getCoords()
Definition: LineModel.cpp:120