TreeItemFactory.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2013 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 TreeItemFactory.cpp
22 
23  \brief A class for building layer items.
24 */
25 
26 #include "TreeItemFactory.h"
27 
28 // TerraLib
29 #include "../../../../maptools/AbstractLayer.h"
30 
31 #include "LayerItem.h"
32 #include "FolderItem.h"
33 
34 // Boost
35 #include <boost/functional/factory.hpp>
36 #include <boost/bind.hpp>
37 
38 std::map<std::string, te::qt::widgets::TreeItemFactory::FactoryFnctType> te::qt::widgets::TreeItemFactory::sm_factories;
39 
40 void te::qt::widgets::TreeItemFactory::reg(const std::string& key, const FactoryFnctType& f)
41 {
42  sm_factories[key] = f;
43 }
44 
46 {
47  if(!sm_factories.empty())
48  return;
49 }
50 
52 {
53  sm_factories.clear();
54 }
55 
57 {
58  if(layer->getType() == "DATASETLAYER" || layer->getType() == "DATASETADAPTERLAYER" || layer->getType() == "QUERYLAYER" || layer->getType() == "RASTERLAYER")
59  return new LayerItem(layer);
60 
61  if(layer->getType() == "FOLDERLAYER")
62  return new FolderItem(layer);
63 
64  if(sm_factories.find(layer->getType()) == sm_factories.end())
65  return new LayerItem(layer);
66 
67  return sm_factories[layer->getType()](layer);
68 }
69 
Defines a folder item, just containing LayerItem.
static TreeItem * make(const te::map::AbstractLayerPtr &layer)
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
static std::map< std::string, FactoryFnctType > sm_factories
Defines a hierarchical structure.
Represents a folder item that contains layers and / or other folders.
Definition: FolderItem.h:48
Defines a layer item.
boost::function< TreeItem *(const te::map::AbstractLayerPtr &)> FactoryFnctType
static void reg(const std::string &key, const FactoryFnctType &f)
A class for building layer items.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr