diff options
Diffstat (limited to 'src/widgets/itemviews')
21 files changed, 233 insertions, 199 deletions
diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index eecc18e5c7..bb47881c03 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -255,7 +255,7 @@ QWidget *QAbstractItemDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const { - return 0; + return nullptr; } diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index c2afed775c..0e54cf235f 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -77,13 +77,13 @@ QT_BEGIN_NAMESPACE QAbstractItemViewPrivate::QAbstractItemViewPrivate() : model(QAbstractItemModelPrivate::staticEmptyModel()), - itemDelegate(0), - selectionModel(0), + itemDelegate(nullptr), + selectionModel(nullptr), ctrlDragSelectionFlag(QItemSelectionModel::NoUpdate), noSelectionOnMousePress(false), selectionMode(QAbstractItemView::ExtendedSelection), selectionBehavior(QAbstractItemView::SelectItems), - currentlyCommittingEditor(0), + currentlyCommittingEditor(nullptr), pressedModifiers(Qt::NoModifier), pressedPosition(QPoint(-1, -1)), pressedAlreadySelected(false), @@ -145,8 +145,8 @@ void QAbstractItemViewPrivate::init() q->setAttribute(Qt::WA_InputMethodEnabled); - verticalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, q, 0)); - horizontalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, q, 0)); + verticalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, q, nullptr)); + horizontalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, q, nullptr)); } void QAbstractItemViewPrivate::setHoverIndex(const QPersistentModelIndex &index) @@ -757,7 +757,7 @@ void QAbstractItemView::setModel(QAbstractItemModel *model) QAbstractItemModel *QAbstractItemView::model() const { Q_D(const QAbstractItemView); - return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ? 0 : d->model); + return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ? nullptr : d->model); } /*! @@ -915,7 +915,7 @@ QVariant QAbstractItemView::inputMethodQuery(Qt::InputMethodQuery query) const void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *delegate) { Q_D(QAbstractItemView); - if (QAbstractItemDelegate *rowDelegate = d->rowDelegates.value(row, 0)) { + if (QAbstractItemDelegate *rowDelegate = d->rowDelegates.value(row, nullptr)) { if (d->delegateRefCount(rowDelegate) == 1) { disconnect(rowDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); @@ -949,7 +949,7 @@ void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *de QAbstractItemDelegate *QAbstractItemView::itemDelegateForRow(int row) const { Q_D(const QAbstractItemView); - return d->rowDelegates.value(row, 0); + return d->rowDelegates.value(row, nullptr); } /*! @@ -975,7 +975,7 @@ QAbstractItemDelegate *QAbstractItemView::itemDelegateForRow(int row) const void QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate) { Q_D(QAbstractItemView); - if (QAbstractItemDelegate *columnDelegate = d->columnDelegates.value(column, 0)) { + if (QAbstractItemDelegate *columnDelegate = d->columnDelegates.value(column, nullptr)) { if (d->delegateRefCount(columnDelegate) == 1) { disconnect(columnDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); @@ -1009,7 +1009,7 @@ void QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelega QAbstractItemDelegate *QAbstractItemView::itemDelegateForColumn(int column) const { Q_D(const QAbstractItemView); - return d->columnDelegates.value(column, 0); + return d->columnDelegates.value(column, nullptr); } /*! @@ -1084,7 +1084,7 @@ void QAbstractItemView::setCurrentIndex(const QModelIndex &index) { Q_D(QAbstractItemView); if (d->selectionModel && (!index.isValid() || d->isIndexEnabled(index))) { - QItemSelectionModel::SelectionFlags command = selectionCommand(index, 0); + QItemSelectionModel::SelectionFlags command = selectionCommand(index, nullptr); d->selectionModel->setCurrentIndex(index, command); d->currentIndexSet = true; if ((command & QItemSelectionModel::Current) == 0) @@ -1201,7 +1201,7 @@ void QAbstractItemView::edit(const QModelIndex &index) Q_D(QAbstractItemView); if (Q_UNLIKELY(!d->isIndexValid(index))) qWarning("edit: index was invalid"); - if (Q_UNLIKELY(!edit(index, AllEditTriggers, 0))) + if (Q_UNLIKELY(!edit(index, AllEditTriggers, nullptr))) qWarning("edit: editing failed"); } @@ -1286,7 +1286,7 @@ QAbstractItemView::ScrollMode QAbstractItemView::verticalScrollMode() const void QAbstractItemView::resetVerticalScrollMode() { - auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, this, 0)); + auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, this, nullptr)); setVerticalScrollMode(sm); d_func()->verticalScrollModeSet = false; } @@ -1323,7 +1323,7 @@ QAbstractItemView::ScrollMode QAbstractItemView::horizontalScrollMode() const void QAbstractItemView::resetHorizontalScrollMode() { - auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, this, 0)); + auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, this, nullptr)); setHorizontalScrollMode(sm); d_func()->horizontalScrollModeSet = false; } @@ -1964,7 +1964,7 @@ void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event) QPersistentModelIndex persistent = index; emit doubleClicked(persistent); if ((event->button() == Qt::LeftButton) && !edit(persistent, DoubleClicked, event) - && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) + && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, this)) emit activated(persistent); d->pressedIndex = QModelIndex(); } @@ -2388,7 +2388,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) setFocus(); QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event); if (command != QItemSelectionModel::NoUpdate - || style()->styleHint(QStyle::SH_ItemView_MovementWithoutUpdatingSelection, 0, this)) { + || style()->styleHint(QStyle::SH_ItemView_MovementWithoutUpdatingSelection, nullptr, this)) { // note that we don't check if the new current index is enabled because moveCursor() makes sure it is if (command & QItemSelectionModel::Current) { d->selectionModel->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); @@ -2654,7 +2654,7 @@ bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEve if (!d->isIndexValid(index)) return false; - if (QWidget *w = (d->persistent.isEmpty() ? static_cast<QWidget*>(0) : d->editorForIndex(index).widget.data())) { + if (QWidget *w = (d->persistent.isEmpty() ? static_cast<QWidget*>(nullptr) : d->editorForIndex(index).widget.data())) { if (w->focusPolicy() == Qt::NoFocus) return false; w->setFocus(); @@ -2692,7 +2692,7 @@ bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEve if (trigger == SelectedClicked) d->delayedEditing.start(QApplication::doubleClickInterval(), this); else - d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : 0); + d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : nullptr); return true; } @@ -2909,7 +2909,7 @@ void QAbstractItemView::commitData(QWidget *editor) editor->removeEventFilter(delegate); delegate->setModelData(editor, d->model, index); editor->installEventFilter(delegate); - d->currentlyCommittingEditor = 0; + d->currentlyCommittingEditor = nullptr; } /*! @@ -3074,9 +3074,10 @@ void QAbstractItemView::keyboardSearch(const QString &search) QSize QAbstractItemView::sizeHintForIndex(const QModelIndex &index) const { Q_D(const QAbstractItemView); - if (!d->isIndexValid(index) || !d->itemDelegate) + if (!d->isIndexValid(index)) return QSize(); - return d->delegateForIndex(index)->sizeHint(d->viewOptionsV1(), index); + const auto delegate = d->delegateForIndex(index); + return delegate ? delegate->sizeHint(d->viewOptionsV1(), index) : QSize(); } /*! @@ -3260,7 +3261,7 @@ QWidget* QAbstractItemView::indexWidget(const QModelIndex &index) const if (QWidget *editor = d->editorForIndex(index).widget.data()) return editor; - return 0; + return nullptr; } /*! @@ -3318,6 +3319,8 @@ void QAbstractItemView::update(const QModelIndex &index) The \a roles which have been changed can either be an empty container (meaning everything has changed), or a non-empty container with the subset of roles which have changed. + + \note: Qt::ToolTipRole is not honored by dataChanged() in the views provided by Qt. */ void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) { @@ -3673,7 +3676,7 @@ void QAbstractItemView::currentChanged(const QModelIndex ¤t, const QModelI if (d->autoScroll) scrollTo(current); update(current); - edit(current, CurrentChanged, 0); + edit(current, CurrentChanged, nullptr); if (current.row() == (d->model->rowCount(d->root) - 1)) d->fetchMore(); } else { @@ -3737,7 +3740,7 @@ QStyleOptionViewItem QAbstractItemView::viewOptions() const if (d->iconSize.isValid()) { option.decorationSize = d->iconSize; } else { - int pm = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); + int pm = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this); option.decorationSize = QSize(pm, pm); } option.decorationPosition = QStyleOptionViewItem::Left; @@ -3745,7 +3748,7 @@ QStyleOptionViewItem QAbstractItemView::viewOptions() const option.displayAlignment = Qt::AlignLeft|Qt::AlignVCenter; option.textElideMode = d->textElideMode; option.rect = QRect(); - option.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, this); + option.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, nullptr, this); if (d->wrapItemText) option.features = QStyleOptionViewItem::WrapText; option.locale = locale(); @@ -3967,7 +3970,7 @@ QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QM case SingleSelection: // ClearAndSelect on valid index otherwise NoUpdate if (event && event->type() == QEvent::MouseButtonRelease) return QItemSelectionModel::NoUpdate; - if ((keyModifiers & Qt::ControlModifier) && d->selectionModel->isSelected(index)) + if ((keyModifiers & Qt::ControlModifier) && d->selectionModel->isSelected(index) && event->type() != QEvent::MouseMove) return QItemSelectionModel::Deselect | d->selectionBehaviorFlags(); else return QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); @@ -4231,7 +4234,7 @@ QWidget *QAbstractItemViewPrivate::editor(const QModelIndex &index, if (!w) { QAbstractItemDelegate *delegate = delegateForIndex(index); if (!delegate) - return 0; + return nullptr; w = delegate->createEditor(viewport, options, index); if (w) { w->installEventFilter(delegate); @@ -4451,7 +4454,9 @@ QItemViewPaintPairs QAbstractItemViewPrivate::draggablePaintPairs(const QModelIn rect |= current; } } - rect &= viewportRect; + QRect clipped = rect & viewportRect; + rect.setLeft(clipped.left()); + rect.setRight(clipped.right()); return ret; } diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp index a4eed2d885..4d0161025c 100644 --- a/src/widgets/itemviews/qcolumnview.cpp +++ b/src/widgets/itemviews/qcolumnview.cpp @@ -142,7 +142,7 @@ void QColumnView::setResizeGripsVisible(bool visible) connect(grip, SIGNAL(gripMoved(int)), this, SLOT(_q_gripMoved(int))); } else { QWidget *widget = view->cornerWidget(); - view->setCornerWidget(0); + view->setCornerWidget(nullptr); widget->deleteLater(); } } @@ -327,7 +327,7 @@ void QColumnView::scrollTo(const QModelIndex &index, ScrollHint hint) } #if QT_CONFIG(animation) - if (const int animationDuration = style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, this)) { + if (const int animationDuration = style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, this)) { d->currentAnimation.setDuration(animationDuration); d->currentAnimation.setEndValue(newScrollbarValue); d->currentAnimation.start(); @@ -638,7 +638,7 @@ void QColumnViewPrivate::_q_clicked(const QModelIndex &index) { Q_Q(QColumnView); QModelIndex parent = index.parent(); - QAbstractItemView *columnClicked = 0; + QAbstractItemView *columnClicked = nullptr; for (int column = 0; column < columns.count(); ++column) { if (columns.at(column)->rootIndex() == parent) { columnClicked = columns[column]; @@ -666,7 +666,7 @@ void QColumnViewPrivate::_q_clicked(const QModelIndex &index) QAbstractItemView *QColumnViewPrivate::createColumn(const QModelIndex &index, bool show) { Q_Q(QColumnView); - QAbstractItemView *view = 0; + QAbstractItemView *view = nullptr; if (model->hasChildren(index)) { view = q->createColumn(index); q->connect(view, SIGNAL(clicked(QModelIndex)), @@ -1045,8 +1045,8 @@ QColumnViewPrivate::QColumnViewPrivate() : QAbstractItemViewPrivate() ,showResizeGrips(true) ,offset(0) -,previewWidget(0) -,previewColumn(0) +,previewWidget(nullptr) +,previewColumn(nullptr) { } diff --git a/src/widgets/itemviews/qcolumnviewgrip.cpp b/src/widgets/itemviews/qcolumnviewgrip.cpp index 4a4237805f..00cd7df20a 100644 --- a/src/widgets/itemviews/qcolumnviewgrip.cpp +++ b/src/widgets/itemviews/qcolumnviewgrip.cpp @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE Use setModel() to set the model. */ QColumnViewGrip::QColumnViewGrip(QWidget *parent) -: QWidget(*new QColumnViewGripPrivate, parent, 0) + : QWidget(*new QColumnViewGripPrivate, parent, { }) { #ifndef QT_NO_CURSOR setCursor(Qt::SplitHCursor); diff --git a/src/widgets/itemviews/qcolumnviewgrip_p.h b/src/widgets/itemviews/qcolumnviewgrip_p.h index 4311edbeb4..13e4c764e8 100644 --- a/src/widgets/itemviews/qcolumnviewgrip_p.h +++ b/src/widgets/itemviews/qcolumnviewgrip_p.h @@ -73,7 +73,7 @@ public: int moveGrip(int offset); protected: - QColumnViewGrip(QColumnViewGripPrivate &, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr); + QColumnViewGrip(QColumnViewGripPrivate &, QWidget *parent = nullptr, Qt::WindowFlags f = { }); void paintEvent(QPaintEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; diff --git a/src/widgets/itemviews/qdatawidgetmapper.cpp b/src/widgets/itemviews/qdatawidgetmapper.cpp index 125ee73194..24039c42f6 100644 --- a/src/widgets/itemviews/qdatawidgetmapper.cpp +++ b/src/widgets/itemviews/qdatawidgetmapper.cpp @@ -56,7 +56,7 @@ public: Q_DECLARE_PUBLIC(QDataWidgetMapper) QDataWidgetMapperPrivate() - : model(QAbstractItemModelPrivate::staticEmptyModel()), delegate(0), + : model(QAbstractItemModelPrivate::staticEmptyModel()), delegate(nullptr), orientation(Qt::Horizontal), submitPolicy(QDataWidgetMapper::AutoSubmit) { } @@ -226,7 +226,7 @@ void QDataWidgetMapperPrivate::_q_modelDestroyed() { Q_Q(QDataWidgetMapper); - model = 0; + model = nullptr; q->setModel(QAbstractItemModelPrivate::staticEmptyModel()); } @@ -374,7 +374,7 @@ QAbstractItemModel *QDataWidgetMapper::model() const { Q_D(const QDataWidgetMapper); return d->model == QAbstractItemModelPrivate::staticEmptyModel() - ? static_cast<QAbstractItemModel *>(0) + ? static_cast<QAbstractItemModel *>(nullptr) : d->model; } @@ -567,7 +567,7 @@ QWidget *QDataWidgetMapper::mappedWidgetAt(int section) const return e.widget; } - return 0; + return nullptr; } /*! diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp index ba7ee15314..0d387d7def 100644 --- a/src/widgets/itemviews/qdirmodel.cpp +++ b/src/widgets/itemviews/qdirmodel.cpp @@ -75,7 +75,7 @@ class QDirModelPrivate : public QAbstractItemModelPrivate public: struct QDirNode { - QDirNode() : parent(0), populated(false), stat(false) {} + QDirNode() : parent(nullptr), populated(false), stat(false) {} QDirNode *parent; QFileInfo info; QIcon icon; // cache the icon @@ -238,7 +238,7 @@ QDirModel::QDirModel(const QStringList &nameFilters, d->nameFilters = nameFilters.isEmpty() ? QStringList(QLatin1String("*")) : nameFilters; d->filters = filters; d->sort = sort; - d->root.parent = 0; + d->root.parent = nullptr; d->root.info = QFileInfo(); d->clear(&d->root); } @@ -293,7 +293,7 @@ QModelIndex QDirModel::index(int row, int column, const QModelIndex &parent) con if (row >= p->children.count()) return QModelIndex(); // now get the internal pointer for the index - QDirModelPrivate::QDirNode *n = d->node(row, d->indexValid(parent) ? p : 0); + QDirModelPrivate::QDirNode *n = d->node(row, d->indexValid(parent) ? p : nullptr); Q_ASSERT(n); return createIndex(row, column, n); @@ -310,8 +310,8 @@ QModelIndex QDirModel::parent(const QModelIndex &child) const if (!d->indexValid(child)) return QModelIndex(); QDirModelPrivate::QDirNode *node = d->node(child); - QDirModelPrivate::QDirNode *par = (node ? node->parent : 0); - if (par == 0) // parent is the root node + QDirModelPrivate::QDirNode *par = (node ? node->parent : nullptr); + if (par == nullptr) // parent is the root node return QModelIndex(); // get the parent's row @@ -1159,10 +1159,10 @@ void QDirModelPrivate::init() filters = QDir::AllEntries | QDir::NoDotAndDotDot; sort = QDir::Name; nameFilters << QLatin1String("*"); - root.parent = 0; + root.parent = nullptr; root.info = QFileInfo(); clear(&root); - roleNames.insertMulti(QDirModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration + roleNames.insert(QDirModel::FileIconRole, QByteArrayLiteral("fileIcon")); // == Qt::decoration roleNames.insert(QDirModel::FilePathRole, QByteArrayLiteral("filePath")); roleNames.insert(QDirModel::FileNameRole, QByteArrayLiteral("fileName")); } @@ -1170,7 +1170,7 @@ void QDirModelPrivate::init() QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) const { if (row < 0) - return 0; + return nullptr; bool isDir = !parent || parent->info.isDir(); QDirNode *p = (parent ? parent : &root); @@ -1179,7 +1179,7 @@ QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) co if (Q_UNLIKELY(row >= p->children.count())) { qWarning("node: the row does not exist"); - return 0; + return nullptr; } return const_cast<QDirNode*>(&p->children.at(row)); @@ -1190,7 +1190,7 @@ QVector<QDirModelPrivate::QDirNode> QDirModelPrivate::children(QDirNode *parent, Q_ASSERT(parent); QFileInfoList infoList; if (parent == &root) { - parent = 0; + parent = nullptr; infoList = QDir::drives(); } else if (parent->info.isDir()) { //resolve directory links only if requested. @@ -1333,7 +1333,7 @@ void QDirModelPrivate::appendChild(QDirModelPrivate::QDirNode *parent, const QSt QDirModelPrivate::QDirNode node; node.populated = false; node.stat = shouldStat; - node.parent = (parent == &root ? 0 : parent); + node.parent = (parent == &root ? nullptr : parent); node.info = QFileInfo(path); node.info.setCaching(true); diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index d7bdf6aa4c..790f305463 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -1583,7 +1583,7 @@ int QHeaderView::minimumSectionSize() const Q_D(const QHeaderView); if (d->minimumSectionSize == -1) { QSize strut = QApplication::globalStrut(); - int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this); + int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this); if (d->orientation == Qt::Horizontal) return qMax(strut.width(), (fontMetrics().maxWidth() + margin)); return qMax(strut.height(), (fontMetrics().height() + margin)); @@ -2883,12 +2883,12 @@ void QHeaderView::paintSection(QPainter *painter, const QRect &rect, int logical opt.text = d->model->headerData(logicalIndex, d->orientation, Qt::DisplayRole).toString(); - int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this); + int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this); - const Qt::Alignment headerArrowAlignment = static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_Header_ArrowAlignment, 0, this)); + const Qt::Alignment headerArrowAlignment = static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_Header_ArrowAlignment, nullptr, this)); const bool isHeaderArrowOnTheSide = headerArrowAlignment & Qt::AlignVCenter; if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex && isHeaderArrowOnTheSide) - margin += style()->pixelMetric(QStyle::PM_HeaderMarkSize, 0, this); + margin += style()->pixelMetric(QStyle::PM_HeaderMarkSize, nullptr, this); const QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::DecorationRole); @@ -2896,8 +2896,8 @@ void QHeaderView::paintSection(QPainter *painter, const QRect &rect, int logical if (opt.icon.isNull()) opt.icon = qvariant_cast<QPixmap>(variant); if (!opt.icon.isNull()) // see CT_HeaderSection - margin += style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this) + - style()->pixelMetric(QStyle::PM_HeaderMargin, 0, this); + margin += style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this) + + style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this); if (d->textElideMode != Qt::ElideNone) { const QRect textRect = style()->subElementRect(QStyle::SE_HeaderLabel, &opt, this); @@ -3275,7 +3275,7 @@ int QHeaderViewPrivate::sectionHandleAt(int position) return -1; int log = logicalIndex(visual); int pos = q->sectionViewportPosition(log); - int grip = q->style()->pixelMetric(QStyle::PM_HeaderGripMargin, 0, q); + int grip = q->style()->pixelMetric(QStyle::PM_HeaderGripMargin, nullptr, q); bool atLeft = position < pos + grip; bool atRight = (position > pos + q->sectionSize(log) - grip); @@ -3814,10 +3814,10 @@ void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle() { Q_Q(QHeaderView); if (orientation == Qt::Horizontal) { - defaultSectionSize = q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeHorizontal, 0, q); + defaultSectionSize = q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeHorizontal, nullptr, q); } else { defaultSectionSize = qMax(q->minimumSectionSize(), - q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeVertical, 0, q)); + q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeVertical, nullptr, q)); } } diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 460764f1b8..daea907963 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -77,7 +77,7 @@ class QItemDelegatePrivate : public QAbstractItemDelegatePrivate Q_DECLARE_PUBLIC(QItemDelegate) public: - QItemDelegatePrivate() : f(0), clipPainting(true) {} + QItemDelegatePrivate() : f(nullptr), clipPainting(true) {} inline const QItemEditorFactory *editorFactory() const { return f ? f : QItemEditorFactory::defaultFactory(); } @@ -149,7 +149,7 @@ QRect QItemDelegatePrivate::textLayoutBounds(const QStyleOptionViewItem &option, QStyle *style = w ? w->style() : QApplication::style(); const bool wrapText = option.features & QStyleOptionViewItem::WrapText; // see QItemDelegate::drawDisplay - const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, w) + 1; + const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, w) + 1; switch (option.decorationPosition) { case QStyleOptionViewItem::Left: case QStyleOptionViewItem::Right: @@ -502,9 +502,9 @@ QWidget *QItemDelegate::createEditor(QWidget *parent, { Q_D(const QItemDelegate); if (!index.isValid()) - return 0; + return nullptr; const QItemEditorFactory *factory = d->f; - if (factory == 0) + if (factory == nullptr) factory = QItemEditorFactory::defaultFactory(); QWidget *w = factory->createEditor(index.data(Qt::EditRole).userType(), parent); if (w) @@ -533,7 +533,7 @@ void QItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con if (!n.isEmpty()) { if (!v.isValid()) - v = QVariant(editor->property(n).userType(), (const void *)0); + v = QVariant(editor->property(n).userType(), (const void *)nullptr); editor->setProperty(n, v); } #endif @@ -586,7 +586,7 @@ void QItemDelegate::updateEditorGeometry(QWidget *editor, QPixmap pixmap = decoration(option, index.data(Qt::DecorationRole)); QString text = QItemDelegatePrivate::replaceNewLine(index.data(Qt::DisplayRole).toString()); QRect pixmapRect = QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect()); - QRect textRect = textRectangle(0, option.rect, option.font, text); + QRect textRect = textRectangle(nullptr, option.rect, option.font, text); QRect checkRect = doCheck(option, textRect, index.data(Qt::CheckStateRole)); QStyleOptionViewItem opt = option; opt.showDecorationSelected = true; // let the editor take up all available space @@ -654,7 +654,7 @@ void QItemDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &o const QWidget *widget = d->widget(option); QStyle *style = widget ? widget->style() : QApplication::style(); - const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1; + const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1; QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding const bool wrapText = opt.features & QStyleOptionViewItem::WrapText; d->textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap); @@ -841,7 +841,7 @@ void QItemDelegate::doLayout(const QStyleOptionViewItem &option, const bool hasText = textRect->isValid(); const bool hasMargin = (hasText | hasPixmap | hasCheck); const int frameHMargin = hasMargin ? - style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1 : 0; + style->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, widget) + 1 : 0; const int textMargin = hasText ? frameHMargin : 0; const int pixmapMargin = hasPixmap ? frameHMargin : 0; const int checkMargin = hasCheck ? frameHMargin : 0; @@ -1242,7 +1242,7 @@ QStyleOptionViewItem QItemDelegate::setOptions(const QModelIndex &index, opt.palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value)); // disable style animations for checkboxes etc. within itemviews (QTBUG-30146) - opt.styleObject = 0; + opt.styleObject = nullptr; return opt; } diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index 8ed2ee5f28..f874597d59 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -91,7 +91,7 @@ class QUIntSpinBox : public QSpinBox Q_OBJECT Q_PROPERTY(uint value READ uintValue WRITE setUIntValue NOTIFY uintValueChanged USER true) public: - explicit QUIntSpinBox(QWidget *parent = 0) + explicit QUIntSpinBox(QWidget *parent = nullptr) : QSpinBox(parent) { connect(this, SIGNAL(valueChanged(int)), SIGNAL(uintValueChanged())); @@ -176,7 +176,7 @@ QWidget *QItemEditorFactory::createEditor(int userType, QWidget *parent) const QItemEditorCreatorBase *creator = creatorMap.value(userType, 0); if (!creator) { const QItemEditorFactory *dfactory = defaultFactory(); - return dfactory == this ? 0 : dfactory->createEditor(userType, parent); + return dfactory == this ? nullptr : dfactory->createEditor(userType, parent); } return creator->createWidget(parent); } @@ -295,8 +295,8 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) default: { // the default editor is a lineedit QExpandingLineEdit *le = new QExpandingLineEdit(parent); - le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, 0, le)); - if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, le)) + le->setFrame(le->style()->styleHint(QStyle::SH_ItemView_DrawDelegateFrame, nullptr, le)); + if (!le->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, nullptr, le)) le->setWidgetOwnsGeometry(true); return le; } #else @@ -304,7 +304,7 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) break; #endif } - return 0; + return nullptr; } QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const @@ -335,11 +335,11 @@ QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const } } -static QItemEditorFactory *q_default_factory = 0; +static QItemEditorFactory *q_default_factory = nullptr; struct QDefaultFactoryCleaner { inline QDefaultFactoryCleaner() {} - ~QDefaultFactoryCleaner() { delete q_default_factory; q_default_factory = 0; } + ~QDefaultFactoryCleaner() { delete q_default_factory; q_default_factory = nullptr; } }; /*! diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 04cddf2926..ec01922746 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -664,7 +664,9 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList rect |= current; } } - rect &= viewportRect; + QRect clipped = rect & viewportRect; + rect.setLeft(clipped.left()); + rect.setRight(clipped.right()); return ret; } @@ -933,8 +935,8 @@ QStyleOptionViewItem QListView::viewOptions() const QStyleOptionViewItem option = QAbstractItemView::viewOptions(); if (!d->iconSize.isValid()) { // otherwise it was already set in abstractitemview int pm = (d->viewMode == QListView::ListMode - ? style()->pixelMetric(QStyle::PM_ListViewIconSize, 0, this) - : style()->pixelMetric(QStyle::PM_IconViewIconSize, 0, this)); + ? style()->pixelMetric(QStyle::PM_ListViewIconSize, nullptr, this) + : style()->pixelMetric(QStyle::PM_IconViewIconSize, nullptr, this)); option.decorationSize = QSize(pm, pm); } if (d->viewMode == QListView::IconMode) { @@ -1688,7 +1690,7 @@ bool QListView::event(QEvent *e) QListViewPrivate::QListViewPrivate() : QAbstractItemViewPrivate(), - commonListView(0), + commonListView(nullptr), wrap(false), space(0), flow(QListView::TopToBottom), @@ -1733,10 +1735,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, vbar) + frameAroundContents + ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, vbar) + frameAroundContents : 0; int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded - ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, hbar) + frameAroundContents + ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, nullptr, hbar) + frameAroundContents : 0; layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin); @@ -3072,7 +3074,7 @@ void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) moved.resize(items.count()); QRect rect(QPoint(), topLeft); - QListViewItem *item = 0; + QListViewItem *item = nullptr; for (int row = info.first; row <= info.last; ++row) { item = &items[row]; if (isHidden(row)) { @@ -3178,7 +3180,7 @@ QVector<QModelIndex> QIconModeViewBase::intersectingSet(const QRect &area) const QVector<QModelIndex> res; that->interSectingVector = &res; that->tree.climbTree(area, &QIconModeViewBase::addLeaf, data); - that->interSectingVector = 0; + that->interSectingVector = nullptr; return res; } diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index c45d41dab5..4aca923151 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -75,7 +75,7 @@ void QListModel::clear() for (int i = 0; i < items.count(); ++i) { if (items.at(i)) { items.at(i)->d->theid = -1; - items.at(i)->view = 0; + items.at(i)->view = nullptr; delete items.at(i); } } @@ -96,7 +96,7 @@ void QListModel::remove(QListWidgetItem *item) Q_ASSERT(row != -1); beginRemoveRows(QModelIndex(), row, row); items.at(row)->d->theid = -1; - items.at(row)->view = 0; + items.at(row)->view = nullptr; items.removeAt(row); endRemoveRows(); } @@ -156,11 +156,11 @@ void QListModel::insert(int row, const QStringList &labels) QListWidgetItem *QListModel::take(int row) { if (row < 0 || row >= items.count()) - return 0; + return nullptr; beginRemoveRows(QModelIndex(), row, row); items.at(row)->d->theid = -1; - items.at(row)->view = 0; + items.at(row)->view = nullptr; QListWidgetItem *item = items.takeAt(row); endRemoveRows(); return item; @@ -263,7 +263,7 @@ bool QListModel::insertRows(int row, int count, const QModelIndex &parent) beginInsertRows(QModelIndex(), row, row + count - 1); QListWidget *view = qobject_cast<QListWidget*>(QObject::parent()); - QListWidgetItem *itm = 0; + QListWidgetItem *itm = nullptr; for (int r = row; r < row + count; ++r) { itm = new QListWidgetItem; @@ -282,10 +282,10 @@ bool QListModel::removeRows(int row, int count, const QModelIndex &parent) return false; beginRemoveRows(QModelIndex(), row, row + count - 1); - QListWidgetItem *itm = 0; + QListWidgetItem *itm = nullptr; for (int r = row; r < row + count; ++r) { itm = items.takeAt(row); - itm->view = 0; + itm->view = nullptr; itm->d->theid = -1; delete itm; } @@ -301,16 +301,23 @@ bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co { if (sourceRow < 0 || sourceRow + count - 1 >= rowCount(sourceParent) - || destinationChild <= 0 + || destinationChild < 0 || destinationChild > rowCount(destinationParent) + || sourceRow == destinationChild || sourceRow == destinationChild - 1 - || count <= 0) { + || count <= 0 + || sourceParent.isValid() + || destinationParent.isValid()) { return false; } if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild)) return false; - destinationChild--; - const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; + + int fromRow = sourceRow; + if (destinationChild < sourceRow) + fromRow += count - 1; + else + destinationChild--; while (count--) items.move(fromRow, destinationChild); endMoveRows(); @@ -987,8 +994,9 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item) \fn void QListWidgetItem::setSizeHint(const QSize &size) \since 4.1 - Sets the size hint for the list item to be \a size. If no size hint is set, - the item delegate will compute the size hint based on the item data. + Sets the size hint for the list item to be \a size. + If no size hint is set or \a size is invalid, the item + delegate will compute the size hint based on the item data. */ /*! @@ -1119,6 +1127,8 @@ void QListWidgetItem::setFlags(Qt::ItemFlags aflags) \since 4.2 Sets the background brush of the list item to the given \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. \sa background(), setForeground() */ @@ -1137,6 +1147,8 @@ void QListWidgetItem::setFlags(Qt::ItemFlags aflags) \since 4.2 Sets the foreground brush of the list item to the given \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. \sa foreground(), setBackground() */ @@ -1215,7 +1227,7 @@ void QListWidgetPrivate::_q_emitCurrentItemChanged(const QModelIndex ¤t, //persistentCurrent is invalid if something changed the model in response //to the currentItemChanged signal emission and the item was removed if (!persistentCurrent.isValid()) { - currentItem = 0; + currentItem = nullptr; } emit q->currentTextChanged(currentItem ? currentItem->text() : QString()); @@ -1473,7 +1485,7 @@ QListWidgetItem *QListWidget::item(int row) const { Q_D(const QListWidget); if (row < 0 || row >= d->model->rowCount()) - return 0; + return nullptr; return d->listModel()->at(row); } @@ -1543,7 +1555,7 @@ QListWidgetItem *QListWidget::takeItem(int row) { Q_D(QListWidget); if (row < 0 || row >= d->model->rowCount()) - return 0; + return nullptr; return d->listModel()->take(row); } @@ -2059,7 +2071,7 @@ QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const Q_D(const QListWidget); if (d->isIndexValid(index)) return d->listModel()->at(index.row()); - return 0; + return nullptr; } /*! diff --git a/src/widgets/itemviews/qlistwidget.h b/src/widgets/itemviews/qlistwidget.h index c102b144df..1319d658ab 100644 --- a/src/widgets/itemviews/qlistwidget.h +++ b/src/widgets/itemviews/qlistwidget.h @@ -127,7 +127,7 @@ public: inline QBrush background() const { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); } inline void setBackground(const QBrush &brush) - { setData(Qt::BackgroundRole, brush); } + { setData(Qt::BackgroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); } #if QT_DEPRECATED_SINCE(5, 13) QT_DEPRECATED_X ("Use QListWidgetItem::foreground() instead") @@ -141,7 +141,7 @@ public: inline QBrush foreground() const { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); } inline void setForeground(const QBrush &brush) - { setData(Qt::ForegroundRole, brush); } + { setData(Qt::ForegroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); } inline Qt::CheckState checkState() const { return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); } @@ -151,7 +151,7 @@ public: inline QSize sizeHint() const { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); } inline void setSizeHint(const QSize &size) - { setData(Qt::SizeHintRole, size); } + { setData(Qt::SizeHintRole, size.isValid() ? QVariant(size) : QVariant()); } virtual QVariant data(int role) const; virtual void setData(int role, const QVariant &value); diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index 702e290da3..f42af2ea00 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -83,7 +83,7 @@ class QStyledItemDelegatePrivate : public QAbstractItemDelegatePrivate Q_DECLARE_PUBLIC(QStyledItemDelegate) public: - QStyledItemDelegatePrivate() : factory(0) { } + QStyledItemDelegatePrivate() : factory(nullptr) { } static const QWidget *widget(const QStyleOptionViewItem &option) { @@ -351,7 +351,7 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, option->backgroundBrush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)); // disable style animations for checkboxes etc. within itemviews (QTBUG-30146) - option->styleObject = 0; + option->styleObject = nullptr; } /*! @@ -426,7 +426,7 @@ QWidget *QStyledItemDelegate::createEditor(QWidget *parent, { Q_D(const QStyledItemDelegate); if (!index.isValid()) - return 0; + return nullptr; return d->editorFactory()->createEditor(index.data(Qt::EditRole).userType(), parent); } @@ -450,7 +450,7 @@ void QStyledItemDelegate::setEditorData(QWidget *editor, const QModelIndex &inde if (!n.isEmpty()) { if (!v.isValid()) - v = QVariant(editor->property(n).userType(), (const void *)0); + v = QVariant(editor->property(n).userType(), (const void *)nullptr); editor->setProperty(n, v); } #endif @@ -507,7 +507,7 @@ void QStyledItemDelegate::updateEditorGeometry(QWidget *editor, //or it is in a QTableView #if QT_CONFIG(tableview) && QT_CONFIG(lineedit) if (qobject_cast<QExpandingLineEdit*>(editor) && !qobject_cast<const QTableView*>(widget)) - opt.showDecorationSelected = editor->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, editor); + opt.showDecorationSelected = editor->style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, nullptr, editor); else #endif opt.showDecorationSelected = true; diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 11c5be10fd..81fceba8dc 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1431,7 +1431,7 @@ void QTableView::paintEvent(QPaintEvent *event) const bool showGrid = d->showGrid; const int gridSize = showGrid ? 1 : 0; const int gridHint = style()->styleHint(QStyle::SH_Table_GridLineColor, &option, this); - const QColor gridColor = static_cast<QRgb>(gridHint); + const QColor gridColor = QColor::fromRgba(static_cast<QRgb>(gridHint)); const QPen gridPen = QPen(gridColor, 0, d->gridStyle); const QHeaderView *verticalHeader = d->verticalHeader; const QHeaderView *horizontalHeader = d->horizontalHeader; diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index b1dbafa997..60abd02564 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE QTableModel::QTableModel(int rows, int columns, QTableWidget *parent) : QAbstractTableModel(parent), - prototype(0), + prototype(nullptr), tableItems(rows * columns, 0), verticalHeaderItems(rows, 0), horizontalHeaderItems(columns, 0) @@ -104,18 +104,18 @@ bool QTableModel::removeRows(int row, int count, const QModelIndex &) beginRemoveRows(QModelIndex(), row, row + count - 1); int i = tableIndex(row, 0); int n = count * columnCount(); - QTableWidgetItem *oldItem = 0; + QTableWidgetItem *oldItem = nullptr; for (int j = i; j < n + i; ++j) { oldItem = tableItems.at(j); if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete oldItem; } tableItems.remove(qMax(i, 0), n); for (int v = row; v < row + count; ++v) { oldItem = verticalHeaderItems.at(v); if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete oldItem; } verticalHeaderItems.remove(row, count); @@ -129,13 +129,13 @@ bool QTableModel::removeColumns(int column, int count, const QModelIndex &) return false; beginRemoveColumns(QModelIndex(), column, column + count - 1); - QTableWidgetItem *oldItem = 0; + QTableWidgetItem *oldItem = nullptr; for (int row = rowCount() - 1; row >= 0; --row) { int i = tableIndex(row, column); for (int j = i; j < i + count; ++j) { oldItem = tableItems.at(j); if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete oldItem; } tableItems.remove(i, count); @@ -143,7 +143,7 @@ bool QTableModel::removeColumns(int column, int count, const QModelIndex &) for (int h=column; h<column+count; ++h) { oldItem = horizontalHeaderItems.at(h); if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete oldItem; } horizontalHeaderItems.remove(column, count); @@ -162,7 +162,7 @@ void QTableModel::setItem(int row, int column, QTableWidgetItem *item) // remove old if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete tableItems.at(i); QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); @@ -180,7 +180,7 @@ void QTableModel::setItem(int row, int column, QTableWidgetItem *item) if (row < colItems.count()) colItems.remove(row); int sortedRow; - if (item == 0) { + if (item == nullptr) { // move to after all non-0 (sortable) items sortedRow = colItems.count(); } else { @@ -222,7 +222,7 @@ QTableWidgetItem *QTableModel::takeItem(int row, int column) long i = tableIndex(row, column); QTableWidgetItem *itm = tableItems.value(i); if (itm) { - itm->view = 0; + itm->view = nullptr; itm->d->id = -1; tableItems[i] = 0; const QModelIndex ind = index(row, column); @@ -239,7 +239,7 @@ QTableWidgetItem *QTableModel::item(int row, int column) const QTableWidgetItem *QTableModel::item(const QModelIndex &index) const { if (!isValid(index)) - return 0; + return nullptr; return tableItems.at(tableIndex(index.row(), index.column())); } @@ -277,7 +277,7 @@ void QTableModel::setHorizontalHeaderItem(int section, QTableWidgetItem *item) return; if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete oldItem; QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); @@ -299,7 +299,7 @@ void QTableModel::setVerticalHeaderItem(int section, QTableWidgetItem *item) return; if (oldItem) - oldItem->view = 0; + oldItem->view = nullptr; delete oldItem; QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent()); @@ -315,10 +315,10 @@ void QTableModel::setVerticalHeaderItem(int section, QTableWidgetItem *item) QTableWidgetItem *QTableModel::takeHorizontalHeaderItem(int section) { if (section < 0 || section >= horizontalHeaderItems.count()) - return 0; + return nullptr; QTableWidgetItem *itm = horizontalHeaderItems.at(section); if (itm) { - itm->view = 0; + itm->view = nullptr; itm->itemFlags &= ~ItemIsHeaderItem; horizontalHeaderItems[section] = 0; } @@ -328,10 +328,10 @@ QTableWidgetItem *QTableModel::takeHorizontalHeaderItem(int section) QTableWidgetItem *QTableModel::takeVerticalHeaderItem(int section) { if (section < 0 || section >= verticalHeaderItems.count()) - return 0; + return nullptr; QTableWidgetItem *itm = verticalHeaderItems.at(section); if (itm) { - itm->view = 0; + itm->view = nullptr; itm->itemFlags &= ~ItemIsHeaderItem; verticalHeaderItems[section] = 0; } @@ -571,7 +571,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order, sorting.reserve(count); for (int row = start; row <= end; ++row) { QTableWidgetItem *itm = item(row, column); - if (itm == 0) { + if (itm == nullptr) { // no more sortable items (all 0-items are // at the end of the table when it is sorted) break; @@ -649,7 +649,7 @@ QVector<QTableWidgetItem*> QTableModel::columnItems(int column) const items.reserve(rc); for (int row = 0; row < rc; ++row) { QTableWidgetItem *itm = item(row, column); - if (itm == 0) { + if (itm == nullptr) { // no more sortable items (all 0-items are // at the end of the table when it is sorted) break; @@ -718,7 +718,7 @@ QVariant QTableModel::headerData(int section, Qt::Orientation orientation, int r if (section < 0) return QVariant(); - QTableWidgetItem *itm = 0; + QTableWidgetItem *itm = nullptr; if (orientation == Qt::Horizontal && section < horizontalHeaderItems.count()) itm = horizontalHeaderItems.at(section); else if (orientation == Qt::Vertical && section < verticalHeaderItems.count()) @@ -741,7 +741,7 @@ bool QTableModel::setHeaderData(int section, Qt::Orientation orientation, (orientation == Qt::Vertical && verticalHeaderItems.size() <= section)) return false; - QTableWidgetItem *itm = 0; + QTableWidgetItem *itm = nullptr; if (orientation == Qt::Horizontal) itm = horizontalHeaderItems.at(section); else @@ -764,14 +764,14 @@ void QTableModel::clear() { for (int j = 0; j < verticalHeaderItems.count(); ++j) { if (verticalHeaderItems.at(j)) { - verticalHeaderItems.at(j)->view = 0; + verticalHeaderItems.at(j)->view = nullptr; delete verticalHeaderItems.at(j); verticalHeaderItems[j] = 0; } } for (int k = 0; k < horizontalHeaderItems.count(); ++k) { if (horizontalHeaderItems.at(k)) { - horizontalHeaderItems.at(k)->view = 0; + horizontalHeaderItems.at(k)->view = nullptr; delete horizontalHeaderItems.at(k); horizontalHeaderItems[k] = 0; } @@ -784,7 +784,7 @@ void QTableModel::clearContents() beginResetModel(); for (int i = 0; i < tableItems.count(); ++i) { if (tableItems.at(i)) { - tableItems.at(i)->view = 0; + tableItems.at(i)->view = nullptr; delete tableItems.at(i); tableItems[i] = 0; } @@ -853,7 +853,7 @@ QMimeData *QTableModel::mimeData(const QModelIndexList &indexes) const // cachedIndexes is a little hack to avoid copying from QModelIndexList to // QList<QTreeWidgetItem*> and back again in the view cachedIndexes = indexes; - QMimeData *mimeData = (view ? view->mimeData(items) : 0); + QMimeData *mimeData = (view ? view->mimeData(items) : nullptr); cachedIndexes.clear(); return mimeData; } @@ -923,8 +923,8 @@ QTableWidgetSelectionRange::QTableWidgetSelectionRange(int top, int left, int bo Constructs a the table selection range by copying the given \a other table selection range. */ -QTableWidgetSelectionRange::QTableWidgetSelectionRange(const QTableWidgetSelectionRange &other) = default; -QTableWidgetSelectionRange &QTableWidgetSelectionRange::operator=(const QTableWidgetSelectionRange &other) = default; +QTableWidgetSelectionRange::QTableWidgetSelectionRange(const QTableWidgetSelectionRange &) = default; +QTableWidgetSelectionRange &QTableWidgetSelectionRange::operator=(const QTableWidgetSelectionRange &) = default; /*! Destroys the table selection range. @@ -1064,8 +1064,8 @@ QTableWidgetSelectionRange::~QTableWidgetSelectionRange() \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. + If no size hint is set or \a size is invalid, the item + delegate will compute the size hint based on the item data. */ /*! @@ -1279,6 +1279,8 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags) \since 4.2 Sets the item's background brush to the specified \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. \sa setForeground() */ @@ -1313,6 +1315,8 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags) \since 4.2 Sets the item's foreground brush to the specified \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. \sa setBackground() */ @@ -2036,7 +2040,7 @@ QTableWidgetItem *QTableWidget::takeItem(int row, int column) Q_D(QTableWidget); QTableWidgetItem *item = d->tableModel()->takeItem(row, column); if (item) - item->view = 0; + item->view = nullptr; return item; } @@ -2072,7 +2076,7 @@ QTableWidgetItem *QTableWidget::takeVerticalHeaderItem(int row) Q_D(QTableWidget); QTableWidgetItem *itm = d->tableModel()->takeVerticalHeaderItem(row); if (itm) - itm->view = 0; + itm->view = nullptr; return itm; } @@ -2111,7 +2115,7 @@ QTableWidgetItem *QTableWidget::takeHorizontalHeaderItem(int column) Q_D(QTableWidget); QTableWidgetItem *itm = d->tableModel()->takeHorizontalHeaderItem(column); if (itm) - itm->view = 0; + itm->view = nullptr; return itm; } @@ -2122,7 +2126,7 @@ void QTableWidget::setVerticalHeaderLabels(const QStringList &labels) { Q_D(QTableWidget); QTableModel *model = d->tableModel(); - QTableWidgetItem *item = 0; + QTableWidgetItem *item = nullptr; for (int i = 0; i < model->rowCount() && i < labels.count(); ++i) { item = model->verticalHeaderItem(i); if (!item) { @@ -2140,7 +2144,7 @@ void QTableWidget::setHorizontalHeaderLabels(const QStringList &labels) { Q_D(QTableWidget); QTableModel *model = d->tableModel(); - QTableWidgetItem *item = 0; + QTableWidgetItem *item = nullptr; for (int i = 0; i < model->columnCount() && i < labels.count(); ++i) { item = model->horizontalHeaderItem(i); if (!item) { diff --git a/src/widgets/itemviews/qtablewidget.h b/src/widgets/itemviews/qtablewidget.h index 0d93a0a075..70e2046400 100644 --- a/src/widgets/itemviews/qtablewidget.h +++ b/src/widgets/itemviews/qtablewidget.h @@ -146,7 +146,7 @@ public: inline QBrush background() const { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); } inline void setBackground(const QBrush &brush) - { setData(Qt::BackgroundRole, brush); } + { setData(Qt::BackgroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); } #if QT_DEPRECATED_SINCE(5, 13) QT_DEPRECATED_X ("Use QTableWidgetItem::foreground() instead") @@ -160,7 +160,7 @@ public: inline QBrush foreground() const { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); } inline void setForeground(const QBrush &brush) - { setData(Qt::ForegroundRole, brush); } + { setData(Qt::ForegroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); } inline Qt::CheckState checkState() const { return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); } @@ -170,7 +170,7 @@ public: inline QSize sizeHint() const { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); } inline void setSizeHint(const QSize &size) - { setData(Qt::SizeHintRole, size); } + { setData(Qt::SizeHintRole, size.isValid() ? QVariant(size) : QVariant()); } virtual QVariant data(int role) const; virtual void setData(int role, const QVariant &value); diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 413cc2a9cd..9aba17be70 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -233,7 +233,9 @@ void QTreeView::setModel(QAbstractItemModel *model) d->viewItems.clear(); d->expandedIndexes.clear(); d->hiddenIndexes.clear(); + d->geometryRecursionBlock = true; // do not update geometries due to signals from the headers d->header->setModel(model); + d->geometryRecursionBlock = false; QAbstractItemView::setModel(model); // QAbstractItemView connects to a private slot @@ -1515,7 +1517,7 @@ void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const /// ### move to QObject :) static inline bool ancestorOf(QObject *widget, QObject *other) { - for (QObject *parent = other; parent != 0; parent = parent->parent()) { + for (QObject *parent = other; parent != nullptr; parent = parent->parent()) { if (parent == widget) return true; } @@ -1886,10 +1888,12 @@ void QTreeView::mousePressEvent(QMouseEvent *event) { Q_D(QTreeView); bool handled = false; - if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonPress) + if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, this) == QEvent::MouseButtonPress) handled = d->expandOrCollapseItemAtPos(event->pos()); if (!handled && d->itemDecorationAt(event->pos()) == -1) QAbstractItemView::mousePressEvent(event); + else + d->pressedIndex = QModelIndex(); } /*! @@ -1903,7 +1907,7 @@ void QTreeView::mouseReleaseEvent(QMouseEvent *event) } else { if (state() == QAbstractItemView::DragSelectingState || state() == QAbstractItemView::DraggingState) setState(QAbstractItemView::NoState); - if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonRelease) + if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, this) == QEvent::MouseButtonRelease) d->expandOrCollapseItemAtPos(event->pos()); } } @@ -1940,7 +1944,7 @@ void QTreeView::mouseDoubleClickEvent(QMouseEvent *event) if (edit(persistent, DoubleClicked, event) || state() != NoState) return; // the double click triggered editing - if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) + if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, this)) emit activated(persistent); d->pressedIndex = QModelIndex(); @@ -2204,7 +2208,7 @@ QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie d->collapse(vi, true); d->moveCursorUpdatedView = true; } else { - bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); + bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, nullptr, this); if (descend) { QModelIndex par = current.parent(); if (par.isValid() && par != rootIndex()) @@ -2240,7 +2244,7 @@ QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie d->expand(vi, true); d->moveCursorUpdatedView = true; } else { - bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); + bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, nullptr, this); if (descend) { QModelIndex idx = d->modelIndex(d->below(vi)); if (idx.parent() == current) @@ -3047,7 +3051,7 @@ void QTreeViewPrivate::initialize() header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter); q->setHeader(header); #if QT_CONFIG(animation) - animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, q) > 0; + animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, q) > 0; QObject::connect(&animatedOperation, SIGNAL(finished()), q, SLOT(_q_endAnimatedOperation())); #endif // animation } @@ -3340,7 +3344,7 @@ void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninit int hidden = 0; int last = 0; int children = 0; - QTreeViewItem *item = 0; + QTreeViewItem *item = nullptr; for (int j = first; j < first + count; ++j) { current = model->index(j - first, 0, parent); if (isRowHidden(current)) { @@ -3951,7 +3955,7 @@ int QTreeViewPrivate::accessibleTree2Index(const QModelIndex &index) const void QTreeViewPrivate::updateIndentationFromStyle() { Q_Q(const QTreeView); - indent = q->style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, q); + indent = q->style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr, q); } /*! diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 68338228b2..4908ad6ad2 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -144,7 +144,7 @@ QTreeModel::~QTreeModel() clear(); headerItem->view = nullptr; delete headerItem; - rootItem->view = 0; + rootItem->view = nullptr; delete rootItem; } @@ -160,8 +160,8 @@ void QTreeModel::clear() beginResetModel(); for (int i = 0; i < rootItem->childCount(); ++i) { QTreeWidgetItem *item = rootItem->children.at(i); - item->par = 0; - item->view = 0; + item->par = nullptr; + item->view = nullptr; delete item; } rootItem->children.clear(); @@ -214,7 +214,7 @@ void QTreeModel::setColumnCount(int columns) QTreeWidgetItem *QTreeModel::item(const QModelIndex &index) const { if (!index.isValid()) - return 0; + return nullptr; return static_cast<QTreeWidgetItem*>(index.internalPointer()); } @@ -515,9 +515,9 @@ bool QTreeModel::removeRows(int row, int count, const QModelIndex &parent) { for (int i = row + count - 1; i >= row; --i) { QTreeWidgetItem *child = itm ? itm->takeChild(i) : rootItem->children.takeAt(i); Q_ASSERT(child); - child->view = 0; + child->view = nullptr; delete child; - child = 0; + child = nullptr; } blocker.unblock(); @@ -1285,6 +1285,11 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const Sets the background brush of the label in the given \a column to the specified \a brush. + Setting a default-constructed brush will let the view use the + default color from the style. + + \note If \l{Qt Style Sheets} are used on the same widget as setBackground(), + style sheets will take precedence if the settings conflict. \sa setForeground() */ @@ -1311,6 +1316,8 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const Returns the brush used to render the foreground (e.g. text) of the specified \a column. + Setting a default-constructed brush will let the view use the + default color from the style. \sa background() */ @@ -1354,8 +1361,8 @@ bool QTreeWidgetItem::isFirstColumnSpanned() const \since 4.1 Sets the size hint for the tree item in the given \a column to be \a size. - If no size hint is set, the item delegate will compute the size hint based - on the item data. + If no size hint is set or \a size is invalid, the item + delegate will compute the size hint based on the item data. */ /*! @@ -1605,11 +1612,11 @@ QTreeWidgetItem::~QTreeWidgetItem() } } else if (model) { if (this == model->headerItem) { - model->headerItem = 0; + model->headerItem = nullptr; } else { int i = model->rootItem->children.indexOf(this); if (i >= 0) { - model->beginRemoveItems(0, i, 1); + model->beginRemoveItems(nullptr, i, 1); // users _could_ do changes when connected to rowsAboutToBeRemoved, // so we check again to make sure 'i' is valid if (!model->rootItem->children.isEmpty() && model->rootItem->children.at(i) == this) @@ -1623,9 +1630,9 @@ QTreeWidgetItem::~QTreeWidgetItem() for (int i = 0; i < children.count(); ++i) { QTreeWidgetItem *child = children.at(i); // make sure the child does not try to remove itself from our children list - child->par = 0; + child->par = nullptr; // make sure the child does not try to remove itself from the top level list - child->view = 0; + child->view = nullptr; delete child; } @@ -1641,16 +1648,16 @@ QTreeWidgetItem::~QTreeWidgetItem() */ QTreeWidgetItem *QTreeWidgetItem::clone() const { - QTreeWidgetItem *copy = 0; + QTreeWidgetItem *copy = nullptr; QStack<const QTreeWidgetItem*> stack; QStack<QTreeWidgetItem*> parentStack; stack.push(this); parentStack.push(0); - QTreeWidgetItem *root = 0; - const QTreeWidgetItem *item = 0; - QTreeWidgetItem *parent = 0; + QTreeWidgetItem *root = nullptr; + const QTreeWidgetItem *item = nullptr; + QTreeWidgetItem *parent = nullptr; while (!stack.isEmpty()) { // get current item, and copied parent item = stack.pop(); @@ -1985,8 +1992,8 @@ void QTreeWidgetItem::write(QDataStream &out) const \sa data(), flags() */ QTreeWidgetItem::QTreeWidgetItem(const QTreeWidgetItem &other) - : rtti(Type), values(other.values), view(0), - d(new QTreeWidgetItemPrivate(this)), par(0), + : rtti(Type), values(other.values), view(nullptr), + d(new QTreeWidgetItemPrivate(this)), par(nullptr), itemFlags(other.itemFlags) { d->display = other.d->display; @@ -2029,14 +2036,14 @@ void QTreeWidgetItem::addChild(QTreeWidgetItem *child) */ void QTreeWidgetItem::insertChild(int index, QTreeWidgetItem *child) { - if (index < 0 || index > children.count() || child == 0 || child->view != 0 || child->par != 0) + if (index < 0 || index > children.count() || child == nullptr || child->view != nullptr || child->par != nullptr) return; if (QTreeModel *model = treeModel()) { const bool wasSkipSort = model->skipPendingSort; model->skipPendingSort = true; if (model->rootItem == this) - child->par = 0; + child->par = nullptr; else child->par = this; if (view->isSortingEnabled()) { @@ -2096,12 +2103,12 @@ QTreeWidgetItem *QTreeWidgetItem::takeChild(int index) if (model) model->beginRemoveItems(this, index, 1); d->updateHiddenStatus(children.at(index), false); QTreeWidgetItem *item = children.takeAt(index); - item->par = 0; + item->par = nullptr; QStack<QTreeWidgetItem*> stack; stack.push(item); while (!stack.isEmpty()) { QTreeWidgetItem *i = stack.pop(); - i->view = 0; + i->view = nullptr; for (int c = 0; c < i->children.count(); ++c) stack.push(i->children.at(c)); } @@ -2109,7 +2116,7 @@ QTreeWidgetItem *QTreeWidgetItem::takeChild(int index) if (model) model->endRemoveRows(); return item; } - return 0; + return nullptr; } /*! @@ -2156,7 +2163,7 @@ void QTreeWidgetItem::insertChildren(int index, const QList<QTreeWidgetItem*> &c stack.push(child); } if (model && (model->rootItem == this)) - child->par = 0; + child->par = nullptr; else child->par = this; } @@ -2199,12 +2206,12 @@ QList<QTreeWidgetItem*> QTreeWidgetItem::takeChildren() if (model) model->beginRemoveItems(this, 0, children.count()); for (int n = 0; n < children.count(); ++n) { QTreeWidgetItem *item = children.at(n); - item->par = 0; + item->par = nullptr; QStack<QTreeWidgetItem*> stack; stack.push(item); while (!stack.isEmpty()) { QTreeWidgetItem *i = stack.pop(); - i->view = 0; + i->view = nullptr; for (int c = 0; c < i->children.count(); ++c) stack.push(i->children.at(c)); } @@ -3299,7 +3306,7 @@ QTreeWidgetItem *QTreeWidget::itemAbove(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); if (item == d->treeModel()->headerItem) - return 0; + return nullptr; const QModelIndex index = d->index(item); const QModelIndex above = indexAbove(index); return d->item(above); @@ -3314,7 +3321,7 @@ QTreeWidgetItem *QTreeWidget::itemBelow(const QTreeWidgetItem *item) const { Q_D(const QTreeWidget); if (item == d->treeModel()->headerItem) - return 0; + return nullptr; const QModelIndex index = d->index(item); const QModelIndex below = indexBelow(index); return d->item(below); @@ -3417,14 +3424,14 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const for (const auto *item : items) { if (Q_UNLIKELY(!item)) { qWarning("QTreeWidget::mimeData: Null-item passed"); - return 0; + return nullptr; } for (int c = 0; c < item->values.count(); ++c) { const QModelIndex index = indexFromItem(item, c); if (Q_UNLIKELY(!index.isValid())) { qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item; - return 0; + return nullptr; } indexes << index; } diff --git a/src/widgets/itemviews/qtreewidget.h b/src/widgets/itemviews/qtreewidget.h index bed77b336d..b9543fb954 100644 --- a/src/widgets/itemviews/qtreewidget.h +++ b/src/widgets/itemviews/qtreewidget.h @@ -146,7 +146,7 @@ public: inline QBrush background(int column) const { return qvariant_cast<QBrush>(data(column, Qt::BackgroundRole)); } inline void setBackground(int column, const QBrush &brush) - { setData(column, Qt::BackgroundRole, brush); } + { setData(column, Qt::BackgroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); } #if QT_DEPRECATED_SINCE(5, 13) QT_DEPRECATED_X ("Use QTreeWidgetItem::foreground() instead") @@ -160,7 +160,7 @@ public: inline QBrush foreground(int column) const { return qvariant_cast<QBrush>(data(column, Qt::ForegroundRole)); } inline void setForeground(int column, const QBrush &brush) - { setData(column, Qt::ForegroundRole, brush); } + { setData(column, Qt::ForegroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); } inline Qt::CheckState checkState(int column) const { return static_cast<Qt::CheckState>(data(column, Qt::CheckStateRole).toInt()); } @@ -170,7 +170,7 @@ public: inline QSize sizeHint(int column) const { return qvariant_cast<QSize>(data(column, Qt::SizeHintRole)); } inline void setSizeHint(int column, const QSize &size) - { setData(column, Qt::SizeHintRole, size); } + { setData(column, Qt::SizeHintRole, size.isValid() ? QVariant(size) : QVariant()); } virtual QVariant data(int column, int role) const; virtual void setData(int column, int role, const QVariant &value); diff --git a/src/widgets/itemviews/qtreewidgetitemiterator.cpp b/src/widgets/itemviews/qtreewidgetitemiterator.cpp index 14c19fcb9c..a24106d90e 100644 --- a/src/widgets/itemviews/qtreewidgetitemiterator.cpp +++ b/src/widgets/itemviews/qtreewidgetitemiterator.cpp @@ -90,7 +90,7 @@ QTreeWidgetItemIterator::QTreeWidgetItemIterator(const QTreeWidgetItemIterator & */ QTreeWidgetItemIterator::QTreeWidgetItemIterator(QTreeWidget *widget, IteratorFlags flags) -: current(0), flags(flags) +: current(nullptr), flags(flags) { Q_ASSERT(widget); QTreeModel *model = qobject_cast<QTreeModel*>(widget->model()); @@ -266,7 +266,7 @@ bool QTreeWidgetItemIterator::matchesFlags(const QTreeWidgetItem *item) const QTreeWidgetItem* QTreeWidgetItemIteratorPrivate::nextSibling(const QTreeWidgetItem* item) const { Q_ASSERT(item); - QTreeWidgetItem *next = 0; + QTreeWidgetItem *next = nullptr; if (QTreeWidgetItem *par = item->parent()) { int i = par->indexOfChild(const_cast<QTreeWidgetItem*>(item)); next = par->child(i + 1); @@ -280,9 +280,9 @@ QTreeWidgetItem* QTreeWidgetItemIteratorPrivate::nextSibling(const QTreeWidgetIt QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::next(const QTreeWidgetItem *current) { - if (!current) return 0; + if (!current) return nullptr; - QTreeWidgetItem *next = 0; + QTreeWidgetItem *next = nullptr; if (current->childCount()) { // walk the child m_parentIndex.push(m_currentIndex); @@ -307,9 +307,9 @@ QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::next(const QTreeWidgetItem *cur QTreeWidgetItem *QTreeWidgetItemIteratorPrivate::previous(const QTreeWidgetItem *current) { - if (!current) return 0; + if (!current) return nullptr; - QTreeWidgetItem *prev = 0; + QTreeWidgetItem *prev = nullptr; // walk the previous sibling QTreeWidgetItem *parent = current->parent(); prev = parent ? parent->child(m_currentIndex - 1) @@ -347,7 +347,7 @@ void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem * // we need to adjust the iterator. if (nextItem == itemToBeRemoved) { QTreeWidgetItem *parent = nextItem; - nextItem = 0; + nextItem = nullptr; while (parent && !nextItem) { nextItem = nextSibling(parent); parent = parent->parent(); @@ -358,7 +358,7 @@ void QTreeWidgetItemIteratorPrivate::ensureValidIterator(const QTreeWidgetItem * if (!(q->matchesFlags(nextItem))) ++(*q); } else { // set it to null. - q->current = 0; + q->current = nullptr; m_parentIndex.clear(); return; } |