summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@theqtcompany.com>2014-10-23 10:30:39 +0200
committerThorbjørn Lund Martsum <tmartsum@gmail.com>2014-11-29 15:21:48 +0100
commitf9408317e70bc2e635a2f9baeff35d1c06227734 (patch)
tree27c91a72faee001c62e9ded59b88666733502e40 /tests/manual
parent62bf16d99278374d54670691ea0cdcd562f00ecf (diff)
Auto-scroll while selecting entire rows/columns did not work
If you press and hold a section in a header view you can extend the selection to more rows by moving the mouse. This worked fine until you moved the mouse outside the geometry of the header view. The expected behavior was then to scroll the view (this is what happens with extended selections on regular table cells). [ChangeLog][QtWidgets][QHeaderView] Auto-scroll the view when making extended row/column selections. Change-Id: Ic65aa34d370e74054b2123ab57edb1add0e8adb9 Task-number: QTBUG-21201 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp163
1 files changed, 152 insertions, 11 deletions
diff --git a/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp b/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp
index cfe24a25da..e01e2cec5e 100644
--- a/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp
+++ b/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp
@@ -33,6 +33,148 @@
#include <QtWidgets/QtWidgets>
+struct ManualTask {
+ const char *title;
+ const char *instructions;
+ unsigned sectionsMovable : 1;
+ unsigned selectionMode : 3;
+};
+
+ManualTask tasks[] = {
+{ QT_TR_NOOP("0. Default"),
+ "Please provide instructions",
+ true, QAbstractItemView::SingleSelection
+},
+{ QT_TR_NOOP("1. Autoscroll"),
+ "<ol>"
+ "<li>Press and hold on section 9 of vertical header.<br/>"
+ "<em>(all cells in the row will be selected)</em>"
+ "</li>"
+ "<li>Extend the selection by moving the mouse down.<br/>"
+ "<em>(selection will extend to the next rows)</em>"
+ "</li>"
+ "<li>Continue to move the mouse down and outside the window geometry.<br/>"
+ "<em>(The view should scroll automatically and the selection should still extend)</em>"
+ "</li>"
+ "<li>While still holding the button, do the same in the opposite direction, i.e. move mouse up and outside the window geometry.<br/>"
+ "<em>(Verify that the view scrolls automatically and the selection changes)</em>"
+ "</li>"
+ "<li>Verify that it works in the other dimension, i.e Press and hold section 9 of the horizontal header.<br/>"
+ "<em>All cells in the column will be selected</em>"
+ "</li>"
+ "<li>Extend the selection by moving the mouse to the far right and outside the window geometry.<br/>"
+ "<em>(selection will extend to the next columns)</em>"
+ "</li>"
+ "<li>Verify that it works in the opposite direction (i.e. move mouse to the left of the window geometry).<br/>"
+ "<em>(Verify that the view scrolls automatically and the selection changes)</em>"
+ "</li>"
+ "</ol>",
+ false, QAbstractItemView::ExtendedSelection
+}
+
+};
+
+
+class Window : public QWidget
+{
+ Q_OBJECT
+public:
+ Window(QWidget *parent = 0): QWidget(parent), ckMovable(0), tableView(0), cbSelectionMode(0), m_taskInstructions(0)
+ {
+ m_taskInstructions = new QLabel();
+ if (sizeof(tasks) > 0)
+ m_taskInstructions->setText(tr(tasks[0].instructions));
+
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ vbox->addLayout(setupComboBox());
+ vbox->addWidget(setupGroupBox());
+ vbox->addWidget(setupTableView());
+ vbox->addWidget(m_taskInstructions);
+ }
+
+ void updateControls()
+ {
+ ckMovable->setChecked(tableView->verticalHeader()->sectionsMovable());
+ QAbstractItemView::SelectionMode sMode = tableView->selectionMode();
+ cbSelectionMode->setCurrentIndex((int)sMode);
+ }
+
+private:
+ QFormLayout *setupComboBox()
+ {
+ QComboBox *combo = new QComboBox;
+ for (size_t i = 0; i < sizeof(tasks) / sizeof(tasks[0]); ++i) {
+ combo->addItem(tr(tasks[i].title));
+ }
+
+ connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_taskCombo_currentIndexChanged(int)));
+ QFormLayout *form = new QFormLayout;
+ form->addRow(tr("Choose task:"), combo);
+ return form;
+ }
+
+ QGroupBox *setupGroupBox()
+ {
+ QGroupBox *grp = new QGroupBox(tr("Properties"));
+ QFormLayout *form = new QFormLayout;
+ grp->setLayout(form);
+ ckMovable = new QCheckBox;
+ ckMovable->setObjectName(QLatin1String("ckMovable"));
+ connect(ckMovable, SIGNAL(toggled(bool)), this, SLOT(on_ckMovable_toggled(bool)));
+ form->addRow(tr("SectionsMovable"), ckMovable);
+
+ cbSelectionMode = new QComboBox;
+ cbSelectionMode->setObjectName(QLatin1String("cbSelectionMode"));
+ cbSelectionMode->addItems(QStringList() << QLatin1String("NoSelection")
+ << QLatin1String("SingleSelection")
+ << QLatin1String("MultiSelection")
+ << QLatin1String("ExtendedSelection")
+ << QLatin1String("ContiguousSelection")
+ );
+
+ connect(cbSelectionMode, SIGNAL(currentIndexChanged(int)), this, SLOT(on_cbSelectionMode_currentIndexChanged(int)));
+ form->addRow(tr("SelectionMode"), cbSelectionMode);
+ return grp;
+ }
+
+ QTableView *setupTableView()
+ {
+ tableView = new QTableView;
+ m.setRowCount(500);
+ m.setColumnCount(250);
+ tableView->setSelectionMode(QAbstractItemView::SingleSelection);
+ tableView->setModel(&m);
+ return tableView;
+ }
+
+private Q_SLOTS:
+ void on_ckMovable_toggled(bool arg)
+ {
+ tableView->verticalHeader()->setSectionsMovable(arg);
+ tableView->horizontalHeader()->setSectionsMovable(arg);
+ }
+
+ void on_cbSelectionMode_currentIndexChanged(int idx)
+ {
+ tableView->setSelectionMode((QAbstractItemView::SelectionMode)idx);
+ }
+
+ void on_taskCombo_currentIndexChanged(int idx)
+ {
+ ManualTask &task = tasks[idx];
+ m_taskInstructions->setText(tr(task.instructions));
+ ckMovable->setChecked(task.sectionsMovable);
+ cbSelectionMode->setCurrentIndex((QAbstractItemView::SelectionMode)task.selectionMode);
+ }
+
+public:
+ QCheckBox *ckMovable;
+ QTableView *tableView;
+ QStandardItemModel m;
+ QComboBox *cbSelectionMode;
+ QLabel *m_taskInstructions;
+};
+
class SomeHandler : public QObject
{
Q_OBJECT
@@ -86,19 +228,18 @@ void SomeHandler::slotSectionResized(int logsection, int oldsize, int newsize)
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QTableView tv;
- QStandardItemModel m;
- m.setRowCount(500);
- m.setColumnCount(250);
- tv.setModel(&m);
- tv.setSelectionMode(QAbstractItemView::SingleSelection);
+ Window window;
// Comment in the line below to test selection with keyboard (space)
// tv.setEditTriggers(QAbstractItemView::NoEditTriggers);
- SomeHandler handler(tv.horizontalHeader(), &tv);
- tv.horizontalHeader()->setDefaultSectionSize(30);
- tv.show();
- tv.horizontalHeader()->setSectionsMovable(true);
- tv.verticalHeader()->setSectionsMovable(true);
+ QHeaderView *hHeader = window.tableView->horizontalHeader();
+ QHeaderView *vHeader = window.tableView->verticalHeader();
+ SomeHandler handler(hHeader, window.tableView);
+ hHeader->setDefaultSectionSize(30);
+ window.resize(600, 600);
+ window.show();
+ hHeader->setSectionsMovable(true);
+ vHeader->setSectionsMovable(true);
+ window.updateControls();
app.exec();
}
#include "qheaderviewtest1.moc"