Isis 3.0 Programmer Reference
Back | Home
Isis::ProjectItemProxyModel Class Reference

Allows access to items in a ProjectItemModel through a proxy model. More...

#include <ProjectItemProxyModel.h>

Inheritance diagram for Isis::ProjectItemProxyModel:
Inheritance graph
Collaboration diagram for Isis::ProjectItemProxyModel:
Collaboration graph

Public Slots

ProjectItemaddItem (ProjectItem *sourceItem)
 Adds an item and its children to the proxy model. More...
 
void addItems (QList< ProjectItem * > sourceItems)
 Adds a list of items to the proxy model. More...
 

Signals

void itemRemoved (ProjectItem *)
 
void itemAdded (ProjectItem *)
 This signal is emitted when a ProjectItem is added to the model. More...
 

Public Member Functions

 ProjectItemProxyModel (QObject *parent=0)
 Constructs the proxy model. More...
 
QModelIndex mapIndexFromSource (const QModelIndex &sourceIndex)
 Returns the QModelIndex of an item in the proxy model that corresponds with the QModelIndex of an item in the source model. More...
 
QModelIndex mapIndexToSource (const QModelIndex &proxyIndex)
 Returns the QModelIndex of an item in the souce model that corresponds with the QModelIndex of an item in the proxy model. More...
 
QItemSelection mapSelectionFromSource (const QItemSelection &sourceSelection)
 Returns a QItemSelection of items in the proxy model that corresponds with a QItemSelection of items in the source model. More...
 
QItemSelection mapSelectionToSource (const QItemSelection &proxySelection)
 Returns a QItemSelection of items in the source model that corresponds with a QItemSelection of itesm in the proxy model. More...
 
ProjectItemmapItemFromSource (ProjectItem *sourceItem)
 Returns the ProjectItem in the proxy model that corresponds with a ProjectItem in the source model. More...
 
ProjectItemmapItemToSource (ProjectItem *proxyItem)
 Returns the ProjectItem in the source model that corresponds with a ProjectItem in the source model. More...
 
void removeItem (ProjectItem *item)
 Removes an item and its children from the proxy model. More...
 
void setSourceModel (ProjectItemModel *sourceModel)
 Sets the source model. More...
 
ProjectItemModelsourceModel ()
 Returns the source model. More...
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
 Returns true. More...
 
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. More...
 
QItemSelectionModel * selectionModel ()
 Returns the internal selection model. More...
 
ProjectItemaddProject (Project *project)
 Adds a Project to the model. More...
 
ProjectItemfindItemData (const QVariant &data, int role=Qt::UserRole+1)
 Returns the first item found that contains the given data in the given role or a null pointer if no item is found. More...
 
virtual void removeItems (QList< ProjectItem * > items)
 Removes a list of items and their children from the model. More...
 
ProjectItemcurrentItem ()
 Returns the current item of the internal selection model. More...
 
QList< ProjectItem * > selectedItems ()
 Returns a list of the selected items of the internal selection model. More...
 
void appendRow (ProjectItem *item)
 Appends a top-level item to the model. More...
 
QModelIndex indexFromItem (const ProjectItem *item)
 Returns the QModelIndex corresponding to a given ProjectItem. More...
 
void insertRow (int row, ProjectItem *item)
 Inserts a top-level item at the given row. More...
 
ProjectItemitem (int row)
 Returns the top-level item at the given row. More...
 
ProjectItemitemFromIndex (const QModelIndex &index)
 Returns the ProjectItem corresponding to a given QModelIndex. More...
 
void setItem (int row, ProjectItem *item)
 Sets the item at the top-level row. More...
 
ProjectItemtakeItem (int row)
 Removes the top-level row and returns the removed item. More...
 

Protected Slots

void updateItem (ProjectItem *sourceItem)
 Given an item in the source model, this method changes the data of the corresponding item in the proxy model to match that of the item in the source model. More...
 
