diff options
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 14 | ||||
-rw-r--r-- | src/gui/itemviews/qabstractitemview_p.h | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qcolumnview.cpp | 40 | ||||
-rw-r--r-- | src/gui/itemviews/qheaderview.cpp | 7 | ||||
-rw-r--r-- | src/gui/itemviews/qlistview.cpp | 10 | ||||
-rw-r--r-- | src/gui/itemviews/qlistwidget.cpp | 92 | ||||
-rw-r--r-- | src/gui/itemviews/qlistwidget_p.h | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qstandarditemmodel.cpp | 36 | ||||
-rw-r--r-- | src/gui/itemviews/qtablewidget.cpp | 118 | ||||
-rw-r--r-- | src/gui/itemviews/qtablewidget_p.h | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qtreeview.cpp | 47 | ||||
-rw-r--r-- | src/gui/itemviews/qtreewidget.cpp | 97 | ||||
-rw-r--r-- | src/gui/itemviews/qtreewidget_p.h | 7 |
13 files changed, 236 insertions, 238 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index d353c2d..9effc70 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -108,16 +108,16 @@ void QAbstractItemViewPrivate::init() Q_Q(QAbstractItemView); q->setItemDelegate(new QStyledItemDelegate(q)); - q->verticalScrollBar()->setRange(0, 0); - q->horizontalScrollBar()->setRange(0, 0); + vbar->setRange(0, 0); + hbar->setRange(0, 0); - QObject::connect(q->verticalScrollBar(), SIGNAL(actionTriggered(int)), + QObject::connect(vbar, SIGNAL(actionTriggered(int)), q, SLOT(verticalScrollbarAction(int))); - QObject::connect(q->horizontalScrollBar(), SIGNAL(actionTriggered(int)), + QObject::connect(hbar, SIGNAL(actionTriggered(int)), q, SLOT(horizontalScrollbarAction(int))); - QObject::connect(q->verticalScrollBar(), SIGNAL(valueChanged(int)), + QObject::connect(vbar, SIGNAL(valueChanged(int)), q, SLOT(verticalScrollbarValueChanged(int))); - QObject::connect(q->horizontalScrollBar(), SIGNAL(valueChanged(int)), + QObject::connect(hbar, SIGNAL(valueChanged(int)), q, SLOT(horizontalScrollbarValueChanged(int))); viewport->setBackgroundRole(QPalette::Base); @@ -3784,7 +3784,7 @@ void QAbstractItemViewPrivate::clearOrRemove() void QAbstractItemViewPrivate::checkPersistentEditorFocus() { Q_Q(QAbstractItemView); - if (QWidget *widget = qApp->focusWidget()) { + if (QWidget *widget = QApplication::focusWidget()) { if (persistent.contains(widget)) { //a persistent editor has gained the focus QModelIndex index = indexForEditor(widget); diff --git a/src/gui/itemviews/qabstractitemview_p.h b/src/gui/itemviews/qabstractitemview_p.h index 139d0b7..8594ad7 100644 --- a/src/gui/itemviews/qabstractitemview_p.h +++ b/src/gui/itemviews/qabstractitemview_p.h @@ -99,7 +99,7 @@ public: QVariant data(const QModelIndex &, int) const { return QVariant(); } }; -class QAbstractItemViewPrivate : public QAbstractScrollAreaPrivate +class Q_AUTOTEST_EXPORT QAbstractItemViewPrivate : public QAbstractScrollAreaPrivate { Q_DECLARE_PUBLIC(QAbstractItemView) diff --git a/src/gui/itemviews/qcolumnview.cpp b/src/gui/itemviews/qcolumnview.cpp index 4fb08bb..16ae8e9 100644 --- a/src/gui/itemviews/qcolumnview.cpp +++ b/src/gui/itemviews/qcolumnview.cpp @@ -108,9 +108,9 @@ void QColumnViewPrivate::initialize() { Q_Q(QColumnView); q->setTextElideMode(Qt::ElideMiddle); - q->connect(¤tAnimation, SIGNAL(frameChanged(int)), - q->horizontalScrollBar(), SLOT(setValue(int))); - q->connect(¤tAnimation, SIGNAL(finished()), q, SLOT(_q_changeCurrentColumn())); + QObject::connect(¤tAnimation, SIGNAL(frameChanged(int)), + hbar, SLOT(setValue(int))); + QObject::connect(¤tAnimation, SIGNAL(finished()), q, SLOT(_q_changeCurrentColumn())); delete itemDelegate; q->setItemDelegate(new QColumnViewDelegate(q)); } @@ -421,23 +421,23 @@ void QColumnViewPrivate::updateScrollbars() horizontalLength = (columns.first()->x() + columns.first()->width()) - columns.last()->x(); } - QSize viewportSize = q->viewport()->size(); - if (horizontalLength < viewportSize.width() && q->horizontalScrollBar()->value() == 0) { - q->horizontalScrollBar()->setRange(0, 0); + QSize viewportSize = viewport->size(); + if (horizontalLength < viewportSize.width() && hbar->value() == 0) { + hbar->setRange(0, 0); } else { int visibleLength = qMin(horizontalLength + q->horizontalOffset(), viewportSize.width()); int hiddenLength = horizontalLength - visibleLength; - if (hiddenLength != q->horizontalScrollBar()->maximum()) - q->horizontalScrollBar()->setRange(0, hiddenLength); + if (hiddenLength != hbar->maximum()) + hbar->setRange(0, hiddenLength); } if (!columns.isEmpty()) { int pageStepSize = columns.at(0)->width(); - if (pageStepSize != q->horizontalScrollBar()->pageStep()) - q->horizontalScrollBar()->setPageStep(pageStepSize); + if (pageStepSize != hbar->pageStep()) + hbar->setPageStep(pageStepSize); } - bool visible = (q->horizontalScrollBar()->maximum() > 0); - if (visible != q->horizontalScrollBar()->isVisible()) - q->horizontalScrollBar()->setVisible(visible); + bool visible = (hbar->maximum() > 0); + if (visible != hbar->isVisible()) + hbar->setVisible(visible); } /*! @@ -696,7 +696,7 @@ QAbstractItemView *QColumnViewPrivate::createColumn(const QModelIndex &index, bo q, SIGNAL(pressed(const QModelIndex &))); view->setFocusPolicy(Qt::NoFocus); - view->setParent(q->viewport()); + view->setParent(viewport); Q_ASSERT(view); // Setup corner grip @@ -707,13 +707,13 @@ QAbstractItemView *QColumnViewPrivate::createColumn(const QModelIndex &index, bo } if (columnSizes.count() > columns.count()) { - view->setGeometry(0, 0, columnSizes.at(columns.count()), q->viewport()->height()); + view->setGeometry(0, 0, columnSizes.at(columns.count()), viewport->height()); } else { int initialWidth = view->sizeHint().width(); if (q->isRightToLeft()) - view->setGeometry(q->viewport()->width() - initialWidth, 0, initialWidth, q->viewport()->height()); + view->setGeometry(viewport->width() - initialWidth, 0, initialWidth, viewport->height()); else - view->setGeometry(0, 0, initialWidth, q->viewport()->height()); + view->setGeometry(0, 0, initialWidth, viewport->height()); columnSizes.resize(qMax(columnSizes.count(), columns.count() + 1)); columnSizes[columns.count()] = initialWidth; } @@ -1056,11 +1056,11 @@ void QColumnViewPrivate::doLayout() if (!model || columns.isEmpty()) return; - int viewportHeight = q->viewport()->height(); + int viewportHeight = viewport->height(); int x = columns.at(0)->x(); if (q->isRightToLeft()) { - x = q->viewport()->width() + q->horizontalOffset(); + x = viewport->width() + q->horizontalOffset(); for (int i = 0; i < columns.size(); ++i) { QAbstractItemView *view = columns.at(i); x -= view->width(); @@ -1116,7 +1116,7 @@ void QColumnViewDelegate::paint(QPainter *painter, // Draw > if (index.model()->hasChildren(index)) { const QWidget *view = opt.widget; - QStyle *style = view ? view->style() : qApp->style(); + QStyle *style = view ? view->style() : QApplication::style(); style->drawPrimitive(QStyle::PE_IndicatorColumnViewArrow, &opt, painter, view); } } diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index 7ad825a..d0321d8 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -3474,11 +3474,10 @@ void QHeaderViewPrivate::setGlobalHeaderResizeMode(QHeaderView::ResizeMode mode) int QHeaderViewPrivate::viewSectionSizeHint(int logical) const { - Q_Q(const QHeaderView); - if (QAbstractItemView *parent = qobject_cast<QAbstractItemView*>(q->parent())) { + if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent)) { return (orientation == Qt::Horizontal - ? parent->sizeHintForColumn(logical) - : parent->sizeHintForRow(logical)); + ? view->sizeHintForColumn(logical) + : view->sizeHintForRow(logical)); } return 0; } diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 03ba641..fe7916c 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -610,7 +610,7 @@ int QListViewPrivate::horizontalScrollToValue(const QModelIndex &index, const QR const bool rightOf = q->isRightToLeft() ? rect.right() > area.right() : (rect.right() > area.right()) && (rect.left() > area.left()); - int horizontalValue = q->horizontalScrollBar()->value(); + int horizontalValue = hbar->value(); // ScrollPerItem if (q->horizontalScrollMode() == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) { @@ -652,10 +652,10 @@ int QListViewPrivate::verticalScrollToValue(const QModelIndex &index, const QRec const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top()); const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom()); - int verticalValue = q->verticalScrollBar()->value(); + int verticalValue = vbar->value(); // ScrollPerItem - if (q->verticalScrollMode() == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) { + if (verticalScrollMode == QAbstractItemView::ScrollPerItem && viewMode == QListView::ListMode) { const QListViewItem item = indexToListViewItem(index); const QRect rect = q->visualRect(index); verticalValue = staticListView->verticalPerItemValue(itemIndex(item), @@ -1972,10 +1972,10 @@ void QListViewPrivate::prepareItemsLayout() // Qt::ScrollBarAlwaysOn but scrollbar extent must be deduced if policy // is Qt::ScrollBarAsNeeded int verticalMargin = vbarpolicy==Qt::ScrollBarAsNeeded - ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q->verticalScrollBar()) + frameAroundContents + ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, vbar) + frameAroundContents : 0; int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded - ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q->horizontalScrollBar()) + frameAroundContents + ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, hbar) + frameAroundContents : 0; layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin); diff --git a/src/gui/itemviews/qlistwidget.cpp b/src/gui/itemviews/qlistwidget.cpp index 504908f..51861b3 100644 --- a/src/gui/itemviews/qlistwidget.cpp +++ b/src/gui/itemviews/qlistwidget.cpp @@ -1020,51 +1020,51 @@ void QListWidgetPrivate::setup() QObject::connect(q, SIGNAL(activated(QModelIndex)), q, SLOT(_q_emitItemActivated(QModelIndex))); QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex))); - QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_q_emitItemChanged(QModelIndex))); QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), q, SLOT(_q_emitCurrentItemChanged(QModelIndex,QModelIndex))); QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), q, SIGNAL(itemSelectionChanged())); - QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); - QObject::connect(model(), SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort())); + QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort())); } void QListWidgetPrivate::_q_emitItemPressed(const QModelIndex &index) { Q_Q(QListWidget); - emit q->itemPressed(model()->at(index.row())); + emit q->itemPressed(listModel()->at(index.row())); } void QListWidgetPrivate::_q_emitItemClicked(const QModelIndex &index) { Q_Q(QListWidget); - emit q->itemClicked(model()->at(index.row())); + emit q->itemClicked(listModel()->at(index.row())); } void QListWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index) { Q_Q(QListWidget); - emit q->itemDoubleClicked(model()->at(index.row())); + emit q->itemDoubleClicked(listModel()->at(index.row())); } void QListWidgetPrivate::_q_emitItemActivated(const QModelIndex &index) { Q_Q(QListWidget); - emit q->itemActivated(model()->at(index.row())); + emit q->itemActivated(listModel()->at(index.row())); } void QListWidgetPrivate::_q_emitItemEntered(const QModelIndex &index) { Q_Q(QListWidget); - emit q->itemEntered(model()->at(index.row())); + emit q->itemEntered(listModel()->at(index.row())); } void QListWidgetPrivate::_q_emitItemChanged(const QModelIndex &index) { Q_Q(QListWidget); - emit q->itemChanged(model()->at(index.row())); + emit q->itemChanged(listModel()->at(index.row())); } void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, @@ -1072,8 +1072,8 @@ void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, { Q_Q(QListWidget); QPersistentModelIndex persistentCurrent = current; - QListWidgetItem *currentItem = model()->at(persistentCurrent.row()); - emit q->currentItemChanged(currentItem, model()->at(previous.row())); + QListWidgetItem *currentItem = listModel()->at(persistentCurrent.row()); + emit q->currentItemChanged(currentItem, listModel()->at(previous.row())); //persistentCurrent is invalid if something changed the model in response //to the currentItemChanged signal emission and the item was removed @@ -1088,14 +1088,14 @@ void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, void QListWidgetPrivate::_q_sort() { if (sortingEnabled) - model()->sort(0, sortOrder); + model->sort(0, sortOrder); } void QListWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { if (sortingEnabled && topLeft.isValid() && bottomRight.isValid()) - model()->ensureSorted(topLeft.column(), sortOrder, + listModel()->ensureSorted(topLeft.column(), sortOrder, topLeft.row(), bottomRight.row()); } @@ -1308,9 +1308,9 @@ QListWidget::~QListWidget() QListWidgetItem *QListWidget::item(int row) const { Q_D(const QListWidget); - if (row < 0 || row >= d->model()->rowCount()) + if (row < 0 || row >= d->model->rowCount()) return 0; - return d->model()->at(row); + return d->listModel()->at(row); } /*! @@ -1322,7 +1322,7 @@ QListWidgetItem *QListWidget::item(int row) const int QListWidget::row(const QListWidgetItem *item) const { Q_D(const QListWidget); - return d->model()->index(const_cast<QListWidgetItem*>(item)).row(); + return d->listModel()->index(const_cast<QListWidgetItem*>(item)).row(); } @@ -1336,7 +1336,7 @@ void QListWidget::insertItem(int row, QListWidgetItem *item) { Q_D(QListWidget); if (item && !item->view) - d->model()->insert(row, item); + d->listModel()->insert(row, item); } /*! @@ -1349,7 +1349,7 @@ void QListWidget::insertItem(int row, QListWidgetItem *item) void QListWidget::insertItem(int row, const QString &label) { Q_D(QListWidget); - d->model()->insert(row, new QListWidgetItem(label)); + d->listModel()->insert(row, new QListWidgetItem(label)); } /*! @@ -1362,7 +1362,7 @@ void QListWidget::insertItem(int row, const QString &label) void QListWidget::insertItems(int row, const QStringList &labels) { Q_D(QListWidget); - d->model()->insert(row, labels); + d->listModel()->insert(row, labels); } /*! @@ -1378,9 +1378,9 @@ void QListWidget::insertItems(int row, const QStringList &labels) QListWidgetItem *QListWidget::takeItem(int row) { Q_D(QListWidget); - if (row < 0 || row >= d->model()->rowCount()) + if (row < 0 || row >= d->model->rowCount()) return 0; - return d->model()->take(row); + return d->listModel()->take(row); } /*! @@ -1391,7 +1391,7 @@ QListWidgetItem *QListWidget::takeItem(int row) int QListWidget::count() const { Q_D(const QListWidget); - return d->model()->rowCount(); + return d->model->rowCount(); } /*! @@ -1400,7 +1400,7 @@ int QListWidget::count() const QListWidgetItem *QListWidget::currentItem() const { Q_D(const QListWidget); - return d->model()->at(currentIndex().row()); + return d->listModel()->at(currentIndex().row()); } @@ -1438,7 +1438,7 @@ int QListWidget::currentRow() const void QListWidget::setCurrentRow(int row) { Q_D(QListWidget); - QModelIndex index = d->model()->index(row); + QModelIndex index = d->listModel()->index(row); if (d->selectionMode == SingleSelection) selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect); else if (d->selectionMode == NoSelection) @@ -1455,7 +1455,7 @@ void QListWidget::setCurrentRow(int row) void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags command) { Q_D(QListWidget); - d->selectionModel->setCurrentIndex(d->model()->index(row), command); + d->selectionModel->setCurrentIndex(d->listModel()->index(row), command); } /*! @@ -1464,7 +1464,7 @@ void QListWidget::setCurrentRow(int row, QItemSelectionModel::SelectionFlags com QListWidgetItem *QListWidget::itemAt(const QPoint &p) const { Q_D(const QListWidget); - return d->model()->at(indexAt(p).row()); + return d->listModel()->at(indexAt(p).row()); } @@ -1482,7 +1482,7 @@ QListWidgetItem *QListWidget::itemAt(const QPoint &p) const QRect QListWidget::visualItemRect(const QListWidgetItem *item) const { Q_D(const QListWidget); - QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item)); + QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); return visualRect(index); } @@ -1493,7 +1493,7 @@ void QListWidget::sortItems(Qt::SortOrder order) { Q_D(QListWidget); d->sortOrder = order; - d->model()->sort(0, order); + d->listModel()->sort(0, order); } /*! @@ -1532,7 +1532,7 @@ Qt::SortOrder QListWidget::sortOrder() const void QListWidget::editItem(QListWidgetItem *item) { Q_D(QListWidget); - edit(d->model()->index(item)); + edit(d->listModel()->index(item)); } /*! @@ -1543,7 +1543,7 @@ void QListWidget::editItem(QListWidgetItem *item) void QListWidget::openPersistentEditor(QListWidgetItem *item) { Q_D(QListWidget); - QModelIndex index = d->model()->index(item); + QModelIndex index = d->listModel()->index(item); QAbstractItemView::openPersistentEditor(index); } @@ -1555,7 +1555,7 @@ void QListWidget::openPersistentEditor(QListWidgetItem *item) void QListWidget::closePersistentEditor(QListWidgetItem *item) { Q_D(QListWidget); - QModelIndex index = d->model()->index(item); + QModelIndex index = d->listModel()->index(item); QAbstractItemView::closePersistentEditor(index); } @@ -1567,7 +1567,7 @@ void QListWidget::closePersistentEditor(QListWidgetItem *item) QWidget *QListWidget::itemWidget(QListWidgetItem *item) const { Q_D(const QListWidget); - QModelIndex index = d->model()->index(item); + QModelIndex index = d->listModel()->index(item); return QAbstractItemView::indexWidget(index); } @@ -1585,7 +1585,7 @@ QWidget *QListWidget::itemWidget(QListWidgetItem *item) const void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget) { Q_D(QListWidget); - QModelIndex index = d->model()->index(item); + QModelIndex index = d->listModel()->index(item); QAbstractItemView::setIndexWidget(index, widget); } @@ -1599,7 +1599,7 @@ void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget) bool QListWidget::isItemSelected(const QListWidgetItem *item) const { Q_D(const QListWidget); - QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item)); + QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); return selectionModel()->isSelected(index); } @@ -1614,7 +1614,7 @@ bool QListWidget::isItemSelected(const QListWidgetItem *item) const void QListWidget::setItemSelected(const QListWidgetItem *item, bool select) { Q_D(QListWidget); - QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item)); + QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); if (d->selectionMode == SingleSelection) { selectionModel()->select(index, select @@ -1638,7 +1638,7 @@ QList<QListWidgetItem*> QListWidget::selectedItems() const QModelIndexList indexes = selectionModel()->selectedIndexes(); QList<QListWidgetItem*> items; for (int i = 0; i < indexes.count(); ++i) - items.append(d->model()->at(indexes.at(i).row())); + items.append(d->listModel()->at(indexes.at(i).row())); return items; } @@ -1649,11 +1649,11 @@ QList<QListWidgetItem*> QListWidget::selectedItems() const QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const { Q_D(const QListWidget); - QModelIndexList indexes = d->model()->match(model()->index(0, 0, QModelIndex()), + QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()), Qt::DisplayRole, text, -1, flags); QList<QListWidgetItem*> items; for (int i = 0; i < indexes.size(); ++i) - items.append(d->model()->at(indexes.at(i).row())); + items.append(d->listModel()->at(indexes.at(i).row())); return items; } @@ -1690,7 +1690,7 @@ void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide) void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint) { Q_D(QListWidget); - QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item)); + QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item)); QListView::scrollTo(index, hint); } @@ -1703,7 +1703,7 @@ void QListWidget::clear() { Q_D(QListWidget); selectionModel()->clear(); - d->model()->clear(); + d->listModel()->clear(); } /*! @@ -1714,7 +1714,7 @@ void QListWidget::clear() */ QStringList QListWidget::mimeTypes() const { - return d_func()->model()->QAbstractListModel::mimeTypes(); + return d_func()->listModel()->QAbstractListModel::mimeTypes(); } /*! @@ -1727,7 +1727,7 @@ QStringList QListWidget::mimeTypes() const */ QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*>) const { - return d_func()->model()->internalMimeData(); + return d_func()->listModel()->internalMimeData(); } #ifndef QT_NO_DRAGANDDROP @@ -1750,7 +1750,7 @@ bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction row = -1; column = -1; } - return d_func()->model()->QAbstractListModel::dropMimeData(data, action , row, column, idx); + return d_func()->listModel()->QAbstractListModel::dropMimeData(data, action , row, column, idx); } /*! \reimp */ @@ -1809,7 +1809,7 @@ void QListWidget::dropEvent(QDropEvent *event) { Qt::DropActions QListWidget::supportedDropActions() const { Q_D(const QListWidget); - return d->model()->QAbstractListModel::supportedDropActions() | Qt::MoveAction; + return d->listModel()->QAbstractListModel::supportedDropActions() | Qt::MoveAction; } #endif // QT_NO_DRAGANDDROP @@ -1833,7 +1833,7 @@ QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const QModelIndex QListWidget::indexFromItem(QListWidgetItem *item) const { Q_D(const QListWidget); - return d->model()->index(item); + return d->listModel()->index(item); } /*! @@ -1844,7 +1844,7 @@ QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const { Q_D(const QListWidget); if (d->isIndexValid(index)) - return d->model()->at(index.row()); + return d->listModel()->at(index.row()); return 0; } diff --git a/src/gui/itemviews/qlistwidget_p.h b/src/gui/itemviews/qlistwidget_p.h index 8556047..6887d9d 100644 --- a/src/gui/itemviews/qlistwidget_p.h +++ b/src/gui/itemviews/qlistwidget_p.h @@ -143,7 +143,7 @@ class QListWidgetPrivate : public QListViewPrivate Q_DECLARE_PUBLIC(QListWidget) public: QListWidgetPrivate() : QListViewPrivate(), sortOrder(Qt::AscendingOrder), sortingEnabled(false) {} - inline QListModel *model() const { return qobject_cast<QListModel*>(q_func()->model()); } + inline QListModel *listModel() const { return qobject_cast<QListModel*>(model); } void setup(); void _q_emitItemPressed(const QModelIndex &index); void _q_emitItemClicked(const QModelIndex &index); diff --git a/src/gui/itemviews/qstandarditemmodel.cpp b/src/gui/itemviews/qstandarditemmodel.cpp index 9d0f796..30daed2 100644 --- a/src/gui/itemviews/qstandarditemmodel.cpp +++ b/src/gui/itemviews/qstandarditemmodel.cpp @@ -1742,18 +1742,21 @@ QList<QStandardItem*> QStandardItem::takeRow(int row) Q_D(QStandardItem); if ((row < 0) || (row >= rowCount())) return QList<QStandardItem*>(); + if (d->model) + d->model->d_func()->rowsAboutToBeRemoved(this, row, row); QList<QStandardItem*> items; int index = d->childIndex(row, 0); - for (int column = 0; column < d->columnCount(); ++column) { - QStandardItem *ch = d->children.at(index); - if (ch) { + int col_count = d->columnCount(); + for (int column = 0; column < col_count; ++column) { + QStandardItem *ch = d->children.at(index + column); + if (ch) ch->d_func()->setParentAndModel(0, 0); - d->children.replace(index, 0); - } items.append(ch); - ++index; } - removeRow(row); + d->children.remove(index, col_count); + d->rows--; + if (d->model) + d->model->d_func()->rowsRemoved(this, row, 1); return items; } @@ -1769,18 +1772,21 @@ QList<QStandardItem*> QStandardItem::takeColumn(int column) Q_D(QStandardItem); if ((column < 0) || (column >= columnCount())) return QList<QStandardItem*>(); + if (d->model) + d->model->d_func()->columnsAboutToBeRemoved(this, column, column); QList<QStandardItem*> items; - int index = d->childIndex(0, column); - for (int row = 0; row < d->rowCount(); ++row) { + + for (int row = d->rowCount() - 1; row >= 0; --row) { + int index = d->childIndex(row, column); QStandardItem *ch = d->children.at(index); - if (ch) { + if (ch) ch->d_func()->setParentAndModel(0, 0); - d->children.replace(index, 0); - } - items.append(ch); - index += d->columnCount(); + d->children.remove(index); + items.prepend(ch); } - removeColumn(column); + d->columns--; + if (d->model) + d->model->d_func()->columnsRemoved(this, column, 1); return items; } diff --git a/src/gui/itemviews/qtablewidget.cpp b/src/gui/itemviews/qtablewidget.cpp index 072e435..6645376 100644 --- a/src/gui/itemviews/qtablewidget.cpp +++ b/src/gui/itemviews/qtablewidget.cpp @@ -1570,7 +1570,7 @@ void QTableWidgetPrivate::setup() QObject::connect(q, SIGNAL(activated(QModelIndex)), q, SLOT(_q_emitItemActivated(QModelIndex))); QObject::connect(q, SIGNAL(entered(QModelIndex)), q, SLOT(_q_emitItemEntered(QModelIndex))); // model signals - QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_q_emitItemChanged(QModelIndex))); // selection signals QObject::connect(q->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), @@ -1578,15 +1578,15 @@ void QTableWidgetPrivate::setup() QObject::connect(q->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), q, SIGNAL(itemSelectionChanged())); // sorting - QObject::connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), + QObject::connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), q, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); - QObject::connect(model(), SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort())); + QObject::connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), q, SLOT(_q_sort())); } void QTableWidgetPrivate::_q_emitItemPressed(const QModelIndex &index) { Q_Q(QTableWidget); - if (QTableWidgetItem *item = model()->item(index)) + if (QTableWidgetItem *item = tableModel()->item(index)) emit q->itemPressed(item); emit q->cellPressed(index.row(), index.column()); } @@ -1594,7 +1594,7 @@ void QTableWidgetPrivate::_q_emitItemPressed(const QModelIndex &index) void QTableWidgetPrivate::_q_emitItemClicked(const QModelIndex &index) { Q_Q(QTableWidget); - if (QTableWidgetItem *item = model()->item(index)) + if (QTableWidgetItem *item = tableModel()->item(index)) emit q->itemClicked(item); emit q->cellClicked(index.row(), index.column()); } @@ -1602,7 +1602,7 @@ void QTableWidgetPrivate::_q_emitItemClicked(const QModelIndex &index) void QTableWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index) { Q_Q(QTableWidget); - if (QTableWidgetItem *item = model()->item(index)) + if (QTableWidgetItem *item = tableModel()->item(index)) emit q->itemDoubleClicked(item); emit q->cellDoubleClicked(index.row(), index.column()); } @@ -1610,7 +1610,7 @@ void QTableWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index) void QTableWidgetPrivate::_q_emitItemActivated(const QModelIndex &index) { Q_Q(QTableWidget); - if (QTableWidgetItem *item = model()->item(index)) + if (QTableWidgetItem *item = tableModel()->item(index)) emit q->itemActivated(item); emit q->cellActivated(index.row(), index.column()); } @@ -1618,7 +1618,7 @@ void QTableWidgetPrivate::_q_emitItemActivated(const QModelIndex &index) void QTableWidgetPrivate::_q_emitItemEntered(const QModelIndex &index) { Q_Q(QTableWidget); - if (QTableWidgetItem *item = model()->item(index)) + if (QTableWidgetItem *item = tableModel()->item(index)) emit q->itemEntered(item); emit q->cellEntered(index.row(), index.column()); } @@ -1626,7 +1626,7 @@ void QTableWidgetPrivate::_q_emitItemEntered(const QModelIndex &index) void QTableWidgetPrivate::_q_emitItemChanged(const QModelIndex &index) { Q_Q(QTableWidget); - if (QTableWidgetItem *item = model()->item(index)) + if (QTableWidgetItem *item = tableModel()->item(index)) emit q->itemChanged(item); emit q->cellChanged(index.row(), index.column()); } @@ -1635,8 +1635,8 @@ void QTableWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, const QModelIndex &previous) { Q_Q(QTableWidget); - QTableWidgetItem *currentItem = model()->item(current); - QTableWidgetItem *previousItem = model()->item(previous); + QTableWidgetItem *currentItem = tableModel()->item(current); + QTableWidgetItem *previousItem = tableModel()->item(previous); if (currentItem || previousItem) emit q->currentItemChanged(currentItem, previousItem); emit q->currentCellChanged(current.row(), current.column(), previous.row(), previous.column()); @@ -1647,7 +1647,7 @@ void QTableWidgetPrivate::_q_sort() if (sortingEnabled) { int column = horizontalHeader->sortIndicatorSection(); Qt::SortOrder order = horizontalHeader->sortIndicatorOrder(); - model()->sort(column, order); + model->sort(column, order); } } @@ -1658,7 +1658,7 @@ void QTableWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, int column = horizontalHeader->sortIndicatorSection(); if (column >= topLeft.column() && column <= bottomRight.column()) { Qt::SortOrder order = horizontalHeader->sortIndicatorOrder(); - model()->ensureSorted(column, order, topLeft.row(), bottomRight.row()); + tableModel()->ensureSorted(column, order, topLeft.row(), bottomRight.row()); } } } @@ -1862,7 +1862,7 @@ QTableWidget::~QTableWidget() void QTableWidget::setRowCount(int rows) { Q_D(QTableWidget); - d->model()->setRowCount(rows); + d->tableModel()->setRowCount(rows); } /*! @@ -1872,7 +1872,7 @@ void QTableWidget::setRowCount(int rows) int QTableWidget::rowCount() const { Q_D(const QTableWidget); - return d->model()->rowCount(); + return d->model->rowCount(); } /*! @@ -1885,7 +1885,7 @@ int QTableWidget::rowCount() const void QTableWidget::setColumnCount(int columns) { Q_D(QTableWidget); - d->model()->setColumnCount(columns); + d->tableModel()->setColumnCount(columns); } /*! @@ -1895,7 +1895,7 @@ void QTableWidget::setColumnCount(int columns) int QTableWidget::columnCount() const { Q_D(const QTableWidget); - return d->model()->columnCount(); + return d->model->columnCount(); } /*! @@ -1904,7 +1904,7 @@ int QTableWidget::columnCount() const int QTableWidget::row(const QTableWidgetItem *item) const { Q_D(const QTableWidget); - return d->model()->index(item).row(); + return d->tableModel()->index(item).row(); } /*! @@ -1913,7 +1913,7 @@ int QTableWidget::row(const QTableWidgetItem *item) const int QTableWidget::column(const QTableWidgetItem *item) const { Q_D(const QTableWidget); - return d->model()->index(item).column(); + return d->tableModel()->index(item).column(); } @@ -1926,7 +1926,7 @@ int QTableWidget::column(const QTableWidgetItem *item) const QTableWidgetItem *QTableWidget::item(int row, int column) const { Q_D(const QTableWidget); - return d->model()->item(row, column); + return d->tableModel()->item(row, column); } /*! @@ -1955,7 +1955,7 @@ void QTableWidget::setItem(int row, int column, QTableWidgetItem *item) qWarning("QTableWidget: cannot insert an item that is already owned by another QTableWidget"); } else { item->view = this; - d->model()->setItem(row, column, item); + d->tableModel()->setItem(row, column, item); } } else { delete takeItem(row, column); @@ -1968,7 +1968,7 @@ void QTableWidget::setItem(int row, int column, QTableWidgetItem *item) QTableWidgetItem *QTableWidget::takeItem(int row, int column) { Q_D(QTableWidget); - QTableWidgetItem *item = d->model()->takeItem(row, column); + QTableWidgetItem *item = d->tableModel()->takeItem(row, column); if (item) item->view = 0; return item; @@ -1980,7 +1980,7 @@ QTableWidgetItem *QTableWidget::takeItem(int row, int column) QTableWidgetItem *QTableWidget::verticalHeaderItem(int row) const { Q_D(const QTableWidget); - return d->model()->verticalHeaderItem(row); + return d->tableModel()->verticalHeaderItem(row); } /*! @@ -1991,7 +1991,7 @@ void QTableWidget::setVerticalHeaderItem(int row, QTableWidgetItem *item) Q_D(QTableWidget); if (item) { item->view = this; - d->model()->setVerticalHeaderItem(row, item); + d->tableModel()->setVerticalHeaderItem(row, item); } else { delete takeVerticalHeaderItem(row); } @@ -2004,7 +2004,7 @@ void QTableWidget::setVerticalHeaderItem(int row, QTableWidgetItem *item) QTableWidgetItem *QTableWidget::takeVerticalHeaderItem(int row) { Q_D(QTableWidget); - QTableWidgetItem *itm = d->model()->takeVerticalHeaderItem(row); + QTableWidgetItem *itm = d->tableModel()->takeVerticalHeaderItem(row); if (itm) itm->view = 0; return itm; @@ -2017,7 +2017,7 @@ QTableWidgetItem *QTableWidget::takeVerticalHeaderItem(int row) QTableWidgetItem *QTableWidget::horizontalHeaderItem(int column) const { Q_D(const QTableWidget); - return d->model()->horizontalHeaderItem(column); + return d->tableModel()->horizontalHeaderItem(column); } /*! @@ -2028,7 +2028,7 @@ void QTableWidget::setHorizontalHeaderItem(int column, QTableWidgetItem *item) Q_D(QTableWidget); if (item) { item->view = this; - d->model()->setHorizontalHeaderItem(column, item); + d->tableModel()->setHorizontalHeaderItem(column, item); } else { delete takeHorizontalHeaderItem(column); } @@ -2041,7 +2041,7 @@ void QTableWidget::setHorizontalHeaderItem(int column, QTableWidgetItem *item) QTableWidgetItem *QTableWidget::takeHorizontalHeaderItem(int column) { Q_D(QTableWidget); - QTableWidgetItem *itm = d->model()->takeHorizontalHeaderItem(column); + QTableWidgetItem *itm = d->tableModel()->takeHorizontalHeaderItem(column); if (itm) itm->view = 0; return itm; @@ -2053,7 +2053,7 @@ QTableWidgetItem *QTableWidget::takeHorizontalHeaderItem(int column) void QTableWidget::setVerticalHeaderLabels(const QStringList &labels) { Q_D(QTableWidget); - QTableModel *model = d->model(); + QTableModel *model = d->tableModel(); QTableWidgetItem *item = 0; for (int i = 0; i < model->rowCount() && i < labels.count(); ++i) { item = model->verticalHeaderItem(i); @@ -2071,7 +2071,7 @@ void QTableWidget::setVerticalHeaderLabels(const QStringList &labels) void QTableWidget::setHorizontalHeaderLabels(const QStringList &labels) { Q_D(QTableWidget); - QTableModel *model = d->model(); + QTableModel *model = d->tableModel(); QTableWidgetItem *item = 0; for (int i = 0; i < model->columnCount() && i < labels.count(); ++i) { item = model->horizontalHeaderItem(i); @@ -2111,7 +2111,7 @@ int QTableWidget::currentColumn() const QTableWidgetItem *QTableWidget::currentItem() const { Q_D(const QTableWidget); - return d->model()->item(currentIndex()); + return d->tableModel()->item(currentIndex()); } /*! @@ -2125,7 +2125,7 @@ QTableWidgetItem *QTableWidget::currentItem() const void QTableWidget::setCurrentItem(QTableWidgetItem *item) { Q_D(QTableWidget); - setCurrentIndex(d->model()->index(item)); + setCurrentIndex(d->tableModel()->index(item)); } /*! @@ -2138,7 +2138,7 @@ void QTableWidget::setCurrentItem(QTableWidgetItem *item) void QTableWidget::setCurrentItem(QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command) { Q_D(QTableWidget); - d->selectionModel->setCurrentIndex(d->model()->index(item), command); + d->selectionModel->setCurrentIndex(d->tableModel()->index(item), command); } /*! @@ -2177,7 +2177,7 @@ void QTableWidget::setCurrentCell(int row, int column, QItemSelectionModel::Sele void QTableWidget::sortItems(int column, Qt::SortOrder order) { Q_D(QTableWidget); - d->model()->sort(column, order); + d->model->sort(column, order); horizontalHeader()->setSortIndicator(column, order); } @@ -2206,7 +2206,7 @@ void QTableWidget::editItem(QTableWidgetItem *item) Q_D(QTableWidget); if (!item) return; - edit(d->model()->index(item)); + edit(d->tableModel()->index(item)); } /*! @@ -2219,7 +2219,7 @@ void QTableWidget::openPersistentEditor(QTableWidgetItem *item) Q_D(QTableWidget); if (!item) return; - QModelIndex index = d->model()->index(item); + QModelIndex index = d->tableModel()->index(item); QAbstractItemView::openPersistentEditor(index); } @@ -2233,7 +2233,7 @@ void QTableWidget::closePersistentEditor(QTableWidgetItem *item) Q_D(QTableWidget); if (!item) return; - QModelIndex index = d->model()->index(item); + QModelIndex index = d->tableModel()->index(item); QAbstractItemView::closePersistentEditor(index); } @@ -2283,7 +2283,7 @@ void QTableWidget::setCellWidget(int row, int column, QWidget *widget) bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const { Q_D(const QTableWidget); - QModelIndex index = d->model()->index(item); + QModelIndex index = d->tableModel()->index(item); return selectionModel()->isSelected(index); } @@ -2297,7 +2297,7 @@ bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const void QTableWidget::setItemSelected(const QTableWidgetItem *item, bool select) { Q_D(QTableWidget); - QModelIndex index = d->model()->index(item); + QModelIndex index = d->tableModel()->index(item); selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect); } @@ -2354,7 +2354,7 @@ QList<QTableWidgetItem*> QTableWidget::selectedItems() QModelIndex index = indexes.at(i); if (isIndexHidden(index)) continue; - QTableWidgetItem *item = d->model()->item(index); + QTableWidgetItem *item = d->tableModel()->item(index); if (item) items.append(item); } @@ -2370,11 +2370,11 @@ QList<QTableWidgetItem*> QTableWidget::findItems(const QString &text, Qt::MatchF Q_D(const QTableWidget); QModelIndexList indexes; for (int column = 0; column < columnCount(); ++column) - indexes += d->model()->match(model()->index(0, column, QModelIndex()), + 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))); + items.append(d->tableModel()->item(indexes.at(i))); return items; } @@ -2408,7 +2408,7 @@ int QTableWidget::visualColumn(int logicalColumn) const QTableWidgetItem *QTableWidget::itemAt(const QPoint &p) const { Q_D(const QTableWidget); - return d->model()->item(indexAt(p)); + return d->tableModel()->item(indexAt(p)); } /*! @@ -2419,7 +2419,7 @@ QRect QTableWidget::visualItemRect(const QTableWidgetItem *item) const Q_D(const QTableWidget); if (!item) return QRect(); - QModelIndex index = d->model()->index(const_cast<QTableWidgetItem*>(item)); + QModelIndex index = d->tableModel()->index(const_cast<QTableWidgetItem*>(item)); Q_ASSERT(index.isValid()); return visualRect(index); } @@ -2435,7 +2435,7 @@ void QTableWidget::scrollToItem(const QTableWidgetItem *item, QAbstractItemView: Q_D(QTableWidget); if (!item) return; - QModelIndex index = d->model()->index(const_cast<QTableWidgetItem*>(item)); + QModelIndex index = d->tableModel()->index(const_cast<QTableWidgetItem*>(item)); Q_ASSERT(index.isValid()); QTableView::scrollTo(index, hint); } @@ -2448,7 +2448,7 @@ void QTableWidget::scrollToItem(const QTableWidgetItem *item, QAbstractItemView: const QTableWidgetItem *QTableWidget::itemPrototype() const { Q_D(const QTableWidget); - return d->model()->itemPrototype(); + return d->tableModel()->itemPrototype(); } /*! @@ -2467,7 +2467,7 @@ const QTableWidgetItem *QTableWidget::itemPrototype() const void QTableWidget::setItemPrototype(const QTableWidgetItem *item) { Q_D(QTableWidget); - d->model()->setItemPrototype(item); + d->tableModel()->setItemPrototype(item); } /*! @@ -2476,7 +2476,7 @@ void QTableWidget::setItemPrototype(const QTableWidgetItem *item) void QTableWidget::insertRow(int row) { Q_D(QTableWidget); - d->model()->insertRows(row); + d->tableModel()->insertRows(row); } /*! @@ -2485,7 +2485,7 @@ void QTableWidget::insertRow(int row) void QTableWidget::insertColumn(int column) { Q_D(QTableWidget); - d->model()->insertColumns(column); + d->tableModel()->insertColumns(column); } /*! @@ -2494,7 +2494,7 @@ void QTableWidget::insertColumn(int column) void QTableWidget::removeRow(int row) { Q_D(QTableWidget); - d->model()->removeRows(row); + d->tableModel()->removeRows(row); } /*! @@ -2503,7 +2503,7 @@ void QTableWidget::removeRow(int row) void QTableWidget::removeColumn(int column) { Q_D(QTableWidget); - d->model()->removeColumns(column); + d->tableModel()->removeColumns(column); } /*! @@ -2516,7 +2516,7 @@ void QTableWidget::clear() { Q_D(QTableWidget); selectionModel()->clear(); - d->model()->clear(); + d->tableModel()->clear(); } /*! @@ -2530,7 +2530,7 @@ void QTableWidget::clearContents() { Q_D(QTableWidget); selectionModel()->clear(); - d->model()->clearContents(); + d->tableModel()->clearContents(); } /*! @@ -2541,7 +2541,7 @@ void QTableWidget::clearContents() */ QStringList QTableWidget::mimeTypes() const { - return d_func()->model()->QAbstractTableModel::mimeTypes(); + return d_func()->tableModel()->QAbstractTableModel::mimeTypes(); } /*! @@ -2554,7 +2554,7 @@ QStringList QTableWidget::mimeTypes() const */ QMimeData *QTableWidget::mimeData(const QList<QTableWidgetItem*>) const { - return d_func()->model()->internalMimeData(); + return d_func()->tableModel()->internalMimeData(); } /*! @@ -2576,7 +2576,7 @@ bool QTableWidget::dropMimeData(int row, int column, const QMimeData *data, Qt:: column = -1; } #endif - return d_func()->model()->QAbstractTableModel::dropMimeData(data, action , row, column, idx); + return d_func()->tableModel()->QAbstractTableModel::dropMimeData(data, action , row, column, idx); } /*! @@ -2586,7 +2586,7 @@ bool QTableWidget::dropMimeData(int row, int column, const QMimeData *data, Qt:: */ Qt::DropActions QTableWidget::supportedDropActions() const { - return d_func()->model()->QAbstractTableModel::supportedDropActions() | Qt::MoveAction; + return d_func()->tableModel()->QAbstractTableModel::supportedDropActions() | Qt::MoveAction; } /*! @@ -2610,7 +2610,7 @@ QList<QTableWidgetItem*> QTableWidget::items(const QMimeData *data) const QModelIndex QTableWidget::indexFromItem(QTableWidgetItem *item) const { Q_D(const QTableWidget); - return d->model()->index(item); + return d->tableModel()->index(item); } /*! @@ -2620,7 +2620,7 @@ QModelIndex QTableWidget::indexFromItem(QTableWidgetItem *item) const QTableWidgetItem *QTableWidget::itemFromIndex(const QModelIndex &index) const { Q_D(const QTableWidget); - return d->model()->item(index); + return d->tableModel()->item(index); } /*! diff --git a/src/gui/itemviews/qtablewidget_p.h b/src/gui/itemviews/qtablewidget_p.h index d8bfcc5..2acaf9b 100644 --- a/src/gui/itemviews/qtablewidget_p.h +++ b/src/gui/itemviews/qtablewidget_p.h @@ -189,7 +189,7 @@ class QTableWidgetPrivate : public QTableViewPrivate Q_DECLARE_PUBLIC(QTableWidget) public: QTableWidgetPrivate() : QTableViewPrivate() {} - inline QTableModel *model() const { return qobject_cast<QTableModel*>(q_func()->model()); } + inline QTableModel *tableModel() const { return qobject_cast<QTableModel*>(model); } void setup(); // view signals diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 9910118..ecbd683 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1319,7 +1319,7 @@ bool QTreeViewPrivate::expandOrCollapseItemAtPos(const QPoint &pos) expand(i, true); if (!isAnimating()) { q->updateGeometries(); - q->viewport()->update(); + viewport->update(); } return true; } @@ -3201,19 +3201,18 @@ int QTreeViewPrivate::itemHeight(int item) const */ int QTreeViewPrivate::coordinateForItem(int item) const { - Q_Q(const QTreeView); if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) { if (uniformRowHeights) - return (item * defaultItemHeight) - q->verticalScrollBar()->value(); + return (item * defaultItemHeight) - vbar->value(); // ### optimize (spans or caching) int y = 0; for (int i = 0; i < viewItems.count(); ++i) { if (i == item) - return y - q->verticalScrollBar()->value(); + return y - vbar->value(); y += itemHeight(i); } } else { // ScrollPerItem - int topViewItemIndex = q->verticalScrollBar()->value(); + int topViewItemIndex = vbar->value(); if (uniformRowHeights) return defaultItemHeight * (item - topViewItemIndex); if (item >= topViewItemIndex) { @@ -3253,7 +3252,6 @@ int QTreeViewPrivate::coordinateForItem(int item) const */ int QTreeViewPrivate::itemAtCoordinate(int coordinate) const { - Q_Q(const QTreeView); const int itemCount = viewItems.count(); if (itemCount == 0) return -1; @@ -3261,19 +3259,19 @@ int QTreeViewPrivate::itemAtCoordinate(int coordinate) const return -1; if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) { if (uniformRowHeights) { - const int viewItemIndex = (coordinate + q->verticalScrollBar()->value()) / defaultItemHeight; + const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight; return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex); } // ### optimize int viewItemCoordinate = 0; - const int contentsCoordinate = coordinate + q->verticalScrollBar()->value(); + const int contentsCoordinate = coordinate + vbar->value(); for (int viewItemIndex = 0; viewItemIndex < viewItems.count(); ++viewItemIndex) { viewItemCoordinate += itemHeight(viewItemIndex); if (viewItemCoordinate >= contentsCoordinate) return (viewItemIndex >= itemCount ? -1 : viewItemIndex); } } else { // ScrollPerItem - int topViewItemIndex = q->verticalScrollBar()->value(); + int topViewItemIndex = vbar->value(); if (uniformRowHeights) { if (coordinate < 0) coordinate -= defaultItemHeight - 1; @@ -3365,8 +3363,7 @@ QModelIndex QTreeViewPrivate::modelIndex(int i, int column) const int QTreeViewPrivate::firstVisibleItem(int *offset) const { - Q_Q(const QTreeView); - const int value = q->verticalScrollBar()->value(); + const int value = vbar->value(); if (verticalScrollMode == QAbstractItemView::ScrollPerItem) { if (offset) *offset = 0; @@ -3443,9 +3440,9 @@ void QTreeViewPrivate::updateScrollBars() if (verticalScrollMode == QAbstractItemView::ScrollPerItem) { if (!viewItems.isEmpty()) itemsInViewport = qMax(1, itemsInViewport); - q->verticalScrollBar()->setRange(0, viewItems.count() - itemsInViewport); - q->verticalScrollBar()->setPageStep(itemsInViewport); - q->verticalScrollBar()->setSingleStep(1); + vbar->setRange(0, viewItems.count() - itemsInViewport); + vbar->setPageStep(itemsInViewport); + vbar->setSingleStep(1); } else { // scroll per pixel int contentsHeight = 0; if (uniformRowHeights) { @@ -3454,9 +3451,9 @@ void QTreeViewPrivate::updateScrollBars() for (int i = 0; i < viewItems.count(); ++i) contentsHeight += itemHeight(i); } - q->verticalScrollBar()->setRange(0, contentsHeight - viewportSize.height()); - q->verticalScrollBar()->setPageStep(viewportSize.height()); - q->verticalScrollBar()->setSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2)); + vbar->setRange(0, contentsHeight - viewportSize.height()); + vbar->setPageStep(viewportSize.height()); + vbar->setSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2)); } const int columnCount = header->count(); @@ -3472,23 +3469,23 @@ void QTreeViewPrivate::updateScrollBars() if (columnCount > 0) columnsInViewport = qMax(1, columnsInViewport); if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) { - q->horizontalScrollBar()->setRange(0, columnCount - columnsInViewport); - q->horizontalScrollBar()->setPageStep(columnsInViewport); - q->horizontalScrollBar()->setSingleStep(1); + hbar->setRange(0, columnCount - columnsInViewport); + hbar->setPageStep(columnsInViewport); + hbar->setSingleStep(1); } else { // scroll per pixel const int horizontalLength = header->length(); const QSize maxSize = q->maximumViewportSize(); - if (maxSize.width() >= horizontalLength && q->verticalScrollBar()->maximum() <= 0) + if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0) viewportSize = maxSize; - q->horizontalScrollBar()->setPageStep(viewportSize.width()); - q->horizontalScrollBar()->setRange(0, qMax(horizontalLength - viewportSize.width(), 0)); - q->horizontalScrollBar()->setSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2)); + hbar->setPageStep(viewportSize.width()); + hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0)); + hbar->setSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2)); } } int QTreeViewPrivate::itemDecorationAt(const QPoint &pos) const { - const_cast<QTreeView *>(q_func())->executeDelayedItemsLayout(); + executePostedLayout(); int x = pos.x(); int column = header->logicalIndexAt(x); if (column != 0) diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 5604f8d..2a6ac30 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -2280,11 +2280,10 @@ void QTreeWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, void QTreeWidgetPrivate::_q_sort() { - Q_Q(QTreeWidget); if (sortingEnabled) { - int column = q->header()->sortIndicatorSection(); - Qt::SortOrder order = q->header()->sortIndicatorOrder(); - model()->sort(column, order); + int column = header->sortIndicatorSection(); + Qt::SortOrder order = header->sortIndicatorOrder(); + treeModel()->sort(column, order); } } @@ -2293,7 +2292,7 @@ void QTreeWidgetPrivate::_q_selectionChanged(const QItemSelection &selected, con Q_Q(QTreeWidget); QModelIndexList indices = selected.indexes(); int i; - QTreeModel *m = model(); + QTreeModel *m = treeModel(); for (i = 0; i < indices.count(); ++i) { QTreeWidgetItem *item = m->item(indices.at(i)); item->d->selected = true; @@ -2311,13 +2310,12 @@ void QTreeWidgetPrivate::_q_selectionChanged(const QItemSelection &selected, con void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { - Q_Q(QTreeWidget); if (sortingEnabled && topLeft.isValid() && bottomRight.isValid() - && !model()->sortPendingTimer.isActive()) { - int column = q->header()->sortIndicatorSection(); + && !treeModel()->sortPendingTimer.isActive()) { + int column = header->sortIndicatorSection(); if (column >= topLeft.column() && column <= bottomRight.column()) { - Qt::SortOrder order = q->header()->sortIndicatorOrder(); - model()->ensureSorted(column, order, topLeft.row(), + Qt::SortOrder order = header->sortIndicatorOrder(); + treeModel()->ensureSorted(column, order, topLeft.row(), bottomRight.row(), topLeft.parent()); } } @@ -2545,7 +2543,7 @@ QTreeWidget::~QTreeWidget() int QTreeWidget::columnCount() const { Q_D(const QTreeWidget); - return d->model()->columnCount(); + return d->model->columnCount(); } /* @@ -2557,7 +2555,7 @@ void QTreeWidget::setColumnCount(int columns) Q_D(QTreeWidget); if (columns < 0) return; - d->model()->setColumnCount(columns); + d->treeModel()->setColumnCount(columns); } /*! @@ -2574,7 +2572,7 @@ void QTreeWidget::setColumnCount(int columns) QTreeWidgetItem *QTreeWidget::invisibleRootItem() const { Q_D(const QTreeWidget); - return d->model()->rootItem; + return d->treeModel()->rootItem; } /*! @@ -2587,7 +2585,7 @@ QTreeWidgetItem *QTreeWidget::invisibleRootItem() const QTreeWidgetItem *QTreeWidget::topLevelItem(int index) const { Q_D(const QTreeWidget); - return d->model()->rootItem->child(index); + return d->treeModel()->rootItem->child(index); } /*! @@ -2602,7 +2600,7 @@ QTreeWidgetItem *QTreeWidget::topLevelItem(int index) const int QTreeWidget::topLevelItemCount() const { Q_D(const QTreeWidget); - return d->model()->rootItem->childCount(); + return d->treeModel()->rootItem->childCount(); } /*! @@ -2616,7 +2614,7 @@ int QTreeWidget::topLevelItemCount() const void QTreeWidget::insertTopLevelItem(int index, QTreeWidgetItem *item) { Q_D(QTreeWidget); - d->model()->rootItem->insertChild(index, item); + d->treeModel()->rootItem->insertChild(index, item); } /*! @@ -2641,7 +2639,7 @@ void QTreeWidget::addTopLevelItem(QTreeWidgetItem *item) QTreeWidgetItem *QTreeWidget::takeTopLevelItem(int index) { Q_D(QTreeWidget); - return d->model()->rootItem->takeChild(index); + return d->treeModel()->rootItem->takeChild(index); } /*! @@ -2650,8 +2648,8 @@ QTreeWidgetItem *QTreeWidget::takeTopLevelItem(int index) int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) { Q_D(QTreeWidget); - d->model()->executePendingSort(); - return d->model()->rootItem->children.indexOf(item); + d->treeModel()->executePendingSort(); + return d->treeModel()->rootItem->children.indexOf(item); } /*! @@ -2663,8 +2661,8 @@ int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) const { Q_D(const QTreeWidget); - d->model()->executePendingSort(); - return d->model()->rootItem->children.indexOf(item); + d->treeModel()->executePendingSort(); + return d->treeModel()->rootItem->children.indexOf(item); } /*! @@ -2679,7 +2677,7 @@ int QTreeWidget::indexOfTopLevelItem(QTreeWidgetItem *item) const void QTreeWidget::insertTopLevelItems(int index, const QList<QTreeWidgetItem*> &items) { Q_D(QTreeWidget); - d->model()->rootItem->insertChildren(index, items); + d->treeModel()->rootItem->insertChildren(index, items); } /*! @@ -2701,7 +2699,7 @@ void QTreeWidget::addTopLevelItems(const QList<QTreeWidgetItem*> &items) QTreeWidgetItem *QTreeWidget::headerItem() const { Q_D(const QTreeWidget); - return d->model()->headerItem; + return d->treeModel()->headerItem; } /*! @@ -2722,16 +2720,16 @@ void QTreeWidget::setHeaderItem(QTreeWidgetItem *item) int oldCount = columnCount(); if (oldCount < item->columnCount()) - d->model()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount()); + d->treeModel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount()); else - d->model()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount); - delete d->model()->headerItem; - d->model()->headerItem = item; + d->treeModel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount); + delete d->treeModel()->headerItem; + d->treeModel()->headerItem = item; if (oldCount < item->columnCount()) - d->model()->endInsertColumns(); + d->treeModel()->endInsertColumns(); else - d->model()->endRemoveColumns(); - d->model()->headerDataChanged(Qt::Horizontal, 0, oldCount); + d->treeModel()->endRemoveColumns(); + d->treeModel()->headerDataChanged(Qt::Horizontal, 0, oldCount); } @@ -2748,8 +2746,7 @@ void QTreeWidget::setHeaderLabels(const QStringList &labels) Q_D(QTreeWidget); if (columnCount() < labels.count()) setColumnCount(labels.count()); - QTreeModel *model = d->model(); - QTreeWidgetItem *item = model->headerItem; + QTreeWidgetItem *item = d->treeModel()->headerItem; for (int i = 0; i < labels.count(); ++i) item->setText(i, labels.at(i)); } @@ -2877,7 +2874,7 @@ void QTreeWidget::sortItems(int column, Qt::SortOrder order) { Q_D(QTreeWidget); header()->setSortIndicator(column, order); - d->model()->sort(column, order); + d->model->sort(column, order); } /*! @@ -3044,7 +3041,7 @@ QList<QTreeWidgetItem*> QTreeWidget::selectedItems() const QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFlags flags, int column) const { Q_D(const QTreeWidget); - QModelIndexList indexes = d->model()->match(model()->index(0, column, QModelIndex()), + QModelIndexList indexes = d->model->match(model()->index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags); QList<QTreeWidgetItem*> items; for (int i = 0; i < indexes.size(); ++i) @@ -3062,11 +3059,11 @@ QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFla bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); - if (item == d->model()->headerItem) + if (item == d->treeModel()->headerItem) return header()->isHidden(); if (d->hiddenIndexes.isEmpty()) return false; - QTreeModel::SkipSorting skipSorting(d->model()); + QTreeModel::SkipSorting skipSorting(d->treeModel()); return d->isRowHidden(d->index(item)); } @@ -3082,7 +3079,7 @@ bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide) { Q_D(QTreeWidget); - if (item == d->model()->headerItem) { + if (item == d->treeModel()->headerItem) { header()->setHidden(hide); } else { const QModelIndex index = d->index(item); @@ -3102,7 +3099,7 @@ void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide) bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); - QTreeModel::SkipSorting skipSorting(d->model()); + QTreeModel::SkipSorting skipSorting(d->treeModel()); return isExpanded(d->index(item)); } @@ -3119,7 +3116,7 @@ bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand) { Q_D(QTreeWidget); - QTreeModel::SkipSorting skipSorting(d->model()); + QTreeModel::SkipSorting skipSorting(d->treeModel()); setExpanded(d->index(item), expand); } @@ -3134,7 +3131,7 @@ void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand) bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); - if (item == d->model()->headerItem) + if (item == d->treeModel()->headerItem) return false; // We can't set the header items to spanning const QModelIndex index = d->index(item); return isFirstColumnSpanned(index.row(), index.parent()); @@ -3151,7 +3148,7 @@ bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span) { Q_D(QTreeWidget); - if (item == d->model()->headerItem) + if (item == d->treeModel()->headerItem) return; // We can't set header items to spanning const QModelIndex index = d->index(item); setFirstColumnSpanned(index.row(), index.parent(), span); @@ -3165,7 +3162,7 @@ void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool sp QTreeWidgetItem *QTreeWidget::itemAbove(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); - if (item == d->model()->headerItem) + if (item == d->treeModel()->headerItem) return 0; const QModelIndex index = d->index(item); const QModelIndex above = indexAbove(index); @@ -3180,7 +3177,7 @@ QTreeWidgetItem *QTreeWidget::itemAbove(const QTreeWidgetItem *item) const QTreeWidgetItem *QTreeWidget::itemBelow(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); - if (item == d->model()->headerItem) + if (item == d->treeModel()->headerItem) return 0; const QModelIndex index = d->index(item); const QModelIndex below = indexBelow(index); @@ -3220,7 +3217,7 @@ void QTreeWidget::scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::S void QTreeWidget::expandItem(const QTreeWidgetItem *item) { Q_D(QTreeWidget); - QTreeModel::SkipSorting skipSorting(d->model()); + QTreeModel::SkipSorting skipSorting(d->treeModel()); expand(d->index(item)); } @@ -3233,7 +3230,7 @@ void QTreeWidget::expandItem(const QTreeWidgetItem *item) void QTreeWidget::collapseItem(const QTreeWidgetItem *item) { Q_D(QTreeWidget); - QTreeModel::SkipSorting skipSorting(d->model()); + QTreeModel::SkipSorting skipSorting(d->treeModel()); collapse(d->index(item)); } @@ -3250,7 +3247,7 @@ void QTreeWidget::clear() { Q_D(QTreeWidget); selectionModel()->clear(); - d->model()->clear(); + d->treeModel()->clear(); } /*! @@ -3275,7 +3272,7 @@ QStringList QTreeWidget::mimeTypes() const QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const { Q_D(const QTreeWidget); - if (d->model()->cachedIndexes.isEmpty()) { + if (d->treeModel()->cachedIndexes.isEmpty()) { QList<QModelIndex> indexes; for (int i = 0; i < items.count(); ++i) { QTreeWidgetItem *item = items.at(i); @@ -3283,9 +3280,9 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const indexes << indexFromItem(item, c); } } - return model()->QAbstractItemModel::mimeData(indexes); + return d->model->QAbstractItemModel::mimeData(indexes); } - return d->model()->internalMimeData(); + return d->treeModel()->internalMimeData(); } /*! @@ -3429,7 +3426,7 @@ bool QTreeWidget::event(QEvent *e) { Q_D(QTreeWidget); if (e->type() == QEvent::Polish) - d->model()->executePendingSort(); + d->treeModel()->executePendingSort(); return QTreeView::event(e); } diff --git a/src/gui/itemviews/qtreewidget_p.h b/src/gui/itemviews/qtreewidget_p.h index a089cf5..fb0ee11 100644 --- a/src/gui/itemviews/qtreewidget_p.h +++ b/src/gui/itemviews/qtreewidget_p.h @@ -219,12 +219,11 @@ class QTreeWidgetPrivate : public QTreeViewPrivate Q_DECLARE_PUBLIC(QTreeWidget) public: QTreeWidgetPrivate() : QTreeViewPrivate(), explicitSortColumn(-1) {} - inline QTreeModel *model() const - { return qobject_cast<QTreeModel*>(q_func()->model()); } + inline QTreeModel *treeModel() const { return qobject_cast<QTreeModel*>(model); } inline QModelIndex index(const QTreeWidgetItem *item, int column = 0) const - { return model()->index(item, column); } + { return treeModel()->index(item, column); } inline QTreeWidgetItem *item(const QModelIndex &index) const - { return model()->item(index); } + { return treeModel()->item(index); } void _q_emitItemPressed(const QModelIndex &index); void _q_emitItemClicked(const QModelIndex &index); void _q_emitItemDoubleClicked(const QModelIndex &index); |