Isis Developer Reference
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.
 
void addItems (QList< ProjectItem * > sourceItems)
 Adds a list of items to the proxy model.
 

Signals

void itemsAdded ()
 
void itemRemoved (ProjectItem *)
 
void itemAdded (ProjectItem *)
 This signal is emitted when a ProjectItem is added to the model.
 
void cleanProject (bool)
 This signal is emitted whrn a ProjectItem's name is changed.
 
void projectNameEdited (QString)
 This signal is emitted when the project name is edited.
 

Public Member Functions

 ProjectItemProxyModel (QObject *parent=0)
 Constructs the proxy model.
 
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.
 
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.
 
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.
 
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.
 
ProjectItemmapItemFromSource (ProjectItem *sourceItem)
 Returns the ProjectItem in the proxy model that corresponds with a ProjectItem in the source model.
 
ProjectItemmapItemToSource (ProjectItem *proxyItem)
 Returns the ProjectItem in the source model that corresponds with a ProjectItem in the source model.
 
void removeItem (ProjectItem *item)
 Removes an item and its children from the proxy model.
 
void setSourceModel (ProjectItemModel *sourceModel)
 Sets the source model.
 
ProjectItemModelsourceModel ()
 Returns the source model.
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
 Returns true.
 
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.
 
QItemSelectionModel * selectionModel ()
 Returns the internal selection model.
 
ProjectItemaddProject (Project *project)
 Adds a Project to the model.
 
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.
 
virtual void removeItems (QList< ProjectItem * > items)
 Removes a list of items and their children from the model.
 
ProjectItemcurrentItem ()
 Returns the current item of the internal selection model.
 
QList< ProjectItem * > selectedItems ()
 Returns a list of the selected items of the internal selection model.
 
QList< ProjectItem * > selectedBOSSImages ()
 ProjectItemModel::selectedBOSSImages.
 
void appendRow (ProjectItem *item)
 Appends a top-level item to the model.
 
void clean ()
 Used to clean the ProjectItemModel of everything but the headers.
 
QModelIndex indexFromItem (const ProjectItem *item)
 Returns the QModelIndex corresponding to a given ProjectItem.
 
void insertRow (int row, ProjectItem *item)
 Inserts a top-level item at the given row.
 
ProjectItemitem (int row)
 Returns the top-level item at the given row.
 
ProjectItemitemFromIndex (const QModelIndex &index)
 Returns the ProjectItem corresponding to a given QModelIndex.
 
void setItem (int row, ProjectItem *item)
 Sets the item at the top-level row.
 
ProjectItemtakeItem (int row)
 Removes the top-level row and returns the removed item.
 
bool setData (const QModelIndex &index, const QVariant &value, int role)
 This virtual method was added to handle changing the project name by double-clicking the project name on the project tree.
 
Qt::ItemFlags flags (const QModelIndex &index) const
 This virtual method was added to handle changing the project name by double-clicking the project name on the project tree.
 

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.
 
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.
 
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.
 
void updateProxySelection ()
 Slot that updates the selection in the proxy model only if it is different than the corresponding selection in the source model.
 
void updateSourceSelection ()
 Slot that updates the selection in the source model only if it is different than the corresponding selection in the proxy model.
 
void onSelectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 Slot to connect to the selectionChanged() signal from a selection model.
 

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.
 

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.

model->addProject(project);
proxyModel->setSourceModel(model);
for (int i=0; i < model.rowCount(); i++) {
proxyModel->addItem( model->item(i) );
}
Provides access to data stored in a Project through Qt's model-view framework.
Definition ProjectItemModel.h:132
ProjectItemModel(QObject *parent=0)
Constructs an empty model.
Definition ProjectItemModel.cpp:42
ProjectItem * item(int row)
Returns the top-level item at the given row.
Definition ProjectItemModel.cpp:387
ProjectItem * addProject(Project *project)
Adds a Project to the model.
Definition ProjectItemModel.cpp:105
Allows access to items in a ProjectItemModel through a proxy model.
Definition ProjectItemProxyModel.h:70
ProjectItemProxyModel(QObject *parent=0)
Constructs the proxy model.
Definition ProjectItemProxyModel.cpp:28
Author
2015-10-21 Jeffrey Covington

Constructor & Destructor Documentation

◆ ProjectItemProxyModel()

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

Constructs the proxy model.

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

Member Function Documentation

◆ addChild()

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.

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

Referenced by addItem().

◆ 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.

References addChild(), addItem(), and mapItemFromSource().

Referenced by addItem(), and addItems().

◆ 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.

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

Referenced by dropMimeData().

◆ addProject()

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
project(Project *) The Project to be added.
Returns
ProjectItem* The new item that corresponds to the Project.

References Isis::ProjectItemModel::appendRow().

◆ appendRow()

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

Appends a top-level item to the model.

Parameters
item(ProjectItem *) The item to append.

References Isis::ProjectItemModel::item().

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

◆ canDropMimeData()

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.

◆ clean()

void Isis::ProjectItemModel::clean ( )
inherited

Used to clean the ProjectItemModel of everything but the headers.

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

◆ cleanProject

void Isis::ProjectItemModel::cleanProject ( bool )
signalinherited

This signal is emitted whrn a ProjectItem's name is changed.

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

◆ currentItem()

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

Returns the current item of the internal selection model.

Returns
ProjectItem* The current item.

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

◆ dropMimeData()

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.

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

◆ findItemData()

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.
role(int) The role of the data (see Qt::ItemDataRole).
Returns
ProjectItem* First project item found.

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

