return sourceIndex;
}
-QItemSelection MappedSelectionModel::mapFromSource(const QItemSelection &sourceSelection) {
- if(isProxyModel()) {
- QItemSelection mappedSelection;
- foreach(QItemSelectionRange range, sourceSelection) {
- QModelIndex topleft = mapFromSource(range.topLeft());
- QModelIndex bottomright = mapFromSource(range.bottomRight());
- if(topleft.isValid() && bottomright.isValid())
- mappedSelection << QItemSelectionRange(topleft, bottomright);
- else
- Q_ASSERT(!topleft.isValid() && !bottomright.isValid());
- }
- return mappedSelection;
- } else {
+QItemSelection MappedSelectionModel::mapSelectionFromSource(const QItemSelection &sourceSelection) {
+ if(isProxyModel())
+ return proxyModel()->mapSelectionFromSource(sourceSelection);
+ else
return sourceSelection;
- }
}
QModelIndex MappedSelectionModel::mapToSource(const QModelIndex &proxyIndex) {
return proxyIndex;
}
-QItemSelection MappedSelectionModel::mapToSource(const QItemSelection &proxySelection) {
- if(isProxyModel()) {
- QItemSelection mappedSelection;
- foreach(QItemSelectionRange range, proxySelection) {
- mappedSelection << QItemSelectionRange(mapToSource(range.topLeft()), mapToSource(range.bottomRight()));
- }
- return mappedSelection;
- } else {
+QItemSelection MappedSelectionModel::mapSelectionToSource(const QItemSelection &proxySelection) {
+ if(isProxyModel())
+ return proxyModel()->mapSelectionToSource(proxySelection);
+ else
return proxySelection;
- }
}
void MappedSelectionModel::mappedSelect(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
}
void MappedSelectionModel::mappedSelect(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) {
- QItemSelection mappedSelection = mapFromSource(selection);
+ QItemSelection mappedSelection = mapSelectionFromSource(selection);
if(mappedSelection != QItemSelectionModel::selection())
select(mappedSelection, command);
}
QModelIndex mappedIndex = mapFromSource(index);
if(mappedIndex == currentIndex())
return;
-
- if(mappedIndex.isValid())
- setCurrentIndex(mappedIndex, command);
- else if(hasSelection())
- setCurrentIndex(currentIndex(), QItemSelectionModel::Clear);
+ setCurrentIndex(mappedIndex, command);
}
void MappedSelectionModel::_currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
Q_UNUSED(previous)
- emit mappedCurrentChanged(mapToSource(current));
+ if(current.isValid())
+ emit mappedCurrentChanged(mapToSource(current));
}
void MappedSelectionModel::_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
Q_UNUSED(selected)
Q_UNUSED(deselected)
- emit mappedSelectionChanged(mapToSource(QItemSelectionModel::selection()));
+ emit mappedSelectionChanged(mapSelectionToSource(QItemSelectionModel::selection()));
}
-
+