23 #include "IsisDebug.h"
28 #include <QItemSelection>
31 #include <QModelIndex>
63 return proxyItem->index();
84 return sourceItem->index();
102 const QItemSelection &sourceSelection) {
104 QItemSelection proxySelection = QItemSelection();
106 foreach ( QModelIndex sourceIndex, sourceSelection.indexes() ) {
108 if ( proxyIndex.isValid() ) {
109 proxySelection.select(proxyIndex, proxyIndex);
113 return proxySelection;
127 QItemSelection sourceSelection = QItemSelection();
129 foreach ( QModelIndex proxyIndex, proxySelection.indexes() ) {
131 if ( sourceIndex.isValid() ) {
132 sourceSelection.select(sourceIndex, sourceIndex);
136 return sourceSelection;
149 return m_sourceProxyMap.value(sourceItem, 0);
162 return m_sourceProxyMap.key(proxyItem, 0);
190 proxyItem =
addChild(sourceItem, parentItem);
193 proxyItem =
addChild(sourceItem, 0);
196 for (
int i=0; i < sourceItem->rowCount(); i++) {
253 SIGNAL( currentChanged(
const QModelIndex &,
const QModelIndex &) ),
257 SIGNAL( currentChanged(
const QModelIndex &,
const QModelIndex &) ),
261 SIGNAL( selectionChanged(
const QItemSelection &,
const QItemSelection &) ),
265 SIGNAL( selectionChanged(
const QItemSelection &,
const QItemSelection &) ),
271 connect(sourceModel, SIGNAL(itemRemoved(
ProjectItem *)),
295 proxyItem->setProjectItem(sourceItem);
308 selectionModel()->setCurrentIndex(newProxyCurrent, QItemSelectionModel::Current);
321 QItemSelectionModel::Current);
334 selectionModel()->select(newProxySelection, QItemSelectionModel::ClearAndSelect);
348 QItemSelectionModel::ClearAndSelect);
379 if ( parentItem && (parentItem->
model() !=
this) ) {
388 m_sourceProxyMap.insert(sourceItem, proxyItem);
392 oldParent->takeRow( proxyItem->row() );
395 model->takeRow( proxyItem->row() );
418 updateItem( static_cast<ProjectItem *>(item) );
434 Qt::DropAction action,
436 const QModelIndex &parent)
const {
453 Qt::DropAction action,
455 const QModelIndex &parent) {
456 if ( data->hasFormat(
"application/x-qabstractitemmodeldatalist") ) {
QModelIndex mapIndexFromSource(const QModelIndex &sourceIndex)
Returns the QModelIndex of an item in the proxy model that corresponds with the QModelIndex of an ite...
void updateProxySelection()
Slot that updates the selection in the proxy model only if it is different than the corresponding sel...
void appendRow(ProjectItem *item)
Appends an item to the children of this item.
void updateSourceSelection()
Slot that updates the selection in the source model only if it is different than the corresponding se...
ProjectItem * itemFromIndex(const QModelIndex &index)
Returns the ProjectItem corresponding to a given QModelIndex.
void updateItem(ProjectItem *sourceItem)
Given an item in the source model, this method changes the data of the corresponding item in the prox...
ProjectItem * parent() const
Returns the parent item of this item.
ProjectItemProxyModel(QObject *parent=0)
Constructs the proxy model.
Provides access to data stored in a Project through Qt's model-view framework.
ProjectItem * addItem(ProjectItem *sourceItem)
Adds an item and its children to the proxy model.
void setProjectItem(ProjectItem *item)
Sets the text, icon, and data to those of another item.
void updateProxyCurrent()
Slot that updates the current item in the proxy model only if it is different than the corresponding ...
QModelIndex mapIndexToSource(const QModelIndex &proxyIndex)
Returns the QModelIndex of an item in the souce model that corresponds with the QModelIndex of an ite...
void appendRow(ProjectItem *item)
Appends a top-level item to the model.
ProjectItemModel * model() const
Returns the ProjectItemModel associated with this item.
ProjectItem * addChild(ProjectItem *sourceItem, ProjectItem *parentItem)
Creates an item in the proxy model corresponding to an item in the source model as a child of a paren...
QItemSelectionModel * selectionModel()
Returns the internal selection model.
void updateSourceCurrent()
Slot that updates the current item in the proxy model only if it is different than the corresponding ...
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
ProjectItem * item(int row)
Returns the top-level item at the given row.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Adds the data (selected items) from the source model to the proxy model.
ProjectItemModel * sourceModel()
Returns the source model.
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
Returns true.
void addItems(QList< ProjectItem * > sourceItems)
Adds a list of items to the proxy model.
ProjectItem * mapItemToSource(ProjectItem *proxyItem)
Returns the ProjectItem in the source model that corresponds with a ProjectItem in the source model...
ProjectItemModel * m_sourceModel
The source model. Map of items from the source model to the proxy mo...
QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection)
Returns a QItemSelection of items in the proxy model that corresponds with a QItemSelection of items ...
void onItemChanged(QStandardItem *item)
Signal to connect to the itemChanged() signal from a ProjectItemModel.
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
Represents an item of a ProjectItemModel in Qt's model-view framework.
void removeItem(ProjectItem *item)
Removes an item and its children from the proxy model.
ProjectItem * mapItemFromSource(ProjectItem *sourceItem)
Returns the ProjectItem in the proxy model that corresponds with a ProjectItem in the source model...
QItemSelection mapSelectionToSource(const QItemSelection &proxySelection)
Returns a QItemSelection of items in the source model that corresponds with a QItemSelection of itesm...
ProjectItem * child(int row) const
Returns the child item at a given row.
void setSourceModel(ProjectItemModel *sourceModel)
Sets the source model.