TsLayerExplorer.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 TsLayerExplorer.cpp
22 
23  \brief Test suite for the LayerExplorer framework.
24  */
25 
26 // Unit-Test TerraLib
27 #include "TsLayerExplorer.h"
28 
29 // TerraLib
30 #include <terralib/common.h>
31 #include <terralib/maptools.h>
32 #include <terralib/qt/widgets.h>
33 
34 // Qt
35 #include <QtGui/QApplication>
36 
37 // STL
38 #include <ctime>
39 
41 
43 {
44 }
45 
47 {
48 }
49 
51 {
52 #ifdef TE_COMPILE_ALL
53  int argc = 0;
54  QApplication app(argc, 0);
55 
56 // create the layers
57  te::map::FolderLayer* rootLayer = new te::map::FolderLayer("0", "Root Layer");
58 
59  te::map::FeatureLayer* f1 = new te::map::FeatureLayer("1", "DataSet Layer 1", rootLayer);
60  te::map::FeatureLayer* f11 = new te::map::FeatureLayer("1.1", "DataSet Layer 1.1", f1);
61  te::map::FeatureLayer* f12 = new te::map::FeatureLayer("1.2", "DataSet Layer 1.2", f1);
62  te::map::FeatureLayer* f13 = new te::map::FeatureLayer("1.3", "DataSet Layer 1.3", f1);
63 
64  te::map::FeatureLayer* f2 = new te::map::FeatureLayer("2", "DataSet Layer 2", rootLayer);
65  te::map::FeatureLayer* f21 = new te::map::FeatureLayer("2.1", "DataSet Layer 2.1", f2);
66  te::map::FeatureLayer* f22 = new te::map::FeatureLayer("2.2", "DataSet Layer 2.2", f2);
67  te::map::FeatureLayer* f23 = new te::map::FeatureLayer("2.3", "DataSet Layer 2.3", f2);
68  te::map::FeatureLayer* f24 = new te::map::FeatureLayer("2.4", "DataSet Layer 2.4", f2);
69 
70 // create the explorer model and set the layer tree
71  te::qt::widgets::LayerExplorerModel* model = new te::qt::widgets::LayerExplorerModel(rootLayer, 0);
72 
73 // create the explorer view and set its model
74  te::qt::widgets::LayerExplorer explorer(0);
75  //explorer.setSelectionMode(QAbstractItemView::MultiSelection);
76  explorer.setModel(model);
77 
78  QObject::connect(model, SIGNAL(dragDropEnded(const QModelIndex&, const QModelIndex&)),
79  &explorer, SLOT(updateCurrentIndex(const QModelIndex&, const QModelIndex&)));
80 
81  explorer.setDragEnabled(true);
82  explorer.setAcceptDrops(true);
83  explorer.setDropIndicatorShown(true);
84  explorer.show();
85 
86  app.exec();
87 
88  delete rootLayer;
89 
90  return;
91 #endif
92 }
93 
95 {
96 #ifdef TE_COMPILE_ALL
97  int argc = 0;
98  QApplication app(argc, 0);
99 
100  clock_t begin = 0;
101  clock_t end = 0;
102 
103 // create the layers
104  begin = clock();
105 
106  te::map::FolderLayer* rootLayer = new te::map::FolderLayer("0", "Root Layer");
107 
108  const int maxi = 1000;
109  const int maxj = 10;
110  const int maxk = 5;
111  for(int i = 1; i <= maxi; ++i)
112  {
113  std::string id = te::common::Convert2String(i);
114  std::string title = "DataSet Layer " + id;
115 
116  te::map::FeatureLayer* f = new te::map::FeatureLayer(id, title, rootLayer);
117 
118  for(int j = 1; j <= maxj; ++j)
119  {
120  std::string jid = id + "." + te::common::Convert2String(j);
121  title = "DataSet Layer " + jid;
122 
123  te::map::FeatureLayer* fj = new te::map::FeatureLayer(jid, title, f);
124 
125  for(int k = 1; k <= maxk; ++k)
126  {
127  std::string kid = id + "." + te::common::Convert2String(k);
128  title = "DataSet Layer " + kid;
129 
130  te::map::FeatureLayer* fk = new te::map::FeatureLayer(kid, title, fj);
131  }
132  }
133  }
134 
135  end = clock();
136 
137  std::cout << std::endl << "Time to create te::map::AbstractLayer hierarchical tree with " << maxi * maxj * maxk << " items in: " << end - begin << " miliseconds" << std:: endl;
138 
139 // create the explorer model and set the layer tree
140  begin = clock();
141 
142  te::qt::widgets::LayerExplorerModel* model = new te::qt::widgets::LayerExplorerModel(rootLayer, 0);
143 
144  end = clock();
145 
146  std::cout << std::endl << "Time to create LayerExplorerModel for the hierarchical tree with " << maxi * maxj * maxk << " items in: " << end - begin << " miliseconds" << std:: endl;
147 
148 // create the explorer view and set its model
149  begin = clock();
150 
151  te::qt::widgets::LayerExplorer explorer(0);
152  //explorer.setSelectionMode(QAbstractItemView::MultiSelection);
153  explorer.setModel(model);
154 
155  QObject::connect(model, SIGNAL(dragDropEnded(const QModelIndex&, const QModelIndex&)),
156  &explorer, SLOT(updateCurrentIndex(const QModelIndex&, const QModelIndex&)));
157 
158  explorer.setDragEnabled(true);
159  explorer.setAcceptDrops(true);
160  explorer.setDropIndicatorShown(true);
161 
162  explorer.show();
163 
164  end = clock();
165 
166  std::cout << std::endl << "Time to show the LayerExplorer widget for the first time: " << end - begin << " miliseconds" << std:: endl;
167 
168  app.exec();
169 
170  delete rootLayer;
171 
172  return;
173 
174 #endif
175 }
176 
A layer that can be used as a container for other kind of layers.
Definition: FolderLayer.h:45
Test suite for the LayerExplorer framework.
void tcPerformanceExplorer()
Test Case: do some tests for performance measurement.
CPPUNIT_TEST_SUITE_REGISTRATION(TsLayerExplorer)
This file contains include headers for the TerraLib Qt widgets.
This file contains include headers for the TerraLib Common Runtime module.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
This file contains include headers for the Map Tools module of TerraLib.
Test suite for the LayerExplorer framework.
void tcCreateExplorer()
Test Case: creating a simple explorer for a set of in-memory layers.