9 #include "../../../../dataaccess/datasource/DataSourceManager.h" 10 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h" 12 #include "../../../../core/translator/Translator.h" 13 #include "../../../../common/progress/TaskProgress.h" 15 #include "../../../../maptools/FolderLayer.h" 16 #include "../../../../maptools/DataSetLayer.h" 21 #include <QStringList> 24 #include <boost/uuid/random_generator.hpp> 25 #include <boost/uuid/uuid_io.hpp> 34 std::list<te::common::TreeItemPtr> children = l->getChildren();
36 for(std::list<te::common::TreeItemPtr>::iterator it = children.begin(); it != children.end(); ++it)
42 if(layer->getType() ==
"FOLDERLAYER")
53 for(std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin(); it != layers.end(); ++it)
55 if((*it).get()->getType() ==
"FOLDERLAYER")
68 std::list<te::map::AbstractLayerPtr> ls;
70 for(
size_t i = 0; i < c; i++)
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);
82 for(std::list<te::map::AbstractLayerPtr>::iterator it = ls.begin(); it != ls.end(); ++it)
88 for(std::list<te::map::AbstractLayerPtr>::iterator it=ls.begin(); it!=ls.end(); ++it)
89 layers.push_back((*it));
91 else if(item->
getType() ==
"LAYER")
101 for(
size_t i = 0; i < c; i++)
116 if(lst.contains(idx.parent()))
124 std::vector<QModelIndex> idxs;
126 foreach(QModelIndex idx, lst)
128 if((static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer()))->getType() ==
"LEGEND")
134 for(std::vector<QModelIndex>::iterator it = idxs.begin(); it != idxs.end(); ++it)
135 lst.removeAll((*it));
142 if(idx.internalPointer() == item)
148 for(
int i = 0; i < c; i++)
152 catch(
const QModelIndex& idxE)
170 return QModelIndex();
176 if(item->
getType() ==
"FOLDER")
188 return model->
parent(par);
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);
209 addLayer(layer, QModelIndex(), idxPath);
218 TreeItem* item = (flIdx.isValid()) ? static_cast<TreeItem*>(flIdx.internalPointer()) :
m_root.get();
220 if(layer->getType() ==
"FOLDERLAYER")
228 addLayers(layers, QModelIndex(), idxPath);
237 TreeItem* item = (par.isValid()) ? static_cast<TreeItem*>(par.internalPointer()) :
m_root.get();
239 beginInsertRows(par, row, row + (
int)layers.size() - 1);
250 for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
256 if(layer->getType() ==
"FOLDERLAYER")
272 m_root->removeAllChilds();
282 std::vector<TreeItem*> aux;
284 QModelIndex parentIdx =
FindIndex(
this, parent, QModelIndex());
286 for(std::vector<TreeItem*>::const_iterator it = items.begin(); it != items.end(); ++it)
287 ls <<
FindIndex(
this, (*it), QModelIndex());
291 qSort(ls.begin(), ls.end());
293 std::list<QModelIndex> lIdx = ls.toStdList();
298 for(std::list<QModelIndex>::reverse_iterator it = lIdx.rbegin(); it != lIdx.rend(); ++it)
300 beginRemoveRows((*it).parent(), (*it).row(), (*it).row());
302 QModelIndex auxIdx = (*it).parent();
304 TreeItem* auxPar = (auxIdx.isValid()) ? static_cast<TreeItem*>(auxIdx.internalPointer()) :
m_root.get();
310 if((sameParent && (item->
getPosition() < pos)) || (sameParent && pos < 0))
323 for(std::vector<TreeItem*>::iterator it = aux.begin(); it != aux.end(); ++it)
325 beginInsertRows(parentIdx, (
int)pC, (
int)pC);
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);
352 TreeItem* parItem = (par.isValid()) ? static_cast<TreeItem*>(par.internalPointer()) :
m_root.get();
354 beginInsertRows(par, row, row);
363 std::list<te::map::AbstractLayerPtr> ls;
372 std::list<te::map::AbstractLayerPtr> ls;
386 if(role == Qt::CheckStateRole)
392 int v = value.toInt(&ok);
400 QModelIndex f =
parent(index);
402 while(f.parent().isValid())
408 QModelIndex l = (count == 0) ? index : index.child(count - 1, 0);
417 l = l.child(count - 1, 0);
420 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 424 roles << Qt::CheckStateRole;
426 emit dataChanged(f, l, roles);
429 emit dataChanged(f, l);
448 int last = row + count -1;
450 beginRemoveRows(parent, row, last);
452 TreeItem* parItem = (parent.isValid()) ? static_cast<TreeItem*>(parent.internalPointer()) :
m_root.get();
454 for(
int i = row; i <= last; i++)
455 std::unique_ptr<TreeItem> aux(parItem->
removeChild(i));
464 beginInsertRows(parent, row, row + count);
473 return Qt::MoveAction | Qt::CopyAction | Qt::LinkAction;
479 types <<
"application/x-terralib;value=\"DraggedItems\"";
485 QMimeData *
mimeData =
new QMimeData();
486 std::vector<TreeItem*>* aux =
new std::vector<TreeItem*>();
488 foreach (QModelIndex idx, indexes)
490 aux->push_back(static_cast<TreeItem*>(idx.internalPointer()));
493 s.setNum((qulonglong)aux);
495 QByteArray encodedData(s.toUtf8());
497 mimeData->setData(
"application/x-terralib;value=\"DraggedItems\"", encodedData);
508 if(!data->hasFormat(
"application/x-terralib;value=\"DraggedItems\""))
522 if (action == Qt::IgnoreAction)
525 QByteArray encodedData = data->data(
"application/x-terralib;value=\"DraggedItems\"");
527 qulonglong dataValue = encodedData.toULongLong();
529 std::unique_ptr< std::vector<TreeItem*> > changed(
reinterpret_cast< std::vector<TreeItem*>*
>(dataValue));
537 newPar = (!nP.isValid()) ?
m_root.get() :
static_cast<TreeItem*
>(nP.internalPointer());
542 addItems(*changed.get(), newPar, row);
552 QModelIndexList idxs = lst;
558 while(!idxs.isEmpty())
560 QModelIndex idx = idxs.takeLast();
561 QModelIndex par = idx.parent();
563 removeRow(idx.row(), par);
570 if (!index.isValid())
573 QModelIndex par =
parent(index);
580 if(role == Qt::CheckStateRole)
582 if(item->
flags() & Qt::ItemIsUserCheckable)
588 if(role == Qt::ToolTipRole)
589 return QString::fromUtf8(item->
getToolTip().c_str());
591 if(role == Qt::DisplayRole)
592 return QString::fromUtf8(item->
getAsString().c_str());
603 return item->
flags();
606 return Qt::ItemIsDropEnabled;
610 int , Qt::Orientation orientation,
int role)
const 612 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
620 size_t c =
m_root->getChildrenCount(
"");
623 return QModelIndex();
625 if(!parent.isValid())
627 if(static_cast<std::size_t>(row) >= c)
628 return QModelIndex();
633 return createIndex(row, column, item);
638 if(parentItem ==
nullptr)
642 return QModelIndex();
649 return createIndex(row, column, item);
654 if (!index.isValid())
655 return QModelIndex();
660 if (parentItem ==
m_root.get())
661 return QModelIndex();
663 return createIndex(parentItem->
getPosition(), 0, parentItem);
669 if (parent.column() > 0)
672 if (!parent.isValid())
673 parentItem =
m_root.get();
675 parentItem =
static_cast<TreeItem*
>(parent.internalPointer());
void GetRootFolder(std::list< te::map::AbstractLayerPtr > layers, te::qt::widgets::TreeItem *root, const std::string &idxPath)
Defines a folder item, just containing LayerItem.
A class that represents a style of a layer in a LayerTreeModel.
void CleanRemoveList(QModelIndexList &lst)
te::qt::widgets::TreeItem * GetFolder(te::common::TreeItemPtr l, const std::string &idxPath)
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.
A layer that can be used as a container for other kind of layers.
void add(const TreeItemPtr &childItem)
It adds (appends) the item to the end of the children's list.
#define TE_TR(message)
It marks a string in order to get translated.
boost::intrusive_ptr< FolderLayer > FolderLayerPtr
void GetVisibleLayers(std::list< te::map::AbstractLayerPtr > &layers, const te::qt::widgets::TreeItem *item)
void setTotalSteps(int value)
Set the task total stepes.
boost::intrusive_ptr< TreeItem > TreeItemPtr
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Defines a layer item model for Qt5.
QModelIndex FindInsertInformation(const QModelIndex &par, int &row, te::qt::widgets::LayerItemModel *model)
A class for building layer items.
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)