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

📄 qtablewidget.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            vertical.at(j)->model = 0;            delete vertical.at(j);            vertical[j] = 0;        }    }    for (int k = 0; k < horizontal.count(); ++k) {        if (horizontal.at(k)) {            horizontal.at(k)->model = 0;            delete horizontal.at(k);            horizontal[k] = 0;        }    }    reset();}void QTableModel::itemChanged(QTableWidgetItem *item){    if (!item)        return;    if (item->flags() & ItemIsVerticalHeaderItem) {        int row = vertical.indexOf(item);        if (row >= 0)            emit headerDataChanged(Qt::Vertical, row, row);    } else if (item->flags() & ItemIsHorizontalHeaderItem) {        int column = horizontal.indexOf(item);        if (column >= 0)            emit headerDataChanged(Qt::Horizontal, column, column);    } else {        QModelIndex idx = index(item);        if (idx.isValid())            emit dataChanged(idx, idx);    }}QStringList QTableModel::mimeTypes() const{    const QTableWidget *view = ::qobject_cast<const QTableWidget*>(QObject::parent());    return view->mimeTypes();}QMimeData *QTableModel::internalMimeData()  const{    return QAbstractItemModel::mimeData(cachedIndexes);}QMimeData *QTableModel::mimeData(const QModelIndexList &indexes) const{    QList<QTableWidgetItem*> items;    for (int i = 0; i < indexes.count(); ++i)        items << item(indexes.at(i));    const QTableWidget *view = ::qobject_cast<const QTableWidget*>(QObject::parent());    // cachedIndexes is a little hack to avoid copying from QModelIndexList to QList<QTreeWidgetItem*> and back again in the view    cachedIndexes = indexes;    QMimeData *mimeData = view->mimeData(items);    cachedIndexes.clear();    return mimeData;}bool QTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action,                              int row , int column, const QModelIndex &index){    if (index.isValid()) {        row = index.row();        column = index.column();    }else if (row == -1 || column == -1) {  // The user dropped outside the table.        row = rowCount();        column = 0;    }    QTableWidget *view = ::qobject_cast<QTableWidget*>(QObject::parent());    return view->dropMimeData(row, column, data, action);}Qt::DropActions QTableModel::supportedDropActions() const{    const QTableWidget *view = ::qobject_cast<const QTableWidget*>(QObject::parent());    return view->supportedDropActions();}/*!    \class QTableWidgetSelectionRange    \brief The QTableWidgetSelectionRange class provides a container for    storing a selection range in a QTableWidget.    \ingroup model-view    The QTableWidgetSelectionRange class stores the top left and bottom    right rows and columns of a selection range in a table. The    selections in the table may consist of several selection ranges.    \sa QTableWidget*//*!    Constructs an table selection range, i.e. a range    whose rowCount() and columnCount() are 0.*/QTableWidgetSelectionRange::QTableWidgetSelectionRange()    : top(-1), left(-1), bottom(-2), right(-2){}/*!    Constructs the table selection range from the given \a top, \a    left, \a bottom and \a right table rows and columns.    \sa topRow(), leftColumn(), bottomRow(), rightColumn()*/QTableWidgetSelectionRange::QTableWidgetSelectionRange(int top, int left, int bottom, int right)    : top(top), left(left), bottom(bottom), right(right){}/*!    Constructs a the table selection range by copying the given \a    other table selection range.*/QTableWidgetSelectionRange::QTableWidgetSelectionRange(const QTableWidgetSelectionRange &other)    : top(other.top), left(other.left), bottom(other.bottom), right(other.right){}/*!    Destroys the table selection range.*/QTableWidgetSelectionRange::~QTableWidgetSelectionRange(){}/*!    \fn int QTableWidgetSelectionRange::topRow() const    Returns the top row of the range.    \sa bottomRow(), leftColumn(), rowCount()*//*!    \fn int QTableWidgetSelectionRange::bottomRow() const    Returns the bottom row of the range.    \sa topRow(), rightColumn(), rowCount()*//*!    \fn int QTableWidgetSelectionRange::leftColumn() const    Returns the left column of the range.    \sa rightColumn(), topRow(), columnCount()*//*!    \fn int QTableWidgetSelectionRange::rightColumn() const    Returns the right column of the range.    \sa leftColumn(), bottomRow(), columnCount()*//*!    \since 4.1    \fn int QTableWidgetSelectionRange::rowCount() const    Returns the number of rows in the range.    This is equivalent to bottomRow() - topRow() + 1.    \sa columnCount(), topRow(), bottomRow()*//*!    \since 4.1    \fn int QTableWidgetSelectionRange::columnCount() const    Returns the number of columns in the range.    This is equivalent to rightColumn() - leftColumn() + 1.    \sa rowCount(), leftColumn(), rightColumn()*//*!    \class QTableWidgetItem    \brief The QTableWidgetItem class provides an item for use with the    QTableWidget class.    \ingroup model-view    Table items are used to hold pieces of information for table widgets.    Items usually contain text, icons, or checkboxes    The QTableWidgetItem class is a convenience class that replaces the    \c QTableItem class in Qt 3. It provides an item for use with    the QTableWidget class.    Top-level items are constructed without a parent then inserted at the    position specified by a pair of row and column numbers:    \quotefile snippets/qtablewidget-using/mainwindow.cpp    \skipto QTableWidgetItem *newItem    \printuntil tableWidget->setItem(    Each item can have its own background color which is set with    the setBackgroundColor() function. The current background color can be    found with backgroundColor().    The text label for each item can be rendered with its own font and text    color. These are specified with the setFont() and setTextColor() functions,    and read with font() and textColor().    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() with the appropriate    value (see \l{Qt::ItemFlags}). Checkable items can be checked and unchecked    with the setChecked() function. The corresponding checked() function    indicates whether the item is currently checked.    \sa QTableWidget, {Model/View Programming}, QListWidgetItem, QTreeWidgetItem*//*!  \fn QSize QTableWidgetItem::sizeHint() const  \since 4.1  Returns the size hint set for the table item.*//*!  \fn void QTableWidgetItem::setSizeHint(const QSize &size)  \since 4.1  Sets the size hint for the table item to be \a size.  If no size hint is set, the item delegate will compute the  size hint based on the item data.*//*!    \fn Qt::CheckState QTableWidgetItem::checkState() const    Returns the checked state of the table item.    \sa flags()*//*!    \fn void QTableWidgetItem::setCheckState(Qt::CheckState state)    Sets the check state of the table item to be \a state.*//*!    \fn QTableWidget *QTableWidgetItem::tableWidget() const    Returns the table widget that contains the item.*//*!    \fn Qt::ItemFlags QTableWidgetItem::flags() const    Returns the flags used to describe the item. These determine whether    the item can be checked, edited, and selected.    \sa setFlags()*//*!    \fn void QTableWidgetItem::setFlags(Qt::ItemFlags flags)    Sets the flags for the item to the given \a flags. These determine whether    the item can be selected or modified.    \sa flags()*//*!    \fn QString QTableWidgetItem::text() const    Returns the item's text.    \sa setText()*//*!    \fn void QTableWidgetItem::setText(const QString &text)    Sets the item's text to the \a text specified.    \sa text() setFont() setTextColor()*//*!    \fn QIcon QTableWidgetItem::icon() const    Returns the item's icon.    \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}*//*!    \fn void QTableWidgetItem::setIcon(const QIcon &icon)    Sets the item's icon to the \a icon specified.    \sa icon(), setText(), {QAbstractItemView::iconSize}{iconSize}*//*!    \fn QString QTableWidgetItem::statusTip() const    Returns the item's status tip.    \sa setStatusTip()*//*!    \fn void QTableWidgetItem::setStatusTip(const QString &statusTip)    Sets the item's status tip to the string specified by \a statusTip.    \sa statusTip() setToolTip() setWhatsThis()*//*!    \fn QString QTableWidgetItem::toolTip() const    Returns the item's tooltip.    \sa setToolTip()*//*!    \fn void QTableWidgetItem::setToolTip(const QString &toolTip)    Sets the item's tooltip to the string specified by \a toolTip.    \sa toolTip() setStatusTip() setWhatsThis()*//*!    \fn QString QTableWidgetItem::whatsThis() const    Returns the item's "What's This?" help.    \sa setWhatsThis()*//*!    \fn void QTableWidgetItem::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 QTableWidgetItem::font() const    Returns the font used to render the item's text.    \sa setFont()*//*!    \fn void QTableWidgetItem::setFont(const QFont &font)    Sets the font used to display the item's text to the given \a font.    \sa font() setText() setTextColor()*//*!    \fn QColor QTableWidgetItem::backgroundColor() const    Returns the color used to render the item's background.    \sa textColor() setBackgroundColor()*//*!    \fn void QTableWidgetItem::setBackgroundColor(const QColor &color)    Sets the item's background color to the specified \a color.    \sa backgroundColor() setTextColor()*//*!    \fn QColor QTableWidgetItem::textColor() const    Returns the color used to render the item's text.    \sa backgroundColor() setTextColor()*//*!    \fn void QTableWidgetItem::setTextColor(const QColor &color)    Sets the color used to display the item's text to the given \a color.    \sa textColor() setFont() setText()*//*!    \fn int QTableWidgetItem::textAlignment() const    Returns the text alignment for the item's text.    \sa Qt::Alignment*//*!    \fn void QTableWidgetItem::setTextAlignment(int alignment)    Sets the text alignment for the item's text to the \a alignment    specified.    \sa Qt::Alignment*//*!    Constructs a table item of the specified \a type that does not belong    to any table.    \sa type()*/QTableWidgetItem::QTableWidgetItem(int type)    :  rtti(type), view(0), model(0),      itemFlags(Qt::ItemIsEditable                |Qt::ItemIsSelectable                |Qt::ItemIsUserCheckable                |Qt::ItemIsEnabled                |Qt::ItemIsDragEnabled                |Qt::ItemIsDropEnabled){}/*!    Constructs a table item with the given \a text.    \sa type()*/QTableWidgetItem::QTableWidgetItem(const QString &text, int type)    :  rtti(type), view(0), model(0),      itemFlags(Qt::ItemIsEditable                |Qt::ItemIsSelectable                |Qt::ItemIsUserCheckable                |Qt::ItemIsEnabled                |Qt::ItemIsDragEnabled                |Qt::ItemIsDropEnabled){    setData(Qt::DisplayRole, text);}/*!    Destroys the table item.*/QTableWidgetItem::~QTableWidgetItem(){    if (model)        model->removeItem(this);}/*!    Creates a copy of the item.*/QTableWidgetItem *QTableWidgetItem::clone() const{    return new QTableWidgetItem(*this);}/*!    Sets the item's data for the given \a role to the specified \a value.    \sa Qt::ItemDataRole, data()*/void QTableWidgetItem::setData(int role, const QVariant &value){    bool found = false;    role = (role == Qt::EditRole ? Qt::DisplayRole : role);    for (int i = 0; i < values.count(); ++i) {        if (values.at(i).role == role) {            if (values[i].value == value)                return;            values[i].value = value;            found = true;            break;        }    }    if (!found)        values.append(QWidgetItemData(role, value));    if (model)        model->itemChanged(this);}/*!    Returns the item's data for the given \a role.*/QVariant QTableWidgetItem::data(int role) const{    role = (role == Qt::EditRole ? Qt::DisplayRole : role);    for (int i = 0; i < values.count(); ++i)        if (values.at(i).role == role)            return values.at(i).value;    return QVariant();}/*!    Returns true if the item is less than the \a other item; otherwise returns    false.*/bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const{    return text() < other.text();}#ifndef QT_NO_DATASTREAM/*!    Reads the item from stream \a in.    \sa write()*/void QTableWidgetItem::read(QDataStream &in){    in >> values;}/*!    Writes the item to stream \a out.    \sa read()*/void QTableWidgetItem::write(QDataStream &out) const{    out << values;}/*!    \relates QTableWidgetItem    Reads a table widget item from stream \a in into \a item.    This operator uses QTableWidgetItem::read().    \sa {Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item){    item.read(in);    return in;}/*!    \relates QTableWidgetItem    Writes the table widget item \a item to stream \a out.    This operator uses QTableWidgetItem::write().    \sa {Format of the QDataStream Operators}*/

⌨️ 快捷键说明

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