diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-03-20 11:32:53 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-03-22 08:01:35 +0000 |
commit | b01248ebbd42dd05d45fa655852169978beec40e (patch) | |
tree | 78ee9f46bdca6b093f7e0b1b14ba3ec3293f7162 /src/corelib/itemmodels | |
parent | 03fadc26e7617aece89949bc7d0acf50f6f050a9 (diff) |
Fix tree recursion in QAbstractItemModel::match()
Recurse down the sibling at column 0 of the index instead down the
index.
Change-Id: Ie78d8b28eab7438ca3f83ee0df177115ca82806e
Fixes: QTBUG-73864
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index e816add91d..83dcf68314 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2360,6 +2360,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, bool wrap = flags & Qt::MatchWrap; bool allHits = (hits == -1); QString text; // only convert to a string if it is needed + const int column = start.column(); QModelIndex p = parent(start); int from = start.row(); int to = rowCount(p); @@ -2367,7 +2368,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, // iterates twice if wrapping for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) { for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) { - QModelIndex idx = index(r, start.column(), p); + QModelIndex idx = index(r, column, p); if (!idx.isValid()) continue; QVariant v = data(idx, role); @@ -2406,10 +2407,13 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, result.append(idx); } } - if (recurse && hasChildren(idx)) { // search the hierarchy - result += match(index(0, idx.column(), idx), role, - (text.isEmpty() ? value : text), - (allHits ? -1 : hits - result.count()), flags); + if (recurse) { + const auto parent = column != 0 ? idx.sibling(idx.row(), 0) : idx; + if (hasChildren(parent)) { // search the hierarchy + result += match(index(0, column, parent), role, + (text.isEmpty() ? value : text), + (allHits ? -1 : hits - result.count()), flags); + } } } // prepare for the next iteration |