void updateProxyCurrent ()
 Slot that updates the current item in the proxy model only if it is different than the corresponding item in the source model. More...
 
void updateSourceCurrent ()
 Slot that updates the current item in the proxy model only if it is different than the corresponding item in the source model. More...
 
void updateProxySelection ()
 Slot that updates the selection in the proxy model only if it is different than the corresponding selection in the source model. More...
 
void updateSourceSelection ()
 Slot that updates the selection in the source model only if it is different than the corresponding selection in the proxy model. More...
 
void onSelectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 Slot to connect to the selectionChanged() signal from a selection model. More...
 

Protected Member Functions

ProjectItemaddChild (ProjectItem *sourceItem, ProjectItem *parentItem)
 Creates an item in the proxy model corresponding to an item in the source model as a child of a parent item in the proxy model. More...
 

Private Slots

void onItemChanged (QStandardItem *item)
 Signal to connect to the itemChanged() signal from a ProjectItemModel. More...
 

Private Attributes

ProjectItemModelm_sourceModel
 
                                The source model.

Map of items from the source model to the proxy model. More...

 
QMap< ProjectItem
*, ProjectItem * > 
m_sourceProxyMap
 

Detailed Description

Allows access to items in a ProjectItemModel through a proxy model.

A proxy model can have a different structure than the source model. An item in the proxy model usually corresponds to an item in the source model. The proxy model will update item selections and the current item between the source model and the proxy model.

In the default implementation the only items in the proxy model are item that are added with the addItem() method. The items that are added are organized in the same tree structure that they are in the source model. Subclasses of ProjectItemProxyModel can organize items in a different way by overriding the addItem() method.

The proxy model ensures that its item selection corresponds to the item selection in the source model. When the selection in the proxy model changes the selection in the source model is changed to the items that correspond to the items in the proxy selection. Similarly when the selection in the source model is changed the selection in the proxy model is changed to the items in the proxy model that correpond to the items in the selection.

* ProjectItemModel *model = new ProjectItemModel(this);
* model->addProject(project);
* ProjectItemProxyModel *proxyModel = new ProjectItemProxyModel(this);
* proxyModel->setSourceModel(model);
* for (int i=0; i < model.rowCount(); i++) {
* proxyModel->addItem( model->item(i) );
* }
*
Author
2015-10-21 Jeffrey Covington
History:

2015-10-21 Jeffrey Covington - Original version.

2016-01-13 Jeffrey Covington - Added canDropMimeData() and dropMimeData() methods.

2016-06-27 Ian Humphrey - Added documentation to the canDropMimeData() and dropMimeData() methods. Checked coding standards. Fixes #4006.

2016-08-11 Tracie Sucharski - Added itemRemoved signal.

2016-08-25 Adam Paquette - Updated documentation. Fixes #4299.

Definition at line 82 of file ProjectItemProxyModel.h.

Constructor & Destructor Documentation

Isis::ProjectItemProxyModel::ProjectItemProxyModel ( QObject parent = 0)

Constructs the proxy model.

Parameters
[in]parent(QObject *) The parent QObject.

Definition at line 44 of file ProjectItemProxyModel.cpp.

References m_sourceModel.

Member Function Documentation

ProjectItem * Isis::ProjectItemProxyModel::addChild ( ProjectItem sourceItem,
ProjectItem parentItem 
)
protected

Creates an item in the proxy model corresponding to an item in the source model as a child of a parent item in the proxy model.

If the corresponding item in the proxy model already exits then that item is updated instead of creating a new item. If the corresponding item already has a parent its parent is changed to the new parent. If the parent item is null then the item is added as a top-level item in the model.

Parameters
[in]sourceItem(ProjectItem *) The item in the source model.
[in]parentItem(ProjectItem *) The parent in the proxy model.
Returns
ProjectItem* The correponding item in the proxy model.

Definition at line 366 of file ProjectItemProxyModel.cpp.