Referenced by Isis::JigsawSetupDialog::JigsawSetupDialog(), Isis::ProjectItemModel::selectedBOSSImages(), Isis::Project::setActiveControl(), Isis::Project::setActiveImageList(), Isis::ImportImagesWorkOrder::undoExecution(), Isis::ImportMapTemplateWorkOrder::undoExecution(), Isis::ImportRegistrationTemplateWorkOrder::undoExecution(), and Isis::ImportShapesWorkOrder::undoExecution().

◆ flags()

Qt::ItemFlags Isis::ProjectItemModel::flags ( const QModelIndex & index) const
inherited

This virtual method was added to handle changing the project name by double-clicking the project name on the project tree.

It was required by Qt in order to allow editing capabilities.

See also
http://doc.qt.io/qt-5/modelview.html
Parameters
index(const QModelIndex &) Field which has been edited
Returns
Qt::ItemFlags Add the ItemIsEditable to the standard flags.

◆ indexFromItem()

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

Returns the QModelIndex corresponding to a given ProjectItem.

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

References Isis::ProjectItemModel::item().

◆ insertRow()

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

Inserts a top-level item at the given row.

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

References Isis::ProjectItemModel::item().

◆ item()

◆ itemAdded

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

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

◆ itemFromIndex()

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

◆ itemRemoved

void Isis::ProjectItemProxyModel::itemRemoved ( ProjectItem * )
signal

Referenced by setSourceModel().

◆ itemsAdded

void Isis::ProjectItemProxyModel::itemsAdded ( )
signal

Referenced by addItems().

◆ mapIndexFromSource()

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.

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

Referenced by mapSelectionFromSource(), and updateProxyCurrent().

◆ mapIndexToSource()

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.

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

Referenced by mapSelectionToSource(), and updateSourceCurrent().

◆ mapItemFromSource()

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.

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

◆ mapItemToSource()

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.

Referenced by mapIndexToSource(), and removeItem().

◆ mapSelectionFromSource()

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.

References mapIndexFromSource().

Referenced by updateProxySelection(), and updateSourceSelection().

◆ mapSelectionToSource()

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.

References mapIndexToSource().

Referenced by updateSourceSelection().

◆ onSelectionChanged

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
selected(const QItemSelection &) The selected items.
deselected(const QItemSelection &) The deselected items.

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().

◆ projectNameEdited

void Isis::ProjectItemModel::projectNameEdited ( QString )
signalinherited

This signal is emitted when the project name is edited.

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

◆ removeItem()

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.

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

◆ removeItems()

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

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

Parameters
items(ProjectItem *) The items to be removed.

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

Referenced by Isis::RemoveImagesWorkOrder::execute().

◆ selectedBOSSImages()

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

ProjectItemModel::selectedBOSSImages.

Returns
This is a refinement of the selectedItems function which was needed to display a subset of Images/ImageLists in the Bundle Observation Solve Settings (BOSS) tab of the JigsawSetupDialog widget. The primary consumer of the selected images is going to be the SortFilterProxyModel class.

References Isis::ProjectItem::child(), Isis::ProjectItemModel::findItemData(), Isis::ProjectItem::isImage(), Isis::ProjectItem::isImageList(), Isis::ProjectItemModel::item(), Isis::ProjectItemModel::itemFromIndex(), Isis::ProjectItem::parent(), and Isis::ProjectItemModel::selectionModel().

◆ selectedItems()

◆ selectionModel()

QItemSelectionModel * Isis::ProjectItemModel::selectionModel ( )
inherited

◆ setData()

bool Isis::ProjectItemModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
inherited

This virtual method was added to handle changing the project name by double-clicking the project name on the project tree.

It was required by Qt in order to allow editing capabilities.

See also
http://doc.qt.io/qt-5/modelview.html
Parameters
index(const QModelIndex &) Field which has been edited
value(const QVariant &) Value contained in the field
role(int) Will always be EditRole since field only contains text
Returns
bool Returns true if successful; otherwise false

References Isis::ProjectItem::bundleSolutionInfo(), Isis::ProjectItemModel::cleanProject(), Isis::ProjectItem::controlList(), Isis::ProjectItem::imageList(), Isis::ProjectItem::isBundleSolutionInfo(), Isis::ProjectItem::isControlList(), Isis::ProjectItem::isImageList(), Isis::ProjectItem::isProject(), Isis::ProjectItem::isShapeList(), Isis::ProjectItem::isTemplate(), Isis::ProjectItemModel::item(), Isis::ProjectItemModel::itemFromIndex(), Isis::ProjectItemModel::projectNameEdited(), Isis::BundleSolutionInfo::setName(), Isis::ControlList::setName(), Isis::ImageList::setName(), Isis::ShapeList::setName(), and Isis::ProjectItem::shapeList().

◆ setItem()

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

Sets the item at the top-level row.

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

References Isis::ProjectItemModel::item().

◆ setSourceModel()

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.

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

Referenced by addChild().

◆ sourceModel()

ProjectItemModel * Isis::ProjectItemProxyModel::sourceModel ( )

Returns the source model.

Returns
ProjectItemModel* The source model.

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

◆ takeItem()

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

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

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

◆ updateItem

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.

References mapItemFromSource().

◆ updateProxyCurrent

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.

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

Referenced by setSourceModel().

◆ updateProxySelection

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.

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

Referenced by setSourceModel().

◆ updateSourceCurrent

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.

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

Referenced by setSourceModel().

◆ updateSourceSelection

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.

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

Referenced by setSourceModel().


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