9#include "ProjectItemProxyModel.h"
12#include <QItemSelection>
19#include "ProjectItem.h"
20#include "ProjectItemModel.h"
30 m_sourceProxyMap = QMap<ProjectItem *, ProjectItem *>();
47 return proxyItem->index();
68 return sourceItem->index();
86 const QItemSelection &sourceSelection) {
88 QItemSelection proxySelection = QItemSelection();
90 foreach ( QModelIndex sourceIndex, sourceSelection.indexes() ) {
92 if ( proxyIndex.isValid() ) {
93 proxySelection.select(proxyIndex, proxyIndex);
97 return proxySelection;
111 QItemSelection sourceSelection = QItemSelection();
113 foreach ( QModelIndex proxyIndex, proxySelection.indexes() ) {
115 if ( sourceIndex.isValid() ) {
116 sourceSelection.select(sourceIndex, sourceIndex);
120 return sourceSelection;
133 return m_sourceProxyMap.value(sourceItem, 0);
146 return m_sourceProxyMap.key(proxyItem, 0);
173 proxyItem =
addChild(sourceItem, parentItem);
176 proxyItem =
addChild(sourceItem, 0);
179 for (
int i=0; i < sourceItem->rowCount(); i++) {
180 addItem( sourceItem->child(i) );
236 SIGNAL( currentChanged(
const QModelIndex &,
const QModelIndex &) ),
240 SIGNAL( currentChanged(
const QModelIndex &,
const QModelIndex &) ),
244 SIGNAL( selectionChanged(
const QItemSelection &,
const QItemSelection &) ),
248 SIGNAL( selectionChanged(
const QItemSelection &,
const QItemSelection &) ),
278 proxyItem->setProjectItem(sourceItem);
291 selectionModel()->setCurrentIndex(newProxyCurrent, QItemSelectionModel::Current);
304 QItemSelectionModel::Current);
317 selectionModel()->select(newProxySelection, QItemSelectionModel::ClearAndSelect);
331 QItemSelectionModel::ClearAndSelect);
362 if ( parentItem && (parentItem->model() !=
this) ) {
370 proxyItem->setProjectItem(sourceItem);
371 m_sourceProxyMap.insert(sourceItem, proxyItem);
375 oldParent->takeRow( proxyItem->row() );
378 model->takeRow( proxyItem->row() );
383 parentItem->appendRow(proxyItem);
417 Qt::DropAction action,
419 const QModelIndex &parent)
const {
436 Qt::DropAction action,
438 const QModelIndex &parent) {
439 if ( data->hasFormat(
"application/x-qabstractitemmodeldatalist") ) {
Represents an item of a ProjectItemModel in Qt's model-view framework.
ProjectItem * parent() const
Returns the parent item of this item.
Provides access to data stored in a Project through Qt's model-view framework.
QList< ProjectItem * > selectedItems()
Returns a list of the selected items of the internal selection model.
void appendRow(ProjectItem *item)
Appends a top-level item to the model.
ProjectItem * itemFromIndex(const QModelIndex &index)
Returns the ProjectItem corresponding to a given QModelIndex.
ProjectItem * item(int row)
Returns the top-level item at the given row.
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
QItemSelectionModel * selectionModel()
Returns the internal selection model.
ProjectItemProxyModel(QObject *parent=0)
Constructs the proxy model.
void updateItem(ProjectItem *sourceItem)
Given an item in the source model, this method changes the data of the corresponding item in the prox...
ProjectItemModel * m_sourceModel
The source model. Map of items from the source model to the proxy model.
void updateProxySelection()
Slot that updates the selection in the proxy model only if it is different than the corresponding sel...
QModelIndex mapIndexFromSource(const QModelIndex &sourceIndex)
Returns the QModelIndex of an item in the proxy model that corresponds with the QModelIndex of an ite...
ProjectItemModel * sourceModel()
Returns the source model.
ProjectItem * addItem(ProjectItem *sourceItem)
Adds an item and its children to the proxy model.
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...
QModelIndex mapIndexToSource(const QModelIndex &proxyIndex)
Returns the QModelIndex of an item in the souce model that corresponds with the QModelIndex of an ite...
void removeItem(ProjectItem *item)
Removes an item and its children from the proxy model.
void updateSourceCurrent()
Slot that updates the current item in the proxy model only if it is different than the corresponding ...
void onItemChanged(QStandardItem *item)
Signal to connect to the itemChanged() signal from a ProjectItemModel.
QItemSelection mapSelectionToSource(const QItemSelection &proxySelection)
Returns a QItemSelection of items in the source model that corresponds with a QItemSelection of itesm...
void updateProxyCurrent()
Slot that updates the current item in the proxy model only if it is different than the corresponding ...
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.
void addItems(QList< ProjectItem * > sourceItems)
Adds a list of items to the proxy model.
QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection)
Returns a QItemSelection of items in the proxy model that corresponds with a QItemSelection of items ...
void updateSourceSelection()
Slot that updates the selection in the source model only if it is different than the corresponding se...
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
Returns true.
ProjectItem * mapItemToSource(ProjectItem *proxyItem)
Returns the ProjectItem in the source model that corresponds with a ProjectItem in the source model.
void setSourceModel(ProjectItemModel *sourceModel)
Sets the source model.
ProjectItem * mapItemFromSource(ProjectItem *sourceItem)
Returns the ProjectItem in the proxy model that corresponds with a ProjectItem in the source model.
This is free and unencumbered software released into the public domain.