All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AbstractPropertiesBrowser.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 PropertyBrowser.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
30 #include "../../../core/property/Properties.h"
31 #include "../../../core/enum/Enums.h"
32 #include "../../../core/property/Variant.h"
33 
34 // Qt
35 #include <QVariant>
36 #include <QFont>
37 #include <QColor>
38 
39 // QtPropertyBrowser
40 #include <QtPropertyBrowser/qteditorfactory.h>
41 #include <QtPropertyBrowser/QtProperty>
42 
43 // STL
44 #include <algorithm> // std::find
45 
47  QObject(parent),
48  m_changeProperty(false)
49 {
50 
51 }
52 
54 {
55 
56 }
57 
58 void te::layout::AbstractPropertiesBrowser::addPropertyItem( QtProperty *property, const QString &id )
59 {
60  m_propertyToId[property] = id;
61  m_idToProperty[id] = property;
62 }
63 
65 {
66  m_propertyToId.clear();
67  m_idToProperty.clear();
68 }
69 
71 {
72  QVariant variant;
73 
74  if(!m_idToProperty.contains(name.c_str()))
75  {
76  return variant;
77  }
78 
79  QtVariantProperty* vproperty = 0;
80  QtProperty* prop = m_idToProperty[name.c_str()];
81 
82  if(prop)
83  {
84  vproperty = dynamic_cast<QtVariantProperty*>(prop);
85  if(vproperty)
86  {
87  variant = checkComplexType(vproperty);
88  }
89  else
90  {
91  variant.setValue(prop->valueText());
92  }
93  }
94 
95  return variant;
96 }
97 
99 {
100  QtProperty* prop = 0;
101 
102  if(!m_idToProperty.contains(name.c_str()))
103  {
104  return prop;
105  }
106 
107  prop = m_idToProperty[name.c_str()];
108  return prop;
109 }
110 
111 QVariant te::layout::AbstractPropertiesBrowser::checkComplexType( QtVariantProperty* property )
112 {
113  QVariant variant;
114 
115  if(!property)
116  return variant;
117 
118  variant = property->value();
119 
120  if(QtVariantPropertyManager::enumTypeId() == property->propertyType())
121  {
122  variant = property->attributeValue("enumNames");
123  QStringList list = variant.toStringList();
124  variant = QVariant(list);
125  }
126 
127  return variant;
128 }
129 
131 {
132  if(!prop)
133  {
134  return false;
135  }
136 
137  if(!m_idToProperty.contains(prop->propertyName()))
138  {
139  return false;
140  }
141 
142  m_propertyToId.remove(prop);
143  m_idToProperty.remove(prop->propertyName());
144 
145  return true;
146 }
147 
148 
149 
150 
151 
152 
153 
154 
155 
virtual QVariant findPropertyValue(std::string name)
virtual QtProperty * findProperty(std::string name)
virtual void addPropertyItem(QtProperty *property, const QString &id)
virtual QVariant checkComplexType(QtVariantProperty *property)