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

📄 qtablewidget.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*!  Sets the horizontal header item for column \a column to \a item.*/void QTableWidget::setHorizontalHeaderItem(int column, QTableWidgetItem *item){    Q_D(QTableWidget);    if (item) {        item->view = this;        item->itemFlags = Qt::ItemFlags(int(item->itemFlags) |                    QTableModel::ItemIsHorizontalHeaderItem);        d->model()->setHorizontalHeaderItem(column, item);    } else {        delete takeHorizontalHeaderItem(column);    }}/*!  \since 4.1    Removes the horizontal header item at \a column from the header without deleting it.*/QTableWidgetItem *QTableWidget::takeHorizontalHeaderItem(int column){    Q_D(QTableWidget);    QTableWidgetItem *itm = d->model()->takeHorizontalHeaderItem(column);    if (itm) {        itm->view = 0;        itm->itemFlags &= ~QTableModel::ItemIsHorizontalHeaderItem;    }    return itm;}/*!  Sets the vertical header labels using \a labels.*/void QTableWidget::setVerticalHeaderLabels(const QStringList &labels){    Q_D(QTableWidget);    QTableModel *model = d->model();    QTableWidgetItem *item = 0;    for (int i = 0; i < model->rowCount() && i < labels.count(); ++i) {        item = model->verticalHeaderItem(i);        if (!item) {            item = model->createItem();            setVerticalHeaderItem(i, item);        }        item->setText(labels.at(i));    }}/*!  Sets the horizontal header labels using \a labels.*/void QTableWidget::setHorizontalHeaderLabels(const QStringList &labels){    Q_D(QTableWidget);    QTableModel *model = d->model();    QTableWidgetItem *item = 0;    for (int i = 0; i < model->columnCount() && i < labels.count(); ++i) {        item = model->horizontalHeaderItem(i);        if (!item) {            item = model->createItem();            setHorizontalHeaderItem(i, item);        }        item->setText(labels.at(i));    }}/*!    Returns the row of the current item.    \sa currentColumn(), setCurrentCell()*/int QTableWidget::currentRow() const{    return currentIndex().row();}/*!    Returns the column of the current item.    \sa currentRow(), setCurrentCell()*/int QTableWidget::currentColumn() const{    return currentIndex().column();}/*!    Returns the current item.    \sa setCurrentItem()*/QTableWidgetItem *QTableWidget::currentItem() const{    Q_D(const QTableWidget);    return d->model()->item(currentIndex());}/*!    Sets the current item to \a item.    Depending on the current selection mode, the item may also be selected.    \sa currentItem(), setCurrentCell()*/void QTableWidget::setCurrentItem(QTableWidgetItem *item){    Q_D(QTableWidget);    setCurrentIndex(d->model()->index(item));}/*!    \since 4.1    Sets the current cell to be the cell at position (\a row, \a    column).    Depending on the current selection mode, the cell may also be selected.    \sa setCurrentItem(), currentRow(), currentColumn()*/void QTableWidget::setCurrentCell(int row, int column){    setCurrentIndex(model()->index(row, column, QModelIndex()));}/*!  Sorts all the rows in the table widget based on \a column and \a order.*/void QTableWidget::sortItems(int column, Qt::SortOrder order){    Q_D(QTableWidget);    d->model()->sort(column, order);    horizontalHeader()->setSortIndicator(column, order);}/*!  If \a enable is true, the items in the widget will be sorted if the user  clicks on a horizontal header section; otherwise sorting is disabled.*/void QTableWidget::setSortingEnabled(bool enable){    Q_D(QTableWidget);    d->sortingEnabled = enable;    if (enable) {        disconnect(horizontalHeader(), SIGNAL(sectionPressed(int)),                   this, SLOT(selectColumn(int)));        connect(horizontalHeader(), SIGNAL(sectionClicked(int)),                this, SLOT(sortByColumn(int)));    } else {        connect(horizontalHeader(), SIGNAL(sectionPressed(int)),                this, SLOT(selectColumn(int)));        disconnect(horizontalHeader(), SIGNAL(sectionClicked(int)),                   this, SLOT(sortByColumn(int)));    }}/*!  Returns if sorting is enabled; otherwise returns false.  Sorting is enabled when the user clicks on a horizontal header section.*/bool QTableWidget::isSortingEnabled() const{    Q_D(const QTableWidget);    return d->sortingEnabled;}/*!  Starts editing the \a item if it is editable.*/void QTableWidget::editItem(QTableWidgetItem *item){    Q_ASSERT(item);    Q_D(QTableWidget);    edit(d->model()->index(item));}/*!  Opens an editor for the give \a item. The editor remains open after editing.  \sa closePersistentEditor()*/void QTableWidget::openPersistentEditor(QTableWidgetItem *item){    Q_ASSERT(item);    Q_D(QTableWidget);    QModelIndex index = d->model()->index(item);    QAbstractItemView::openPersistentEditor(index);}/*!  Closes the persistent editor for \a item.  \sa openPersistentEditor()*/void QTableWidget::closePersistentEditor(QTableWidgetItem *item){    Q_ASSERT(item);    Q_D(QTableWidget);    QModelIndex index = d->model()->index(item);    QAbstractItemView::closePersistentEditor(index);}/*!  \since 4.1  Returns the widget displayed in the cell in the given \a row and \a column.  \sa setCellWidget()*/QWidget *QTableWidget::cellWidget(int row, int column) const{    QModelIndex index = model()->index(row, column, QModelIndex());    return QAbstractItemView::indexWidget(index);}/*!  \since 4.1  Sets the \a widget to be displayed in the cell in the given \a row and \a column.  \sa cellWidget()*/void QTableWidget::setCellWidget(int row, int column, QWidget *widget){    Q_ASSERT(widget);    QModelIndex index = model()->index(row, column, QModelIndex());    QAbstractItemView::setIndexWidget(index, widget);}/*!  Returns true if the \a item is selected, otherwise returns false.*/bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const{    Q_D(const QTableWidget);    QModelIndex index = d->model()->index(item);    return selectionModel()->isSelected(index);}/*!  Selects or deselects \a item depending on \a select.*/void QTableWidget::setItemSelected(const QTableWidgetItem *item, bool select){    Q_D(QTableWidget);    QModelIndex index = d->model()->index(item);    selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);}/*!  Selects or deselects the \a range depending on \a select.*/void QTableWidget::setRangeSelected(const QTableWidgetSelectionRange &range, bool select){    if (!model()->hasIndex(range.topRow(), range.leftColumn(), rootIndex()) ||        !model()->hasIndex(range.bottomRow(), range.rightColumn(), rootIndex()))        return;    QModelIndex topLeft = model()->index(range.topRow(), range.leftColumn(), rootIndex());    QModelIndex bottomRight = model()->index(range.bottomRow(), range.rightColumn(), rootIndex());    selectionModel()->select(QItemSelection(topLeft, bottomRight),                             select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);}/*!  Returns a list of all selected ranges.  \sa QTableWidgetSelectionRange*/QList<QTableWidgetSelectionRange> QTableWidget::selectedRanges() const{    const QList<QItemSelectionRange> ranges = selectionModel()->selection();    QList<QTableWidgetSelectionRange> result;    for (int i = 0; i < ranges.count(); ++i)        result.append(QTableWidgetSelectionRange(ranges.at(i).top(),                                                 ranges.at(i).left(),                                                 ranges.at(i).bottom(),                                                 ranges.at(i).right()));    return result;}/*!  Returns a list of all selected items.*/QList<QTableWidgetItem*> QTableWidget::selectedItems(){    Q_D(QTableWidget);    QModelIndexList indexes = selectionModel()->selectedIndexes();    QList<QTableWidgetItem*> items;    for (int i = 0; i < indexes.count(); ++i) {        QModelIndex index = indexes.at(i);        if(isIndexHidden(index))            continue;        QTableWidgetItem *item = d->model()->item(index);        if (item)            items.append(item);    }    return items;}/*!  Finds items that matches the \a text using the given \a flags.*/QList<QTableWidgetItem*> QTableWidget::findItems(const QString &text, Qt::MatchFlags flags) const{    Q_D(const QTableWidget);    QModelIndexList indexes;    for (int column = 0; column < columnCount(); ++column)        indexes += d->model()->match(model()->index(0, column, QModelIndex()),                                     Qt::DisplayRole, text, -1, flags);    QList<QTableWidgetItem*> items;    for (int i = 0; i < indexes.size(); ++i)        items.append(d->model()->item(indexes.at(i)));    return items;}/*!  Returns the visual row of the given \a logicalRow.*/int QTableWidget::visualRow(int logicalRow) const{    return verticalHeader()->visualIndex(logicalRow);}/*!  Returns the visual column of the given \a logicalColumn.*/int QTableWidget::visualColumn(int logicalColumn) const{    return horizontalHeader()->visualIndex(logicalColumn);}/*!  \fn QTableWidgetItem *QTableWidget::itemAt(const QPoint &point) const  Returns a pointer to the item at the given \a point, or returns 0 if  the point is not covered by an item in the table widget.  \sa item()*/QTableWidgetItem *QTableWidget::itemAt(const QPoint &p) const{    Q_D(const QTableWidget);    return d->model()->item(indexAt(p));}/*!  Returns the rectangle on the viewport occupied by the item at \a item.*/QRect QTableWidget::visualItemRect(const QTableWidgetItem *item) const{    Q_ASSERT(item);    Q_D(const QTableWidget);    QModelIndex index = d->model()->index(const_cast<QTableWidgetItem*>(item));    Q_ASSERT(index.isValid());    return visualRect(index);}/*!    Scrolls the view if necessary to ensure that the \a item is visible.    The \a hint parameter specifies more precisely where the    \a item should be located after the operation.*/void QTableWidget::scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint){    Q_ASSERT(item);    Q_D(QTableWidget);    QModelIndex index = d->model()->index(const_cast<QTableWidgetItem*>(item));    Q_ASSERT(index.isValid());    QTableView::scrollTo(index, hint);}/*!    Returns the item prototype used by the table.    Copies of the item prototype are returned by the createItem()    function.    \sa setItemPrototype()*/const QTableWidgetItem *QTableWidget::itemPrototype() const{    Q_D(const QTableWidget);    return d->model()->itemPrototype();}/*!    Sets the item prototype for the table to the specified \a item.    \sa itemPrototype()*/void QTableWidget::setItemPrototype(const QTableWidgetItem *item){    Q_D(QTableWidget);    d->model()->setItemPrototype(item);}/*!  Inserts an empty row into the table at \a row.*/void QTableWidget::insertRow(int row){    Q_D(QTableWidget);    d->model()->insertRows(row);}/*!  Inserts an empty column into the table at \a column.*/void QTableWidget::insertColumn(int column){    Q_D(QTableWidget);    d->model()->insertColumns(column);}/*!  Removes the row \a row and all its items from the table.*/void QTableWidget::removeRow(int row){    Q_D(QTableWidget);    d->model()->removeRows(row);}/*!  Removes the column \a column and all its items from the table.*/void QTableWidget::removeColumn(int column){    Q_D(QTableWidget);    d->model()->removeColumns(column);}/*!  Removes all items and selections in the view.  The table dimentions stay the same.*/void QTableWidget::clear(){    Q_D(QTableWidget);    selectionModel()->clear();    d->model()->clear();}/*!    Returns a list of MIME types that can be used to describe a list of    tablewidget items.    \sa mimeData()*/QStringList QTableWidget::mimeTypes() const{    return d_func()->model()->QAbstractTableModel::mimeTypes();}/*!    Returns an object that contains a serialized description of the specified    \a items. The format used to describe the items is obtained from the    mimeTypes() function.    If the list of items is empty, 0 is returned rather than a serialized    empty list.*/QMimeData *QTableWidget::mimeData(const QList<QTableWidgetItem*>) const{    return d_func()->model()->internalMimeData();}/*!    Handles the \a data supplied by a drag and drop operation that ended with    the given \a action in the given \a row and \a column.    \sa supportedDropActions()*/bool QTableWidget::dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action){    QModelIndex idx;#ifndef QT_NO_DRAGANDDROP    if (dropIndicatorPosition() == QAbstractItemView::OnItem) {        // QAbstractTableModel::dropMimeData will overwrite on the index if row == -1 and column == -1        idx = model()->index(row, column);        row = -1;        column = -1;    }#endif    return d_func()->model()->QAbstractTableModel::dropMimeData(data, action , row, column, idx);}/*!  Returns the drop actions supported by this view.  \sa Qt::DropActions*/Qt::DropActions QTableWidget::supportedDropActions() const{    return d_func()->model()->QAbstractTableModel::supportedDropActions();}/*!  Returns a list of pointers to the items contained in the \a data object.  If the object was not created by a QTreeWidget in the same process, the list  is empty.*/QList<QTableWidgetItem*> QTableWidget::items(const QMimeData *data) const{    const QTableWidgetMimeData *twd = qobject_cast<const QTableWidgetMimeData*>(data);    if (twd)        return twd->items;    return QList<QTableWidgetItem*>();}/*!  Returns the QModelIndex assocated with the given \a item.*/QModelIndex QTableWidget::indexFromItem(QTableWidgetItem *item) const{    Q_D(const QTableWidget);    Q_ASSERT(item);    return d->model()->index(item);}/*!  Returns a pointer to the QTableWidgetItem assocated with the given \a index.*/QTableWidgetItem *QTableWidget::itemFromIndex(const QModelIndex &index) const{    Q_D(const QTableWidget);    Q_ASSERT(index.isValid());    return d->model()->item(index);}/*!    \internal*/void QTableWidget::setModel(QAbstractItemModel * /*model*/){    qFatal("QTableWidget::setModel() - Changing the model of the QTableWidget is not allowed.");}/* \reimp */bool QTableWidget::event(QEvent *e){    return QTableView::event(e);}#include "moc_qtablewidget.cpp"#endif // QT_NO_TABLEWIDGET

⌨️ 快捷键说明

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