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

📄 qstandarditemmodel.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void QStandardItemModelPrivate::rowsAboutToBeInserted(QStandardItem *parent,                                                      int start, int end){    Q_Q(QStandardItemModel);    QModelIndex index = q->indexFromItem(parent);    q->beginInsertRows(index, start, end);}/*!  \internal*/void QStandardItemModelPrivate::columnsAboutToBeInserted(QStandardItem *parent,                                                         int start, int end){    Q_Q(QStandardItemModel);    QModelIndex index = q->indexFromItem(parent);    q->beginInsertColumns(index, start, end);}/*!  \internal*/void QStandardItemModelPrivate::rowsAboutToBeRemoved(QStandardItem *parent,                                                     int start, int end){    Q_Q(QStandardItemModel);    QModelIndex index = q->indexFromItem(parent);    q->beginRemoveRows(index, start, end);}/*!  \internal*/void QStandardItemModelPrivate::columnsAboutToBeRemoved(QStandardItem *parent,                                                        int start, int end){    Q_Q(QStandardItemModel);    QModelIndex index = q->indexFromItem(parent);    q->beginRemoveColumns(index, start, end);}/*!  \internal*/void QStandardItemModelPrivate::rowsInserted(QStandardItem *parent,                                             int row, int count){    Q_Q(QStandardItemModel);    if (parent == root)        rowHeaderItems.insert(row, count, 0);    q->endInsertRows();}/*!  \internal*/void QStandardItemModelPrivate::columnsInserted(QStandardItem *parent,                                                int column, int count){    Q_Q(QStandardItemModel);    if (parent == root)        columnHeaderItems.insert(column, count, 0);    q->endInsertColumns();}/*!  \internal*/void QStandardItemModelPrivate::rowsRemoved(QStandardItem *parent,                                            int row, int count){    Q_Q(QStandardItemModel);    if (parent == root) {        for (int i = row; i < row + count; ++i) {            QStandardItem *oldItem = rowHeaderItems.at(i);            if (oldItem)                oldItem->d_func()->setModel(0);            delete oldItem;        }        rowHeaderItems.remove(row, count);    }    q->endRemoveRows();}/*!  \internal*/void QStandardItemModelPrivate::columnsRemoved(QStandardItem *parent,                                               int column, int count){    Q_Q(QStandardItemModel);    if (parent == root) {        for (int i = column; i < column + count; ++i) {            QStandardItem *oldItem = columnHeaderItems.at(i);            if (oldItem)                oldItem->d_func()->setModel(0);            delete oldItem;        }        columnHeaderItems.remove(column, count);    }    q->endRemoveColumns();}/*!    \class QStandardItem    \brief The QStandardItem class provides an item for use with the    QStandardItemModel class.    \since 4.2    \ingroup model-view    Items usually contain text, icons, or checkboxes.    Each item can have its own background brush which is set with the    setBackground() function. The current background brush can be found with    background().  The text label for each item can be rendered with its own    font and brush. These are specified with the setFont() and setForeground()    functions, and read with font() and foreground().    By default, items are enabled, editable, selectable, checkable, and can be    used both as the source of a drag and drop operation and as a drop target.    Each item's flags can be changed by calling setFlags(). Checkable items    can be checked and unchecked with the setCheckState() function. The    corresponding checkState() function indicates whether the item is    currently checked.    You can store application-specific data in an item by calling setData().    Each item can have a two-dimensional table of child items. This makes it    possible to build hierarchies of items. The typical hierarchy is the tree,    in which case the child table is a table with a single column (a list).    The dimensions of the child table can be set with setRowCount() and    setColumnCount(). Items can be positioned in the child table with    setChild(). Get a pointer to a child item with child(). New rows and    columns of children can also be inserted with insertRow() and    insertColumn(), or appended with appendRow() and appendColumn(). When    using the append and insert functions, the dimensions of the child table    will grow as needed.    An existing row of children can be removed with removeRow() or takeRow();    correspondingly, a column can be removed with removeColumn() or    takeColumn().    An item's children can be sorted by calling sortChildren().    \section1 Subclassing    When subclassing QStandardItem to provide custom items, it is possible to    define new types for them so that they can be distinguished from the base    class. The type() function should be reimplemented to return a new type    value equal to or greater than \l UserType.    Reimplement data() and setData() if you want to perform custom handling of    data queries and/or control how an item's data is represented.    Reimplement clone() if you want QStandardItemModel to be able to create    instances of your custom item class on demand (see    QStandardItemModel::setItemPrototype()).    Reimplement read() and write() if you want to control how items are    represented in their serialized form.    Reimplement \l{operator<()} if you want to control the semantics of item    comparison. \l{operator<()} determines the sorted order when sorting items    with sortChildren() or with QStandardItemModel::sort().    \sa QStandardItemModel, {Item View Convenience Classes}, {Model/View Programming}*//*!    \enum QStandardItem::ItemType    This enum describes the types that are used to describe standard items.    \value Type     The default type for standard items.    \value UserType The minimum value for custom types. Values below UserType are                    reserved by Qt.    You can define new user types in QStandardItem subclasses to ensure that    custom items are treated specially; for example, when items are sorted.    \sa type()*//*!    Constructs an item.*/QStandardItem::QStandardItem()    : d_ptr(new QStandardItemPrivate){    Q_D(QStandardItem);    d->q_ptr = this;}/*!    Constructs an item with the given \a text.*/QStandardItem::QStandardItem(const QString &text)    : d_ptr(new QStandardItemPrivate){    Q_D(QStandardItem);    d->q_ptr = this;    setText(text);}/*!    Constructs an item with the given \a icon and \a text.*/QStandardItem::QStandardItem(const QIcon &icon, const QString &text)    : d_ptr(new QStandardItemPrivate){    Q_D(QStandardItem);    d->q_ptr = this;    setIcon(icon);    setText(text);}/*!   Constructs an item with \a rows rows and \a columns columns of child items.*/QStandardItem::QStandardItem(int rows, int columns)    : d_ptr(new QStandardItemPrivate){    Q_D(QStandardItem);    d->q_ptr = this;    setRowCount(rows);    setColumnCount(columns);}/*!  \internal*/QStandardItem::QStandardItem(QStandardItemPrivate &dd)    : d_ptr(&dd){    Q_D(QStandardItem);    d->q_ptr = this;}/*!  Constructs a copy of \a other. Note that model() is  not copied.  This function is useful when reimplementing clone().*/QStandardItem::QStandardItem(const QStandardItem &other)    : d_ptr(new QStandardItemPrivate){    Q_D(QStandardItem);    d->q_ptr = this;    operator=(other);}/*!  Assigns \a other's data and flags to this item. Note that  type() and model() are not copied.  This function is useful when reimplementing clone().*/QStandardItem &QStandardItem::operator=(const QStandardItem &other){    Q_D(QStandardItem);    d->values = other.d_func()->values;    return *this;}/*!  Destructs the item.  This causes the item's children to be destructed as well.*/QStandardItem::~QStandardItem(){    Q_D(QStandardItem);    delete d;}/*!  Returns the item's parent item, or 0 if the item has no parent.  \sa child()*/QStandardItem *QStandardItem::parent() const{    Q_D(const QStandardItem);    if (!d->model || (d->model->d_func()->root != d->parent))        return d->parent;    return 0;}/*!    Sets the item's data for the given \a role to the specified \a value.    \sa Qt::ItemDataRole, data(), setFlags()*/void QStandardItem::setData(const QVariant &value, int role){    Q_D(QStandardItem);    role = (role == Qt::EditRole) ? Qt::DisplayRole : role;    QVector<QWidgetItemData>::iterator it;    for (it = d->values.begin(); it != d->values.end(); ++it) {        if ((*it).role == role) {            if (value.isValid()) {                if ((*it).value == value)                    return;                (*it).value = value;            } else {                d->values.erase(it);            }            if (d->model)                d->model->d_func()->itemChanged(this);            return;        }    }    d->values.append(QWidgetItemData(role, value));    if (d->model)        d->model->d_func()->itemChanged(this);}/*!    Returns the item's data for the given \a role, or an invalid    QVariant if there is no data for the role.*/QVariant QStandardItem::data(int role) const{    Q_D(const QStandardItem);    role = (role == Qt::EditRole) ? Qt::DisplayRole : role;    QVector<QWidgetItemData>::const_iterator it;    for (it = d->values.begin(); it != d->values.end(); ++it) {        if ((*it).role == role)            return (*it).value;    }    return QVariant();}/*!  Sets the item flags for the item to \a flags.  The item flags determine how the user can interact with the item.  This is often used to disable an item.  \sa flags(), setData()*/void QStandardItem::setFlags(Qt::ItemFlags flags){    setData((int)flags, Qt::UserRole - 1);}/*!  Returns the item flags for the item.  The item flags determine how the user can interact with the item.  By default, items are enabled, editable, selectable, checkable, and can be  used both as the source of a drag and drop operation and as a drop target.  \sa setFlags()*/Qt::ItemFlags QStandardItem::flags() const{    QVariant v = data(Qt::UserRole - 1);    if (!v.isValid())        return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable                |Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled);    return ((Qt::ItemFlags)(v.toInt()));}/*!    \fn QString QStandardItem::text() const    Returns the item's text. This is the text that's presented to the user    in a view.    \sa setText()*//*!    \fn void QStandardItem::setText(const QString &text)    Sets the item's text to the \a text specified.    \sa text(), setFont(), setForeground()*//*!    \fn QIcon QStandardItem::icon() const    Returns the item's icon.    \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}*//*!    \fn void QStandardItem::setIcon(const QIcon &icon)    Sets the item's icon to the \a icon specified.*//*!    \fn QString QStandardItem::statusTip() const    Returns the item's status tip.    \sa setStatusTip(), toolTip(), whatsThis()*//*!    \fn void QStandardItem::setStatusTip(const QString &statusTip)    Sets the item's status tip to the string specified by \a statusTip.    \sa statusTip(), setToolTip(), setWhatsThis()*//*!    \fn QString QStandardItem::toolTip() const    Returns the item's tooltip.    \sa setToolTip(), statusTip(), whatsThis()*//*!    \fn void QStandardItem::setToolTip(const QString &toolTip)    Sets the item's tooltip to the string specified by \a toolTip.    \sa toolTip(), setStatusTip(), setWhatsThis()*//*!    \fn QString QStandardItem::whatsThis() const    Returns the item's "What's This?" help.    \sa setWhatsThis(), toolTip(), statusTip()*//*!    \fn void QStandardItem::setWhatsThis(const QString &whatsThis)    Sets the item's "What's This?" help to the string specified by \a whatsThis.    \sa whatsThis(), setStatusTip(), setToolTip()*//*!    \fn QFont QStandardItem::font() const    Returns the font used to render the item's text.    \sa setFont()*//*!    \fn void QStandardItem::setFont(const QFont &font)    Sets the font used to display the item's text to the given \a font.    \sa font() setText() setForeground()*//*!    \fn QBrush QStandardItem::background() const    Returns the brush used to render the item's background.    \sa  foreground() setBackground()*//*!    \fn void QStandardItem::setBackground(const QBrush &brush)

⌨️ 快捷键说明

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