35 #include <boost/tuple/tuple.hpp>
38 #include <QtCore/QMimeData>
39 #include <QtCore/QUrl>
40 #include <QtGui/QDragEnterEvent>
41 #include <QtGui/QDragLeaveEvent>
42 #include <QtGui/QDragMoveEvent>
43 #include <QtGui/QDropEvent>
44 #include <QtGui/QMenu>
45 #include <QtGui/QMessageBox>
56 typedef boost::tuple<QAction*, std::string, std::string, te::qt::widgets::LayerTreeView::ContextMenuSelectionType, bool>
tuple_type;
63 void add(QAction* action,
64 const std::string& menu,
65 const std::string& layerType,
71 void remove(QAction* action)
73 std::list<tuple_type>::iterator it =
m_menus.begin();
77 if(it->get<0>() == action)
79 std::list<tuple_type>::iterator auxit = it;
96 if(selectedItems.empty())
99 for(std::list<tuple_type>::const_iterator it =
m_menus.begin(); it !=
m_menus.end(); ++it)
101 QAction* action = it->get<0>();
105 menu.addAction(action);
108 else if(selectedItems.size() == 1)
116 std::string selectedItemType;
118 if(layer && layer->getSchema().get() && layer->getSchema()->hasRaster())
119 selectedItemType =
"RASTER_LAYER_ITEM";
123 std::list<tuple_type>::const_iterator it;
126 QAction* action = it->get<0>();
127 std::string aItemType = it->get<2>();
135 if((selectedItemType ==
"GROUPING_ITEM" || selectedItemType ==
"CHART_ITEM" || selectedItemType ==
"COLORMAP_ITEM") &&
136 aItemType ==
"ITEM_OF_LAYER")
138 menu.addAction(action);
144 if(selectedItemType ==
"RASTER_LAYER_ITEM" || selectedItemType ==
"FOLDER_LAYER_ITEM")
146 if(aItemType == selectedItemType)
147 menu.addAction(action);
151 if(aItemType.empty() || aItemType == selectedItemType)
152 menu.addAction(action);
159 std::map<std::string, std::vector<QAction*> > actionsByLayerType;
162 std::string layerType;
164 std::list<AbstractTreeItem*>::const_iterator it;
165 for(it = selectedItems.begin(); it != selectedItems.end(); ++it)
171 if(layer->getSchema().get() && layer->getSchema()->hasRaster())
172 layerType =
"RASTER_LAYER_ITEM";
174 layerType = (*it)->getItemType();
176 actionsByLayerType[layerType] = std::vector<QAction*>();
180 for(std::list<tuple_type>::const_iterator it =
m_menus.begin(); it !=
m_menus.end(); ++it)
182 QAction* action = it->get<0>();
183 std::string alayerType = it->get<2>();
189 layerType = alayerType;
191 if(layerType.empty())
193 for(std::map<std::string, std::vector<QAction*> >::iterator it = actionsByLayerType.begin();
194 it != actionsByLayerType.end(); ++it)
196 it->second.push_back(action);
200 actionsByLayerType[layerType].push_back(action);
204 std::vector<std::vector<QAction*> > setVec;
206 for(std::map<std::string, std::vector<QAction*> >::iterator it = actionsByLayerType.begin();
207 it != actionsByLayerType.end(); ++it)
209 setVec.push_back(it->second);
215 std::vector<QAction*> commonActions = setVec[0];
216 std::sort(commonActions.begin(), commonActions.end());
218 for(std::size_t i = 1; i < setVec.size(); ++i)
220 std::sort(setVec[i].begin(), setVec[i].end());
222 std::vector<QAction*> intersect;
223 std::set_intersection(commonActions.begin(), commonActions.end(),
224 setVec[i].begin(), setVec[i].end(),
225 std::inserter(intersect, intersect.begin()));
227 commonActions = intersect;
231 for(std::size_t i = 0; i < commonActions.size(); ++ i)
232 menu.addAction(commonActions[i]);
248 setAcceptDrops(
true);
249 setDragEnabled(
true);
251 setDefaultDropAction(Qt::MoveAction);
253 setRootIsDecorated(
true);
254 setSelectionMode(QAbstractItemView::ExtendedSelection);
256 viewport()->setAutoFillBackground(
true);
275 std::list<AbstractTreeItem*> selectedItems;
277 QModelIndexList indexes = selectedIndexes();
281 foreach(idx, indexes)
286 selectedItems.push_back(selectedItem);
289 return selectedItems;
294 std::list<te::qt::widgets::AbstractTreeItem*> selectedItems = getSelectedItems();
296 std::list<te::qt::widgets::AbstractTreeItem*> selectedLayerItems;
298 std::list<te::qt::widgets::AbstractTreeItem*>::const_iterator it;
299 for(it = selectedItems.begin(); it != selectedItems.end(); ++it)
304 selectedLayerItems.push_back(selectedItem);
307 return selectedLayerItems;
312 std::list<te::qt::widgets::AbstractTreeItem*> selectedLayerItems = getSelectedLayerItems();
314 std::list<te::qt::widgets::AbstractTreeItem*> selectedSingleLayerItems;
316 std::list<te::qt::widgets::AbstractTreeItem*>::const_iterator it;
317 for(it = selectedLayerItems.begin(); it != selectedLayerItems.end(); ++it)
321 if(selectedLayerItem->
getLayer() && selectedLayerItem->
getItemType() !=
"FOLDER_ITEM_TYPE")
322 selectedSingleLayerItems.push_back(selectedLayerItem);
325 return selectedSingleLayerItems;
330 std::list<te::map::AbstractLayerPtr> selectedSingleLayers;
332 std::list<te::qt::widgets::AbstractTreeItem*> selectedItems = getSelectedItems();
334 std::list<te::qt::widgets::AbstractTreeItem*>::const_iterator it;
335 for(it = selectedItems.begin(); it != selectedItems.end(); ++it)
341 if(layer && layer->getType() !=
"FOLDERLAYER")
342 selectedSingleLayers.push_back(layer);
345 return selectedSingleLayers;
350 std::list<te::map::AbstractLayerPtr> selectedAndVisibleSingleLayers;
352 std::list<te::map::AbstractLayerPtr> selectedSingleLayers = getSelectedSingleLayers();
354 std::list<te::map::AbstractLayerPtr>::const_iterator it;
355 for(it = selectedSingleLayers.begin(); it != selectedSingleLayers.end(); ++it)
359 selectedAndVisibleSingleLayers.push_back(layer);
362 return selectedAndVisibleSingleLayers;
367 std::list<te::map::AbstractLayerPtr> selectedLayers;
369 std::list<te::qt::widgets::AbstractTreeItem*> selectedItems = getSelectedItems();
371 std::list<te::qt::widgets::AbstractTreeItem*>::const_iterator it;
372 for(it = selectedItems.begin(); it != selectedItems.end(); ++it)
377 selectedLayers.push_back(selectedLayer);
380 if(!selectedLayers.empty())
381 emit selectedLayersChanged(selectedLayers);
385 const std::string& menu,
386 const std::string& itemType,
389 m_pImpl->add(action, menu, itemType, menuSelectionType);
394 m_pImpl->remove(action);
401 emit activated(item);
421 if((itemLayer != 0) && itemLayer->hasVisibilityChanged())
423 if(itemLayer->getType() !=
"FOLDERLAYER")
424 emit visibilityChanged(itemLayer);
427 std::vector<AbstractTreeItem*> descendantItems = item->
getDescendants();
428 for(std::size_t i = 0; i < descendantItems.size(); ++i)
432 if((descendantLayer != 0) && descendantLayer->hasVisibilityChanged())
434 if(descendantLayer->getType() !=
"FOLDERLAYER")
435 emit visibilityChanged(descendantLayer);
440 std::vector<AbstractTreeItem*> ancestorItems = item->
getAncestors();
441 for(std::size_t i = 0; i < ancestorItems.size(); ++i)
445 if((ancestorLayer != 0) && ancestorLayer->hasVisibilityChanged())
447 if(ancestorLayer->getType() !=
"FOLDERLAYER")
448 emit visibilityChanged(ancestorLayer);
458 emit doubleClicked(item);
486 QTreeView::dragEnterEvent(e);
491 if(e->keyboardModifiers() == Qt::ControlModifier)
492 e->setDropAction(Qt::CopyAction);
494 e->setDropAction(Qt::MoveAction);
498 QTreeView::dragMoveEvent(e);
507 QTreeView::dragLeaveEvent(e);
529 QTreeView::dropEvent(e);
536 m_pImpl->showContextMenu(e->globalPos());
std::list< tuple_type > m_menus
A list of information about context menus.
void clicked(te::qt::widgets::AbstractTreeItem *item)
virtual te::map::AbstractLayerPtr getLayer() const =0
void contextMenuEvent(QContextMenuEvent *e)
void onItemClicked(const QModelIndex &index)
std::list< AbstractTreeItem * > getSelectedLayerItems() const
It gets the single and folder layer items that are selected in the tree view.
LayerTreeView implementation.
boost::tuple< QAction *, std::string, std::string, te::qt::widgets::LayerTreeView::ContextMenuSelectionType, bool > tuple_type
This is the base class for layers.
std::list< AbstractTreeItem * > getSelectedSingleLayerItems() const
It gets the single layer items that are selected in the tree view.
void onSelectedLayersChanged(const QItemSelection &selected, const QItemSelection &deselected)
std::list< AbstractTreeItem * > getSelectedItems() const
It gets the items that are selected in the tree view.
void add(QAction *action, const std::string &menu="", const std::string &itemType="", ContextMenuSelectionType menuSelectionType=te::qt::widgets::LayerTreeView::UNIQUE_ITEM_SELECTED)
It adds the action to a specified menu of a given item type when a context menu is displayed...
void setVisibilityAsChanged(bool visChanged)
It sets that the status of the layer visibility is to be changed or not..
void activated(te::qt::widgets::AbstractTreeItem *item)
void onItemDoubleClicked(const QModelIndex &index)
void remove(QAction *action)
It removes the action from the list of context menu.
void dropEvent(QDropEvent *e)
virtual const std::string getItemType() const =0
It returns the item type.
std::list< te::map::AbstractLayerPtr > getSelectedAndVisibleSingleLayers() const
It gets the single layers that are selected and visible in the tree view.
std::list< te::map::AbstractLayerPtr > getSelectedSingleLayers() const
It gets the single layers that are selected in the view.
Impl(te::qt::widgets::LayerTreeView *ltv)
void dragEnterEvent(QDragEnterEvent *e)
te::qt::widgets::LayerTreeView * m_ltv
The layer tree view associated to this implementation.
void onItemPressed(const QModelIndex &index)
void entered(te::qt::widgets::AbstractTreeItem *item)
std::vector< te::qt::widgets::AbstractTreeItem * > getAncestors()
A tree view for the layers of an application.
void showContextMenu(const QPoint &pos)
void dragMoveEvent(QDragMoveEvent *e)
~LayerTreeView()
Destructor.
Impl * m_pImpl
The tree view implementation.
void dragLeaveEvent(QDragLeaveEvent *e)
The class that represents an item in a LayerTreeModel.
This class defines the model used in the Qt Model/View architecture for the tree of layers...
void pressed(te::qt::widgets::AbstractTreeItem *item)
void onItemEntered(const QModelIndex &index)
void add(QAction *action, const std::string &menu, const std::string &layerType, te::qt::widgets::LayerTreeView::ContextMenuSelectionType menuSelectionType)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::vector< te::qt::widgets::AbstractTreeItem * > getDescendants()
bool isCheckable() const
It verifies if the model items are checkable or not.
void onItemActivated(const QModelIndex &index)
void doubleClicked(te::qt::widgets::AbstractTreeItem *item)
LayerTreeView(QWidget *parent=0)
Constructor.
A tree view for the layers of an application.
The class that represents an item in a LayerTreeModel.