LayerItem.cpp
Go to the documentation of this file.
1 #include "LayerItem.h"
2 
3 #include "ChartItem.h"
4 #include "StyleItem.h"
5 
6 #include "../../se/SymbologyPreview.h"
7 
8 #include "../../../../core/uri/URI.h"
9 #include "../../../../core/uri/Utils.h"
10 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
11 #include "../../../../maptools/DataSetLayer.h"
12 #include "../../../../maptools/DataSetAdapterLayer.h"
13 #include "../../../../maptools/Utils.h"
14 
15 #include "../../../../se/Style.h"
16 #include "../../../../se/Utils.h"
17 
18 #include "../../../../srs/SpatialReferenceSystemManager.h"
19 
21 {
22  // Gets the data set name
23  QString toolTip = QObject::tr("DataSet") + ": " + ((l->getType() == "DATASETADAPTERLAYER") ?
24  ((te::map::DataSetAdapterLayer*)l.get())->getDataSetName().c_str() :
25  (l->getType() == "DATASETLAYER") ?
26  ((te::map::DataSetLayer*)l.get())->getDataSetName().c_str() :
27  "" + QString("\n"));
28  return toolTip;
29 }
30 
32 {
33  // Gets the connection info
34  const std::string& id = l->getDataSourceId();
35 
37  const te::core::URI& connInfo = info->getConnInfo();
38 
39  QString toolTip = QObject::tr("Connection Info") + ":\n";
40 
41  toolTip += QObject::tr("\tScheme: ") + (connInfo.scheme() + "\n").c_str();
42 
43  if(!connInfo.user().empty())
44  toolTip += QObject::tr("\tUser: ") + (connInfo.user() + "\n").c_str();
45 
46  if(!connInfo.host().empty())
47  toolTip += QObject::tr("\tHost: ") + (connInfo.host() + "\n").c_str();
48 
49  if(!connInfo.port().empty())
50  toolTip += QObject::tr("\tPort: ") + (connInfo.port() + "\n").c_str();
51 
52  if(!connInfo.path().empty())
53  toolTip += QObject::tr("\tPath: ") + (connInfo.path() + "\n").c_str();
54 
55  std::map<std::string, std::string> kvp = te::core::Expand(connInfo.query());
56  std::map<std::string, std::string>::iterator itBegin = kvp.begin();
57  std::map<std::string, std::string>::iterator itEnd = kvp.end();
58 
59  while (itBegin != itEnd)
60  {
61  toolTip += itBegin->first.c_str();
62  toolTip += ": ";
63  toolTip += itBegin->second.c_str();
64  toolTip += "\n";
65  ++itBegin;
66  }
67 
68  toolTip += QObject::tr("SRID: ");
69  toolTip += QString::number(l->getSRID());
70  toolTip += QObject::tr(" - ");
71  toolTip += QString(te::srs::SpatialReferenceSystemManager::getInstance().getName(l->getSRID()).c_str());
72 
73  return toolTip;
74 }
75 
76 
78 {
80 
81  if(!l->isValid())
82  return QObject::tr("Invalid Layer");
83 
84  QString toolTip = GetDataSetName(l) +"\n"+ GetTooltip(l);
85 
86  return toolTip;
87 }
88 
90  TreeItem("LAYER"),
91  m_layer(layer)
92 {
93  if(!m_layer->isValid())
94  return;
95 
96  if (m_layer->getStyle() != nullptr)
97  addChild(new StyleItem(m_layer->getStyle()));
98 
99  updateChart();
100 }
101 
103 {
104  std::vector<TreeItem*> items;
105  getChildren(items, "CHART");
106 
107  if(!items.empty())
108  ((*items.begin())->setParent(nullptr));
109 
110  items.clear();
111  getChildren(items, "STYLE");
112 
113  if(!items.empty())
114  ((*items.begin())->setParent(nullptr));
115 }
116 
118 {
119  return m_layer->getTitle();
120 }
121 
123 {
124  return (m_layer->getVisibility() == te::map::VISIBLE) ? TOTALLY : NONE;
125 }
126 
127 void te::qt::widgets::LayerItem::setVisible(const VISIBLE& visible, const bool& updateAncestors, const bool&)
128 {
129  m_layer->setVisibility((visible == TOTALLY) ? te::map::VISIBLE : te::map::NOT_VISIBLE);
130 
131  if(updateAncestors)
132  m_parent->setVisible(visible, true);
133 }
134 
136 {
137  return TreeItem::flags() | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable;
138 }
139 
141 {
142  return m_layer.get();
143 }
144 
146 {
147  std::vector<TreeItem*> items;
148 
149  getChildren(items, "LEGEND");
150 
151  if(m_layer->getChart() != nullptr)
152  insertChild(new ChartItem(m_layer->getChart()), items.size());
153 }
154 
156 {
157  StyleItem* si = new StyleItem(m_layer->getStyle());
158 
159  addChild(si);
160 
161  return si->getPosition();
162 }
163 
165 {
166  return BuildToolIip(this).toUtf8().data();
167 }
std::string path() const
Retrieving the path.
Definition: URI.cpp:118
TreeItem * m_parent
Pointer to the parent.
std::string scheme() const
Retrieving the scheme.
Definition: URI.cpp:93
A class that represents a style of a layer in a LayerTreeModel.
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
te::map::AbstractLayerPtr getLayer() const
Returns the layer contained in the item.
Definition: LayerItem.cpp:140
QString BuildToolIip(te::qt::widgets::LayerItem const *item)
Definition: LayerItem.cpp:77
void updateChart()
Updates the chart item.
Definition: LayerItem.cpp:145
QString GetDataSetName(te::map::AbstractLayerPtr l)
Definition: LayerItem.cpp:20
VISIBLE isVisible() const
Returns the visibilty state of the item.
Definition: LayerItem.cpp:122
int updateLegend()
updateLegend
Definition: LayerItem.cpp:155
Defines a hierarchical structure.
std::string query() const
Retrieving the query.
Definition: URI.cpp:123
void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
Definition: LayerItem.cpp:127
QString GetTooltip(te::map::AbstractLayerPtr l)
Definition: LayerItem.cpp:31
A layer with reference to a DataSetTypeConverter.
te::map::AbstractLayerPtr m_layer
The asbtract layer.
Definition: LayerItem.h:115
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
A class that represents a chart of a layer in a LayerTreeModel.
Definition: ChartItem.h:50
std::string port() const
Retrieving the port.
Definition: URI.cpp:113
void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
std::string host() const
Retrieving the host.
Definition: URI.cpp:108
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
VISIBLE
Defines the visibility of an item.
A class that represents a chart of a layer in a LayerTreeModel.
int getPosition()
Returns the position of item in its parent&#39;s list of children.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
Defines a layer item.
void setParent(TreeItem *item)
Updates the item parent.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
std::string getAsString() const
Returns the label of the item to be presented in a Qt view.
Definition: LayerItem.cpp:117
virtual void insertChild(TreeItem *item, const size_t &pos)
Inserts a child item at the desired position.
std::string getToolTip() const
Returns the item tooltip (for information purposes).
Definition: LayerItem.cpp:164
LayerItem(te::map::AbstractLayerPtr layer)
Constructor.
Definition: LayerItem.cpp:89
A class that represents a style of a layer in a LayerTreeModel.
Definition: StyleItem.h:50
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
Qt::ItemFlags flags()
Returns the flags to be used by the model.
Definition: LayerItem.cpp:135
std::string user() const
Retrieving the user information.
Definition: URI.cpp:98
void getChildren(std::vector< TreeItem * > &items, const std::string &type) const
Returns all children of a certain type.
virtual void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
virtual Qt::ItemFlags flags()
Returns the flags to be used by the model.