References Isis::ProjectItemModel::appendRow(), Isis::ProjectItem::appendRow(), mapItemFromSource(), Isis::ProjectItem::model(), Isis::ProjectItem::parent(), Isis::ProjectItem::setProjectItem(), setSourceModel(), and sourceModel().

Referenced by addItem().

ProjectItem * Isis::ProjectItemProxyModel::addItem ( ProjectItem sourceItem)
slot

Adds an item and its children to the proxy model.

Creates items in the proxy model from an item in the source model and returns the created item. If the item in the source model has already been added, then the corresponding item in the proxy model is updated and returned instead.

When an item in the source model is added the children of that item are also added as children of the corresponding item in the proxy model.

Parameters
[in]sourceItem(ProjectItem *) The item in the source model.
Returns
ProjectItem* The item in the proxy model.

Definition at line 181 of file ProjectItemProxyModel.cpp.

References addChild(), Isis::ProjectItem::child(), mapItemFromSource(), and Isis::ProjectItem::parent().

Referenced by addItems().

void Isis::ProjectItemProxyModel::addItems ( QList< ProjectItem * >  sourceItems)
slot

Adds a list of items to the proxy model.

Parameters
[in]sourceItem(QList<ProjectItem *>) The list of items in the source model.

Definition at line 210 of file ProjectItemProxyModel.cpp.

References addItem(), and Isis::ProjectItemModel::item().

Referenced by dropMimeData().

ProjectItem * Isis::ProjectItemModel::addProject ( Project project)
inherited

Adds a Project to the model.

An item is created that corresponds to the Project as well as children items that correspond to various parts of the Project.

Parameters
[in]project(Project *) The Project to be added.
Returns
ProjectItem* The new item that corresponds to the Project.

Definition at line 114 of file ProjectItemModel.cpp.

References Isis::ProjectItemModel::appendRow(), Isis::ProjectItemModel::onBundleSolutionInfoAdded(), Isis::ProjectItemModel::onControlAdded(), Isis::ProjectItemModel::onControlListAdded(), Isis::ProjectItemModel::onGuiCamerasAdded(), Isis::ProjectItemModel::onImagesAdded(), Isis::ProjectItemModel::onNameChanged(), Isis::ProjectItemModel::onShapesAdded(), and Isis::ProjectItemModel::onTargetsAdded().

void Isis::ProjectItemModel::appendRow ( ProjectItem item)
inherited

Appends a top-level item to the model.

Parameters
[in]item(ProjectItem *) The item to append.

Definition at line 230 of file ProjectItemModel.cpp.

Referenced by addChild(), and Isis::ProjectItemModel::addProject().

bool Isis::ProjectItemProxyModel::canDropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
) const
virtual

Returns true.

You can drop data into a ProjectItemProxyModel

Parameters
data(const QMimeData *) The data to drop
action(Qt::DropAction) The drop action
row(int) ???
column(int)???
QModelIndex(const QModelIndex &) Index of the data's parent item
Returns
bool True if the proxy model can accept the mime data.

Reimplemented from Isis::ProjectItemModel.

Definition at line 433 of file ProjectItemProxyModel.cpp.

ProjectItem * Isis::ProjectItemModel::currentItem ( )
inherited

Returns the current item of the internal selection model.

Returns
ProjectItem* The current item.

Definition at line 144 of file ProjectItemModel.cpp.

References Isis::ProjectItemModel::itemFromIndex(), and Isis::ProjectItemModel::selectionModel().

Referenced by Isis::AbstractProjectItemView::currentItem(), and Isis::RemoveImagesWorkOrder::syncRedo().

bool Isis::ProjectItemProxyModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
virtual

Adds the data (selected items) from the source model to the proxy model.

Parameters
data(const QMimeData *)
action(Qt::DropAction)
row(int)
column(int)
QModelIndex(const QModelIndex &)
Returns
bool True if the data was successfully added to the proxy model.

Definition at line 452 of file ProjectItemProxyModel.cpp.

References addItems(), Isis::ProjectItemModel::selectedItems(), and sourceModel().

