All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LayerTreeModel.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-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 terralib/qt/widgets/layer/explorer/LayerTreeModel.cpp
22 
23  \brief This class defines the model used in the Qt Model/View architecture for the tree of layers.
24 */
25 
26 // TerraLib
27 #include "../../../../common/STLUtils.h"
28 #include "../../../../common/Translator.h"
29 #include "../../../../maptools/AbstractLayer.h"
30 #include "../../Exception.h"
31 #include "AbstractTreeItem.h"
33 #include "FolderLayerItem.h"
34 #include "LayerTreeModel.h"
35 
36 // Qt
37 #include <QtGui/QMessageBox>
38 #include <QtCore/QMimeData>
39 #include <QtCore/QStringList>
40 
42  : QAbstractItemModel(parent),
43  m_checkable(false)
44 {
45  setSupportedDragActions(Qt::MoveAction | Qt::CopyAction);
46 }
47 
48 te::qt::widgets::LayerTreeModel::LayerTreeModel(const std::list<te::map::AbstractLayerPtr>& layers, QObject * parent)
49  : QAbstractItemModel(parent),
50  m_checkable(false)
51 {
52  setSupportedDragActions(Qt::MoveAction | Qt::CopyAction);
53 }
54 
56 {
57  te::common::FreeContents(m_items);
58 }
59 
60 void te::qt::widgets::LayerTreeModel::set(const std::list<te::map::AbstractLayerPtr>& layers)
61 {
62  beginResetModel();
63 
64  te::common::FreeContents(m_items);
65 
66  m_items.clear();
67 
68  m_layers.clear();
69 
70  for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
71  {
73 
74  if(litem)
75  m_items.push_back(litem);
76 
77  m_layers.push_back(*it);
78  }
79 
80  endResetModel();
81 }
82 
83 const std::vector<te::map::AbstractLayerPtr>& te::qt::widgets::LayerTreeModel::getTopLayers() const
84 {
85  return m_layers;
86 }
87 
88 const std::vector<te::qt::widgets::AbstractTreeItem*>& te::qt::widgets::LayerTreeModel::getTopLayerItems() const
89 {
90  return m_items;
91 }
92 
93 bool te::qt::widgets::LayerTreeModel::canFetchMore(const QModelIndex& parent) const
94 {
95  if(!parent.isValid())
96  return !m_items.empty();
97 
98  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(parent.internalPointer());
99 
100  return item->canFetchMore();
101 }
102 
103 void te::qt::widgets::LayerTreeModel::fetchMore(const QModelIndex& parent)
104 {
105  if(!parent.isValid())
106  return;
107 
108  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(parent.internalPointer());
109 
110  if(item == 0)
111  throw Exception(TR_QT_WIDGETS("Invalid data associated to the layer model!"));
112 
113  item->fetchMore();
114 }
115 
116 int te::qt::widgets::LayerTreeModel::columnCount(const QModelIndex& /*parent*/) const
117 {
118  return 1;
119 }
120 
121 int te::qt::widgets::LayerTreeModel::rowCount(const QModelIndex& parent) const
122 {
123  if(!parent.isValid()) // if parent index isnot valid we assume we are asking for root items
124  return static_cast<int>(m_items.size());
125 
126  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(parent.internalPointer());
127 
128  if(item == 0)
129  throw Exception(TR_QT_WIDGETS("Error: NULL layer item!"));
130 
131  return item->children().count();
132 }
133 
134 QModelIndex te::qt::widgets::LayerTreeModel::index(int row, int column, const QModelIndex& parent) const
135 {
136  if(m_items.empty())
137  return QModelIndex();
138 
139  if(!parent.isValid())
140  {
141  if(static_cast<std::size_t>(row) >= m_items.size())
142  return QModelIndex();
143 
144  // row and column is about a top-level item?
145  AbstractTreeItem* item = m_items[row];
146 
147  return createIndex(row, column, item);
148  }
149 
150  AbstractTreeItem* parentItem = static_cast<AbstractTreeItem*>(parent.internalPointer());
151 
152  if(parentItem == 0)
153  throw Exception(TR_QT_WIDGETS("Invalid data associated to the layer model!"));
154 
155  if(row >= parentItem->children().count())
156  return QModelIndex();
157 
158  AbstractTreeItem* item = dynamic_cast<AbstractTreeItem*>(parentItem->children().at(row));
159 
160  if(item == 0)
161  throw Exception(TR_QT_WIDGETS("The layer item is not an AbstractTreeItem!"));
162 
163  return createIndex(row, column, item);
164 }
165 
166 QModelIndex te::qt::widgets::LayerTreeModel::parent(const QModelIndex& index) const
167 {
168  if(!index.isValid())
169  return QModelIndex();
170 
171  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(index.internalPointer());
172 
173  if(item == 0 || item->parent() == 0)
174  return QModelIndex();
175 
176  AbstractTreeItem* parentItem = dynamic_cast<AbstractTreeItem*>(item->parent());
177 
178  if(parentItem == 0)
179  throw Exception(TR_QT_WIDGETS("The layer item is not an AbstractTreeItem!"));
180 
181  AbstractTreeItem* grandParentItem = dynamic_cast<AbstractTreeItem*>(parentItem->parent());
182 
183  if(grandParentItem == 0)
184  {
185  // the parent is a top level item
186  for(std::size_t i = 0; i != m_items.size(); ++i)
187  {
188  if(m_items[i] == parentItem)
189  return createIndex(static_cast<int>(i), index.column(), parentItem);
190  }
191  }
192  else
193  {
194  // the parent has a grandparent
195  const QObjectList& items = grandParentItem->children();
196 
197  int i = 0;
198 
199  for(QObjectList::const_iterator it = items.begin(); it != items.end(); ++it, ++i)
200  {
201  if((*it) == parentItem)
202  return createIndex(i, index.column(), parentItem);
203  }
204  }
205 
206  throw Exception(TR_QT_WIDGETS("Could not determine the layer index in the model!"));
207 }
208 
209 Qt::ItemFlags te::qt::widgets::LayerTreeModel::flags(const QModelIndex& index) const
210 {
211  if(!index.isValid())
212  return QAbstractItemModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
213 
214  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(index.internalPointer());
215 
216  if(item == 0)
217  throw Exception(TR_QT_WIDGETS("Invalid data associated to the layer model!"));
218 
219  return QAbstractItemModel::flags(index) | item->flags();
220 }
221 
222 QVariant te::qt::widgets::LayerTreeModel::data(const QModelIndex& index, int role) const
223 {
224  if(!index.isValid())
225  return QVariant();
226 
227  if(role == Qt::CheckStateRole && !m_checkable)
228  return QVariant();
229 
230  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(index.internalPointer());
231 
232  if(item == 0)
233  return QVariant();
234 
235  return item->data(index.column(), role);
236 }
237 
238 bool te::qt::widgets::LayerTreeModel::setData(const QModelIndex& index, const QVariant& value, int role)
239 {
240  if(!index.isValid())
241  return false;
242 
243  if(role == Qt::CheckStateRole && !m_checkable)
244  return false;
245 
246  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(index.internalPointer());
247 
248  if(item == 0)
249  return false;
250 
251  bool retVal;
252 
253  retVal = item->setData(index.column(), value, role);
254 
255  emit dataChanged(index, index);
256 
257  // Emit dataChanged signals for the descendants of this index (if any)
258  emitDataChangedForDescendants(index);
259 
260  // Emit dataChanged signals for the descendants of this index (if any)
261  emitDataChangedForAncestors(index);
262 
263  return retVal;
264 }
265 
266 bool te::qt::widgets::LayerTreeModel::hasChildren(const QModelIndex& parent) const
267 {
268  if(!parent.isValid())
269  return !m_items.empty();
270 
271  AbstractTreeItem* item = static_cast<AbstractTreeItem*>(parent.internalPointer());
272 
273  if(item == 0)
274  throw Exception(TR_QT_WIDGETS("Invalid data associated to the layer model!"));
275 
276  return item->hasChildren();
277 }
278 
280 {
281  QStringList mimes;
282 
283  mimes << "application/x-terralib;value=\"DraggedItems\"";
284 
285  return mimes;
286 }
287 
289 {
290  return Qt::MoveAction | Qt::CopyAction;
291 }
292 
293 QMimeData* te::qt::widgets::LayerTreeModel::mimeData(const QModelIndexList& indexes) const
294 {
295  if(indexes.empty())
296  return 0;
297 
298  std::vector<AbstractTreeItem*>* draggedItems = new std::vector<AbstractTreeItem*>;
299 
300  for(int i = 0; i < indexes.count(); ++i)
301  draggedItems->push_back(static_cast<AbstractTreeItem*>(indexes.at(i).internalPointer()));
302 
303  QString s;
304  s.setNum((qulonglong)draggedItems);
305 
306  QByteArray encodedData(s.toStdString().c_str());
307 
308  QMimeData* mimeData = new QMimeData();
309 
310  mimeData->setData("application/x-terralib;value=\"DraggedItems\"", encodedData);
311 
312  return mimeData;
313 }
314 
316  Qt::DropAction action,
317  int row, int column,
318  const QModelIndex& parent)
319 {
320  if(data == 0 || column > 0 || action != Qt::MoveAction)
321  return false;
322 
323  if(action == Qt::IgnoreAction)
324  return true;
325 
326  if(!data->hasFormat("application/x-terralib;value=\"DraggedItems\""))
327  return false;
328 
329  // Get the item that was dragged
330  QString sitem = data->data("application/x-terralib;value=\"DraggedItems\"");
331 
332  if(sitem.isEmpty())
333  return false;
334 
335  qulonglong dataValue = sitem.toULongLong();
336 
337  // Get the layer items that were dragged
338  std::vector<AbstractTreeItem*>* draggedItems = reinterpret_cast<std::vector<AbstractTreeItem*>*>(dataValue);
339  int count = draggedItems->size();
340 
341  m_insertingLayers.clear();
342  for(int i = 0; i < count; ++i)
343  m_insertingLayers.push_back(draggedItems->operator[](i)->getLayer());
344 
345  // Get the drop item and its associated layer
346  QModelIndex dropIndex = parent;
347  AbstractTreeItem* dropItem = static_cast<AbstractTreeItem*>(dropIndex.internalPointer());
348 
349  te::map::AbstractLayerPtr dropLayer = 0;
350  if(dropItem)
351  dropLayer= dropItem->getLayer();
352 
353  // Get the parent index of the dropped item and its associated layer
354  QModelIndex dropParentIndex = dropIndex.parent();
355  AbstractTreeItem* dropParentItem = static_cast<AbstractTreeItem*>(dropParentIndex.internalPointer());
356 
357  te::map::AbstractLayerPtr dropParentLayer = 0;
358  if(dropParentItem)
359  dropParentLayer = dropParentItem->getLayer();
360 
361  // Set the row and the parent where the dragged items will be inserted
362  int insertingRow;
363  QModelIndex insertingItemParentIndex;
364 
365  removeLayerFromParentChildrenList(m_insertingLayers);
366 
367  // Check if the drop item is a folder item and if it has no children; in that case,
368  // the dragged items will be made children of this folder item
369  //bool folderItemWasEmpty = false;
370 
371  if(row < 0 && dropItem && dropLayer.get() &&
372  dropLayer->getType() == "FOLDERLAYER" &&
373  dropLayer->hasChildren() == false)
374  {
375  insertingRow = 0;
376  insertingItemParentIndex = dropIndex;
377 
378  // Insert the dragged layers into its new parent
379  for(int i = 0; i < count; ++i)
380  dropLayer->insert(i, m_insertingLayers[i]);
381 
382  //folderItemWasEmpty = true;
383  }
384  else
385  {
386  // Get the index of the parent of the dropped item
387  QModelIndex dropParentIndex = dropIndex.parent();
388 
389  if(row < 0)
390  {
391  // The dragged items were dragged exactly on the dropped item
392  if(dropParentIndex == QModelIndex())
393  {
394  // Drop item is a top level item
395  if(dropIndex.row() == -1)
396  insertingRow = m_items.size(); // The items were dropped after the last top level item
397  else
398  insertingRow = dropIndex.row(); // The item was dropped exactly on a top level item
399 
400  // Insert the dragged layers into its new parent
401  if(insertingRow >= (int)m_layers.size())
402  {
403  for(int i = 0; i < count; ++i)
404  m_layers.push_back(m_insertingLayers[i]);
405  }
406  else
407  {
408  for(int i = 0; i < count; ++i)
409  m_layers.insert(m_layers.begin() + insertingRow + i, m_insertingLayers[i]);
410  }
411  }
412  else
413  {
414  // Drop item is not a top level item
415  insertingRow = dropIndex.row(); // The item will be inserted in the position of the dropped item.
416  insertingItemParentIndex = dropParentIndex;
417 
418  // Insert the dragged layers into its new parent
419  int k = insertingRow;
420  for(int i = 0; i < count; ++i, ++k)
421  dropParentLayer->insert(k, m_insertingLayers[i]);
422  }
423  } //end of row < 0
424  else
425  { // begin of row >= 0
426  // The item will be inserted as the last top level item
427  // The result of this operation has no effect because
428  // the item is inserted and removed afterwards
429  insertingRow = m_layers.size();
430 
431  // Insert the dragged layers into its new parent
432  for(int i = 0; i < count; ++i)
433  m_layers.insert(m_layers.begin() + insertingRow + i, m_insertingLayers[i]);
434  } // end of row >= 0
435  }
436 
437  bool ret = insertRows(insertingRow, count, insertingItemParentIndex);
438 
439  // If the dropped item is a folder item that was empty emit a signal for expand it.
440  //if(folderItemWasEmpty)
441  // emit expandItem(dropItem);
442 
443  // Emit a signal to indicate that the order of the layers were changed inside the tree
444  if(ret)
445  emit layerOrderChanged();
446 
447  return ret;
448 }
449 
450 bool te::qt::widgets::LayerTreeModel::insertRows(int row, int count, const QModelIndex& parent)
451 {
452  AbstractTreeItem* parentItem = static_cast<AbstractTreeItem*>(parent.internalPointer());
453 
454  beginInsertRows(parent, row, row + count - 1);
455 
456  if(!parentItem)
457  {
458  if(row == m_items.size())
459  {
460  for(int i = 0; i < count; ++i)
461  {
462  AbstractTreeItem* newItem = AbstractTreeItemFactory::make(m_insertingLayers[i], 0);
463  m_items.push_back(newItem);
464  }
465  }
466  else
467  {
468  int k = 0;
469  for(int i = row; i < row + count; ++i, ++k)
470  {
471  AbstractTreeItem* newItem = AbstractTreeItemFactory::make(m_insertingLayers[k], 0);
472  m_items.insert(m_items.begin() + i, newItem);
473  }
474  }
475  }
476  else
477  {
478  // Get the children of the parent item and disconnect them from the tree item
479  int numChildren = parentItem->children().count();
480  QList<QObject*> savedItemsList = parentItem->children();
481 
482  for(int i = 0; i < numChildren; ++i)
483  savedItemsList.at(i)->setParent(0);
484 
485  // Insert the items into the list
486  int k = 0;
487  for(int i = row; i < row + count; ++i, ++k)
488  {
489  AbstractTreeItem* newItem = AbstractTreeItemFactory::make(m_insertingLayers[k], 0);
490  savedItemsList.insert(i, newItem);
491  }
492 
493  // Reinsert the saved items into the tree
494  for(int i = 0; i < savedItemsList.count(); ++i)
495  savedItemsList.at(i)->setParent(parentItem);
496  }
497 
498  endInsertRows();
499 
500  // Adjust the visibility of the ancestors that are folder layers of the inserted items
501  m_insertingLayers[0]->updateVisibilityOfAncestors();
502  emitDataChangedForAncestors(parent);
503 
504  return true;
505 }
506 
507 bool te::qt::widgets::LayerTreeModel::removeRows(int row, int count, const QModelIndex& parent)
508 {
509  bool ret = false;
510 
511  beginRemoveRows(parent, row, row + count - 1);
512 
513  if(!parent.isValid())
514  {
515  for(int i = row; i < row + count; ++i)
516  delete m_items[i];
517 
518  m_items.erase(m_items.begin() + row, m_items.begin() + row + count);
519  }
520  else
521  {
522  // Get the parent of the items to be removed
523  AbstractTreeItem* parentItem = static_cast<AbstractTreeItem*>(parent.internalPointer());
524 
525  // Get the parent layer associated to the items to be removed
526  te::map::AbstractLayerPtr parentLayer = parentItem->getLayer();
527 
528  // Finally, remove the item from the tree
529  const QList<QObject*>& childrenList = parentItem->children();
530  int numChildren = childrenList.count();
531 
532  std::vector<QObject*> items;
533  for(int i = row; i < row + count; ++i)
534  {
535  QObject* item = childrenList.at(i);
536  items.push_back(item);
537  }
538 
539  for(std::size_t i = 0; i < items.size(); ++i)
540  delete items[i];
541 
542  // Emit the dataChanged signal for the ancestors of the parent of the item removed
543  emitDataChangedForAncestors(parent);
544 
545  // Adjust the parent visibility of the removed layer and of their ancestors
546  parentLayer->updateVisibility();
547 
548  // Adjust the visibility of the ancestors of the parent of the removed layer
549  parentLayer->updateVisibilityOfAncestors();
550  }
551 
552  ret = true;
553 
554  endRemoveRows();
555 
556  return ret;
557 }
558 
560 {
561  m_checkable = checkable;
562 }
563 
565 {
566  return m_checkable;
567 }
568 
570 {
571  if(!item)
572  return QModelIndex();
573 
574  int itemRow; // The item row
575  QModelIndex parentIndex; // The parent index of the item
576 
577  AbstractTreeItem* parentItem = static_cast<AbstractTreeItem*>(item->parent());
578 
579  if(!parentItem)
580  {
581  // The item is a top level item; get its row
582  for(std::size_t i = 0; i < m_items.size(); ++i)
583  {
584  if(m_items[i] == item)
585  {
586  itemRow = i;
587  break;
588  }
589  }
590  }
591  else
592  itemRow = parentItem->children().indexOf(item);
593 
594  return createIndex(itemRow, 0, item);
595 }
596 
598 {
599  if(!layer)
600  return 0;
601 
602  te::map::AbstractLayerPtr parentLayer = static_cast<te::map::AbstractLayer*>(layer->getParent());
603 
604  if(!parentLayer)
605  {
606  // The layer is a top layer
607  for(std::size_t i = 0; i < m_layers.size(); ++i)
608  {
609  if(m_layers[i] == layer)
610  return m_items[i];
611  }
612  }
613 
614  // Get the list of rows of the ancestors of the given layer,
615  // and the index of its top level ancestor layer.
616  std::vector<std::size_t> rows;
617  QModelIndex topLayerIndex;
618 
619  te::map::AbstractLayerPtr auxLayer = layer;
620 
621  while(parentLayer)
622  {
623  rows.push_back(auxLayer->getIndex());
624  auxLayer = parentLayer;
625  parentLayer = static_cast<te::map::AbstractLayer*>(parentLayer->getParent());
626  }
627 
628  te::map::AbstractLayerPtr topLayer = auxLayer;
630 
631  for(std::size_t i = 0; i < m_layers.size(); ++i)
632  {
633  if(m_layers[i] == topLayer)
634  {
635  topItem = m_items[i];
636  topLayerIndex = index(i, 0, QModelIndex());
637  break;
638  }
639  }
640 
641  QModelIndex inLayerIndex = topLayerIndex;
642 
643  std::vector<std::size_t>::reverse_iterator it;
644  for(it = rows.rbegin(); it != rows.rend(); ++it)
645  inLayerIndex = index(*it, 0, inLayerIndex);
646 
647  return static_cast<AbstractTreeItem*>(inLayerIndex.internalPointer());
648 }
649 
651 {
652  std::size_t row = 0;
653 
654  QModelIndex parentIndex;
655 
656  if(!parentItem)
657  {
658  row = m_layers.size();
659  m_layers.push_back(layer);
660  }
661  else
662  {
663  row = parentItem->children().size();
664  parentIndex = getIndex(parentItem);
665  }
666 
667  m_insertingLayers.clear();
668  m_insertingLayers.push_back(layer);
669 
670  insertRows(row, 1, parentIndex);
671 }
672 
674 {
675  QModelIndex itemIndex = getIndex(item);
676 
677  int itemRow = itemIndex.row();
678  QModelIndex parentIndex = parent(itemIndex);
679 
680  AbstractTreeItem* parentItem = static_cast<AbstractTreeItem*>(item->parent());
681 
682  if(item->getLayer())
683  {
684  // If the item is a single layer item or a folder layer item, remove the layer associated to the item.
685  if(!parentItem)
686  {
687  // The item is a top level item; get its row
688  for(std::size_t i = 0; i < m_items.size(); ++i)
689  {
690  if(m_items[i] == item)
691  {
692  m_layers.erase(m_layers.begin() + i);
693  break;
694  }
695  }
696  }
697  }
698 
699  return removeRows(itemRow, 1, parentIndex);
700 }
701 
702 void te::qt::widgets::LayerTreeModel::removeLayerFromParentChildrenList(std::vector<te::map::AbstractLayerPtr>& layers)
703 {
704  for(std::size_t i = 0; i < layers.size(); ++i)
705  {
706  te::map::AbstractLayerPtr layer = layers[i];
707 
708  te::map::AbstractLayerPtr parentLayer = static_cast<te::map::AbstractLayer*>(layer->getParent());
709 
710  if(!parentLayer)
711  {
712  for(std::size_t j = 0; j < m_layers.size(); ++j)
713  {
714  if(m_layers[j] == layer)
715  m_layers.erase(m_layers.begin() + j);
716  }
717  }
718  else
719  parentLayer->remove(layer->getIndex());
720  }
721 }
722 
724 {
725  if(!parent.isValid())
726  return;
727 
728  int rows = rowCount(parent);
729 
730  for(int i = 0; i != rows; ++i)
731  {
732  QModelIndex idx = index(i, 0, parent);
733 
734  emit dataChanged(idx, idx);
735 
736  if(hasChildren(idx))
737  emitDataChangedForDescendants(idx);
738  }
739 }
740 
742 {
743  QModelIndex ancestorIndex = parent(index);
744  if(parent(index).isValid())
745  {
746  // Emit the dataChanged signal for the ascendants indexes
747  while(ancestorIndex.isValid())
748  {
749  emit dataChanged(ancestorIndex, ancestorIndex);
750  ancestorIndex = parent(ancestorIndex);
751  }
752  }
753 }
Qt::DropActions supportedDropActions() const
It returns the drop actions supported by this model.
virtual te::map::AbstractLayerPtr getLayer() const =0
void set(const std::list< te::map::AbstractLayerPtr > &layers)
It resets the model and associates the new top level items to the given top level layers...
te::qt::widgets::AbstractTreeItem * getLayerItem(const te::map::AbstractLayerPtr &layer)
It gets the layer item that is associated to the given layer.
virtual bool setData(int column, const QVariant &value, int role=Qt::EditRole)=0
This is the base class for layers.
Definition: AbstractLayer.h:76
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
It returns the index of the item in the model specified by the given row, column and parent index...
virtual QVariant data(int column, int role) const =0
void add(const te::map::AbstractLayerPtr &layer, AbstractTreeItem *parentItem=0)
It adds a item layer to the list of item layers of the parent layer item. If the parent layer is not ...
const std::vector< te::map::AbstractLayerPtr > & getTopLayers() const
It gets the top level layers of the model.
void setCheckable(const bool checkable)
It sets the model items as checkable or not.
bool remove(AbstractTreeItem *item)
It removes a item from the model.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
It handles the data supplied by a drag and drop operation that ended with the given action...
A class for building layer items.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
It sets the role data for the item at index to value.
static AbstractTreeItem * make(const te::map::AbstractLayerPtr &layer, QObject *parent)
const std::vector< te::qt::widgets::AbstractTreeItem * > & getTopLayerItems() const
It gets the top level layer items of the model.
void removeLayerFromParentChildrenList(std::vector< te::map::AbstractLayerPtr > &layers)
It removes the given layers from the list of children of their parents.
bool hasChildren(const QModelIndex &parent=QModelIndex()) const
It checks if the given index has children.
virtual Qt::ItemFlags flags() const =0
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
It inserts a determined number of rows given by the &quot;count&quot; parameter, starting with the given row un...
QModelIndex parent(const QModelIndex &index) const
It returns the item parent of the given index, or QModelIndex(), if it has no parent.
TreeItemPtr remove(std::size_t i)
It removes the i-th child.
Definition: TreeItem.cpp:116
Qt::ItemFlags flags(const QModelIndex &index) const
It returns the item flags for the given index.
int columnCount(const QModelIndex &parent=QModelIndex()) const
It returns the number of columns for the children of the given parent.
virtual bool canFetchMore() const =0
QMimeData * mimeData(const QModelIndexList &indexes) const
It returns an object that contains serialized items of data corresponding to the list of indexes spec...
The class that represents an item in a LayerTreeModel.
The class that represents a folder layer item in a LayerTreeModel.
void fetchMore(const QModelIndex &parent)
It fetches any available data for the items with the parent specified by the parent index...
#define TR_QT_WIDGETS(message)
It marks a string in order to get translated. This is a special mark used in the TerraLib Qt Widgets ...
Definition: Config.h:60
void emitDataChangedForAncestors(const QModelIndex &index)
It emits the dataChanged signal for the indexes that are ancestors of the given index.
This class defines the model used in the Qt Model/View architecture for the tree of layers...
LayerTreeModel(QObject *parent=0)
It constructs a layer tree model with the given parent.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
It returns the data stored under the given role for the item referred to by the index.
QModelIndex getIndex(AbstractTreeItem *item)
It gets the index that is associated to the given item.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
bool isCheckable() const
It verifies if the model items are checkable or not.
bool canFetchMore(const QModelIndex &parent) const
It fetches more data for the given parent.
QStringList mimeTypes() const
It returns a list of MIME types that can be used to describe a list of model indexes.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
It removes a determined number of rows given by the &quot;count&quot; parameter, starting with the given row un...
int rowCount(const QModelIndex &parent=QModelIndex()) const
It returns the number of rows of the given parent.
virtual bool hasChildren() const =0
void emitDataChangedForDescendants(const QModelIndex &parent)
It emits the dataChanged signal for the descendants indexes of the given index.
The class that represents an item in a LayerTreeModel.