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