ProjectItem * Isis::ProjectItemModel::findItemData ( const QVariant &  data,
int  role = Qt::UserRole+1 
)
inherited

Returns the first item found that contains the given data in the given role or a null pointer if no item is found.

Parameters
data(const QVariant &) The data contained in the item.
data(int) The role of the data (see Qt::ItemDataRole).
Returns
ProjectItem* First project item found.

Definition at line 176 of file ProjectItemModel.cpp.

References Isis::ProjectItem::findItemData(), and Isis::ProjectItemModel::item().

QModelIndex Isis::ProjectItemModel::indexFromItem ( const ProjectItem item)
inherited

Returns the QModelIndex corresponding to a given ProjectItem.

Parameters
[in]item(const ProjectItem *) The item.
Returns
QModelIndex The index of the item.

Definition at line 242 of file ProjectItemModel.cpp.

void Isis::ProjectItemModel::insertRow ( int  row,
ProjectItem item 
)
inherited

Inserts a top-level item at the given row.

Parameters
[in]row(int) The row where the item will be inserted.
[in]item(ProjectItem *) The item to insert.

Definition at line 253 of file ProjectItemModel.cpp.

void Isis::ProjectItemModel::itemAdded ( ProjectItem )
signalinherited

This signal is emitted when a ProjectItem is added to the model.

Referenced by Isis::ProjectItemModel::onRowsInserted().

ProjectItem * Isis::ProjectItemModel::itemFromIndex ( const QModelIndex &  index)
inherited

Returns the ProjectItem corresponding to a given QModelIndex.

Parameters
[in]index(const QModelIndex &) The index of the item.
Returns
ProjectItem* The item.

Definition at line 277 of file ProjectItemModel.cpp.

Referenced by Isis::ProjectItemModel::currentItem(), mapIndexFromSource(), mapIndexToSource(), Isis::CubeDnView::onCurrentChanged(), Isis::ProjectItemModel::onRowsInserted(), Isis::ProjectItemModel::onRowsRemoved(), Isis::ProjectItemModel::onSelectionChanged(), and Isis::ProjectItemModel::selectedItems().

QModelIndex Isis::ProjectItemProxyModel::mapIndexFromSource ( const QModelIndex &  sourceIndex)

Returns the QModelIndex of an item in the proxy model that corresponds with the QModelIndex of an item in the source model.

Parameters
[in]sourceIndex(const QModelIndex &) The index from the source model.
Returns
QModelIndex The index from the proxy model.

Definition at line 59 of file ProjectItemProxyModel.cpp.

References Isis::ProjectItemModel::itemFromIndex(), mapItemFromSource(), and sourceModel().

Referenced by mapSelectionFromSource(), and updateProxyCurrent().

QModelIndex Isis::ProjectItemProxyModel::mapIndexToSource ( const QModelIndex &  proxyIndex)

Returns the QModelIndex of an item in the souce model that corresponds with the QModelIndex of an item in the proxy model.

Parameters
[in]proxyIndex(const QModelIndex &) The index from the proxy model.
Returns
QModelIndex The index from the source model.

Definition at line 80 of file ProjectItemProxyModel.cpp.

References Isis::ProjectItemModel::itemFromIndex(), and mapItemToSource().

Referenced by mapSelectionToSource(), and updateSourceCurrent().

ProjectItem * Isis::ProjectItemProxyModel::mapItemFromSource ( ProjectItem sourceItem)

Returns the ProjectItem in the proxy model that corresponds with a ProjectItem in the source model.

Parameters
[in]sourceItem(ProjectItem *) The item in the source model.
Returns
ProjectItem* The item in the proxy model.

Definition at line 148 of file ProjectItemProxyModel.cpp.

Referenced by addChild(), addItem(), mapIndexFromSource(), and updateItem().

ProjectItem * Isis::ProjectItemProxyModel::mapItemToSource ( ProjectItem proxyItem)

Returns the ProjectItem in the source model that corresponds with a ProjectItem in the source model.

