| 87 | } |
| 88 | |
| 89 | void SearchLineController::onSearchFinished(const QString &searchTerm) |
| 90 | { |
| 91 | if (!m_targetTreeView) { |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | if (searchTerm.isEmpty()) { |
| 96 | // Make sure we keep the current item in view on clearing |
| 97 | auto current = m_targetTreeView->currentIndex(); |
| 98 | if (current.isValid()) { |
| 99 | m_targetTreeView->scrollTo(current); |
| 100 | } |
| 101 | return; |
| 102 | } |
| 103 | m_delayedIdxesToExpand.clear(); |
| 104 | |
| 105 | if (!m_delayedExpandTimer) { |
| 106 | m_delayedExpandTimer = new QTimer(this); |
| 107 | m_delayedExpandTimer->setSingleShot(true); |
| 108 | m_delayedExpandTimer->setInterval(125); |
| 109 | |
| 110 | connect(m_delayedExpandTimer, &QTimer::timeout, this, [this] { |
| 111 | QVector<QPersistentModelIndex> stillNotLoaded; |
| 112 | const auto copy = m_delayedIdxesToExpand; |
| 113 | m_delayedIdxesToExpand.clear(); |
| 114 | auto it = copy.cbegin(); |
| 115 | auto end = copy.cend(); |
| 116 | for (; it != end; ++it) { |
| 117 | const QModelIndex index = *it; |
| 118 | if (!index.isValid()) { |
| 119 | continue; |
| 120 | } |
| 121 | if (m_targetTreeView->isExpanded(index)) { |
| 122 | continue; |
| 123 | } |
| 124 | const auto state = index.data(RemoteModelRole::LoadingState).value<RemoteModelNodeState::NodeStates>(); |
| 125 | if (!state.testFlag(RemoteModelNodeState::Empty)) { |
| 126 | expandRecursively(index); |
| 127 | continue; |
| 128 | } |
| 129 | QPersistentModelIndex notLoaded = index; |
| 130 | stillNotLoaded.append(notLoaded); |
| 131 | } |
| 132 | |
| 133 | m_delayedIdxesToExpand << stillNotLoaded; |
| 134 | if (!m_delayedIdxesToExpand.isEmpty()) { |
| 135 | m_delayedExpandTimer->start(); |
| 136 | } |
| 137 | }); |
| 138 | } |
| 139 | |
| 140 | auto *model = m_targetTreeView->model(); |
| 141 | const int rowCount = model->rowCount({}); |
| 142 | // Walk the top level indexes and expand everything |
| 143 | for (int r = 0; r < rowCount; ++r) { |
| 144 | expandRecursively(model->index(r, 0)); |
| 145 | } |
| 146 | // Start the timer to expand the not loaded indexes |