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

📄 qsortfilterproxymodel.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    int source_column = (column >= m->source_columns.count()                         ? m->source_columns.count()                         : m->source_columns.at(column));    return d->model->insertColumns(source_column, count, source_parent);}/*!  \reimp*/bool QSortFilterProxyModel::removeRows(int row, int count, const QModelIndex &parent){    Q_D(QSortFilterProxyModel);    if (row < 0 || count <= 0)        return false;    QModelIndex source_parent = d->proxy_to_source(parent);    QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();    if (row + count > m->source_rows.count())        return false;    int source_row = (row >= m->source_rows.count()                      ? m->source_rows.at(m->source_rows.count()) + 1                      : m->source_rows.at(row));    return d->model->removeRows(source_row, count, source_parent);}/*!  \reimp*/bool QSortFilterProxyModel::removeColumns(int column, int count, const QModelIndex &parent){    Q_D(QSortFilterProxyModel);    if (column < 0 || count <= 0)        return false;    QModelIndex source_parent = d->proxy_to_source(parent);    QSortFilterProxyModelPrivate::Mapping *m = d->create_mapping(source_parent).value();    if (column + count > m->source_columns.count())        return false;    int source_column = (column >= m->source_columns.count()                         ? m->source_columns.at(m->source_columns.count()) + 1                         : m->source_columns.at(column));    return d->model->removeColumns(source_column, count, source_parent);}/*!  \reimp*/void QSortFilterProxyModel::fetchMore(const QModelIndex &parent){    Q_D(QSortFilterProxyModel);    QModelIndex source_parent;    if (parent.isValid())        source_parent = d->proxy_to_source(parent);    d->model->fetchMore(source_parent);}/*!  \reimp*/bool QSortFilterProxyModel::canFetchMore(const QModelIndex &parent) const{    Q_D(const QSortFilterProxyModel);    QModelIndex source_parent;    if (parent.isValid())        source_parent = d->proxy_to_source(parent);    return d->model->canFetchMore(source_parent);}/*!  \reimp*/Qt::ItemFlags QSortFilterProxyModel::flags(const QModelIndex &index) const{    Q_D(const QSortFilterProxyModel);    QModelIndex source_index;    if (index.isValid())        source_index = d->proxy_to_source(index);    return d->model->flags(source_index);}/*!  \reimp*/QModelIndex QSortFilterProxyModel::buddy(const QModelIndex &index) const{    Q_D(const QSortFilterProxyModel);    if (!index.isValid())        return QModelIndex();    QModelIndex source_index = d->proxy_to_source(index);    QModelIndex source_buddy = d->model->buddy(source_index);    if (source_index == source_buddy)        return index;    return d->source_to_proxy(source_buddy);}/*!  \reimp*/QModelIndexList QSortFilterProxyModel::match(const QModelIndex &start, int role,                                             const QVariant &value, int hits,                                             Qt::MatchFlags flags) const{    Q_D(const QSortFilterProxyModel);    QModelIndex source_start = d->proxy_to_source(start);    QModelIndexList result = d->model->match(source_start, role, value, hits, flags);    for (int i = 0; i < result.count(); ++i)        result[i] = d->source_to_proxy(result.at(i));    return result;}/*!  \reimp*/QSize QSortFilterProxyModel::span(const QModelIndex &index) const{    Q_D(const QSortFilterProxyModel);    QModelIndex source_index = d->proxy_to_source(index);    return d->model->span(source_index);}/*!  \reimp*/void QSortFilterProxyModel::sort(int column, Qt::SortOrder order){    Q_D(QSortFilterProxyModel);    d->sort_column = column;    d->sort_order = order;    clear();}/*!    \property QSortFilterProxyModel::filterRegExp    \brief the QRegExp used to filter the contents of the source model    Setting this property overwrites the current \l filterCaseSensitivity.    \sa setCaseSensitivity(), setFilterWildcard(), setFilterFixedString()*/QRegExp QSortFilterProxyModel::filterRegExp() const{    Q_D(const QSortFilterProxyModel);    return d->filter_regexp;}void QSortFilterProxyModel::setFilterRegExp(const QRegExp &regExp){    Q_D(QSortFilterProxyModel);    d->filter_regexp = regExp;    clear();}/*!    \property QSortFilterProxyModel::filterKeyColumn    \brief the column where the key used to filter the contents of the    source model is read from.    The default value is 0.*/int QSortFilterProxyModel::filterKeyColumn() const{    Q_D(const QSortFilterProxyModel);    return d->filter_column;}void QSortFilterProxyModel::setFilterKeyColumn(int column){    Q_D(QSortFilterProxyModel);    Q_ASSERT(d->model == &d->empty || column < d->model->columnCount());    d->filter_column = column;    clear();}/*!    \property QSortFilterProxyModel::filterCaseSensitivity    \brief the case sensitivity of the QRegExp pattern used to filter the    contents of the source model.    By default, the filter is case sensistive.    \sa setFilterRegExp(), setFilterWildcard(), setFilterFixedString()*/Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity() const{    Q_D(const QSortFilterProxyModel);    return d->filter_regexp.caseSensitivity();}void QSortFilterProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs){    Q_D(QSortFilterProxyModel);    if (cs == d->filter_regexp.caseSensitivity())        return;    d->filter_regexp.setCaseSensitivity(cs);    clear();}/*!    \overload    Sets the regular expression used to filter the contents    of the source model to \a pattern.    \sa setFilterCaseSensitivity(), setFilterWildcard(), setFilterFixedString()*/void QSortFilterProxyModel::setFilterRegExp(const QString &pattern){    Q_D(QSortFilterProxyModel);    d->filter_regexp.setPatternSyntax(QRegExp::RegExp);    d->filter_regexp.setPattern(pattern);    clear();}/*!    Sets the wildcard expression used to filter the contents    of the source model to the given \a pattern.    \sa setFilterCaseSensitivity(), setFilterRegExp(), setFilterFixedString()*/void QSortFilterProxyModel::setFilterWildcard(const QString &pattern){    Q_D(QSortFilterProxyModel);    d->filter_regexp.setPatternSyntax(QRegExp::Wildcard);    d->filter_regexp.setPattern(pattern);    clear();}/*!    Sets the fixed string used to filter the contents    of the source model to the given \a pattern.    \sa setFilterCaseSensitivity(), setFilterRegExp(), setFilterWildcard()*/void QSortFilterProxyModel::setFilterFixedString(const QString &pattern){    Q_D(QSortFilterProxyModel);    d->filter_regexp.setPatternSyntax(QRegExp::FixedString);    d->filter_regexp.setPattern(pattern);    clear();}/*!    Clears this sorting filter model, removing all mapping.*/void QSortFilterProxyModel::clear(){    Q_D(QSortFilterProxyModel);    d->clear_mapping();    emit layoutChanged();}/*!    Returns true if the value of the item referred to by the given    index \a left is less than the value of the item referred to by    the given index \a right, otherwise returns false.  This function    is used as the < operator when sorting, and handles several    QVariant types:    \list        \o QVariant::Int        \o QVariant::UInt        \o QVariant::LongLong        \o QVariant::ULongLong        \o QVariant::Double        \o QVariant::Char        \o QVariant::Date        \o QVariant::Time        \o QVariant::DateTime        \o QVariant::String    \endlist    \sa sort()*/bool QSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{    QVariant l = (left.model() ? left.model()->data(left, Qt::DisplayRole) : QVariant());    QVariant r = (right.model() ? right.model()->data(right, Qt::DisplayRole) : QVariant());    switch (l.type()) {    case QVariant::Int:        return l.toInt() < r.toInt();    case QVariant::UInt:        return l.toUInt() < r.toUInt();    case QVariant::LongLong:        return l.toLongLong() < r.toLongLong();    case QVariant::ULongLong:        return l.toULongLong() < r.toULongLong();    case QVariant::Double:        return l.toDouble() < r.toDouble();    case QVariant::Char:        return l.toChar() < r.toChar();    case QVariant::Date:        return l.toDate() < r.toDate();    case QVariant::Time:            return l.toTime() < r.toTime();    case QVariant::DateTime:        return l.toDateTime() < r.toDateTime();    case QVariant::String:    default:        return l.toString() < r.toString();    }    return false;}/*!    Returns true if the value in the item in the row indicated by the    given \a source_row and \a source_parent should be included in the    model.    The default implementation uses filterRegExp with the data    returned for the Qt::DisplayRole to determine if the row should be    accepted or not.    \sa filterAcceptsColumn()*/bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const{    Q_D(const QSortFilterProxyModel);    if (d->filter_regexp.isEmpty() || d->filter_column == -1)        return true;    QModelIndex source_index = d->model->index(source_row, d->filter_column, source_parent);    if (!source_index.isValid()) // the column may not exist        return true;    QString key = d->model->data(source_index, Qt::DisplayRole).toString();    return key.contains(d->filter_regexp);}/*!    Returns true if the value in the item in the column indicated by    the given \a source_column and \a source_parent should be included    in the model.    The default implementation returns true.    \sa filterAcceptsRow()*/bool QSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const{    Q_UNUSED(source_column);    Q_UNUSED(source_parent);    return true;}/*!   Returns the source model index corresponding to the given \a   proxyIndex from the sorting filter model.   \sa mapFromSource()*/QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const{    Q_D(const QSortFilterProxyModel);    return d->proxy_to_source(proxyIndex);}/*!    Returns the model index in the QSortFilterProxyModel given the \a    sourceIndex from the source model.    \sa mapToSource()*/QModelIndex QSortFilterProxyModel::mapFromSource(const QModelIndex &sourceIndex) const{    Q_D(const QSortFilterProxyModel);    return d->source_to_proxy(sourceIndex);}/*!  \reimp*/QItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const{    return QAbstractProxyModel::mapSelectionToSource(proxySelection);}/*!  \reimp*/QItemSelection QSortFilterProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const{    return QAbstractProxyModel::mapSelectionFromSource(sourceSelection);}#include "moc_qsortfilterproxymodel.cpp"#endif // QT_NO_SORTFILTERPROXYMODEL

⌨️ 快捷键说明

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