Parameters
[in]proxyItem(ProjectItem *) The item in the proxy model.
Returns
ProjectItem* The item in the source model.

Definition at line 161 of file ProjectItemProxyModel.cpp.

Referenced by mapIndexToSource(), and removeItem().

QItemSelection Isis::ProjectItemProxyModel::mapSelectionFromSource ( const QItemSelection &  sourceSelection)

Returns a QItemSelection of items in the proxy model that corresponds with a QItemSelection of items in the source model.

Parameters
[in]sourceSelection(const QItemSelection &) The selection of items in the source model.
Returns
QItemSelection The selection of items in the proxy model.

Definition at line 101 of file ProjectItemProxyModel.cpp.

References mapIndexFromSource().

Referenced by updateProxySelection(), and updateSourceSelection().

QItemSelection Isis::ProjectItemProxyModel::mapSelectionToSource ( const QItemSelection &  proxySelection)

Returns a QItemSelection of items in the source model that corresponds with a QItemSelection of itesm in the proxy model.

Parameters
[in]proxySelection(const QItemSelection &) The selection of items in the proxy model.
Returns
QItemSelection The selection of items in the source model.

Definition at line 126 of file ProjectItemProxyModel.cpp.

References mapIndexToSource().

Referenced by updateSourceSelection().

void Isis::ProjectItemProxyModel::onItemChanged ( QStandardItem item)
privateslot

Signal to connect to the itemChanged() signal from a ProjectItemModel.

Updates the corresponding item in the proxy model.

Parameters
[in]item(QStandardItem *) The item that has been changed.

Definition at line 417 of file ProjectItemProxyModel.cpp.

References updateItem().

Referenced by setSourceModel().

void Isis::ProjectItemModel::onSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
protectedslotinherited

Slot to connect to the selectionChanged() signal from a selection model.

Updates other factors in the model that rely on selected items but do not directly correspond with the selection model. Currently changes the selected property of Images that correspond with selected or deselected items.

Parameters
[in]selected(const QItemSelection &) The selected items.
[in]deselected(const QItemSelection &) The deselected items.

Definition at line 579 of file ProjectItemModel.cpp.

References Isis::Image::displayProperties(), Isis::ProjectItem::image(), Isis::ProjectItem::isImage(), Isis::ProjectItemModel::item(), Isis::ProjectItemModel::itemFromIndex(), Isis::ProjectItemModel::selectedItems(), and Isis::ImageDisplayProperties::setSelected().

Referenced by Isis::ProjectItemModel::ProjectItemModel().

void Isis::ProjectItemProxyModel::removeItem ( ProjectItem item)
virtual

Removes an item and its children from the proxy model.

Parameters
[in]proxyItem(ProjectItem *) The item to be removed.

Reimplemented from Isis::ProjectItemModel.

Definition at line 223 of file ProjectItemProxyModel.cpp.

References mapItemToSource(), and Isis::ProjectItemModel::removeItem().

void Isis::ProjectItemModel::removeItems ( QList< ProjectItem * >  items)
virtualinherited

Removes a list of items and their children from the model.

Parameters
[in]item(ProjectItem *) The items to be removed.

Definition at line 218 of file ProjectItemModel.cpp.

References Isis::ProjectItemModel::item(), and Isis::ProjectItemModel::removeItem().

QList< ProjectItem * > Isis::ProjectItemModel::selectedItems ( )
inherited

Returns a list of the selected items of the internal selection model.

Returns
QList<ProjectItem*> The list of selected items.

Definition at line 154 of file ProjectItemModel.cpp.

References Isis::ProjectItemModel::itemFromIndex(), and Isis::ProjectItemModel::selectionModel().

Referenced by dropMimeData(), Isis::ProjectItemModel::onSelectionChanged(), Isis::AbstractProjectItemView::selectedItems(), Isis::CubeDnViewWorkOrder::syncRedo(), and Isis::Footprint2DViewWorkOrder::syncRedo().

