All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TextModel.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 TextModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "TextModel.h"
30 #include "../core/property/Property.h"
31 #include "../core/property/Properties.h"
32 #include "../core/property/SharedProperties.h"
33 #include "../core/enum/Enums.h"
34 #include "../core/pattern/singleton/Context.h"
35 
36 // STL
37 #include <string>
38 #include <sstream> // std::stringstream
39 
41  m_text("")
42 {
43  m_type = Enums::getInstance().getEnumObjectType()->getTextItem();
44 
45  m_box = te::gm::Envelope(0., 0., 40., 20.);
46 
47  m_font.setPointSize(12);
48 
49  m_resizable = false;
50 }
51 
53 {
54 
55 }
56 
58 {
60 
62 
63  Property pro_font(m_hashCode);
64  pro_font.setName("Font");
65  pro_font.setValue(m_font, dataType->getDataTypeFont());
66  pro_font.setMenu(true);
67  m_properties->addProperty(pro_font);
68 
69  Property pro_text(m_hashCode);
70  pro_text.setName("Text");
71  pro_text.setValue(m_text, dataType->getDataTypeString());
72  pro_text.setVisible(false);
73  m_properties->addProperty(pro_text);
74 
75  return m_properties;
76 }
77 
79 {
81 
82  Properties* vectorProps = const_cast<Properties*>(properties);
83 
84  Property pro_text = vectorProps->contains("Text");
85 
86  if(!pro_text.isNull())
87  {
88  m_text = pro_text.getValue().toString();
89  }
90 
91  Property pro_font = vectorProps->contains("Font");
92 
93  if(!pro_font.isNull())
94  {
95  m_font = pro_font.getValue().toFont();
96  }
97 }
98 
99 void te::layout::TextModel::setText( std::string txt )
100 {
101  m_text = txt;
102 }
103 
105 {
106  return m_text;
107 }
108 
110 {
111  return m_font;
112 }
113 
115 {
116  m_font = ft;
117 }
virtual void setText(std::string txt)
Definition: TextModel.cpp:99
Class specifies a font.
Definition: Font.h:46
virtual ~TextModel()
Destructor.
Definition: TextModel.cpp:52
Variant getValue()
Returns stored value.
Definition: Property.cpp:72
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
bool isNull()
Returns true if no value has been set, false otherwise.
Definition: Property.cpp:146
virtual void setVisible(bool visible)
Sets the visibility of this property.
Definition: Property.cpp:253
Class that represents a "Model" part of Text MVC component. Its coordinate system is the same of scen...
virtual std::string getText()
Definition: TextModel.cpp:104
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Definition: Properties.h:52
void setPointSize(int point)
Sets point size of the font.
Definition: Font.cpp:66
EnumType * m_type
type of the MVC component
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
Font toFont()
Returns the value of te::layout::Font type. (The setValue method received a te::layout::Font). Complex type.
Definition: Variant.cpp:346
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
Definition: TextModel.cpp:78
static Enums & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
Definition: EnumDataType.h:48
te::gm::Envelope m_box
bounding rectangle
bool m_resizable
true if resizable, false otherwise
TextModel()
Constructor.
Definition: TextModel.cpp:40
virtual Properties * getProperties() const
Reimplemented from Observable.
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Property.h:298
virtual EnumType * getDataTypeFont() const
Returns value that represents type Font belonging to enumeration.
std::string toString()
Returns the value of string type. (The setValue method received a string)
Definition: Variant.cpp:311
void setName(std::string name)
Sets the name of this property.
Definition: Property.cpp:62
virtual void setMenu(bool menu)
Sets true if property will be used in a menu, false otherwise.
Definition: Property.cpp:228
virtual Font getFont()
Definition: TextModel.cpp:109
virtual te::layout::Properties * getProperties() const
Reimplemented from Observable.
Definition: TextModel.cpp:57
virtual EnumType * getDataTypeString() const
Returns value that represents type string belonging to enumeration.
virtual bool contains(Property property)
Checks if the property is contained within the set of properties.
Definition: Properties.h:251
A property acts like a attribute member of a object and stores the state of this attribute. A set of properties stores the state of an object. Any data type, not included in the convertValue method in the class te::layout::Variant, it will be by default "std::string" value.
Definition: Property.h:47
virtual void setFont(Font ft)
Definition: TextModel.cpp:114