1 Star 0 Fork 19

Zhao Hang/qt5-qtbase

forked from src-anolis-os/qt5-qtbase 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
QTBUG-92583-fix-pagedown-behavior-and-pageup.patch 5.99 KB
一键复制 编辑 原始数据 按行查看 历史
xingwei-liu 提交于 2022-10-13 02:47 . !8 feature: add patchs for DDE
From: Tang Haixiang <[email protected]>
Date: Mon, May 31 13:24:30 2021 +0800
Subject: Fix PageDown behavior and PageUP
Upstream: https://codereview.qt-project.org/c/qt/qtbase/+/351728
---
Index: qtbase-opensource-src/src/widgets/itemviews/qlistview.cpp
===================================================================
--- qtbase-opensource-src.orig/src/widgets/itemviews/qlistview.cpp
+++ qtbase-opensource-src/src/widgets/itemviews/qlistview.cpp
@@ -1155,13 +1155,25 @@ QModelIndex QListView::moveCursor(Cursor
d->removeCurrentAndDisabled(&intersectVector, current);
}
return d->closestIndex(initialRect, intersectVector);
- case MovePageUp:
- // move current by (visibileRowCount - 1) items.
- // rect.translate(0, -rect.height()); will happen in the switch fallthrough for MoveUp.
- rect.moveTop(rect.top() - d->viewport->height() + 2 * rect.height());
- if (rect.top() < rect.height())
- rect.moveTop(rect.height());
- Q_FALLTHROUGH();
+ case MovePageUp: {
+ rect.moveTop(rect.top() - d->viewport->height() + 1 );
+ if (rect.top() < rect.height()) {
+ rect.setTop(0);
+ rect.setBottom(1);
+ }
+ QModelIndex findindex = current;
+ while (intersectVector.isEmpty()
+ || rectForIndex(findindex).top() <= (rectForIndex(current).bottom() - d->viewport->rect().height())
+ || rect.top() <= 0) {
+ rect.translate(0, 1);
+ if (rect.bottom() <= 0) {
+ return current;
+ }
+ intersectVector = d->intersectingSet(rect);
+ findindex = d->closestIndex(initialRect, intersectVector);
+ }
+ return findindex;
+ }
case MovePrevious:
case MoveUp:
while (intersectVector.isEmpty()) {
@@ -1184,13 +1196,26 @@ QModelIndex QListView::moveCursor(Cursor
d->removeCurrentAndDisabled(&intersectVector, current);
}
return d->closestIndex(initialRect, intersectVector);
- case MovePageDown:
- // move current by (visibileRowCount - 1) items.
- // rect.translate(0, rect.height()); will happen in the switch fallthrough for MoveDown.
- rect.moveTop(rect.top() + d->viewport->height() - 2 * rect.height());
- if (rect.bottom() > contents.height() - rect.height())
- rect.moveBottom(contents.height() - rect.height());
- Q_FALLTHROUGH();
+ case MovePageDown: {
+ rect.moveTop(rect.top() + d->viewport->height() - 1 );
+ if (rect.bottom() > contents.height() - rect.height()){
+ rect.setTop(contents.height() - 1);
+ rect.setBottom(contents.height());
+ }
+ QModelIndex index = current;
+ // index's bottom() - current's top() always <= (d->viewport->rect().height()
+ while (intersectVector.isEmpty()
+ || rectForIndex(index).bottom() >= (d->viewport->rect().height() + rectForIndex(current).top())
+ || rect.bottom() > contents.height()) {
+ rect.translate(0, -1);
+ if (rect.top() >= contents.height()) {
+ return current;
+ }
+ intersectVector = d->intersectingSet(rect);
+ index = d->closestIndex(initialRect, intersectVector);
+ }
+ return index;
+ }
case MoveNext:
case MoveDown:
while (intersectVector.isEmpty()) {
Index: qtbase-opensource-src/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
===================================================================
--- qtbase-opensource-src.orig/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ qtbase-opensource-src/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -93,6 +93,7 @@ private slots:
void moveCursor();
void moveCursor2();
void moveCursor3();
+ void moveCursor4();
void indexAt();
void clicked();
void singleSelectionRemoveRow();
@@ -559,6 +560,56 @@ void tst_QListView::moveCursor3()
QCOMPARE(view.selectionModel()->currentIndex(), model.index(0, 0));
}
+void tst_QListView::moveCursor4()
+{
+ int indexCount = 100;
+ PublicListView listView;
+ QStandardItemModel model;
+ for (int i = 0; i < 100; i++)
+ {
+ QStandardItem* item = new QStandardItem(QString("item 0%0").arg(i));
+ QFont font = item->font();
+ font.setPixelSize(14);
+ item->setFont(font);
+ model.appendRow(item);
+ }
+ QFont font = model.item(0)->font();
+ font.setPixelSize(50);
+ font.setBold(true);
+ model.item(0)->setFont(font);
+ listView.setModel(&model);
+ listView.setFixedSize(200, 200);
+ listView.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ listView.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ listView.show();
+ listView.selectionModel()->setCurrentIndex(model.index(0, 0), QItemSelectionModel::SelectCurrent);
+
+ QModelIndex idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+
+ int actualIndex = 0;
+ int indexHeight = 0;
+ while (indexHeight <= listView.viewport()->height()) {
+ indexHeight += listView.visualRect(model.item(actualIndex)->index()).height();
+ actualIndex++;
+ }
+ QTRY_COMPARE(idx, model.index(actualIndex - 2, 0));
+ idx = listView.moveCursor(PublicListView::MoveUp, Qt::NoModifier);
+ QTRY_COMPARE(idx, model.index(0, 0));
+
+ listView.setCurrentIndex(model.index(indexCount - 2, 0));
+ idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+ QTRY_COMPARE(idx, model.index(99, 0));
+
+ listView.setCurrentIndex(model.index(3, 0));
+ actualIndex = 3;
+ indexHeight = 0;
+ while (indexHeight <= listView.viewport()->height()) {
+ indexHeight += listView.visualRect(model.item(actualIndex)->index()).height();
+ actualIndex++;
+ }
+ idx = listView.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+ QTRY_COMPARE(idx, model.index(actualIndex - 2, 0));
+}
class QListViewShowEventListener : public QListView
{
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhaohang_mskdxl/qt5-qtbase.git
[email protected]:zhaohang_mskdxl/qt5-qtbase.git
zhaohang_mskdxl
qt5-qtbase
qt5-qtbase
a8

搜索帮助