27 class KBreadcrumbSelectionModelPrivate
33 : q_ptr(breadcrumbSelector),
34 m_includeActualSelection(true),
36 m_showHiddenAscendantData(false),
37 m_selectionModel(selectionModel),
38 m_direction(direction),
39 m_ignoreCurrentChanged(false)
47 QItemSelection getBreadcrumbSelection(
const QModelIndex &index);
52 QItemSelection getBreadcrumbSelection(
const QItemSelection &selection);
54 void sourceSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected);
57 void syncBreadcrumbs();
59 bool m_includeActualSelection;
61 bool m_showHiddenAscendantData;
63 KBreadcrumbSelectionModel::BreadcrumbTarget m_direction;
64 bool m_ignoreCurrentChanged;
69 d_ptr(new KBreadcrumbSelectionModelPrivate(this, selectionModel, MakeBreadcrumbSelectionInSelf))
74 KBreadcrumbSelectionModel::KBreadcrumbSelectionModel(
QItemSelectionModel *selectionModel, BreadcrumbTarget direction,
QObject* parent)
76 d_ptr(new KBreadcrumbSelectionModelPrivate(this, selectionModel, direction))
78 if ( direction != MakeBreadcrumbSelectionInSelf)
79 connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
80 this, SLOT(sourceSelectionChanged(QItemSelection,QItemSelection)));
85 KBreadcrumbSelectionModel::~KBreadcrumbSelectionModel()
90 bool KBreadcrumbSelectionModel::isActualSelectionIncluded()
const
93 return d->m_includeActualSelection;
96 void KBreadcrumbSelectionModel::setActualSelectionIncluded(
bool includeActualSelection)
99 d->m_includeActualSelection = includeActualSelection;
102 int KBreadcrumbSelectionModel::breadcrumbLength()
const
105 return d->m_selectionDepth;
108 void KBreadcrumbSelectionModel::setBreadcrumbLength(
int breadcrumbLength)
111 d->m_selectionDepth = breadcrumbLength;
114 QItemSelection KBreadcrumbSelectionModelPrivate::getBreadcrumbSelection(
const QModelIndex& index)
116 QItemSelection breadcrumbSelection;
118 if (m_includeActualSelection)
119 breadcrumbSelection.append(QItemSelectionRange(index));
121 QModelIndex parent = index.parent();
122 int sumBreadcrumbs = 0;
123 bool includeAll = m_selectionDepth < 0;
124 while (parent.isValid() && (includeAll || sumBreadcrumbs < m_selectionDepth)) {
125 breadcrumbSelection.append(QItemSelectionRange(parent));
126 parent = parent.parent();
128 return breadcrumbSelection;
131 QItemSelection KBreadcrumbSelectionModelPrivate::getBreadcrumbSelection(
const QItemSelection& selection)
133 QItemSelection breadcrumbSelection;
135 if (m_includeActualSelection)
136 breadcrumbSelection = selection;
138 QItemSelection::const_iterator it = selection.constBegin();
139 const QItemSelection::const_iterator
end = selection.constEnd();
141 for ( ; it !=
end; ++it)
143 QModelIndex parent = it->parent();
145 if (breadcrumbSelection.contains(parent))
148 int sumBreadcrumbs = 0;
149 bool includeAll = m_selectionDepth < 0;
151 while (parent.isValid() && (includeAll || sumBreadcrumbs < m_selectionDepth))
153 breadcrumbSelection.append(QItemSelectionRange(parent));
154 parent = parent.parent();
156 if (breadcrumbSelection.contains(parent))
162 return breadcrumbSelection;
165 void KBreadcrumbSelectionModelPrivate::sourceSelectionChanged(
const QItemSelection& selected,
const QItemSelection& deselected)
168 QItemSelection deselectedCrumbs = getBreadcrumbSelection(deselected);
169 QItemSelection selectedCrumbs = getBreadcrumbSelection(selected);
171 QItemSelection removed = deselectedCrumbs;
172 foreach(
const QItemSelectionRange &range, selectedCrumbs)
174 removed.removeAll(range);
177 QItemSelection added = selectedCrumbs;
178 foreach(
const QItemSelectionRange &range, deselectedCrumbs)
180 added.removeAll(range);
183 if (!removed.isEmpty())
187 if (!added.isEmpty())
189 q->QItemSelectionModel::select(added, QItemSelectionModel::Select);
193 void KBreadcrumbSelectionModel::select(
const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
198 if ( d->m_ignoreCurrentChanged )
200 d->m_ignoreCurrentChanged =
false;
203 if ( d->m_direction == MakeBreadcrumbSelectionInOther )
205 d->m_selectionModel->select(d->getBreadcrumbSelection(index), command);
206 QItemSelectionModel::select(index, command);
208 d->m_selectionModel->select(index, command);
209 QItemSelectionModel::select(d->getBreadcrumbSelection(index), command);
213 void KBreadcrumbSelectionModel::select(
const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
216 QItemSelection bcc = d->getBreadcrumbSelection(selection);
217 if ( d->m_direction == MakeBreadcrumbSelectionInOther )
219 d->m_selectionModel->select(selection, command);
220 QItemSelectionModel::select(bcc, command);
222 d->m_selectionModel->select(bcc, command);
223 QItemSelectionModel::select(selection, command);
227 void KBreadcrumbSelectionModelPrivate::init()
230 q->connect(m_selectionModel->model(), SIGNAL(layoutChanged()), SLOT(syncBreadcrumbs()));
231 q->connect(m_selectionModel->model(), SIGNAL(modelReset()), SLOT(syncBreadcrumbs()));
232 q->connect(m_selectionModel->model(), SIGNAL(rowsMoved(QModelIndex,
int,
int,QModelIndex,
int)), SLOT(syncBreadcrumbs()));
236 void KBreadcrumbSelectionModelPrivate::syncBreadcrumbs()
239 q->select(m_selectionModel->selection(), QItemSelectionModel::ClearAndSelect);
243 #include "kbreadcrumbselectionmodel.moc"
Selects the parents of selected items to create breadcrumbs.
KDialogPrivate *const d_ptr
const KShortcut & end()
Goto end of the document.