LayerItemModel.cpp
Go to the documentation of this file.
1 #include "LayerItemModel.h"
2 
3 #include "FolderItem.h"
4 #include "LayerItem.h"
5 #include "StyleItem.h"
6 
7 #include "TreeItemFactory.h"
8 
9 #include "../../../../dataaccess/datasource/DataSourceManager.h"
10 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
11 
12 #include "../../../../core/translator/Translator.h"
13 #include "../../../../common/progress/TaskProgress.h"
14 
15 #include "../../../../maptools/FolderLayer.h"
16 #include "../../../../maptools/DataSetLayer.h"
17 
18 // Qt
19 #include <QMimeData>
20 #include <QVector>
21 #include <QStringList>
22 
23 // Boost
24 #include <boost/uuid/random_generator.hpp>
25 #include <boost/uuid/uuid_io.hpp>
26 
27 // STL
28 #include <memory>
29 
31 {
32  te::qt::widgets::TreeItem* folder = new te::qt::widgets::FolderItem(dynamic_cast<te::map::FolderLayer*>(l.get()));
33 
34  std::list<te::common::TreeItemPtr> children = l->getChildren();
35 
36  for(std::list<te::common::TreeItemPtr>::iterator it = children.begin(); it != children.end(); ++it)
37  {
38  te::common::TreeItemPtr item = *it;
39 
40  te::map::AbstractLayerPtr layer(boost::dynamic_pointer_cast<te::map::AbstractLayer>(item));
41 
42  if(layer->getType() == "FOLDERLAYER")
43  folder->addChild(GetFolder(layer, idxPath));
44  else
46  }
47 
48  return folder;
49 }
50 
51 void GetRootFolder(std::list<te::map::AbstractLayerPtr> layers, te::qt::widgets::TreeItem* root, const std::string& idxPath)
52 {
53  for(std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin(); it != layers.end(); ++it)
54  {
55  if((*it).get()->getType() == "FOLDERLAYER")
56  root->addChild(GetFolder((*it), idxPath));
57  else
59  }
60 }
61 
62 void GetAllLayers(std::list<te::map::AbstractLayerPtr>& layers, const te::qt::widgets::TreeItem* item, const te::qt::widgets::TreeItem* root)
63 {
64  if(item->getType() == "FOLDER")
65  {
66  size_t c = item->getChildrenCount("");
67 
68  std::list<te::map::AbstractLayerPtr> ls;
69 
70  for(size_t i = 0; i < c; i++)
71  GetAllLayers(ls, item->getChild(i), root);
72 
73  if(item->getParent() != nullptr)
74  {
75  static boost::uuids::basic_random_generator<boost::mt19937> gen;
76  boost::uuids::uuid u = gen();
77  std::string id = boost::uuids::to_string(u);
78 
80  fd->setId(id);
81 
82  for(std::list<te::map::AbstractLayerPtr>::iterator it = ls.begin(); it != ls.end(); ++it)
83  fd->add((*it));
84 
85  layers.push_back(te::map::FolderLayerPtr(fd));
86  }
87  else
88  for(std::list<te::map::AbstractLayerPtr>::iterator it=ls.begin(); it!=ls.end(); ++it)
89  layers.push_back((*it));
90  }
91  else if(item->getType() == "LAYER")
92  layers.push_back(((te::qt::widgets::LayerItem*)item)->getLayer());
93 }
94 
95 void GetVisibleLayers(std::list<te::map::AbstractLayerPtr>& layers, const te::qt::widgets::TreeItem* item)
96 {
97  if(item->getType() == "FOLDER")
98  {
99  size_t c = item->getChildrenCount("");
100 
101  for(size_t i = 0; i < c; i++)
102  GetVisibleLayers(layers, item->getChild(i));
103  }
104  else if(item->getType() == "LAYER" && item->isVisible() == te::qt::widgets::TOTALLY)
105  {
106  te::map::AbstractLayerPtr l = ((te::qt::widgets::LayerItem*)item)->getLayer();
107  layers.push_back(l);
108  }
109 }
110 
111 bool ParentInRemoveList(const QModelIndexList& lst, const QModelIndex& idx)
112 {
113  if(!idx.isValid())
114  return false;
115 
116  if(lst.contains(idx.parent()))
117  return true;
118 
119  return ParentInRemoveList(lst, idx.parent());
120 }
121 
122 void CleanRemoveList(QModelIndexList& lst)
123 {
124  std::vector<QModelIndex> idxs;
125 
126  foreach(QModelIndex idx, lst)
127  {
128  if((static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer()))->getType() == "LEGEND")
129  idxs.push_back(idx);
130  else if(ParentInRemoveList(lst, idx))
131  idxs.push_back(idx);
132  }
133 
134  for(std::vector<QModelIndex>::iterator it = idxs.begin(); it != idxs.end(); ++it)
135  lst.removeAll((*it));
136 }
137 
138 QModelIndex FindIndex(const te::qt::widgets::LayerItemModel* model, const te::qt::widgets::TreeItem* item, const QModelIndex& idx)
139 {
140  try
141  {
142  if(idx.internalPointer() == item)
143  throw idx;
144  else
145  {
146  int c = model->rowCount(idx);
147 
148  for(int i = 0; i < c; i++)
149  FindIndex(model, item, model->index(i, 0, idx));
150  }
151  }
152  catch(const QModelIndex& idxE)
153  {
154  if(!idx.isValid())
155  return idxE;
156  else
157  throw idxE;
158  }
159 
160  return idx;
161 }
162 
163 QModelIndex FindInsertInformation(const QModelIndex& par, int& row, te::qt::widgets::LayerItemModel* model)
164 {
165  // If the parent was not given
166  if(!par.isValid())
167  {
168  row = model->rowCount();
169 
170  return QModelIndex();
171  }
172 
173  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(par.internalPointer());
174 
175  // If the parent is a FolderItem
176  if(item->getType() == "FOLDER")
177  {
178  row = model->rowCount(par);
179 
180  return par;
181  }
182 
183  // If the parent is a LayerItem
184  if(item->getType() == "LAYER")
185  {
186  row = par.row() + 1;
187 
188  return model->parent(par);
189  }
190 
191  return FindInsertInformation(model->parent(par), row, model);
192 }
193 
195  QAbstractItemModel(parent)
196 {
197  static boost::uuids::basic_random_generator<boost::mt19937> gen;
198  boost::uuids::uuid u = gen();
199  std::string id = boost::uuids::to_string(u);
200 
201  te::map::FolderLayerPtr layer(new te::map::FolderLayer(id, "Layers"));
202  m_root.reset(new FolderItem(layer));
203 }
204 
206 
208 {
209  addLayer(layer, QModelIndex(), idxPath);
210 }
211 
212 void te::qt::widgets::LayerItemModel::addLayer(te::map::AbstractLayerPtr layer, const QModelIndex& parent, const std::string& idxPath)
213 {
214  int row;
215 
216  QModelIndex flIdx = FindInsertInformation(parent, row, this);
217 
218  TreeItem* item = (flIdx.isValid()) ? static_cast<TreeItem*>(flIdx.internalPointer()) : m_root.get();
219 
220  if(layer->getType() == "FOLDERLAYER")
221  item->insertChild(GetFolder(layer, idxPath), (size_t)row);
222  else
223  item->insertChild(TreeItemFactory::make(layer), (size_t)row);
224 }
225 
226 void te::qt::widgets::LayerItemModel::addLayers(const std::list<te::map::AbstractLayerPtr>& layers, const std::string& idxPath)
227 {
228  addLayers(layers, QModelIndex(), idxPath);
229 }
230 
231 void te::qt::widgets::LayerItemModel::addLayers(const std::list<te::map::AbstractLayerPtr>& layers, const QModelIndex& parent, const std::string& idxPath)
232 {
233  int row;
234 
235  QModelIndex par = FindInsertInformation(parent, row, this);
236 
237  TreeItem* item = (par.isValid()) ? static_cast<TreeItem*>(par.internalPointer()) : m_root.get();
238 
239  beginInsertRows(par, row, row + (int)layers.size() - 1);
240 
241  if(!item->hasChildren())
242  GetRootFolder(layers, item, idxPath);
243  else
244  {
245  int cont = row;
246 
247  te::common::TaskProgress task(TE_TR("Loading Layers..."));
248  task.setTotalSteps(layers.size());
249 
250  for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
251  {
252  task.pulse();
253 
254  te::map::AbstractLayerPtr layer = *it;
255 
256  if(layer->getType() == "FOLDERLAYER")
257  item->insertChild(GetFolder(layer, idxPath), (size_t)cont);
258  else
259  item->insertChild(TreeItemFactory::make(layer), (size_t)cont);
260 
261  cont++;
262  }
263  }
264 
265  endInsertRows();
266 }
267 
268 void te::qt::widgets::LayerItemModel::setLayers(const std::list<te::map::AbstractLayerPtr>& layers)
269 {
270  beginResetModel();
271 
272  m_root->removeAllChilds();
273 
274  if(!layers.empty())
275  addLayers(layers);
276 
277  endResetModel();
278 }
279 
280 void te::qt::widgets::LayerItemModel::addItems(const std::vector<TreeItem*> items, TreeItem* parent, const int& pos)
281 {
282  std::vector<TreeItem*> aux;
283  QModelIndexList ls;
284  QModelIndex parentIdx = FindIndex(this, parent, QModelIndex());
285 
286  for(std::vector<TreeItem*>::const_iterator it = items.begin(); it != items.end(); ++it)
287  ls << FindIndex(this, (*it), QModelIndex());
288 
289  CleanRemoveList(ls);
290 
291  qSort(ls.begin(), ls.end());
292 
293  std::list<QModelIndex> lIdx = ls.toStdList();
294 
295  int beforePos = 0;
296  size_t pC = parent->getChildrenCount("");
297 
298  for(std::list<QModelIndex>::reverse_iterator it = lIdx.rbegin(); it != lIdx.rend(); ++it)
299  {
300  beginRemoveRows((*it).parent(), (*it).row(), (*it).row());
301 
302  QModelIndex auxIdx = (*it).parent();
303 
304  TreeItem* auxPar = (auxIdx.isValid()) ? static_cast<TreeItem*>(auxIdx.internalPointer()) : m_root.get();
305 
306  TreeItem* item = static_cast<TreeItem*>((*it).internalPointer());
307 
308  bool sameParent = item->getParent() == parent;
309 
310  if((sameParent && (item->getPosition() < pos)) || (sameParent && pos < 0))
311  beforePos++;
312 
313  aux.push_back(auxPar->removeChild((*it).row()));
314 
315  endRemoveRows();
316  }
317 
318  if((size_t)pos < pC)
319  pC = pos;
320 
321  pC -= beforePos;
322 
323  for(std::vector<TreeItem*>::iterator it = aux.begin(); it != aux.end(); ++it)
324  {
325  beginInsertRows(parentIdx, (int)pC, (int)pC);
326 
327  parent->insertChild((*it), pC);
328 
329  endInsertRows();
330  }
331 }
332 
334 {
335  addFolder(name, FindIndex(this, parent, QModelIndex()));
336 }
337 
338 void te::qt::widgets::LayerItemModel::addFolder(const std::string& name, const QModelIndex& idx)
339 {
340  int row;
341 
342  static boost::uuids::basic_random_generator<boost::mt19937> gen;
343  boost::uuids::uuid u = gen();
344  std::string id = boost::uuids::to_string(u);
345 
346  te::map::FolderLayer* layer = new te::map::FolderLayer(id, name);
347 
348  TreeItem* fItem = new FolderItem(layer);
349 
350  QModelIndex par = FindInsertInformation(idx, row, this);
351 
352  TreeItem* parItem = (par.isValid()) ? static_cast<TreeItem*>(par.internalPointer()) : m_root.get();
353 
354  beginInsertRows(par, row, row);
355 
356  parItem->insertChild(fItem, (size_t)row);
357 
358  endInsertRows();
359 }
360 
361 std::list<te::map::AbstractLayerPtr> te::qt::widgets::LayerItemModel::getAllLayers()
362 {
363  std::list<te::map::AbstractLayerPtr> ls;
364 
365  GetAllLayers(ls, m_root.get(), m_root.get());
366 
367  return ls;
368 }
369 
370 std::list<te::map::AbstractLayerPtr> te::qt::widgets::LayerItemModel::getVisibleLayers()
371 {
372  std::list<te::map::AbstractLayerPtr> ls;
373 
374  GetVisibleLayers(ls, m_root.get());
375 
376  return ls;
377 }
378 
379 int te::qt::widgets::LayerItemModel::columnCount(const QModelIndex&) const
380 {
381  return 1;
382 }
383 
384 bool te::qt::widgets::LayerItemModel::setData(const QModelIndex& index, const QVariant& value, int role)
385 {
386  if(role == Qt::CheckStateRole)
387  {
388  TreeItem* itm = static_cast<TreeItem*>(index.internalPointer());
389 
390  bool ok;
391 
392  int v = value.toInt(&ok);
393 
394  if(!ok)
395  return false;
396 
397  itm->setVisible((v == Qt::Checked) ? TOTALLY : NONE, true, true);
398 
399  // Find first parent
400  QModelIndex f = parent(index);
401 
402  while(f.parent().isValid())
403  f = f.parent();
404 
405  // Find the last row
406  int count = rowCount(index);
407 
408  QModelIndex l = (count == 0) ? index : index.child(count - 1, 0);
409 
410  while(true)
411  {
412  count = rowCount(l);
413 
414  if(count == 0)
415  break;
416 
417  l = l.child(count - 1, 0);
418  }
419 
420 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
421 
422  QVector<int> roles;
423 
424  roles << Qt::CheckStateRole;
425 
426  emit dataChanged(f, l, roles);
427 
428 #else
429  emit dataChanged(f, l);
430 #endif
431 
432  if (itm->getType() == "RULE")
433  {
434  StyleItem* styleItem = (StyleItem*)itm->getParent();
435  LayerItem* layerItem = (LayerItem*)styleItem->getParent();
436 
437  emit styleVisibilityChanged(layerItem->getLayer());
438  }
439  else
440  emit visibilityChanged();
441  }
442 
443  return true;
444 }
445 
446 bool te::qt::widgets::LayerItemModel::removeRows(int row, int count, const QModelIndex& parent)
447 {
448  int last = row + count -1;
449 
450  beginRemoveRows(parent, row, last);
451 
452  TreeItem* parItem = (parent.isValid()) ? static_cast<TreeItem*>(parent.internalPointer()) : m_root.get();
453 
454  for(int i = row; i <= last; i++)
455  std::unique_ptr<TreeItem> aux(parItem->removeChild(i));
456 
457  endRemoveRows();
458 
459  return true;
460 }
461 
462 bool te::qt::widgets::LayerItemModel::insertRows(int row, int count, const QModelIndex& parent)
463 {
464  beginInsertRows(parent, row, row + count);
465 
466  endInsertRows();
467 
468  return true;
469 }
470 
472 {
473  return Qt::MoveAction | Qt::CopyAction | Qt::LinkAction;
474 }
475 
477 {
478  QStringList types;
479  types << "application/x-terralib;value=\"DraggedItems\"";
480  return types;
481 }
482 
483 QMimeData* te::qt::widgets::LayerItemModel::mimeData(const QModelIndexList& indexes) const
484 {
485  QMimeData *mimeData = new QMimeData();
486  std::vector<TreeItem*>* aux = new std::vector<TreeItem*>();
487 
488  foreach (QModelIndex idx, indexes)
489  if(idx.isValid())
490  aux->push_back(static_cast<TreeItem*>(idx.internalPointer()));
491 
492  QString s;
493  s.setNum((qulonglong)aux);
494 
495  QByteArray encodedData(s.toUtf8());
496 
497  mimeData->setData("application/x-terralib;value=\"DraggedItems\"", encodedData);
498 
499  return mimeData;
500 }
501 
502 bool te::qt::widgets::LayerItemModel::canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
503 {
504  Q_UNUSED(action);
505  Q_UNUSED(row);
506  Q_UNUSED(parent);
507 
508  if(!data->hasFormat("application/x-terralib;value=\"DraggedItems\""))
509  return false;
510 
511  if (column > 0)
512  return false;
513 
514  return true;
515 }
516 
517 bool te::qt::widgets::LayerItemModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent)
518 {
519  if (!canDropMimeData(data, action, row, column, parent))
520  return false;
521 
522  if (action == Qt::IgnoreAction)
523  return true;
524 
525  QByteArray encodedData = data->data("application/x-terralib;value=\"DraggedItems\"");
526 
527  qulonglong dataValue = encodedData.toULongLong();
528 
529  std::unique_ptr< std::vector<TreeItem*> > changed(reinterpret_cast< std::vector<TreeItem*>* >(dataValue));
530 
531  TreeItem* newPar;
532 
533  if(parent.isValid())
534  {
535  QModelIndex nP = FindInsertInformation(parent, row, this);
536 
537  newPar = (!nP.isValid()) ? m_root.get() : static_cast<TreeItem*>(nP.internalPointer());
538  }
539  else
540  newPar = m_root.get();
541 
542  addItems(*changed.get(), newPar, row);
543 
544  return true;
545 }
546 
547 void te::qt::widgets::LayerItemModel::removeItems(const QModelIndexList& lst)
548 {
549  if(lst.isEmpty())
550  return;
551 
552  QModelIndexList idxs = lst;
553 
554  CleanRemoveList(idxs);
555 
556  qSort(idxs);
557 
558  while(!idxs.isEmpty())
559  {
560  QModelIndex idx = idxs.takeLast();
561  QModelIndex par = idx.parent();
562 
563  removeRow(idx.row(), par);
564  }
565 }
566 
567 
568 QVariant te::qt::widgets::LayerItemModel::data(const QModelIndex &index, int role) const
569 {
570  if (!index.isValid())
571  return QVariant();
572 
573  QModelIndex par = parent(index);
574 
575  if(index.row() >= rowCount(par))
576  return QVariant();
577 
578  TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
579 
580  if(role == Qt::CheckStateRole)
581  {
582  if(item->flags() & Qt::ItemIsUserCheckable)
583  return QVariant((item->isVisible() == NONE) ? Qt::Unchecked : (item->isVisible() == PARTIALLY) ? Qt::PartiallyChecked : Qt::Checked);
584 
585  return QVariant();
586  }
587 
588  if(role == Qt::ToolTipRole)
589  return QString::fromUtf8(item->getToolTip().c_str());
590 
591  if(role == Qt::DisplayRole)
592  return QString::fromUtf8(item->getAsString().c_str());
593 
594  return QVariant();
595 }
596 
597 Qt::ItemFlags te::qt::widgets::LayerItemModel::flags(const QModelIndex &index) const
598 {
599  if(index.isValid())
600  {
601  TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
602 
603  return item->flags();
604  }
605 
606  return Qt::ItemIsDropEnabled;
607 }
608 
610  int /*section*/, Qt::Orientation orientation, int role) const
611 {
612  if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
613  return tr("Layers");
614 
615  return QVariant();
616 }
617 
618 QModelIndex te::qt::widgets::LayerItemModel::index(int row, int column, const QModelIndex &parent) const
619 {
620  size_t c = m_root->getChildrenCount("");
621 
622  if(c == 0)
623  return QModelIndex();
624 
625  if(!parent.isValid())
626  {
627  if(static_cast<std::size_t>(row) >= c)
628  return QModelIndex();
629 
630  // row and column is about a top-level item?
631  TreeItem* item = m_root->getChild((int)row);
632 
633  return createIndex(row, column, item);
634  }
635 
636  TreeItem* parentItem = static_cast<TreeItem*>(parent.internalPointer());
637 
638  if(parentItem == nullptr)
639  throw te::common::Exception(tr("Invalid data associated to the layer model!").toUtf8().data());
640 
641  if(row >= (int)parentItem->getChildrenCount(""))
642  return QModelIndex();
643 
644  TreeItem* item = parentItem->getChild(row);
645 
646  if(item == nullptr)
647  throw te::common::Exception(tr("The layer item is not an AbstractTreeItem!").toUtf8().data());
648 
649  return createIndex(row, column, item);
650 }
651 
652 QModelIndex te::qt::widgets::LayerItemModel::parent(const QModelIndex &index) const
653 {
654  if (!index.isValid())
655  return QModelIndex();
656 
657  TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
658  TreeItem *parentItem = childItem->getParent();
659 
660  if (parentItem == m_root.get())
661  return QModelIndex();
662 
663  return createIndex(parentItem->getPosition(), 0, parentItem);
664 }
665 
667 {
668  TreeItem *parentItem;
669  if (parent.column() > 0)
670  return 0;
671 
672  if (!parent.isValid())
673  parentItem = m_root.get();
674  else
675  parentItem = static_cast<TreeItem*>(parent.internalPointer());
676 
677  return ((int) parentItem->getChildrenCount(""));
678 }
void GetRootFolder(std::list< te::map::AbstractLayerPtr > layers, te::qt::widgets::TreeItem *root, const std::string &idxPath)
Defines a folder item, just containing LayerItem.
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE
A class that represents a style of a layer in a LayerTreeModel.
static TreeItem * make(const te::map::AbstractLayerPtr &layer)
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
void CleanRemoveList(QModelIndexList &lst)
te::qt::widgets::TreeItem * GetFolder(te::common::TreeItemPtr l, const std::string &idxPath)
LayerItemModel(QObject *parent=0)
Constructor.
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
void addLayer(te::map::AbstractLayerPtr layer, const std::string &idxPath="./")
Adds a layer to the model at the end of children list.
te::map::AbstractLayerPtr getLayer() const
Returns the layer contained in the item.
Definition: LayerItem.cpp:140
void addItems(const std::vector< TreeItem * > items, TreeItem *parent, const int &pos=0)
Adds the set of items to the parent at the position pos.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) Q_DECL_OVERRIDE
virtual std::string getAsString() const =0
Returns the label of the item to be presented in a Qt view.
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
void GetAllLayers(std::list< te::map::AbstractLayerPtr > &layers, const te::qt::widgets::TreeItem *item, const te::qt::widgets::TreeItem *root)
bool ParentInRemoveList(const QModelIndexList &lst, const QModelIndex &idx)
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
bool hasChildren() const
Tells us if the item has children or not.
A layer that can be used as a container for other kind of layers.
Definition: FolderLayer.h:45
TreeItem * getChild(const size_t &pos) const
Returns the child located at pos.
void add(const TreeItemPtr &childItem)
It adds (appends) the item to the end of the children&#39;s list.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
boost::intrusive_ptr< FolderLayer > FolderLayerPtr
Definition: FolderLayer.h:123
void GetVisibleLayers(std::list< te::map::AbstractLayerPtr > &layers, const te::qt::widgets::TreeItem *item)
Defines a hierarchical structure.
Represents a folder item that contains layers and / or other folders.
Definition: FolderItem.h:48
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE
void setTotalSteps(int value)
Set the task total stepes.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE
boost::intrusive_ptr< TreeItem > TreeItemPtr
Defines an abstract model based on TreeItem objects.
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE
int columnCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
void addChild(TreeItem *item)
Adds a child to the item. The child is added to the end of the list.
std::unique_ptr< TreeItem > m_root
The root item of the model.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) Q_DECL_OVERRIDE
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
void addFolder(const std::string &name, TreeItem *parent=0)
Adds a new folder item to the model.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Defines a layer item model for Qt5.
void setLayers(const std::list< te::map::AbstractLayerPtr > &layers)
Updates the list of layers in the model.
QMimeData * mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE
QStringList mimeTypes() const Q_DECL_OVERRIDE
std::list< te::map::AbstractLayerPtr > getVisibleLayers()
Returns a list with layers that are visible.
void removeItems(const QModelIndexList &lst)
Removes the items in lst from the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
int getPosition()
Returns the position of item in its parent&#39;s list of children.
QModelIndex FindInsertInformation(const QModelIndex &par, int &row, te::qt::widgets::LayerItemModel *model)
TreeItem * getParent() const
Returns the item parent.
Defines a layer item.
void addLayers(const std::list< te::map::AbstractLayerPtr > &layers, const std::string &idxPath="./")
Adds a list of layers to the model at the end of children list.
TreeItem * removeChild(const size_t &pos)
Removes the child located at pos from the children list.
virtual std::string getToolTip() const
Returns the item tooltip (for information purposes).
virtual void insertChild(TreeItem *item, const size_t &pos)
Inserts a child item at the desired position.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE
size_t getChildrenCount(const std::string &type) const
Returns the number of children.
A class for building layer items.
A class that represents a style of a layer in a LayerTreeModel.
Definition: StyleItem.h:50
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual void setId(const std::string &id)
It sets the layer id.
QModelIndex FindIndex(const te::qt::widgets::LayerItemModel *model, const te::qt::widgets::TreeItem *item, const QModelIndex &idx)
void visibilityChanged()
Signal emited when an item visibility has changed.
void styleVisibilityChanged(te::map::AbstractLayerPtr layer)
virtual void setVisible(const VISIBLE &visible, const bool &updateAncestors=false, const bool &updateDescendents=false)
Updates the visibilty state of the item.
std::string getType() const
Returns the type of the item.
virtual VISIBLE isVisible() const
Returns the visibilty state of the item.
std::list< te::map::AbstractLayerPtr > getAllLayers()
Get all layers contained in the model. Commonly used for persistent pourposes.
virtual Qt::ItemFlags flags()
Returns the flags to be used by the model.