MCPcopy Create free account
hub / github.com/KDE/kdevelop / viewSelectionChanged

Method viewSelectionChanged

kdevplatform/util/multilevellistview.cpp:136–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136void MultiLevelListViewPrivate::viewSelectionChanged(const QModelIndex& current,
137 const QModelIndex& previous)
138{
139 if (!current.isValid()) {
140 // ignore, as we should always have some kind of selection
141 return;
142 }
143
144 // figure out which proxy this signal belongs to
145 auto* proxy = qobject_cast<QAbstractProxyModel*>(
146 const_cast<QAbstractItemModel*>(current.model()));
147 Q_ASSERT(proxy);
148
149 // what level is this proxy in
150 int level = -1;
151 for (int i = 0; i < levels; ++i) {
152 if (views.at(i)->model() == proxy) {
153 level = i;
154 break;
155 }
156 }
157
158 Q_ASSERT(level >= 0 && level < levels);
159
160 if (level + 1 == levels) {
161 // right-most view
162 if (proxy->hasIndex(0, 0, current)) {
163 // select the first leaf node for this view
164 QModelIndex idx = current;
165 QModelIndex child = proxy->index(0, 0, idx);
166 while (child.isValid()) {
167 idx = child;
168 child = proxy->index(0, 0, idx);
169 }
170 views.last()->setCurrentIndex(idx);
171 return;
172 }
173 // signal that our actual selection has changed
174 emit view->currentIndexChanged(mapToSource(current), mapToSource(previous));
175 } else {
176 // some leftish view
177 // ensure the next view's first item is selected
178 QTreeView* treeView = views.at(level + 1);
179
180 // we need to delay the call, because at this point the child view
181 // will still have its old data which is going to be invalidated
182 // right after this method exits
183 // be we must not set the index to 0,0 here directly, since e.g.
184 // MultiLevelListView::setCurrentIndex might have been used, which
185 // sets a proper index already.
186 QMetaObject::invokeMethod(view, "ensureViewSelected", Qt::QueuedConnection,
187 Q_ARG(QTreeView*, treeView));
188 }
189}
190
191void MultiLevelListViewPrivate::lastViewsContentsChanged()
192{

Callers 1

setLevelsMethod · 0.80

Calls 6

setCurrentIndexMethod · 0.80
isValidMethod · 0.45
modelMethod · 0.45
atMethod · 0.45
indexMethod · 0.45
lastMethod · 0.45

Tested by

no test coverage detected