void Isis::ProjectItemModel::setItem ( int  row,
ProjectItem item 
)
inherited

Sets the item at the top-level row.

Parameters
[in]row(int) The row where the item will be set.
[in]item(ProjectItem *) The item to set the row to.

Definition at line 288 of file ProjectItemModel.cpp.

void Isis::ProjectItemProxyModel::setSourceModel ( ProjectItemModel sourceModel)

Sets the source model.

If there are already items in the model and the source model is set to a different source model, the proxy model is cleared first.

Parameters
[in]sourceModel(ProjectItemModel *) The source model.

Definition at line 239 of file ProjectItemProxyModel.cpp.

References m_sourceModel, onItemChanged(), Isis::ProjectItemModel::selectionModel(), sourceModel(), updateProxyCurrent(), updateProxySelection(), updateSourceCurrent(), and updateSourceSelection().

Referenced by addChild().

ProjectItemModel * Isis::ProjectItemProxyModel::sourceModel ( )

Returns the source model.

Returns
ProjectItemModel* The source model.

Definition at line 281 of file ProjectItemProxyModel.cpp.

References m_sourceModel.

Referenced by addChild(), dropMimeData(), mapIndexFromSource(), setSourceModel(), updateProxyCurrent(), updateProxySelection(), updateSourceCurrent(), and updateSourceSelection().

ProjectItem * Isis::ProjectItemModel::takeItem ( int  row)
inherited

Removes the top-level row and returns the removed item.

Parameters
[in]row(int) The row of the item to remove.
Returns
ProjectItem* The removed item.

Definition at line 300 of file ProjectItemModel.cpp.

void Isis::ProjectItemProxyModel::updateItem ( ProjectItem sourceItem)
protectedslot

Given an item in the source model, this method changes the data of the corresponding item in the proxy model to match that of the item in the source model.

Parameters
[in]sourceItem(ProjectItem *) The item in the source model.

Definition at line 293 of file ProjectItemProxyModel.cpp.

References mapItemFromSource().

Referenced by onItemChanged().

void Isis::ProjectItemProxyModel::updateProxyCurrent ( )
protectedslot

Slot that updates the current item in the proxy model only if it is different than the corresponding item in the source model.

Definition at line 304 of file ProjectItemProxyModel.cpp.

References mapIndexFromSource(), Isis::ProjectItemModel::selectionModel(), and sourceModel().

Referenced by setSourceModel().

void Isis::ProjectItemProxyModel::updateProxySelection ( )
protectedslot

Slot that updates the selection in the proxy model only if it is different than the corresponding selection in the source model.

Definition at line 330 of file ProjectItemProxyModel.cpp.

References mapSelectionFromSource(), Isis::ProjectItemModel::selectionModel(), and sourceModel().

Referenced by setSourceModel().

void Isis::ProjectItemProxyModel::updateSourceCurrent ( )
protectedslot

Slot that updates the current item in the proxy model only if it is different than the corresponding item in the source model.

Definition at line 317 of file ProjectItemProxyModel.cpp.

References mapIndexToSource(), Isis::ProjectItemModel::selectionModel(), and sourceModel().

Referenced by setSourceModel().

void Isis::ProjectItemProxyModel::updateSourceSelection ( )
protectedslot

Slot that updates the selection in the source model only if it is different than the corresponding selection in the proxy model.

Definition at line 343 of file ProjectItemProxyModel.cpp.

References mapSelectionFromSource(), mapSelectionToSource(), Isis::ProjectItemModel::selectionModel(), and sourceModel().

Referenced by setSourceModel().

Member Data Documentation

ProjectItemModel* Isis::ProjectItemProxyModel::m_sourceModel
private

                                The source model.

Map of items from the source model to the proxy model.

Definition at line 129 of file ProjectItemProxyModel.h.

Referenced by ProjectItemProxyModel(), setSourceModel(), and sourceModel().


The documentation for this class was generated from the following files:

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/13/2023 00:08:50