예제 #1
0
QStringList HistoryCompleter::splitPath(const QString &path) const
{
    if (path == m_searchString)
        return QStringList() << QLatin1String("a");

    // queue an update to our search string
    // We will wait a bit so that if the user is quickly typing,
    // we don't try to complete until they pause.
    if (m_filterTimer.isActive())
        m_filterTimer.stop();
    m_filterTimer.start(150);

    // if the previous search results are not a superset of
    // the current search results, tell the model that it is not valid yet
    if (!path.startsWith(m_searchString)) {
        HistoryCompletionModel *completionModel = qobject_cast<HistoryCompletionModel*>(model());
        Q_ASSERT(completionModel);
        completionModel->setValid(false);
    }

    m_searchString = path;

    // the actual filtering is done by the HistoryCompletionModel; we just
    // return a short dummy here so that QCompleter thinks we match everything
    return QStringList() << QLatin1String("a");
}
예제 #2
0
void HistoryCompleter::updateFilter()
{
    HistoryCompletionModel *completionModel = qobject_cast<HistoryCompletionModel*>(model());
    Q_ASSERT(completionModel);

    // tell the HistoryCompletionModel about the new search string
    completionModel->setSearchString(m_searchString);

    // sort the model
    completionModel->sort(0);

    // mark it valid
    completionModel->setValid(true);

    // and now update the QCompleter widget, but only if the user is still
    // typing a url
    if (widget() && widget()->hasFocus())
        complete();
}