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

📄 qabstractitemmodel.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qabstractitemmodel.h"#include <private/qabstractitemmodel_p.h>#include <qdatastream.h>#include <qstringlist.h>#include <qsize.h>#include <qmimedata.h>#include <qdebug.h>#include <qvector.h>#include <qstack.h>#include <qbitarray.h>#include <limits.h>class QPersistentModelIndexDataLessThan{public:    inline bool operator()(const QPersistentModelIndexData *left,                           const QPersistentModelIndexData *right) const    { return (left->index < right->index); }};QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &index){    Q_ASSERT(index.isValid()); // we will _never_ insert an invalid index in the list    QPersistentModelIndexData *d = 0;    const QAbstractItemModelPrivate *p = index.model()->d_func();    const QPersistentModelIndexData *previous = p->persistent.previous;    if (previous && previous->index == index) {        d = p->persistent.previous;    } else { // do a binary search, or sorted insert        const QPersistentModelIndexData tmp(index);        QAbstractItemModel *model = const_cast<QAbstractItemModel*>(index.model());        QVector<QPersistentModelIndexData*> *indexes = &(model->d_func()->persistent.indexes);        QVector<QPersistentModelIndexData*>::iterator begin = indexes->begin();        QVector<QPersistentModelIndexData*>::iterator end = indexes->end();        QVector<QPersistentModelIndexData*>::iterator it =            qLowerBound(begin, end, &tmp, QPersistentModelIndexDataLessThan());        if (it != end && (*it)->index == index) {            d = (*it);        } else {            d = new QPersistentModelIndexData();            d->model = index.model();            d->index = index;            model->d_func()->persistent.indexes.insert(it, d);            model->d_func()->addPersistentIndexData(d);        }        model->d_func()->persistent.previous = d;    }    Q_ASSERT(d);    return d;}void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data){    Q_ASSERT(data);    Q_ASSERT(data->ref == 0);    QAbstractItemModel *model = const_cast<QAbstractItemModel*>(data->model);    // a valid persistent model index with a null model pointer can only happen if the model was destroyed    if (model) {        QAbstractItemModelPrivate *p = model->d_func();        Q_ASSERT(p);        p->removePersistentIndexData(data);    }    delete data;}/*!  \class QPersistentModelIndex  \brief The QPersistentModelIndex class is used to locate data in a data model.  \ingroup model-view  A QPersistentModelIndex is a model index that can be stored by an  application, and later used to access information in a model.  Unlike the QModelIndex class, it is safe to store a  QPersistentModelIndex since the model will ensure that references  to items will continue to be valid as long as they can be accessed  by the model.  It is good practice to check that persistent model indexes are valid  before using them.  \sa {Model/View Programming}, QModelIndex, QAbstractItemModel*//*!  \fn QPersistentModelIndex::QPersistentModelIndex()  \internal*/QPersistentModelIndex::QPersistentModelIndex()    : d(0){}/*!  \fn QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other)  Creates a new QPersistentModelIndex that is a copy of the \a other persistent  model index.*/QPersistentModelIndex::QPersistentModelIndex(const QPersistentModelIndex &other)    : d(other.d){    if (d) d->ref.ref();}/*!    Creates a new QPersistentModelIndex that is a copy of the model \a index.*/QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index)    : d(0){    if (index.isValid()) {        d = QPersistentModelIndexData::create(index);        d->ref.ref();    }}/*!    \fn QPersistentModelIndex::~QPersistentModelIndex()    \internal*/QPersistentModelIndex::~QPersistentModelIndex(){    if (d && !d->ref.deref()) {        QPersistentModelIndexData::destroy(d);        d = 0;    }}/*!  Returns true if this persistent model index is equal to the \a other  persistent model index; otherwise returns false.  All values in the persistent model index are used when comparing  with another persistent model index.*/bool QPersistentModelIndex::operator==(const QPersistentModelIndex &other) const{    if (d && other.d)        return d->index == other.d->index;    return d == other.d;}/*!    \since 4.1    Returns true if this persistent model index is smaller than the \a other    persistent model index; otherwise returns false.    All values in the persistent model index are used when comparing    with another persistent model index.*/bool QPersistentModelIndex::operator<(const QPersistentModelIndex &other) const{    if (d && other.d)        return d->index < other.d->index;    return d < other.d;}/*!    \fn bool QPersistentModelIndex::operator!=(const QPersistentModelIndex &other) const    \since 4.2    Returns true if this persistent model index is not equal to the \a    other persistent model index; otherwise returns false.*//*!    Sets the persistent model index to refer to the same item in a model    as the \a other persistent model index.*/QPersistentModelIndex &QPersistentModelIndex::operator=(const QPersistentModelIndex &other){    if (d == other.d)        return *this;    if (d && !d->ref.deref())        QPersistentModelIndexData::destroy(d);    d = other.d;    if (d) d->ref.ref();    return *this;}/*!    Sets the persistent model index to refer to the same item in a model    as the \a other model index.*/QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other){    if (d && !d->ref.deref())        QPersistentModelIndexData::destroy(d);    if (other.isValid()) {        d = QPersistentModelIndexData::create(other);        if (d) d->ref.ref();    } else {        d = 0;    }    return *this;}/*!  \fn QPersistentModelIndex::operator const QModelIndex&() const  Cast operator that returns a const QModelIndex&.*/QPersistentModelIndex::operator const QModelIndex&() const{    static const QModelIndex invalid;    if (d)        return d->index;    return invalid;}/*!    \fn bool QPersistentModelIndex::operator==(const QModelIndex &other) const    Returns true if this persistent model index refers to the same location as    the \a other model index; otherwise returns false.    Note that all values in the persistent model index are used when comparing    with another model index.*/bool QPersistentModelIndex::operator==(const QModelIndex &other) const{    if (d)        return d->index == other;    return !other.isValid();}/*!    \fn bool QPersistentModelIndex::operator!=(const QModelIndex &other) const    Returns true if this persistent model index does not refer to the same    location as the \a other model index; otherwise returns false.*/bool QPersistentModelIndex::operator!=(const QModelIndex &other) const{    if (d)        return d->index != other;    return other.isValid();}/*!    \fn int QPersistentModelIndex::row() const    Returns the row this persistent model index refers to.*/int QPersistentModelIndex::row() const{    if (d)        return d->index.row();    return -1;}/*!    \fn int QPersistentModelIndex::column() const    Returns the column this persistent model index refers to.*/int QPersistentModelIndex::column() const{    if (d)        return d->index.column();    return -1;}/*!    \fn void *QPersistentModelIndex::internalPointer() const    \internal    Returns a \c{void} \c{*} pointer used by the model to associate the index with    the internal data structure.*/void *QPersistentModelIndex::internalPointer() const{    if (d)        return d->index.internalPointer();    return 0;}/*!    \fn void *QPersistentModelIndex::internalId() const    \internal    Returns a \c{qint64} used by the model to associate the index with    the internal data structure.*/qint64 QPersistentModelIndex::internalId() const{    if (d)        return d->index.internalId();    return 0;}/*!  Returns the parent QModelIndex for this persistent index, or  QModelIndex() if it has no parent.  \sa child() sibling() model()*/QModelIndex QPersistentModelIndex::parent() const{    if (d)        return d->index.parent();    return QModelIndex();}/*!  Returns the sibling at \a row and \a column or an invalid  QModelIndex if there is no sibling at this position.  \sa parent() child()*/QModelIndex QPersistentModelIndex::sibling(int row, int column) const{    if (d)        return d->index.sibling(row, column);    return QModelIndex();}/*!  Returns the child of the model index that is stored in the given  \a row and \a column.  \sa parent() sibling()*/QModelIndex QPersistentModelIndex::child(int row, int column) const{    if (d)        return d->index.child(row, column);    return QModelIndex();}

⌨️ 快捷键说明

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