51
63
const QModelIndex index = m_dolphinModel->indexForUrl(url);
52
64
return m_proxyModel->mapFromSource(index);
67
DolphinDetailsView* m_detailsView;
57
71
* This test verifies that DolphinDetailsView::expandedUrls() returns the right set of URLs.
58
* The test creates a folder hierarchy: 3 folders (a, b, c) contain 3 subfolders (also names a, b, c) each.
72
* The test creates a folder hierarchy: 3 folders (a, b, c) contain 3 subfolders (also named a, b, c) each.
59
73
* Each of those contains 3 further subfolders of the same name.
62
76
void DolphinDetailsViewTest::testExpandedUrls()
78
m_detailsView->setFoldersExpandable(true);
65
81
QStringList subFolderNames;
66
82
subFolderNames << "a" << "b" << "c";
76
92
createFiles(files);
78
m_view->setMode(DolphinView::DetailsView);
79
DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView());
81
detailsView->setFoldersExpandable(true);
82
m_view->resize(400, 400);
84
QTest::qWaitForWindowShown(m_view);
85
93
reloadViewAndWait();
87
95
// We start with an empty set of expanded URLs.
88
96
QSet<KUrl> expectedExpandedUrls;
89
QCOMPARE(detailsView->expandedUrls(), expectedExpandedUrls);
97
QCOMPARE(m_detailsView->expandedUrls(), expectedExpandedUrls);
91
99
// Every time we expand a folder, we have to wait until the view has finished loading
92
100
// its contents before we can expand further subfolders. We keep track of the reloading
151
156
for (int i = 0; i < 100; i++) {
152
157
createFile(QString("%1").arg(i));
155
m_view->setMode(DolphinView::DetailsView);
156
DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView());
157
QVERIFY(detailsView);
158
m_view->resize(1000, 400);
160
QTest::qWaitForWindowShown(m_view);
161
159
reloadViewAndWait();
163
161
// Select the first item
164
QModelIndex index0 = detailsView->model()->index(0, 0);
165
detailsView->setCurrentIndex(index0);
166
QCOMPARE(detailsView->currentIndex(), index0);
162
QModelIndex index0 = m_detailsView->model()->index(0, 0);
163
m_detailsView->setCurrentIndex(index0);
164
QCOMPARE(m_detailsView->currentIndex(), index0);
168
166
// Before we test Shift-selection, we verify that the root cause is fixed a bit more
169
167
// directly: we check that passing the corners or the center of an item's visualRect
170
168
// to itemAt() returns the item (and not an invalid model index).
171
QRect rect = detailsView->visualRect(index0);
172
QCOMPARE(detailsView->indexAt(rect.center()), index0);
173
QCOMPARE(detailsView->indexAt(rect.topLeft()), index0);
174
QCOMPARE(detailsView->indexAt(rect.topRight()), index0);
175
QCOMPARE(detailsView->indexAt(rect.bottomLeft()), index0);
176
QCOMPARE(detailsView->indexAt(rect.bottomRight()), index0);
169
QRect rect = m_detailsView->visualRect(index0);
170
QCOMPARE(m_detailsView->indexAt(rect.center()), index0);
171
QCOMPARE(m_detailsView->indexAt(rect.topLeft()), index0);
172
QCOMPARE(m_detailsView->indexAt(rect.topRight()), index0);
173
QCOMPARE(m_detailsView->indexAt(rect.bottomLeft()), index0);
174
QCOMPARE(m_detailsView->indexAt(rect.bottomRight()), index0);
178
176
// Another way to test this is to Ctrl-click the center of the visualRect.
179
177
// The selection state of the item should be toggled.
180
detailsView->clearSelection();
181
QItemSelectionModel* selectionModel = detailsView->selectionModel();
178
m_detailsView->clearSelection();
179
QItemSelectionModel* selectionModel = m_detailsView->selectionModel();
182
180
QCOMPARE(selectionModel->selectedIndexes().count(), 0);
184
QTest::mouseClick(detailsView->viewport(), Qt::LeftButton, Qt::ControlModifier, rect.center());
182
QTest::mouseClick(m_detailsView->viewport(), Qt::LeftButton, Qt::ControlModifier, rect.center());
185
183
QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
186
184
QCOMPARE(selectedIndexes.count(), 1);
187
185
QVERIFY(selectedIndexes.contains(index0));
194
192
while (current < 100) {
195
QTest::keyClick(detailsView->viewport(), Qt::Key_Down, Qt::ShiftModifier);
196
QModelIndex currentIndex = detailsView->model()->index(current, 0);
197
QCOMPARE(detailsView->currentIndex(), currentIndex);
193
QTest::keyClick(m_detailsView->viewport(), Qt::Key_Down, Qt::ShiftModifier);
194
QModelIndex currentIndex = m_detailsView->model()->index(current, 0);
195
QCOMPARE(m_detailsView->currentIndex(), currentIndex);
199
197
selectedIndexes = selectionModel->selectedIndexes();
200
198
QCOMPARE(selectedIndexes.count(), current + 1);
221
216
QStringList files;
222
217
files << "a" << "b" << "c" << "d";
223
219
createFiles(files);
225
m_view->setMode(DolphinView::DetailsView);
226
DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(itemView());
227
QVERIFY(detailsView);
228
m_view->resize(400, 400);
230
QTest::qWaitForWindowShown(m_view);
231
220
reloadViewAndWait();
233
QModelIndex index0 = detailsView->model()->index(0, 0);
234
detailsView->setCurrentIndex(index0);
235
QCOMPARE(detailsView->currentIndex(), index0);
222
QModelIndex index0 = m_detailsView->model()->index(0, 0);
223
m_detailsView->setCurrentIndex(index0);
224
QCOMPARE(m_detailsView->currentIndex(), index0);
237
226
// Setting the zoom level to the minimum value and triggering DolphinDetailsView::currentChanged(...)
238
227
// should make sure that the bug is triggered.
228
int zoomLevelBackup = m_view->zoomLevel();
239
229
int zoomLevel = ZoomLevelInfo::minimumLevel();
240
230
m_view->setZoomLevel(zoomLevel);
242
QModelIndex index1 = detailsView->model()->index(1, 0);
243
detailsView->setCurrentIndex(index1);
244
QCOMPARE(detailsView->currentIndex(), index1);
232
QModelIndex index1 = m_detailsView->model()->index(1, 0);
233
m_detailsView->setCurrentIndex(index1);
234
QCOMPARE(m_detailsView->currentIndex(), index1);
246
236
// Increase the zoom level successively to the maximum.
247
237
while(zoomLevel < ZoomLevelInfo::maximumLevel()) {
249
239
m_view->setZoomLevel(zoomLevel);
240
QCOMPARE(m_view->zoomLevel(), zoomLevel);
251
242
//Check for each zoom level that the height of each item is at least the icon size.
252
QVERIFY(detailsView->visualRect(index1).height() >= ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel));
243
QVERIFY(m_detailsView->visualRect(index1).height() >= ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel));
246
m_view->setZoomLevel(zoomLevelBackup);
250
* The width of the visualRect of an item is usually replaced by the width of the file name.
251
* However, if the file name is wider then the view's name column, this leads to problems with
252
* keyboard navigation if files with very long names are present in the current folder, see
254
* https://bugs.kde.org/show_bug.cgi?id=257401
256
* This test checks that the visualRect of an item is never wider than the "Name" column.
259
void DolphinDetailsViewTest::bug257401_longFilenamesKeyboardNavigation() {
261
for (int i = 0; i < 20; i++) {
262
name += "mmmmmmmmmm";
267
// Select the first item
268
QModelIndex index0 = m_detailsView->model()->index(0, 0);
269
m_detailsView->setCurrentIndex(index0);
270
QCOMPARE(m_detailsView->currentIndex(), index0);
271
QVERIFY(m_detailsView->visualRect(index0).width() < m_detailsView->columnWidth(DolphinModel::Name));
273
QItemSelectionModel* selectionModel = m_detailsView->selectionModel();
274
QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
275
QCOMPARE(selectedIndexes.count(), 1);
276
QVERIFY(selectedIndexes.contains(index0));
278
// Move down successively using the "Down" key and check that current item
279
// and selection are as expected.
280
for (int i = 0; i < 19; i++) {
281
QTest::keyClick(m_detailsView->viewport(), Qt::Key_Down, Qt::NoModifier);
282
QModelIndex currentIndex = m_detailsView->model()->index(i + 1, 0);
283
QCOMPARE(m_detailsView->currentIndex(), currentIndex);
284
QVERIFY(m_detailsView->visualRect(currentIndex).width() <= m_detailsView->columnWidth(DolphinModel::Name));
285
selectedIndexes = selectionModel->selectedIndexes();
286
QCOMPARE(selectedIndexes.count(), 1);
287
QVERIFY(selectedIndexes.contains(currentIndex));
259
291
QTEST_KDEMAIN(DolphinDetailsViewTest, GUI)
261
#include "dolphindetailsviewtest.moc"
b'\\ No newline at end of file'
293
#include "dolphindetailsviewtest.moc"