27 #include "../../common/STLUtils.h"
28 #include "../../common/Translator.h"
29 #include "../Exception.h"
34 : QAbstractItemModel(parent),
35 m_singleSelection(singleSelection)
37 for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
54 return !m_items.empty();
76 return item->
data(index.column(), role);
87 throw Exception(
TR_VP(
"Invalid data associated to the layer model!"));
95 return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled;
100 throw Exception(
TR_VP(
"Invalid data associated to the layer model!"));
102 return QAbstractItemModel::flags(index) | item->
flags();
107 if(!parent.isValid())
108 return !m_items.empty();
113 throw Exception(
TR_VP(
"Invalid data associated to the layer model!"));
121 return QModelIndex();
123 if(!parent.isValid() &&
static_cast<std::size_t
>(row) >= m_items.size())
124 return QModelIndex();
128 if(parentItem && row >= parentItem->children().count())
129 return QModelIndex();
131 if(!parent.isValid())
136 return createIndex(row, column, item);
140 throw Exception(
TR_VP(
"Invalid data associated to the layer model!"));
142 if(parentItem->children().empty())
143 throw Exception(
TR_VP(
"The layer item in the model must have a child item!"));
145 if(row >= parentItem->children().size())
146 throw Exception(
TR_VP(
"The row for the layer item is out of range!"));
151 throw Exception(
TR_VP(
"The layer item is not an te::qt::widgets::AbstractTreeItem!"));
153 return createIndex(row, column, item);
159 return QModelIndex();
163 if(item == 0 || item->parent() == 0)
164 return QModelIndex();
169 throw Exception(
TR_VP(
"The layer item is not an AbstractTreeItem!"));
173 if(grandParentItem == 0)
176 for(std::size_t i = 0; i != m_items.size(); ++i)
178 if(m_items[i] == parentItem)
179 return createIndex(static_cast<int>(i), index.column(), parentItem);
185 const QObjectList& items = grandParentItem->children();
189 for(QObjectList::const_iterator it = items.begin(); it != items.end(); ++it, ++i)
191 if((*it) == parentItem)
192 return createIndex(i, index.column(), parentItem);
196 throw Exception(
TR_VP(
"Could not determine the layer index in the model!"));
201 if(!parent.isValid())
202 return static_cast<int>(m_items.size());
207 throw Exception(
TR_VP(
"Error: NULL layer item!"));
209 return item->children().count();
222 bool retval = item->
setData(index.column(), value, role);
224 emit dataChanged(index, index);
226 if(role == Qt::CheckStateRole)
228 if(parent(index).isValid())
231 QModelIndex ascendentIndex = parent(index);
233 while(ascendentIndex.isValid())
235 emit dataChanged(ascendentIndex, ascendentIndex);
236 ascendentIndex = parent(ascendentIndex);
240 if(m_singleSelection)
246 for(
size_t i = 0; i < m_items.size(); ++i)
248 if(m_items[i] == item)
259 QModelIndex start_ix = createIndex( 0, 0 );
260 QModelIndex end_ix = createIndex( 0, 1 );
261 emit( dataChanged( start_ix, end_ix ) );
268 if(role == Qt::DisplayRole)
270 if(orientation == Qt::Horizontal)
273 return QVariant(
TR_VP(
"Layers"));
274 else if(section == 1)
275 return QVariant(
TR_VP(
"Only Selected"));
279 return QAbstractItemModel::headerData(section, orientation, role);
284 std::map<te::map::AbstractLayerPtr, std::vector<te::dt::Property*> > selected;
286 for(
size_t i = 0; i < m_items.size(); ++i)
306 for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
311 m_items.push_back(litem);
315 QModelIndex start_ix = createIndex( 0, 0 );
316 QModelIndex end_ix = createIndex( 0, 1 );
317 emit( dataChanged( start_ix, end_ix ) );
virtual te::map::AbstractLayerPtr getLayer() const =0
std::map< te::map::AbstractLayerPtr, std::vector< te::dt::Property * > > getSelected()
It get the Layer selected and the Properties selected of the Layer.
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.
LayerTreeModel(const std::list< te::map::AbstractLayerPtr > &layers, bool singleSelection=false, QObject *parent=0)
It constructs an item model with the given parent.
virtual bool setData(int column, const QVariant &value, int role=Qt::EditRole)=0
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...
virtual void fetchMore()=0
virtual QVariant data(int column, int role) const =0
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
int columnCount(const QModelIndex &parent=QModelIndex()) const
It returns the number of columns for the children of the given parent.
void fetchMore(const QModelIndex &parent)
It fetches any available data for the items with the parent specified by the parent index...
void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
std::vector< te::qt::widgets::AbstractTreeItem * > m_items
virtual Qt::ItemFlags flags() const =0
bool canFetchMore(const QModelIndex &parent) const
It fetches more data for parent.
The class that defines the model used in the Qt Model/View architecture.
virtual bool canFetchMore() const =0
A class that represents a Layer in a LayerTreeModel.
The class that represents an item in a LayerTreeModel.
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.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
It sets the role data for the item at index to value.
int rowCount(const QModelIndex &parent=QModelIndex()) const
It returns the number of rows of the given parent.
QModelIndex parent(const QModelIndex &index) const
It returns the item parent of the given index, or QModelIndex(), if it has no parent.
void isSelected(bool selected)
Set the Layer as selected.
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...
#define TR_VP(message)
It marks a string in order to get translated. This is a special mark used in the Terrralib Vector Pro...
te::map::AbstractLayerPtr getLayer() const
virtual bool hasChildren() const =0
std::vector< te::dt::Property * > getSelected()
Get the selected Properties of the Layer.