ElementCollectionWidgetWidget : Set search start when text to search have at least 3 letters.

The goal is to avoid gui freeze when search for 1 or 2 letters (in this
case qet search for every item and take a lot of time).
This commit is contained in:
joshua
2021-02-21 09:44:38 +01:00
parent ef58f34c14
commit 5f908fcd88

View File

@@ -741,17 +741,22 @@ void ElementsCollectionWidget::search()
return; return;
} }
//start the search when text have at least 3 letters.
if (text.count() < 3) {
return;
}
hideCollection(true); hideCollection(true);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) // ### Qt 6: remove
QStringList text_list = text.split("+", QString::SkipEmptyParts); const QStringList text_list = text.split("+", QString::SkipEmptyParts);
#else #else
#if TODO_LIST #if TODO_LIST
#pragma message("@TODO remove code for QT 5.14 or later") #pragma message("@TODO remove code for QT 5.14 or later")
#endif #endif
QStringList text_list = text.split("+", Qt::SkipEmptyParts); const QStringList text_list = text.split("+", Qt::SkipEmptyParts);
#endif #endif
QModelIndexList match_index; QModelIndexList match_index;
foreach (QString txt, text_list) { for (QString txt : text_list) {
match_index << m_model->match(m_showed_index.isValid() match_index << m_model->match(m_showed_index.isValid()
? m_model->index(0,0,m_showed_index) ? m_model->index(0,0,m_showed_index)
: m_model->index(0,0), : m_model->index(0,0),
@@ -762,7 +767,7 @@ void ElementsCollectionWidget::search()
| Qt::MatchRecursive); | Qt::MatchRecursive);
} }
foreach(QModelIndex index, match_index) for(QModelIndex index : match_index)
showAndExpandItem(index); showAndExpandItem(index);
} }