⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qcompleter.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#endif        if (!d->popup->underMouse()) {            d->popup->hide();            return true;        }        }        return false;    case QEvent::InputMethod:        QApplication::sendEvent(d->widget, e);        break;    default:        return false;    }    return false;}/*!    For QCompleter::PopupCompletion and QCompletion::UnfilteredPopupCompletion    modes, calling this function displays the popup displaying the current    completions. By default, if \a rect is not specified, the popup is displayed    on the bottom of the widget(). If \a rect is specified the popup is    displayed on the left edge of the rectangle.    For QCompleter::InlineCompletion mode, the highlighted() signal is fired    with the current completion.*/void QCompleter::complete(const QRect& rect){    Q_D(QCompleter);    QModelIndex idx = d->proxy->currentIndex(false);    if (d->mode == QCompleter::InlineCompletion) {        if (idx.isValid())            d->_q_complete(idx, true);        return;    }    Q_ASSERT(d->widget != 0);    if ((d->mode == QCompleter::PopupCompletion && !idx.isValid())        || (d->mode == QCompleter::UnfilteredPopupCompletion && d->proxy->rowCount() == 0)) {        if (d->popup)            d->popup->hide(); // no suggestion, hide        return;    }    popup();    if (d->mode == QCompleter::UnfilteredPopupCompletion)        d->setCurrentIndex(idx, false);    d->showPopup(rect);    d->popupRect = rect;}/*!    Sets the current row to the \a row specified. Returns true if successful;    otherwise returns false.    This function may be used along with currentCompletion() to iterate    through all the possible completions.    \sa currentCompletion(), completionCount()*/bool QCompleter::setCurrentRow(int row){    Q_D(QCompleter);    return d->proxy->setCurrentRow(row);}/*!    Returns the current row.    \sa setCurrentRow()*/int QCompleter::currentRow() const{    Q_D(const QCompleter);    return d->proxy->currentRow();}/*!    Returns the number of completions for the current prefix. For an unsorted    model with a large number of items this can be expensive. Use setCurrentRow()    and currentCompletion() to iterate through all the completions.*/int QCompleter::completionCount() const{    Q_D(const QCompleter);    return d->proxy->completionCount();}/*!    \enum QCompleter::ModelSorting    This enum specifies how the items in the model are sorted.    \value UnsortedModel                    The model is unsorted.    \value CaseSensitivelySortedModel       The model is sorted case sensitively.    \value CaseInsensitivelySortedModel     The model is sorted case insensitively.    \sa setModelSorting()*//*!    \property QCompleter::modelSorting    \brief the way the model is sorted    By default, no assumptions are made about the order of the items    in the model that provides the completions.    If the model's data for the completionColumn() and completionRole() is sorted in    ascending order, you can set this property to \l CaseSensitivelySortedModel    or \l CaseInsensitivelySortedModel. On large models, this can lead to    significant performance improvements because the completer object can    then use a binary search algorithm instead of linear search algorithm.    The sort order (i.e ascending or descending order) of the model is determined    dynamically by inspecting the contents of the model.    \bold{Note:} The performance improvements described above cannot take place    when the completer's \l caseSensitivity is different to the case sensitivity    used by the model's when sorting.    \sa setCaseSensitivity(), QCompleter::ModelSorting*/void QCompleter::setModelSorting(QCompleter::ModelSorting sorting){    Q_D(QCompleter);    if (d->sorting == sorting)        return;    d->sorting = sorting;    d->proxy->createEngine();    d->proxy->invalidate();}QCompleter::ModelSorting QCompleter::modelSorting() const{    Q_D(const QCompleter);    return d->sorting;}/*!    \property QCompleter::completionColumn    \brief the column in the model in which completions are searched for.    If the popup() is a QListView, it is automatically setup to display    this column.    By default, the match column is 0.    \sa completionRole, caseSensitivity*/void QCompleter::setCompletionColumn(int column){    Q_D(QCompleter);    if (d->column == column)        return;#ifndef QT_NO_LISTVIEW    if (QListView *listView = qobject_cast<QListView *>(d->popup))        listView->setModelColumn(column);#endif    d->column = column;    d->proxy->invalidate();}int QCompleter::completionColumn() const{    Q_D(const QCompleter);    return d->column;}/*!    \property QCompleter::completionRole    \brief the item role to be used to query the contents of items for matching.    The default role is Qt::EditRole.    \sa completionColumn, caseSensitivity*/void QCompleter::setCompletionRole(int role){    Q_D(QCompleter);    if (d->role == role)        return;    d->role = role;    d->proxy->invalidate();}int QCompleter::completionRole() const{    Q_D(const QCompleter);    return d->role;}/*!    \property QCompleter::wrapAround    \brief the completions wrap around when navigating through items    \since 4.3    The default is true.*/void QCompleter::setWrapAround(bool wrap){    Q_D(QCompleter);    if (d->wrap == wrap)        return;    d->wrap = wrap;}bool QCompleter::wrapAround() const{    Q_D(const QCompleter);    return d->wrap;}/*!    \property QCompleter::caseSensitivity    \brief the case sensitivity of the matching    The default is Qt::CaseSensitive.    \sa completionColumn, completionRole, modelSorting*/void QCompleter::setCaseSensitivity(Qt::CaseSensitivity cs){    Q_D(QCompleter);    if (d->cs == cs)        return;    d->cs = cs;    d->proxy->createEngine();    d->proxy->invalidate();}Qt::CaseSensitivity QCompleter::caseSensitivity() const{    Q_D(const QCompleter);    return d->cs;}/*!    \property QCompleter::completionPrefix    \brief the completion prefix used to provide completions.    The completionModel() is updated to reflect the list of possible    matches for \a prefix.*/void QCompleter::setCompletionPrefix(const QString &prefix){    Q_D(QCompleter);    d->prefix = prefix;    d->proxy->filter(splitPath(prefix));}QString QCompleter::completionPrefix() const{    Q_D(const QCompleter);    return d->prefix;}/*!    Returns the model index of the current completion in the completionModel().    \sa setCurrentRow(), currentCompletion(), model()*/QModelIndex QCompleter::currentIndex() const{    Q_D(const QCompleter);    return d->proxy->currentIndex(false);}/*!    Returns the current completion string. This includes the \l completionPrefix.    When used alongside setCurrentRow(), it can be used to iterate through    all the matches.    \sa setCurrentRow(), currentIndex()*/QString QCompleter::currentCompletion() const{    Q_D(const QCompleter);    return pathFromIndex(d->proxy->currentIndex(true));}/*!    Returns the completion model. The completion model is a read-only list model    that contains all the possible matches for the current completion prefix.    The completion model is auto-updated to reflect the current completions.    \sa completionPrefix, model()*/QAbstractItemModel *QCompleter::completionModel() const{    Q_D(const QCompleter);    return d->proxy;}/*!    Returns the path for the given \a index. The completer object uses this to    obtain the completion text from the underlying model.    The default implementation returns the \l{Qt::EditRole}{edit role} of the    item for list models. It returns the absolute file path if the model is a    QDirModel.    \sa splitPath()*/QString QCompleter::pathFromIndex(const QModelIndex& index) const{    Q_D(const QCompleter);    if (!index.isValid())        return QString();    QAbstractItemModel *sourceModel = d->proxy->sourceModel();    if (!sourceModel)        return QString();#ifndef QT_NO_DIRMODEL    QDirModel *dirModel = qobject_cast<QDirModel *>(sourceModel);    if (!dirModel)#endif        return sourceModel->data(index, d->role).toString();    QModelIndex idx = index;    QStringList list;    do {        QString t = sourceModel->data(idx, Qt::EditRole).toString();        list.prepend(t);        QModelIndex parent = idx.parent();        idx = parent.sibling(parent.row(), index.column());    } while (idx.isValid());#ifndef Q_OS_WIN    if (list.count() == 1) // only the separator or some other text        return list[0];    list[0].clear() ; // the join below will provide the separator#endif    return list.join(QDir::separator());}/*!    Splits the given \a path into strings that are used to match at each level    in the model().    The default implementation of splitPath() splits a file system path based on    QDir::separator() when the sourceModel() is a QDirModel.    When used with list models, the first item in the returned list is used for    matching.    \sa pathFromIndex(), {Handling Tree Models}*/QStringList QCompleter::splitPath(const QString& path) const{    bool isDirModel = false;#ifndef QT_NO_DIRMODEL    Q_D(const QCompleter);    isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0;#endif    if (!isDirModel || path.isEmpty())        return QStringList(completionPrefix());    QString pathCopy = QDir::toNativeSeparators(path);    QString sep = QDir::separator();#ifdef Q_OS_WIN    if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\"))        return QStringList(pathCopy);    QString doubleSlash(QLatin1String("\\\\"));    if (pathCopy.startsWith(doubleSlash))        pathCopy = pathCopy.mid(2);    else        doubleSlash.clear();#endif    QRegExp re(QLatin1String("[") + QRegExp::escape(sep) + QLatin1String("]"));    QStringList parts = pathCopy.split(re);#ifdef Q_OS_WIN    if (!doubleSlash.isEmpty())        parts[0].prepend(doubleSlash);#else    if (path[0] == sep[0]) // readd the "/" at the beginning as the split removed it        parts[0] = sep[0];#endif    return parts;}/*!    \fn void QCompleter::activated(const QModelIndex& index)    This signal is sent when an item in the popup() is activated by the user.    (by clicking or pressing return). The item's \a index in the completionModel()    is given.*//*!    \fn void QCompleter::activated(const QString &text)    This signal is sent when an item in the popup() is activated by the user (by    clicking or pressing return). The item's \a text is given.*//*!    \fn void QCompleter::highlighted(const QModelIndex& index)    This signal is sent when an item in the popup() is highlighted by    the user. It is also sent if complete() is called with the completionMode()    set to QCompleter::InlineCompletion. The item's \a index in the completionModel()    is given.*//*!    \fn void QCompleter::highlighted(const QString &text)    This signal is sent when an item in the popup() is highlighted by    the user. It is also sent if complete() is called with the completionMode()    set to QCOmpleter::InlineCompletion. The item's \a text is given.*/#include "moc_qcompleter.cpp"#endif // QT_NO_COMPLETER

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -