All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ItemUtils.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2014 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 ItemUtils.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "ItemUtils.h"
30 #include "ItemModelObservable.h"
31 #include "Context.h"
32 
33 // STL
34 #include <stddef.h> // defines NULL
35 
36 // Boost
37 #include "boost\foreach.hpp"
38 
39 TELAYOUTEXPORT std::vector<te::layout::MapItem*> te::layout::getMapItemList( QList<QGraphicsItem*> graphicsItems )
40 {
41  std::vector<te::layout::MapItem*> list;
42  foreach( QGraphicsItem *item, graphicsItems)
43  {
44  if(!item)
45  continue;
46 
47  te::layout::ItemObserver* lItem = dynamic_cast<te::layout::ItemObserver*>(item);
48  if(!lItem)
49  continue;
50 
51  te::layout::MapItem* mit = dynamic_cast<te::layout::MapItem*>(lItem);
52  if(!mit)
53  continue;
54 
55  list.push_back(mit);
56  }
57 
58  return list;
59 }
60 
61 TELAYOUTEXPORT te::layout::MapItem* te::layout::getMapItem( QList<QGraphicsItem*> graphicsItems, std::string name )
62 {
63  te::layout::MapItem* map = 0;
64 
65  foreach( QGraphicsItem *item, graphicsItems)
66  {
67  if(!item)
68  continue;
69 
70  te::layout::ItemObserver* lItem = dynamic_cast<te::layout::ItemObserver*>(item);
71  if(!lItem)
72  continue;
73 
74  te::layout::MapItem* mit = dynamic_cast<te::layout::MapItem*>(lItem);
75  if(!mit)
76  continue;
77 
78  if(mit->getName().compare(name) != 0)
79  continue;
80 
81  map = mit;
82  }
83 
84  return map;
85 }
86 
87 TELAYOUTEXPORT std::vector<std::string> te::layout::mapNameList( QList<QGraphicsItem*> graphicsItems )
88 {
89  std::vector<std::string> strList;
90 
91  foreach( QGraphicsItem *item, graphicsItems)
92  {
93  if(!item)
94  continue;
95 
96  te::layout::ItemObserver* lItem = dynamic_cast<te::layout::ItemObserver*>(item);
97  if(!lItem)
98  continue;
99 
100  te::layout::MapItem* mit = dynamic_cast<te::layout::MapItem*>(lItem);
101  if(!mit)
102  continue;
103 
104  std::string name = mit->getName();
105  strList.push_back(name);
106  }
107 
108  return strList;
109 }
110 
111 TELAYOUTEXPORT int te::layout::countType( QList<QGraphicsItem*> graphicsItems, LayoutAbstractObjectType type )
112 {
113  int count = 0;
114 
115  foreach( QGraphicsItem *item, graphicsItems)
116  {
117  if(!item)
118  continue;
119 
120  ItemObserver* obs = dynamic_cast<ItemObserver*>(item);
121  if(!obs)
122  continue;
123 
124  if(obs->getModel()->getType() == type)
125  {
126  count+=1;
127  }
128  }
129 
130  return count;
131 }
132 
133 TELAYOUTEXPORT int te::layout::maxTypeId( QList<QGraphicsItem*> graphicsItems, LayoutAbstractObjectType type )
134 {
135  int id = -1;
136 
137  foreach( QGraphicsItem *item, graphicsItems)
138  {
139  if(!item)
140  continue;
141 
142  ItemObserver* obs = dynamic_cast<ItemObserver*>(item);
143  if(!obs)
144  continue;
145 
146  ItemModelObservable* model = dynamic_cast<ItemModelObservable*>(obs->getModel());
147  if(!model)
148  continue;
149 
150  if(obs->getModel()->getType() == type)
151  {
152  if(id == -1)
153  {
154  id = model->getId();
155  }
156  else
157  {
158  if(model->getId() > id)
159  {
160  id = model->getId();
161  }
162  }
163  }
164  }
165 
166  return id;
167 }
168 
170 {
171  bool result = false;
172 
174 
175  switch(mode)
176  {
177  case TypeMapPan:
178  result = true;
179  break;
180  case TypeMapZoomIn:
181  result = true;
182  break;
183  case TypeMapZoomOut:
184  result = true;
185  break;
186  default:
187  result = false;
188  }
189 
190  return result;
191 }
TELAYOUTEXPORT MapItem * getMapItem(QList< QGraphicsItem * > graphicsItems, std::string name)
Definition: ItemUtils.cpp:61
#define TELAYOUTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:99
TELAYOUTEXPORT std::vector< std::string > mapNameList(QList< QGraphicsItem * > graphicsItems)
Definition: ItemUtils.cpp:87
LayoutMode
Enum LayoutMode. This is the enumeration of the components types.
Definition: EnumMode.h:38
TELAYOUTEXPORT int countType(QList< QGraphicsItem * > graphicsItems, te::layout::LayoutAbstractObjectType type)
Definition: ItemUtils.cpp:111
LayoutAbstractObjectType
Enum TdkAbstractComponentType. This is the enumeration of the components types.
Definition: AbstractType.h:38
TELAYOUTEXPORT std::vector< MapItem * > getMapItemList(QList< QGraphicsItem * > graphicsItems)
Definition: ItemUtils.cpp:39
TELAYOUTEXPORT int maxTypeId(QList< QGraphicsItem * > graphicsItems, te::layout::LayoutAbstractObjectType type)
Definition: ItemUtils.cpp:133
virtual Observable * getModel()
TELAYOUTEXPORT bool isCurrentMapTools()
Definition: ItemUtils.cpp:169
virtual LayoutAbstractObjectType getType()=0
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
virtual std::string getName()
LayoutMode getMode()
Definition: Context.cpp:56