diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 6 | ||||
-rw-r--r-- | src/widgets/itemviews/qitemdelegate.cpp | 2 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 35 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistview_p.h | 8 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 44 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistwidget_p.h | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qtablewidget.cpp | 30 | ||||
-rw-r--r-- | src/widgets/itemviews/qtablewidget_p.h | 3 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreewidget.cpp | 29 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreewidget_p.h | 4 | ||||
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 2 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.h | 4 | ||||
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 11 |
14 files changed, 145 insertions, 41 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 3396a91dc5..2f276a7a8c 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3877,9 +3877,9 @@ void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle() void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast) { int pixelpos = 0; - for (QVector<SectionItem>::const_iterator i = sectionItems.constBegin(); i != sectionItems.constEnd(); ++i) { - i->calculated_startpos = pixelpos; // write into const mutable - pixelpos += i->size; + for (const SectionItem &i : sectionItems) { + i.calculated_startpos = pixelpos; // write into const mutable + pixelpos += i.size; } sectionStartposRecalc = false; } diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index dff4cc4593..9c65d5fddd 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -1089,7 +1089,7 @@ QRect QItemDelegate::doCheck(const QStyleOptionViewItem &option, opt.rect = bounding; const QWidget *widget = d->widget(option); // cast QStyle *style = widget ? widget->style() : QApplication::style(); - return style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, widget); + return style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, widget); } return QRect(); } diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index e5769940d4..fdac332367 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -2246,8 +2246,8 @@ int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hi } else { int scrollBarValue = verticalScrollBar()->value(); int numHidden = 0; - for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i) - if (isHidden(i)) + for (const auto &idx : qAsConst(dd->hiddenRows)) + if (idx.row() <= scrollBarValue) ++numHidden; value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1); } @@ -2687,21 +2687,24 @@ int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int view return scrollValue; itemExtent += spacing(); - QVector<int> visibleFlowPositions; - visibleFlowPositions.reserve(flowPositions.count() - 1); - for (int i = 0; i < flowPositions.count() - 1; i++) { // flowPositions count is +1 larger than actual row count - if (!isHidden(i)) - visibleFlowPositions.append(flowPositions.at(i)); - } - + QVector<int> hiddenRows = dd->hiddenRowIds(); + std::sort(hiddenRows.begin(), hiddenRows.end()); + int hiddenRowsBefore = 0; + for (int i = 0; i < hiddenRows.size() - 1; ++i) + if (hiddenRows.at(i) > index + hiddenRowsBefore) + break; + else + ++hiddenRowsBefore; if (!wrap) { int topIndex = index; const int bottomIndex = topIndex; - const int bottomCoordinate = visibleFlowPositions.at(index); - + const int bottomCoordinate = flowPositions.at(index + hiddenRowsBefore); while (topIndex > 0 && - (bottomCoordinate - visibleFlowPositions.at(topIndex - 1) + itemExtent) <= (viewportSize)) { + (bottomCoordinate - flowPositions.at(topIndex + hiddenRowsBefore - 1) + itemExtent) <= (viewportSize)) { topIndex--; + // will the next one be a hidden row -> skip + while (hiddenRowsBefore > 0 && hiddenRows.at(hiddenRowsBefore - 1) >= topIndex + hiddenRowsBefore - 1) + hiddenRowsBefore--; } const int itemCount = bottomIndex - topIndex + 1; @@ -2720,7 +2723,7 @@ int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int view ? Qt::Horizontal : Qt::Vertical); if (flowOrientation == orientation) { // scrolling in the "flow" direction // ### wrapped scrolling in the flow direction - return visibleFlowPositions.at(index); // ### always pixel based for now + return flowPositions.at(index + hiddenRowsBefore); // ### always pixel based for now } else if (!segmentStartRows.isEmpty()) { // we are scrolling in the "segment" direction int segment = qBinarySearch<int>(segmentStartRows, index, 0, segmentStartRows.count() - 1); int leftSegment = segment; @@ -3354,9 +3357,9 @@ int QListView::visualIndex(const QModelIndex &index) const d->executePostedLayout(); QListViewItem itm = d->indexToListViewItem(index); int visualIndex = d->commonListView->itemIndex(itm); - for (int row = 0; row <= index.row() && visualIndex >= 0; row++) { - if (d->isHidden(row)) - visualIndex--; + for (const auto &idx : qAsConst(d->hiddenRows)) { + if (idx.row() <= index.row()) + --visualIndex; } return visualIndex; } diff --git a/src/widgets/itemviews/qlistview_p.h b/src/widgets/itemviews/qlistview_p.h index 181386d4d0..3f997ef7e3 100644 --- a/src/widgets/itemviews/qlistview_p.h +++ b/src/widgets/itemviews/qlistview_p.h @@ -377,6 +377,14 @@ public: QModelIndex idx = model->index(row, 0, root); return isPersistent(idx) && hiddenRows.contains(idx); } + // helper to avoid checking for isPersistent and creating persistent indexes as above in isHidden + QVector<int> hiddenRowIds() const { + QVector<int> rowIds; + rowIds.reserve(hiddenRows.size()); + for (const auto &idx : hiddenRows) + rowIds += idx.row(); + return rowIds; + } inline bool isHiddenOrDisabled(int row) const { return isHidden(row) || !isIndexEnabled(modelIndex(row)); } void removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex ¤t) const; diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 72e0a67a64..895622616e 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -227,6 +227,22 @@ bool QListModel::setData(const QModelIndex &index, const QVariant &value, int ro return true; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QListModel::clearItemData(const QModelIndex &index) +{ + if (!checkIndex(index, CheckIndexOption::IndexIsValid)) + return false; + QListWidgetItem *item = items.at(index.row()); + const auto beginIter = item->d->values.cbegin(); + const auto endIter = item->d->values.cend(); + if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); })) + return true; //it's already cleared + item->d->values.clear(); + emit dataChanged(index, index, QVector<int>{}); + return true; +} +#endif + QMap<int, QVariant> QListModel::itemData(const QModelIndex &index) const { QMap<int, QVariant> roles; @@ -277,6 +293,30 @@ bool QListModel::removeRows(int row, int count, const QModelIndex &parent) return true; } +/*! + \since 5.13 + \reimp +*/ +bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) +{ + if (sourceRow < 0 + || sourceRow + count - 1 >= rowCount(sourceParent) + || destinationChild <= 0 + || destinationChild > rowCount(destinationParent) + || sourceRow == destinationChild - 1 + || count <= 0) { + return false; + } + if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild)) + return false; + destinationChild--; + const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; + while (count--) + items.move(fromRow, destinationChild); + endMoveRows(); + return true; +} + Qt::ItemFlags QListModel::flags(const QModelIndex &index) const { if (!index.isValid() || index.row() >= items.count() || index.model() != this) @@ -289,7 +329,7 @@ void QListModel::sort(int column, Qt::SortOrder order) if (column != 0) return; - emit layoutAboutToBeChanged(); + emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); QVector < QPair<QListWidgetItem*,int> > sorting(items.count()); for (int i = 0; i < items.count(); ++i) { @@ -313,7 +353,7 @@ void QListModel::sort(int column, Qt::SortOrder order) } changePersistentIndexList(fromIndexes, toIndexes); - emit layoutChanged(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); } /** diff --git a/src/widgets/itemviews/qlistwidget_p.h b/src/widgets/itemviews/qlistwidget_p.h index 9cb3d5966b..65a7124322 100644 --- a/src/widgets/itemviews/qlistwidget_p.h +++ b/src/widgets/itemviews/qlistwidget_p.h @@ -100,11 +100,15 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool clearItemData(const QModelIndex &index) override; +#endif QMap<int, QVariant> itemData(const QModelIndex &index) const override; bool insertRows(int row, int count = 1, const QModelIndex &parent = QModelIndex()) override; bool removeRows(int row, int count = 1, const QModelIndex &parent = QModelIndex()) override; + bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override; Qt::ItemFlags flags(const QModelIndex &index) const override; diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 9725a768de..e7edd08d2a 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1383,12 +1383,12 @@ void QTableView::paintEvent(QPaintEvent *event) //firstVisualRow is the visual index of the first visible row. lastVisualRow is the visual index of the last visible Row. //same goes for ...VisualColumn int firstVisualRow = qMax(verticalHeader->visualIndexAt(0),0); - int lastVisualRow = verticalHeader->visualIndexAt(verticalHeader->viewport()->height()); + int lastVisualRow = verticalHeader->visualIndexAt(verticalHeader->height()); if (lastVisualRow == -1) lastVisualRow = d->model->rowCount(d->root) - 1; int firstVisualColumn = horizontalHeader->visualIndexAt(0); - int lastVisualColumn = horizontalHeader->visualIndexAt(horizontalHeader->viewport()->width()); + int lastVisualColumn = horizontalHeader->visualIndexAt(horizontalHeader->width()); if (rightToLeft) qSwap(firstVisualColumn, lastVisualColumn); if (firstVisualColumn == -1) diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index 11925af7a0..169cc5a17c 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -189,7 +189,7 @@ void QTableModel::setItem(int row, int column, QTableWidgetItem *item) sortedRow = qMax((int)(it - colItems.begin()), 0); } if (sortedRow != row) { - emit layoutAboutToBeChanged(); + emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); // move the items @ row to sortedRow int cc = columnCount(); QVector<QTableWidgetItem*> rowItems(cc); @@ -209,7 +209,7 @@ void QTableModel::setItem(int row, int column, QTableWidgetItem *item) changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes); - emit layoutChanged(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); return; } } @@ -480,6 +480,24 @@ bool QTableModel::setItemData(const QModelIndex &index, const QMap<int, QVariant return true; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QTableModel::clearItemData(const QModelIndex &index) +{ + if (!checkIndex(index, CheckIndexOption::IndexIsValid)) + return false; + QTableWidgetItem *itm = item(index); + if (!itm) + return false; + const auto beginIter = itm->values.cbegin(); + const auto endIter = itm->values.cend(); + if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); })) + return true; //it's already cleared + itm->values.clear(); + emit dataChanged(index, index, QVector<int>{}); + return true; +} +#endif + Qt::ItemFlags QTableModel::flags(const QModelIndex &index) const { if (!index.isValid()) @@ -530,12 +548,12 @@ void QTableModel::sort(int column, Qt::SortOrder order) } } - emit layoutAboutToBeChanged(); + emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); tableItems = sorted_table; changePersistentIndexList(from, to); // ### slow - emit layoutChanged(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); } /* @@ -580,7 +598,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order, vit = colItems.insert(vit, item); if (newRow != oldRow) { if (!changed) { - emit layoutAboutToBeChanged(); + emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); oldPersistentIndexes = persistentIndexList(); newPersistentIndexes = oldPersistentIndexes; changed = true; @@ -615,7 +633,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order, verticalHeaderItems = newVertical; changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes); - emit layoutChanged(); + emit layoutChanged({}, QAbstractItemModel::VerticalSortHint); } } diff --git a/src/widgets/itemviews/qtablewidget_p.h b/src/widgets/itemviews/qtablewidget_p.h index 9899272fce..d88326f129 100644 --- a/src/widgets/itemviews/qtablewidget_p.h +++ b/src/widgets/itemviews/qtablewidget_p.h @@ -129,6 +129,9 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool clearItemData(const QModelIndex &index) override; +#endif QMap<int, QVariant> itemData(const QModelIndex &index) const override; diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index a0af27115d..4768869843 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -390,6 +390,27 @@ bool QTreeModel::setData(const QModelIndex &index, const QVariant &value, int ro return false; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool QTreeModel::clearItemData(const QModelIndex &index) +{ + if (!checkIndex(index, CheckIndexOption::IndexIsValid)) + return false; + QTreeWidgetItem *itm = item(index); + if (!itm) + return false; + const auto beginIter = itm->values.at(index.column()).cbegin(); + const auto endIter = itm->values.at(index.column()).cend(); + if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); }) + && !itm->d->display.at(index.column()).isValid()) { + return true; //it's already cleared + } + itm->d->display[index.column()] = QVariant(); + itm->values[index.column()].clear(); + emit dataChanged(index, index, QVector<int>{}); + return true; +} +#endif + QMap<int, QVariant> QTreeModel::itemData(const QModelIndex &index) const { QMap<int, QVariant> roles; @@ -635,7 +656,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order, // we are going to change the persistent indexes, so we need to prepare if (!changed) { // this will only happen once changed = true; - emit layoutAboutToBeChanged(); // the selection model needs to know + emit layoutAboutToBeChanged({parent}, QAbstractItemModel::VerticalSortHint); // the selection model needs to know oldPersistentIndexes = persistentIndexList(); newPersistentIndexes = oldPersistentIndexes; } @@ -668,7 +689,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order, if (changed) { itm->children = lst; changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes); - emit layoutChanged(); + emit layoutChanged({parent}, QAbstractItemModel::VerticalSortHint); } } @@ -2164,9 +2185,9 @@ void QTreeWidgetItem::sortChildren(int column, Qt::SortOrder order, bool climb) QTreeModel::SkipSorting skipSorting(model); int oldSortColumn = view->d_func()->explicitSortColumn; view->d_func()->explicitSortColumn = column; - emit model->layoutAboutToBeChanged(); + emit model->layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint); d->sortChildren(column, order, climb); - emit model->layoutChanged(); + emit model->layoutChanged({}, QAbstractItemModel::VerticalSortHint); view->d_func()->explicitSortColumn = oldSortColumn; } diff --git a/src/widgets/itemviews/qtreewidget_p.h b/src/widgets/itemviews/qtreewidget_p.h index adc2c2c421..ee4a633468 100644 --- a/src/widgets/itemviews/qtreewidget_p.h +++ b/src/widgets/itemviews/qtreewidget_p.h @@ -99,7 +99,9 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; - +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool clearItemData(const QModelIndex &index) override; +#endif QMap<int, QVariant> itemData(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 3ee3e856bc..87d233f024 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -3067,7 +3067,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, } d->cachedOption = new QStyleOptionViewItem(*vopt); } - if (sr == SE_ViewItemCheckIndicator) + if (sr == SE_ItemViewItemCheckIndicator) r = d->checkRect; else if (sr == SE_ItemViewItemDecoration) r = d->decorationRect; diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 9192dae864..8256f908db 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -308,8 +308,8 @@ public: SE_TabWidgetLeftCorner, SE_TabWidgetRightCorner, - SE_ViewItemCheckIndicator, // ### Qt 6: remove - SE_ItemViewItemCheckIndicator = SE_ViewItemCheckIndicator, + SE_ItemViewItemCheckIndicator, + SE_ViewItemCheckIndicator = SE_ItemViewItemCheckIndicator, // ### Qt 6: remove SE_TabBarTearIndicator, SE_TabBarTearIndicatorLeft = SE_TabBarTearIndicator, diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index c2ffcc82b1..5c9d19a49d 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -44,6 +44,7 @@ #include "private/qcssutil_p.h" #include <qdebug.h> +#include <qdir.h> #include <qapplication.h> #if QT_CONFIG(menu) #include <qmenu.h> @@ -952,8 +953,12 @@ QRenderRule::QRenderRule(const QVector<Declaration> &declarations, const QObject Attachment attachment = Attachment_Scroll; origin = Origin_Padding; Origin clip = Origin_Border; - if (v.extractBackground(&brush, &uri, &repeat, &alignment, &origin, &attachment, &clip)) - bg = new QStyleSheetBackgroundData(brush, QPixmap(uri), repeat, alignment, origin, attachment, clip); + if (v.extractBackground(&brush, &uri, &repeat, &alignment, &origin, &attachment, &clip)) { + QPixmap pixmap(uri); + if (!uri.isEmpty() && pixmap.isNull()) + qWarning("Could not create pixmap from %s", qPrintable(QDir::toNativeSeparators(uri))); + bg = new QStyleSheetBackgroundData(brush, pixmap, repeat, alignment, origin, attachment, clip); + } QBrush sfg, fg; QBrush sbg, abg; @@ -5818,7 +5823,7 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c return ParentStyle::subElementRect(se, opt, w); #if QT_CONFIG(itemviews) - case SE_ViewItemCheckIndicator: + case SE_ItemViewItemCheckIndicator: if (!qstyleoption_cast<const QStyleOptionViewItem *>(opt)) { return subElementRect(SE_CheckBoxIndicator, opt, w); } |