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

Method setExpanded

plugins/quickopen/expandingtree/expandingwidgetmodel.cpp:343–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343void ExpandingWidgetModel::setExpanded(const QModelIndex& idx_, bool expanded)
344{
345 Q_ASSERT(idx_.model() == this);
346
347 QModelIndex idx(firstColumn(idx_));
348
349 qCDebug(PLUGIN_QUICKOPEN) << "Setting expand-state of row " << idx.row() << " to " << expanded;
350 if (!idx.isValid()) {
351 return;
352 }
353
354 if (isExpandable(idx)) {
355 if (!expanded && m_expandingWidgets.contains(idx) && m_expandingWidgets[idx]) {
356 m_expandingWidgets[idx]->hide();
357 }
358
359 m_expandState[idx] = expanded ? Expanded : Expandable;
360
361 if (expanded) {
362 partiallyUnExpand(idx);
363 }
364
365 if (expanded && !m_expandingWidgets.contains(idx)) {
366 QVariant v = data(idx, CodeCompletionModel::ExpandingWidget);
367
368 if (v.canConvert<QWidget*>()) {
369 m_expandingWidgets[idx] = v.value<QWidget*>();
370 } else if (v.canConvert<QString>()) {
371 //Create a html widget that shows the given string
372 auto* edit = new KTextEdit(v.toString());
373 edit->setReadOnly(true);
374 edit->resize(200, 50); //Make the widget small so it embeds nicely.
375 m_expandingWidgets[idx] = edit;
376 } else {
377 m_expandingWidgets[idx] = nullptr;
378 }
379 }
380
381 //Eventually partially expand the row
382 if (!expanded && firstColumn(mapToSource(treeView()->currentIndex())) == idx && (isPartiallyExpanded(idx) == ExpandingWidgetModel::ExpansionType::NotExpanded)) {
383 rowSelected(idx); //Partially expand the row.
384 }
385 emit dataChanged(idx, idx);
386
387 if (treeView()) {
388 treeView()->scrollTo(mapFromSource(idx));
389 }
390 }
391}
392
393int ExpandingWidgetModel::basicRowHeight(const QModelIndex& idx_) const
394{

Callers 3

eventFilterMethod · 0.45
editorEventMethod · 0.45

Calls 8

firstColumnFunction · 0.85
dataFunction · 0.50
modelMethod · 0.45
rowMethod · 0.45
isValidMethod · 0.45
containsMethod · 0.45
toStringMethod · 0.45
currentIndexMethod · 0.45

Tested by

no test coverage detected