From 0a6257bce3de877e4ae869f974df645c428d32c9 Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Sat, 18 Oct 2014 15:00:17 +0200 Subject: Fix includes --- src/tests/kfileitemmodeltest.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index c584c5e62..3d505c766 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -20,7 +20,6 @@ #include -#include #include #include "kitemviews/kfileitemmodel.h" -- cgit v1.3 From d9d7926c49c097fd1f5b72576e2c84c3989e89e7 Mon Sep 17 00:00:00 2001 From: Lukáš Tinkl Date: Tue, 21 Oct 2014 00:27:42 +0200 Subject: port Konqueror from KUrl to QUrl REVIEW: 120650 --- src/CMakeLists.txt | 2 +- src/dolphinapplication.cpp | 2 +- src/dolphinmainwindow.cpp | 4 +-- src/dolphinmainwindow.h | 4 +-- src/dolphinpart.cpp | 16 ++++----- src/dolphinpart.h | 12 +++---- src/dolphintabpage.cpp | 6 ++-- src/dolphintabpage.h | 6 ++-- src/dolphintabwidget.cpp | 14 ++++---- src/dolphintabwidget.h | 8 ++--- src/kitemviews/kfileitemmodel.cpp | 24 ++++++------- src/kitemviews/kfileitemmodel.h | 26 +++++++------- src/tests/kfileitemmodeltest.cpp | 75 +++++++++++++++++++++------------------ src/views/dolphinview.cpp | 34 +++++++++--------- src/views/dolphinview.h | 18 +++++----- 15 files changed, 129 insertions(+), 122 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 339c1e5f8..c07490805 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,7 +138,7 @@ target_link_libraries(dolphinpart install(TARGETS dolphinpart DESTINATION ${PLUGIN_INSTALL_DIR}) -install(FILES dolphinpart.rc DESTINATION ${DATA_INSTALL_DIR}/dolphinpart) +install(FILES dolphinpart.rc DESTINATION ${CMAKE_INSTALL_KXMLGUI5DIR}/dolphinpart) install(FILES dolphinpart.desktop DESTINATION ${SERVICES_INSTALL_DIR}) install(FILES views/versioncontrol/fileviewversioncontrolplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) diff --git a/src/dolphinapplication.cpp b/src/dolphinapplication.cpp index 8a6b4cc03..8d4af66df 100644 --- a/src/dolphinapplication.cpp +++ b/src/dolphinapplication.cpp @@ -39,7 +39,7 @@ DolphinApplication::DolphinApplication() : const int argsCount = args->count(); - QList urls; + QList urls; for (int i = 0; i < argsCount; ++i) { const KUrl url = args->url(i); if (url.isValid()) { diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 3f83d054b..1053f15b6 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -172,12 +172,12 @@ DolphinMainWindow::~DolphinMainWindow() { } -void DolphinMainWindow::openDirectories(const QList& dirs) +void DolphinMainWindow::openDirectories(const QList& dirs) { m_tabWidget->openDirectories(dirs); } -void DolphinMainWindow::openFiles(const QList& files) +void DolphinMainWindow::openFiles(const QList& files) { m_tabWidget->openFiles(files); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 0505037ce..893394abc 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -76,14 +76,14 @@ public: * Opens each directory in \p dirs in a separate tab. If the "split view" * option is enabled, 2 directories are collected within one tab. */ - void openDirectories(const QList& dirs); + void openDirectories(const QList &dirs); /** * Opens the directory which contains the files \p files * and selects all files (implements the --select option * of Dolphin). */ - void openFiles(const QList& files); + void openFiles(const QList& files); /** * Returns the 'Create New...' sub menu which also can be shared diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 6f84ab1d8..8146fce28 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "dolphinpart_ext.h" #include "dolphinnewfilemenu.h" @@ -66,8 +67,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL ,m_removeAction(0) { Q_UNUSED(args) -#pragma message("TODO: port to KF5") - //setComponentData(DolphinPartFactory::componentData(), false); + setComponentData(*createAboutData(), false); m_extension = new DolphinPartBrowserExtension(this); // make sure that other apps using this part find Dolphin's view-file-columns icons @@ -381,7 +381,7 @@ void DolphinPart::slotItemsActivated(const KFileItemList& items) } } -void DolphinPart::createNewWindow(const KUrl& url) +void DolphinPart::createNewWindow(const QUrl& url) { // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code // should be moved into DolphinPart::slotItemActivated() @@ -390,7 +390,7 @@ void DolphinPart::createNewWindow(const KUrl& url) void DolphinPart::slotOpenContextMenu(const QPoint& pos, const KFileItem& _item, - const KUrl&, + const QUrl &, const QList& customActions) { KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::DefaultPopupItems @@ -471,12 +471,12 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos, actionGroups); } -void DolphinPart::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl) +void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl) { //kDebug() << oldUrl << newUrl << "currentUrl=" << url(); - if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash /* #207572 */)) { + if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) { KParts::ReadOnlyPart::setUrl(newUrl); - const QString prettyUrl = newUrl.pathOrUrl(); + const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile); emit m_extension->setLocationBarUrl(prettyUrl); } } @@ -585,7 +585,7 @@ void DolphinPart::createDirectory() m_newFileMenu->createDirectory(); } -void DolphinPart::setFilesToSelect(const KUrl::List& files) +void DolphinPart::setFilesToSelect(const QList& files) { if (files.isEmpty()) { return; diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 18ea0bfbf..56e049b22 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -50,7 +50,7 @@ class DolphinPart : public KParts::ReadOnlyPart Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter ) // Used by konqueror to implement the --select command-line option - Q_PROPERTY( KUrl::List filesToSelect READ filesToSelect WRITE setFilesToSelect ) + Q_PROPERTY( QList filesToSelect READ filesToSelect WRITE setFilesToSelect ) public: explicit DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantList& args); @@ -131,7 +131,7 @@ private Q_SLOTS: /** * Creates a new window showing the content of \a url. */ - void createNewWindow(const KUrl& url); + void createNewWindow(const QUrl &url); /** * Opens the context menu on the current mouse position. * @pos Position in screen coordinates. @@ -143,7 +143,7 @@ private Q_SLOTS: */ void slotOpenContextMenu(const QPoint& pos, const KFileItem& item, - const KUrl& url, + const QUrl& url, const QList& customActions); /** @@ -152,7 +152,7 @@ private Q_SLOTS: * Testcase 1: fish://localhost * Testcase 2: showing a directory that is being renamed by another window (#180156) */ - void slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl); + void slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl); /** * Updates the state of the 'Edit' menu actions and emits @@ -220,8 +220,8 @@ private Q_SLOTS: /** * Called by konqueror --select */ - void setFilesToSelect(const KUrl::List& files); - KUrl::List filesToSelect() const { return KUrl::List(); } // silence moc + void setFilesToSelect(const QList &files); + QList filesToSelect() const { return QList(); } // silence moc virtual bool eventFilter(QObject*, QEvent*); diff --git a/src/dolphintabpage.cpp b/src/dolphintabpage.cpp index 763cd8f94..2d02ff049 100644 --- a/src/dolphintabpage.cpp +++ b/src/dolphintabpage.cpp @@ -25,7 +25,7 @@ #include #include -DolphinTabPage::DolphinTabPage(const KUrl& primaryUrl, const KUrl& secondaryUrl, QWidget* parent) : +DolphinTabPage::DolphinTabPage(const QUrl &primaryUrl, const QUrl &secondaryUrl, QWidget* parent) : QWidget(parent), m_primaryViewActive(true), m_splitViewEnabled(false) @@ -135,7 +135,7 @@ int DolphinTabPage::selectedItemsCount() const return selectedItemsCount; } -void DolphinTabPage::markUrlsAsSelected(const QList& urls) +void DolphinTabPage::markUrlsAsSelected(const QList& urls) { m_primaryViewContainer->view()->markUrlsAsSelected(urls); if (m_splitViewEnabled) { @@ -143,7 +143,7 @@ void DolphinTabPage::markUrlsAsSelected(const QList& urls) } } -void DolphinTabPage::markUrlAsCurrent(const KUrl& url) +void DolphinTabPage::markUrlAsCurrent(const QUrl& url) { m_primaryViewContainer->view()->markUrlAsCurrent(url); if (m_splitViewEnabled) { diff --git a/src/dolphintabpage.h b/src/dolphintabpage.h index 2a406f4a9..e4a5ad6c7 100644 --- a/src/dolphintabpage.h +++ b/src/dolphintabpage.h @@ -33,7 +33,7 @@ class DolphinTabPage : public QWidget Q_OBJECT public: - explicit DolphinTabPage(const KUrl& primaryUrl, const KUrl& secondaryUrl = KUrl(), QWidget* parent = 0); + explicit DolphinTabPage(const QUrl& primaryUrl, const QUrl& secondaryUrl = KUrl(), QWidget* parent = 0); /** * @return True if primary view is the active view in this tab. @@ -85,13 +85,13 @@ public: * gets selected if no loading of a directory has been triggered * by DolphinView::setUrl() or DolphinView::reload(). */ - void markUrlsAsSelected(const QList& urls); + void markUrlsAsSelected(const QList &urls); /** * Marks the item indicated by \p url to be scrolled to and as the * current item after directory DolphinView::url() has been loaded. */ - void markUrlAsCurrent(const KUrl& url); + void markUrlAsCurrent(const QUrl& url); /** * Sets the places selector visible, if \a visible is true. diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index 42a8aff09..65cc824f0 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -136,7 +136,7 @@ void DolphinTabWidget::openNewActivatedTab(const KUrl& primaryUrl, const KUrl& s setCurrentIndex(count() - 1); } -void DolphinTabWidget::openNewTab(const KUrl& primaryUrl, const KUrl& secondaryUrl) +void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl) { QWidget* focusWidget = QApplication::focusWidget(); @@ -155,17 +155,17 @@ void DolphinTabWidget::openNewTab(const KUrl& primaryUrl, const KUrl& secondaryU } } -void DolphinTabWidget::openDirectories(const QList& dirs) +void DolphinTabWidget::openDirectories(const QList& dirs) { const bool hasSplitView = GeneralSettings::splitView(); // Open each directory inside a new tab. If the "split view" option has been enabled, // always show two directories within one tab. - QList::const_iterator it = dirs.constBegin(); + QList::const_iterator it = dirs.constBegin(); while (it != dirs.constEnd()) { - const KUrl& primaryUrl = *(it++); + const QUrl& primaryUrl = *(it++); if (hasSplitView && (it != dirs.constEnd())) { - const KUrl& secondaryUrl = *(it++); + const QUrl& secondaryUrl = *(it++); openNewTab(primaryUrl, secondaryUrl); } else { openNewTab(primaryUrl); @@ -173,7 +173,7 @@ void DolphinTabWidget::openDirectories(const QList& dirs) } } -void DolphinTabWidget::openFiles(const QList& files) +void DolphinTabWidget::openFiles(const QList& files) { if (files.isEmpty()) { return; @@ -182,7 +182,7 @@ void DolphinTabWidget::openFiles(const QList& files) // Get all distinct directories from 'files' and open a tab // for each directory. If the "split view" option is enabled, two // directories are shown inside one tab (see openDirectories()). - QList dirs; + QList dirs; foreach (const KUrl& url, files) { const KUrl dir(url.directory()); if (!dirs.contains(dir)) { diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h index 98bcd985a..c5ab8c260 100644 --- a/src/dolphintabwidget.h +++ b/src/dolphintabwidget.h @@ -95,20 +95,20 @@ public slots: * Opens a new tab in the background showing the URL \a primaryUrl and the * optional URL \a secondaryUrl. */ - void openNewTab(const KUrl& primaryUrl, const KUrl& secondaryUrl = KUrl()); + void openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl = KUrl()); /** * Opens each directory in \p dirs in a separate tab. If the "split view" * option is enabled, 2 directories are collected within one tab. */ - void openDirectories(const QList& dirs); + void openDirectories(const QList& dirs); /** * Opens the directory which contains the files \p files * and selects all files (implements the --select option * of Dolphin). */ - void openFiles(const QList& files); + void openFiles(const QList &files); /** * Closes the currently active tab. @@ -187,4 +187,4 @@ private: bool m_placesSelectorVisible; }; -#endif \ No newline at end of file +#endif diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 489e4edb4..524b4f59a 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -116,15 +116,15 @@ KFileItemModel::~KFileItemModel() qDeleteAll(m_pendingItemsToInsert); } -void KFileItemModel::loadDirectory(const KUrl& url) +void KFileItemModel::loadDirectory(const QUrl &url) { m_dirLister->openUrl(url); } -void KFileItemModel::refreshDirectory(const KUrl& url) +void KFileItemModel::refreshDirectory(const QUrl &url) { // Refresh all expanded directories first (Bug 295300) - QHashIterator expandedDirs(m_expandedDirs); + QHashIterator expandedDirs(m_expandedDirs); while (expandedDirs.hasNext()) { expandedDirs.next(); m_dirLister->openUrl(expandedDirs.value(), KDirLister::Reload); @@ -133,7 +133,7 @@ void KFileItemModel::refreshDirectory(const KUrl& url) m_dirLister->openUrl(url, KDirLister::Reload); } -KUrl KFileItemModel::directory() const +QUrl KFileItemModel::directory() const { return m_dirLister->url(); } @@ -353,7 +353,7 @@ KFileItem KFileItemModel::fileItem(int index) const return KFileItem(); } -KFileItem KFileItemModel::fileItem(const KUrl& url) const +KFileItem KFileItemModel::fileItem(const QUrl &url) const { const int indexForUrl = index(url); if (indexForUrl >= 0) { @@ -364,10 +364,10 @@ KFileItem KFileItemModel::fileItem(const KUrl& url) const int KFileItemModel::index(const KFileItem& item) const { - return index(KUrl(item.url())); + return index(item.url()); } -int KFileItemModel::index(const KUrl& url) const +int KFileItemModel::index(const QUrl& url) const { KUrl urlToFind = url; urlToFind.adjustPath(KUrl::RemoveTrailingSlash); @@ -592,17 +592,17 @@ int KFileItemModel::expandedParentsCount(int index) const return 0; } -QSet KFileItemModel::expandedDirectories() const +QSet KFileItemModel::expandedDirectories() const { return m_expandedDirs.values().toSet(); } -void KFileItemModel::restoreExpandedDirectories(const QSet& urls) +void KFileItemModel::restoreExpandedDirectories(const QSet &urls) { m_urlsToExpand = urls; } -void KFileItemModel::expandParentDirectories(const KUrl& url) +void KFileItemModel::expandParentDirectories(const QUrl &url) { const int pos = m_dirLister->url().path().length(); @@ -620,7 +620,7 @@ void KFileItemModel::expandParentDirectories(const KUrl& url) // KDirLister::open() must called at least once to trigger an initial // loading. The pending URLs that must be restored are handled // in slotCompleted(). - QSetIterator it2(m_urlsToExpand); + QSetIterator it2(m_urlsToExpand); while (it2.hasNext()) { const int idx = index(it2.next()); if (idx >= 0 && !isExpanded(idx)) { @@ -898,7 +898,7 @@ void KFileItemModel::slotCanceled() emit directoryLoadingCanceled(); } -void KFileItemModel::slotItemsAdded(const KUrl& directoryUrl, const KFileItemList& items) +void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemList& items) { Q_ASSERT(!items.isEmpty()); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index 62a283d33..aea0341ea 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -56,13 +56,13 @@ public: * indicate the current state of the loading process. The items * of the directory are added after the loading has been completed. */ - void loadDirectory(const KUrl& url); + void loadDirectory(const QUrl& url); /** * Throws away all currently loaded items and refreshes the directory * by reloading all items again. */ - void refreshDirectory(const KUrl& url); + void refreshDirectory(const QUrl& url); /** * @return Parent directory of the items that are shown. In case @@ -70,7 +70,7 @@ public: * the root-parent of all items. * @see rootItem() */ - KUrl directory() const; + QUrl directory() const; /** * Cancels the loading of a directory which has been started by either @@ -126,7 +126,7 @@ public: * URL is found KFileItem::isNull() will be true for the returned * file-item. The runtime complexity of this call is O(1). */ - KFileItem fileItem(const KUrl& url) const; + KFileItem fileItem(const QUrl& url) const; /** * @return The index for the file-item \a item. -1 is returned if no file-item @@ -139,7 +139,7 @@ public: * @return The index for the URL \a url. -1 is returned if no file-item * is found. The amortized runtime complexity of this call is O(1). */ - int index(const KUrl& url) const; + int index(const QUrl &url) const; /** * @return Root item of all items representing the item @@ -163,19 +163,19 @@ public: virtual bool isExpandable(int index) const; virtual int expandedParentsCount(int index) const; - QSet expandedDirectories() const; + QSet expandedDirectories() const; /** * Marks the URLs in \a urls as sub-directories which were expanded previously. * After calling loadDirectory() or refreshDirectory() the marked sub-directories * will be expanded step-by-step. */ - void restoreExpandedDirectories(const QSet& urls); + void restoreExpandedDirectories(const QSet& urls); /** * Expands all parent-directories of the item \a url. */ - void expandParentDirectories(const KUrl& url); + void expandParentDirectories(const QUrl& url); void setNameFilter(const QString& nameFilter); QString nameFilter() const; @@ -251,13 +251,13 @@ signals: * Is emitted if a redirection from the current URL \a oldUrl * to the new URL \a newUrl has been done. */ - void directoryRedirection(const KUrl& oldUrl, const KUrl& newUrl); + void directoryRedirection(const QUrl& oldUrl, const QUrl& newUrl); /** * Is emitted when the URL passed by KFileItemModel::setUrl() represents a file. * In this case no signal errorMessage() will be emitted. */ - void urlIsFileError(const KUrl& url); + void urlIsFileError(const QUrl& url); protected: virtual void onGroupedSortingChanged(bool current); @@ -273,7 +273,7 @@ private slots: void slotCompleted(); void slotCanceled(); - void slotItemsAdded(const KUrl& directoryUrl, const KFileItemList& items); + void slotItemsAdded(const QUrl& directoryUrl, const KFileItemList& items); void slotItemsDeleted(const KFileItemList& items); void slotRefreshItems(const QList >& items); void slotClear(); @@ -489,11 +489,11 @@ private: mutable QList > m_groups; // Stores the URLs (key: target url, value: url) of the expanded directories. - QHash m_expandedDirs; + QHash m_expandedDirs; // URLs that must be expanded. The expanding is initially triggered in setExpanded() // and done step after step in slotCompleted(). - QSet m_urlsToExpand; + QSet m_urlsToExpand; friend class KFileItemModelLessThan; // Accesses lessThan() method friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 3d505c766..758699dad 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -404,8 +404,9 @@ void KFileItemModelTest::testResortAfterChangingName() // We rename d.txt back to a.txt using the dir lister's refreshItems() signal. const KFileItem fileItemD = m_model->fileItem(2); KFileItem fileItemA = fileItemD; - KUrl urlA = fileItemA.url(); - urlA.setFileName("a.txt"); + QUrl urlA = fileItemA.url(); + urlA.adjusted(QUrl::RemoveFilename); + urlA.setPath(urlA.path() + "a.txt"); fileItemA.setUrl(urlA); m_model->slotRefreshItems(QList >() << qMakePair(fileItemD, fileItemA)); @@ -516,8 +517,10 @@ void KFileItemModelTest::testExpandItems() m_testDir->createFiles(files); // Store the URLs of all folders in a set. - QSet allFolders; - allFolders << KUrl(m_testDir->name() + 'a') << KUrl(m_testDir->name() + "a/a") << KUrl(m_testDir->name() + "a/a-1"); + QSet allFolders; + allFolders << QUrl::fromLocalFile(m_testDir->name() + 'a') + << QUrl::fromLocalFile(m_testDir->name() + "a/a") + << QUrl::fromLocalFile(m_testDir->name() + "a/a-1"); m_model->loadDirectory(m_testDir->url()); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); @@ -535,7 +538,7 @@ void KFileItemModelTest::testExpandItems() QVERIFY(m_model->isExpanded(0)); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/a/", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet() << KUrl(m_testDir->name() + 'a')); + QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl(m_testDir->name() + 'a')); QCOMPARE(spyInserted.count(), 1); KItemRangeList itemRangeList = spyInserted.takeFirst().at(0).value(); @@ -551,7 +554,7 @@ void KFileItemModelTest::testExpandItems() QVERIFY(m_model->isExpanded(1)); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); QCOMPARE(m_model->count(), 4); // 4 items: "a/", "a/a/", "a/a/1", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet() << KUrl(m_testDir->name() + 'a') << KUrl(m_testDir->name() + "a/a")); + QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl(m_testDir->name() + 'a') << QUrl(m_testDir->name() + "a/a")); QCOMPARE(spyInserted.count(), 1); itemRangeList = spyInserted.takeFirst().at(0).value(); @@ -580,7 +583,7 @@ void KFileItemModelTest::testExpandItems() m_model->setExpanded(0, false); QVERIFY(!m_model->isExpanded(0)); QCOMPARE(m_model->count(), 1); - QVERIFY(!m_model->expandedDirectories().contains(KUrl(m_testDir->name() + 'a'))); // TODO: Make sure that child URLs are also removed + QVERIFY(!m_model->expandedDirectories().contains(QUrl(m_testDir->name() + 'a'))); // TODO: Make sure that child URLs are also removed QCOMPARE(spyRemoved.count(), 1); itemRangeList = spyRemoved.takeFirst().at(0).value(); @@ -606,7 +609,7 @@ void KFileItemModelTest::testExpandItems() // Move to a sub folder, then call restoreExpandedFolders() *before* going back. // This is how DolphinView restores the expanded folders when navigating in history. - m_model->loadDirectory(KUrl(m_testDir->name() + "a/a/")); + m_model->loadDirectory(QUrl(m_testDir->name() + "a/a/")); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); QCOMPARE(m_model->count(), 1); // 1 item: "1" m_model->restoreExpandedDirectories(allFolders); @@ -620,7 +623,7 @@ void KFileItemModelTest::testExpandItems() m_model->setRoles(originalModelRoles); QVERIFY(!m_model->isExpanded(0)); QCOMPARE(m_model->count(), 1); - QVERIFY(!m_model->expandedDirectories().contains(KUrl(m_testDir->name() + 'a'))); + QVERIFY(!m_model->expandedDirectories().contains(QUrl(m_testDir->name() + 'a'))); QCOMPARE(spyRemoved.count(), 1); itemRangeList = spyRemoved.takeFirst().at(0).value(); @@ -654,7 +657,7 @@ void KFileItemModelTest::testExpandParentItems() QVERIFY(m_model->expandedDirectories().empty()); // Expand the parents of "a2/b2/c2". - m_model->expandParentDirectories(KUrl(m_testDir->name() + "a2/b2/c2")); + m_model->expandParentDirectories(QUrl(m_testDir->name() + "a2/b2/c2")); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); // The model should now contain "a 1/", "a2/", "a2/b2/", and "a2/b2/c2/". @@ -666,7 +669,7 @@ void KFileItemModelTest::testExpandParentItems() QVERIFY(!m_model->isExpanded(3)); // Expand the parents of "a 1/b1". - m_model->expandParentDirectories(KUrl(m_testDir->name() + "a 1/b1")); + m_model->expandParentDirectories(QUrl(m_testDir->name() + "a 1/b1")); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); // The model should now contain "a 1/", "a 1/b1/", "a2/", "a2/b2", and "a2/b2/c2/". @@ -822,11 +825,11 @@ void KFileItemModelTest::testSorting() m_model->loadDirectory(m_testDir->url()); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); - int index = m_model->index(KUrl(m_testDir->url().url() + 'c')); + int index = m_model->index(QUrl(m_testDir->url().url() + 'c')); m_model->setExpanded(index, true); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); - index = m_model->index(KUrl(m_testDir->url().url() + "c/c-2")); + index = m_model->index(QUrl(m_testDir->url().url() + "c/c-2")); m_model->setExpanded(index, true); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); @@ -1021,10 +1024,10 @@ void KFileItemModelTest::testEmptyPath() roles.insert("expandedParentsCount"); m_model->setRoles(roles); - const KUrl emptyUrl; + const QUrl emptyUrl; QVERIFY(emptyUrl.path().isEmpty()); - const KUrl url("file:///test/"); + const QUrl url("file:///test/"); KFileItemList items; items << KFileItem(emptyUrl, QString(), KFileItem::Unknown) << KFileItem(url, QString(), KFileItem::Unknown); @@ -1251,28 +1254,28 @@ void KFileItemModelTest::testGeneralParentChildRelationships() QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2" << "realGrandChild2"); // Add some more children and grand-children. - const KUrl parent1 = m_model->fileItem(0).url(); - const KUrl parent2 = m_model->fileItem(3).url(); - const KUrl realChild1 = m_model->fileItem(1).url(); - const KUrl realChild2 = m_model->fileItem(4).url(); + const QUrl parent1 = m_model->fileItem(0).url(); + const QUrl parent2 = m_model->fileItem(3).url(); + const QUrl realChild1 = m_model->fileItem(1).url(); + const QUrl realChild2 = m_model->fileItem(4).url(); - m_model->slotItemsAdded(parent1, KFileItemList() << KFileItem(KUrl("child1"), QString(), KFileItem::Unknown)); + m_model->slotItemsAdded(parent1, KFileItemList() << KFileItem(QUrl("child1"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2"); - m_model->slotItemsAdded(parent2, KFileItemList() << KFileItem(KUrl("child2"), QString(), KFileItem::Unknown)); + m_model->slotItemsAdded(parent2, KFileItemList() << KFileItem(QUrl("child2"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2"); - m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(KUrl("grandChild1"), QString(), KFileItem::Unknown)); + m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(QUrl("grandChild1"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2"); - m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(KUrl("grandChild1"), QString(), KFileItem::Unknown)); + m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(QUrl("grandChild1"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2"); - m_model->slotItemsAdded(realChild2, KFileItemList() << KFileItem(KUrl("grandChild2"), QString(), KFileItem::Unknown)); + m_model->slotItemsAdded(realChild2, KFileItemList() << KFileItem(QUrl("grandChild2"), QString(), KFileItem::Unknown)); m_model->slotCompleted(); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "grandChild2" << "realGrandChild2" << "child2"); @@ -1355,8 +1358,9 @@ void KFileItemModelTest::testNameRoleGroups() // Change d.txt back to c.txt, but this time using the dir lister's refreshItems() signal. const KFileItem fileItemD = m_model->fileItem(2); KFileItem fileItemC = fileItemD; - KUrl urlC = fileItemC.url(); - urlC.setFileName("c.txt"); + QUrl urlC = fileItemC.url(); + urlC.adjusted(QUrl::RemoveFilename); + urlC.setPath(urlC.path() + "c.txt"); fileItemC.setUrl(urlC); m_model->slotRefreshItems(QList >() << qMakePair(fileItemD, fileItemC)); @@ -1445,7 +1449,7 @@ void KFileItemModelTest::testInconsistentModel() // Note that the first item in the list of added items must be new (i.e., not // in the model yet). Otherwise, KFileItemModel::slotItemsAdded() will see that // it receives items that are in the model already and ignore them. - KUrl url(m_model->directory().url() + "/a2"); + QUrl url(m_model->directory().url() + "/a2"); KFileItem newItem(KFileItem::Unknown, KFileItem::Unknown, url); KFileItemList items; @@ -1582,8 +1586,9 @@ void KFileItemModelTest::testRefreshFilteredItems() // Rename one of the .jpg files. KFileItem fileItemE = fileItemC; - KUrl urlE = fileItemE.url(); - urlE.setFileName("e.jpg"); + QUrl urlE = fileItemE.url(); + urlE.adjusted(QUrl::RemoveFilename); + urlE.setPath(urlE.path() + "e.jpg"); fileItemE.setUrl(urlE); m_model->slotRefreshItems(QList >() << qMakePair(fileItemC, fileItemE)); @@ -1650,11 +1655,12 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() // signal is not emitted yet. const KFileItem fileItemC1 = m_model->fileItem(2); KFileItem fileItemC2 = fileItemC1; - KUrl urlC2 = fileItemC2.url(); - urlC2.setFileName("c2.txt"); + QUrl urlC2 = fileItemC2.url(); + urlC2.adjusted(QUrl::RemoveFilename); + urlC2.setPath(urlC2.path() + "c2.txt"); fileItemC2.setUrl(urlC2); - const KUrl urlB = m_model->fileItem(1).url(); + const QUrl urlB = m_model->fileItem(1).url(); m_model->slotItemsAdded(urlB, KFileItemList() << fileItemC2); QCOMPARE(itemsInModel(), QStringList() << "a2" << "b" << "c1.txt"); @@ -1681,8 +1687,9 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() // completed() signal is not emitted yet. const KFileItem fileItemA2 = m_model->fileItem(0); KFileItem fileItemA1 = fileItemA2; - KUrl urlA1 = fileItemA1.url(); - urlA1.setFileName("a1"); + QUrl urlA1 = fileItemA1.url(); + urlA1.adjusted(QUrl::RemoveFilename); + urlA1.setPath(urlA1.path() + "a1"); fileItemA1.setUrl(urlA1); m_model->slotItemsAdded(m_model->directory(), KFileItemList() << fileItemA1); diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 4ed32ed43..3e35be54b 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -80,7 +80,7 @@ namespace { const int MaxModeEnum = DolphinView::CompactView; }; -DolphinView::DolphinView(const KUrl& url, QWidget* parent) : +DolphinView::DolphinView(const QUrl& url, QWidget* parent) : QWidget(parent), m_active(true), m_tabsForFiles(false), @@ -203,7 +203,7 @@ DolphinView::~DolphinView() { } -KUrl DolphinView::url() const +QUrl DolphinView::url() const { return m_url; } @@ -362,12 +362,12 @@ int DolphinView::selectedItemsCount() const return selectionManager->selectedItems().count(); } -void DolphinView::markUrlsAsSelected(const QList& urls) +void DolphinView::markUrlsAsSelected(const QList& urls) { m_selectedUrls = urls; } -void DolphinView::markUrlAsCurrent(const KUrl& url) +void DolphinView::markUrlAsCurrent(const QUrl &url) { m_currentItemUrl = url; m_scrollToCurrentItem = true; @@ -1049,7 +1049,7 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even // Mark the dropped urls as selected. m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; - connect(op, static_cast(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); + connect(op, static_cast&)>(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); } setActive(true); @@ -1085,14 +1085,14 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons } } -void DolphinView::slotAboutToCreate(const KUrl::List& urls) +void DolphinView::slotAboutToCreate(const QList& urls) { if (!urls.isEmpty()) { if (m_markFirstNewlySelectedItemAsCurrent) { markUrlAsCurrent(urls.first()); m_markFirstNewlySelectedItemAsCurrent = false; } - m_selectedUrls << KUrl::List(KDirModel::simplifiedUrlList(urls)); + m_selectedUrls << KDirModel::simplifiedUrlList(urls); } } @@ -1184,7 +1184,7 @@ void DolphinView::restoreState(QDataStream& stream) stream >> m_restoredContentsPosition; // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes) - QSet urls; + QSet urls; stream >> urls; m_model->restoreExpandedDirectories(urls); } @@ -1271,18 +1271,18 @@ KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh return KUrl(); } -void DolphinView::observeCreatedItem(const KUrl& url) +void DolphinView::observeCreatedItem(const QUrl& url) { if (m_active) { clearSelection(); markUrlAsCurrent(url); - markUrlsAsSelected(QList() << url); + markUrlsAsSelected(QList() << url); } } -void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl) +void DolphinView::slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl) { - if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) { + if (oldUrl.matches(url(), QUrl::StripTrailingSlash)) { emit redirection(oldUrl, newUrl); m_url = newUrl; // #186947 } @@ -1290,7 +1290,7 @@ void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUr void DolphinView::updateViewState() { - if (m_currentItemUrl != KUrl()) { + if (m_currentItemUrl != QUrl()) { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); const int currentIndex = m_model->index(m_currentItemUrl); if (currentIndex != -1) { @@ -1305,7 +1305,7 @@ void DolphinView::updateViewState() selectionManager->setCurrentItem(0); } - m_currentItemUrl = KUrl(); + m_currentItemUrl = QUrl(); } if (!m_restoredContentsPosition.isNull()) { @@ -1327,7 +1327,7 @@ void DolphinView::updateViewState() KItemSet selectedItems = selectionManager->selectedItems(); - QList::iterator it = m_selectedUrls.begin(); + QList::iterator it = m_selectedUrls.begin(); while (it != m_selectedUrls.end()) { const int index = m_model->index(*it); if (index >= 0) { @@ -1389,7 +1389,7 @@ void DolphinView::slotRenamingResult(KJob* job) KIO::CopyJob *copyJob = qobject_cast(job); Q_ASSERT(copyJob); const QUrl newUrl = copyJob->destUrl(); - const int index = m_model->index(KUrl(newUrl)); + const int index = m_model->index(newUrl); if (index >= 0) { QHash data; const QUrl oldUrl = copyJob->srcUrls().first(); @@ -1650,7 +1650,7 @@ void DolphinView::pasteToUrl(const KUrl& url) if (op) { m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; - connect(op, static_cast(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); + connect(op, static_cast&)>(&KonqOperations::aboutToCreate), this, &DolphinView::slotAboutToCreate); } } diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index d6daf2826..9435206d9 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -92,7 +92,7 @@ public: * @param url Specifies the content which should be shown. * @param parent Parent widget of the view. */ - DolphinView(const KUrl& url, QWidget* parent); + DolphinView(const QUrl& url, QWidget* parent); virtual ~DolphinView(); @@ -100,7 +100,7 @@ public: * Returns the current active URL, where all actions are applied. * The URL navigator is synchronized with this URL. */ - KUrl url() const; + QUrl url() const; /** * If \a active is true, the view will marked as active. The active @@ -173,13 +173,13 @@ public: * gets selected if no loading of a directory has been triggered * by DolphinView::setUrl() or DolphinView::reload(). */ - void markUrlsAsSelected(const QList& urls); + void markUrlsAsSelected(const QList &urls); /** * Marks the item indicated by \p url to be scrolled to and as the * current item after directory DolphinView::url() has been loaded. */ - void markUrlAsCurrent(const KUrl& url); + void markUrlAsCurrent(const QUrl& url); /** * All items that match to the pattern \a pattern will get selected @@ -573,7 +573,7 @@ private slots: /* * Is called when new items get pasted or dropped. */ - void slotAboutToCreate(const KUrl::List& urls); + void slotAboutToCreate(const QList &urls); /** * Emits the signal \a selectionChanged() with a small delay. This is @@ -669,13 +669,13 @@ private slots: * model indicates that the item is available, the item will * get selected and it is assured that the item stays visible. */ - void observeCreatedItem(const KUrl& url); + void observeCreatedItem(const QUrl &url); /** * Called when a redirection happens. * Testcase: fish://localhost */ - void slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl); + void slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl); /** * Applies the state that has been restored by restoreViewState() @@ -772,11 +772,11 @@ private: QTimer* m_selectionChangedTimer; - KUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5 + QUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5 bool m_scrollToCurrentItem; // Used for marking we need to scroll to current item or not QPoint m_restoredContentsPosition; - QList m_selectedUrls; // Used for making the view to remember selections after F5 + QList m_selectedUrls; // Used for making the view to remember selections after F5 bool m_clearSelectionBeforeSelectingNewItems; bool m_markFirstNewlySelectedItemAsCurrent; -- cgit v1.3 From 66a1b33e5ab3b23fd82e625391c9cca7553f8277 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Tue, 4 Nov 2014 22:37:42 +0100 Subject: Fix unit test failures These were caused by 86e31084ced8ba4875a6128f91ec2ca3d6df7a31 - note that the correct replacement for KUrl(fileName) is QUrl::fromLocalFile(fileName), and that calling the const function urlA.adjusted(QUrl::RemoveFilename) only has an effect if the return value is taken. --- src/tests/kfileitemmodeltest.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 758699dad..6a8c4f084 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -404,8 +404,7 @@ void KFileItemModelTest::testResortAfterChangingName() // We rename d.txt back to a.txt using the dir lister's refreshItems() signal. const KFileItem fileItemD = m_model->fileItem(2); KFileItem fileItemA = fileItemD; - QUrl urlA = fileItemA.url(); - urlA.adjusted(QUrl::RemoveFilename); + QUrl urlA = fileItemA.url().adjusted(QUrl::RemoveFilename); urlA.setPath(urlA.path() + "a.txt"); fileItemA.setUrl(urlA); @@ -538,7 +537,7 @@ void KFileItemModelTest::testExpandItems() QVERIFY(m_model->isExpanded(0)); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/a/", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl(m_testDir->name() + 'a')); + QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl::fromLocalFile(m_testDir->name() + 'a')); QCOMPARE(spyInserted.count(), 1); KItemRangeList itemRangeList = spyInserted.takeFirst().at(0).value(); @@ -554,7 +553,7 @@ void KFileItemModelTest::testExpandItems() QVERIFY(m_model->isExpanded(1)); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); QCOMPARE(m_model->count(), 4); // 4 items: "a/", "a/a/", "a/a/1", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl(m_testDir->name() + 'a') << QUrl(m_testDir->name() + "a/a")); + QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl::fromLocalFile(m_testDir->name() + 'a') << QUrl::fromLocalFile(m_testDir->name() + "a/a")); QCOMPARE(spyInserted.count(), 1); itemRangeList = spyInserted.takeFirst().at(0).value(); @@ -583,7 +582,7 @@ void KFileItemModelTest::testExpandItems() m_model->setExpanded(0, false); QVERIFY(!m_model->isExpanded(0)); QCOMPARE(m_model->count(), 1); - QVERIFY(!m_model->expandedDirectories().contains(QUrl(m_testDir->name() + 'a'))); // TODO: Make sure that child URLs are also removed + QVERIFY(!m_model->expandedDirectories().contains(QUrl::fromLocalFile(m_testDir->name() + 'a'))); // TODO: Make sure that child URLs are also removed QCOMPARE(spyRemoved.count(), 1); itemRangeList = spyRemoved.takeFirst().at(0).value(); @@ -609,7 +608,7 @@ void KFileItemModelTest::testExpandItems() // Move to a sub folder, then call restoreExpandedFolders() *before* going back. // This is how DolphinView restores the expanded folders when navigating in history. - m_model->loadDirectory(QUrl(m_testDir->name() + "a/a/")); + m_model->loadDirectory(QUrl::fromLocalFile(m_testDir->name() + "a/a/")); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); QCOMPARE(m_model->count(), 1); // 1 item: "1" m_model->restoreExpandedDirectories(allFolders); @@ -623,7 +622,7 @@ void KFileItemModelTest::testExpandItems() m_model->setRoles(originalModelRoles); QVERIFY(!m_model->isExpanded(0)); QCOMPARE(m_model->count(), 1); - QVERIFY(!m_model->expandedDirectories().contains(QUrl(m_testDir->name() + 'a'))); + QVERIFY(!m_model->expandedDirectories().contains(QUrl::fromLocalFile(m_testDir->name() + 'a'))); QCOMPARE(spyRemoved.count(), 1); itemRangeList = spyRemoved.takeFirst().at(0).value(); @@ -657,7 +656,7 @@ void KFileItemModelTest::testExpandParentItems() QVERIFY(m_model->expandedDirectories().empty()); // Expand the parents of "a2/b2/c2". - m_model->expandParentDirectories(QUrl(m_testDir->name() + "a2/b2/c2")); + m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->name() + "a2/b2/c2")); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); // The model should now contain "a 1/", "a2/", "a2/b2/", and "a2/b2/c2/". @@ -669,7 +668,7 @@ void KFileItemModelTest::testExpandParentItems() QVERIFY(!m_model->isExpanded(3)); // Expand the parents of "a 1/b1". - m_model->expandParentDirectories(QUrl(m_testDir->name() + "a 1/b1")); + m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->name() + "a 1/b1")); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); // The model should now contain "a 1/", "a 1/b1/", "a2/", "a2/b2", and "a2/b2/c2/". @@ -1358,8 +1357,7 @@ void KFileItemModelTest::testNameRoleGroups() // Change d.txt back to c.txt, but this time using the dir lister's refreshItems() signal. const KFileItem fileItemD = m_model->fileItem(2); KFileItem fileItemC = fileItemD; - QUrl urlC = fileItemC.url(); - urlC.adjusted(QUrl::RemoveFilename); + QUrl urlC = fileItemC.url().adjusted(QUrl::RemoveFilename); urlC.setPath(urlC.path() + "c.txt"); fileItemC.setUrl(urlC); @@ -1586,8 +1584,7 @@ void KFileItemModelTest::testRefreshFilteredItems() // Rename one of the .jpg files. KFileItem fileItemE = fileItemC; - QUrl urlE = fileItemE.url(); - urlE.adjusted(QUrl::RemoveFilename); + QUrl urlE = fileItemE.url().adjusted(QUrl::RemoveFilename); urlE.setPath(urlE.path() + "e.jpg"); fileItemE.setUrl(urlE); @@ -1687,8 +1684,7 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() // completed() signal is not emitted yet. const KFileItem fileItemA2 = m_model->fileItem(0); KFileItem fileItemA1 = fileItemA2; - QUrl urlA1 = fileItemA1.url(); - urlA1.adjusted(QUrl::RemoveFilename); + QUrl urlA1 = fileItemA1.url().adjusted(QUrl::RemoveFilename); urlA1.setPath(urlA1.path() + "a1"); fileItemA1.setUrl(urlA1); -- cgit v1.3 From cc299154f455cd580772439033adb2782814e515 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Tue, 4 Nov 2014 22:42:45 +0100 Subject: Fix more unit test failures This commit is analogous to 5cf8941ac789e47da70fe466033f45df9af1a3fa, but the problem existed since the frameworks port was started and was not obvious because the QString -> KUrl/QUrl port was done implicitly when calling KIO::rename(oldPath, newPath, KIO::HideProgressInfo). REVIEW: 120941 --- src/tests/kfileitemmodeltest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 6a8c4f084..ec13a8b2a 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -736,10 +736,10 @@ void KFileItemModelTest::testMakeExpandedItemHidden() QCOMPARE(m_model->count(), 6); // Rename "1a/2" and make it hidden. - const QString oldPath = m_model->fileItem(0).url().path() + "/2a"; - const QString newPath = m_model->fileItem(0).url().path() + "/.2a"; + const QUrl oldUrl = QUrl::fromLocalFile(m_model->fileItem(0).url().path() + "/2a"); + const QUrl newUrl = QUrl::fromLocalFile(m_model->fileItem(0).url().path() + "/.2a"); - KIO::SimpleJob* job = KIO::rename(oldPath, newPath, KIO::HideProgressInfo); + KIO::SimpleJob* job = KIO::rename(oldUrl, newUrl, KIO::HideProgressInfo); bool ok = job->exec(); QVERIFY(ok); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout)); -- cgit v1.3 From d0f0f1f2e2644e3738c03374d062dab9acc61eaf Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Mon, 10 Nov 2014 08:45:38 +0100 Subject: make use of initializer lists --- src/dolphinmainwindow.cpp | 14 +++++------ src/dolphinpart.cpp | 2 +- src/kitemviews/kfileitemlistview.cpp | 4 +-- src/kitemviews/kstandarditemlistview.cpp | 2 +- src/panels/folders/folderspanel.cpp | 2 +- src/panels/folders/treeviewcontextmenu.cpp | 4 +-- src/panels/places/placesitemmodel.cpp | 10 ++++---- src/settings/serviceitemdelegate.cpp | 2 +- src/tests/kfileitemlistviewtest.cpp | 4 +-- src/tests/kfileitemmodelbenchmark.cpp | 2 +- src/tests/kfileitemmodeltest.cpp | 14 +++++------ src/tests/kitemlistselectionmanagertest.cpp | 26 ++++++++++---------- src/tests/kitemrangetest.cpp | 38 ++++++++++++++--------------- src/views/dolphinview.cpp | 6 ++--- src/views/dolphinviewactionhandler.cpp | 4 +-- src/views/draganddrophelper.cpp | 2 +- src/views/renamedialog.cpp | 2 +- src/views/viewproperties.cpp | 5 ++-- 18 files changed, 71 insertions(+), 72 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index eece5b878..637d46a01 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -340,7 +340,7 @@ void DolphinMainWindow::openInNewWindow() } if (!newWindowUrl.isEmpty()) { - KRun::run("dolphin %u", QList() << newWindowUrl, this); + KRun::run("dolphin %u", {newWindowUrl}, this); } } @@ -774,7 +774,7 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos, case DolphinContextMenu::OpenParentFolderInNewWindow: { - KRun::run("dolphin %u", QList() << KIO::upUrl(item.url()), this); + KRun::run("dolphin %u", {KIO::upUrl(item.url())}, this); break; } @@ -995,7 +995,7 @@ void DolphinMainWindow::setupActions() QAction* newTab = actionCollection()->addAction("new_tab"); newTab->setIcon(QIcon::fromTheme("tab-new")); newTab->setText(i18nc("@action:inmenu File", "New Tab")); - actionCollection()->setDefaultShortcuts(newTab, QList() << QKeySequence(Qt::CTRL | Qt::Key_T) << QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_N)); + actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N}); connect(newTab, &QAction::triggered, this, static_cast(&DolphinMainWindow::openNewActivatedTab)); QAction* closeTab = actionCollection()->addAction("close_tab"); @@ -1173,7 +1173,7 @@ void DolphinMainWindow::setupDockWidgets() infoDock->setObjectName("infoDock"); infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); InformationPanel* infoPanel = new InformationPanel(infoDock); - infoPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + infoPanel->setCustomContextMenuActions({lockLayoutAction}); connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl); infoDock->setWidget(infoPanel); @@ -1194,7 +1194,7 @@ void DolphinMainWindow::setupDockWidgets() foldersDock->setObjectName("foldersDock"); foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); FoldersPanel* foldersPanel = new FoldersPanel(foldersDock); - foldersPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + foldersPanel->setCustomContextMenuActions({lockLayoutAction}); foldersDock->setWidget(foldersPanel); QAction* foldersAction = foldersDock->toggleViewAction(); @@ -1217,7 +1217,7 @@ void DolphinMainWindow::setupDockWidgets() terminalDock->setObjectName("terminalDock"); terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); TerminalPanel* terminalPanel = new TerminalPanel(terminalDock); - terminalPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + terminalPanel->setCustomContextMenuActions({lockLayoutAction}); terminalDock->setWidget(terminalPanel); connect(terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide); @@ -1248,7 +1248,7 @@ void DolphinMainWindow::setupDockWidgets() placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); PlacesPanel* placesPanel = new PlacesPanel(placesDock); - placesPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + placesPanel->setCustomContextMenuActions({lockLayoutAction}); placesDock->setWidget(placesPanel); QAction* placesAction = placesDock->toggleViewAction(); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 1c79a5980..8484b7ef9 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -556,7 +556,7 @@ void DolphinPart::slotOpenTerminal() void DolphinPart::slotFindFile() { - KRun::run("kfind", QList() << url(), widget()); + KRun::run("kfind", {url()}, widget()); } void DolphinPart::updateNewMenu() diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index f5535a653..4bdd8ff67 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -66,7 +66,7 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) : m_updateIconSizeTimer->setInterval(LongInterval); connect(m_updateIconSizeTimer, &QTimer::timeout, this, &KFileItemListView::updateIconSize); - setVisibleRoles(QList() << "text"); + setVisibleRoles({"text"}); } KFileItemListView::~KFileItemListView() @@ -205,7 +205,7 @@ void KFileItemListView::initializeItemListWidget(KItemListWidget* item) const KFileItem fileItem = fileItemModel->fileItem(item->index()); data.insert("iconName", fileItem.iconName()); - item->setData(data, QSet() << "iconName"); + item->setData(data, {"iconName"}); } } diff --git a/src/kitemviews/kstandarditemlistview.cpp b/src/kitemviews/kstandarditemlistview.cpp index 4ef5bed09..0e6c84ffd 100644 --- a/src/kitemviews/kstandarditemlistview.cpp +++ b/src/kitemviews/kstandarditemlistview.cpp @@ -30,7 +30,7 @@ KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) : { setAcceptDrops(true); setScrollOrientation(Qt::Vertical); - setVisibleRoles(QList() << "text"); + setVisibleRoles({"text"}); } KStandardItemListView::~KStandardItemListView() diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 5bfc88c2a..f56f5a139 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -259,7 +259,7 @@ void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, co KIO::Job* job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, this); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList() << oldUrl, newUrl, job); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->ui()->setAutoErrorHandlingEnabled(true); } } diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index 4fdaef3b6..6120261d0 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -193,7 +193,7 @@ void TreeViewContextMenu::rename() void TreeViewContextMenu::moveToTrash() { - const QList list {m_fileItem.url()}; + const QList list{m_fileItem.url()}; KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(m_parent); if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { @@ -206,7 +206,7 @@ void TreeViewContextMenu::moveToTrash() void TreeViewContextMenu::deleteItem() { - const QList list {m_fileItem.url()}; + const QList list{m_fileItem.url()}; KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(m_parent); if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 057a8b2d7..cfe6d2e46 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -873,22 +873,22 @@ PlacesItem* PlacesItemModel::createSystemPlacesItem(const SystemBookmarkData& da if (path == QLatin1String("/documents")) { props.setViewMode(DolphinView::DetailsView); props.setPreviewsShown(false); - props.setVisibleRoles(QList() << "text" << "path"); + props.setVisibleRoles({"text", "path"}); } else if (path == QLatin1String("/images")) { props.setViewMode(DolphinView::IconsView); props.setPreviewsShown(true); - props.setVisibleRoles(QList() << "text" << "imageSize"); + props.setVisibleRoles({"text", "imageSize"}); } else if (path == QLatin1String("/audio")) { props.setViewMode(DolphinView::DetailsView); props.setPreviewsShown(false); - props.setVisibleRoles(QList() << "text" << "artist" << "album"); + props.setVisibleRoles({"text", "artist", "album"}); } else if (path == QLatin1String("/videos")) { props.setViewMode(DolphinView::IconsView); props.setPreviewsShown(true); - props.setVisibleRoles(QList() << "text"); + props.setVisibleRoles({"text"}); } else if (data.url.scheme() == "timeline") { props.setViewMode(DolphinView::DetailsView); - props.setVisibleRoles(QList() << "text" << "date"); + props.setVisibleRoles({"text", "date"}); } } } diff --git a/src/settings/serviceitemdelegate.cpp b/src/settings/serviceitemdelegate.cpp index 62ab60fd9..774ea78ae 100644 --- a/src/settings/serviceitemdelegate.cpp +++ b/src/settings/serviceitemdelegate.cpp @@ -77,7 +77,7 @@ QList ServiceItemDelegate::createItemWidgets(const QModelIndex&) const QPushButton* configureButton = new QPushButton(); connect(configureButton, &QPushButton::clicked, this, &ServiceItemDelegate::slotConfigureButtonClicked); - return QList() << checkBox << configureButton; + return {checkBox, configureButton}; } void ServiceItemDelegate::updateItemWidgets(const QList widgets, diff --git a/src/tests/kfileitemlistviewtest.cpp b/src/tests/kfileitemlistviewtest.cpp index 4987e8d65..696580c0a 100644 --- a/src/tests/kfileitemlistviewtest.cpp +++ b/src/tests/kfileitemlistviewtest.cpp @@ -93,14 +93,14 @@ void KFileItemListViewTest::testGroupedItemChanges() { m_model->setGroupedSorting(true); - m_testDir->createFiles(QStringList() << "1" << "3" << "5"); + m_testDir->createFiles({"1", "3", "5"}); m_model->loadDirectory(m_testDir->url()); QSignalSpy psy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QVERIFY(psy.wait(DefaultTimeout)); QCOMPARE(m_model->count(), 3); - m_testDir->createFiles(QStringList() << "2" << "4"); + m_testDir->createFiles({"2", "4"}); m_model->m_dirLister->updateDirectory(m_testDir->url()); QSignalSpy psyItemsInserted(m_model, SIGNAL(itemsInserted(KItemRangeList))); QVERIFY(psyItemsInserted.wait(DefaultTimeout)); diff --git a/src/tests/kfileitemmodelbenchmark.cpp b/src/tests/kfileitemmodelbenchmark.cpp index 0da1137c4..43d7173de 100644 --- a/src/tests/kfileitemmodelbenchmark.cpp +++ b/src/tests/kfileitemmodelbenchmark.cpp @@ -167,7 +167,7 @@ void KFileItemModelBenchmark::insertAndRemoveManyItems() // Avoid overhead caused by natural sorting // and determining the isDir/isLink roles. model.m_naturalSorting = false; - model.setRoles(QSet() << "text"); + model.setRoles({"text"}); QSignalSpy spyItemsInserted(&model, SIGNAL(itemsInserted(KItemRangeList))); QSignalSpy spyItemsRemoved(&model, SIGNAL(itemsRemoved(KItemRangeList))); diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index ec13a8b2a..d224e1a2e 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -199,7 +199,7 @@ void KFileItemModelTest::testDirLoadingCompleted() QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); - m_testDir->createFiles(QStringList() << "a.txt" << "b.txt" << "c.txt"); + m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); m_model->loadDirectory(m_testDir->url()); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); @@ -208,7 +208,7 @@ void KFileItemModelTest::testDirLoadingCompleted() QCOMPARE(itemsRemovedSpy.count(), 0); QCOMPARE(m_model->count(), 3); - m_testDir->createFiles(QStringList() << "d.txt" << "e.txt"); + m_testDir->createFiles({"d.txt", "e.txt"}); m_model->m_dirLister->updateDirectory(m_testDir->url()); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); QCOMPARE(loadingCompletedSpy.count(), 2); @@ -408,7 +408,7 @@ void KFileItemModelTest::testResortAfterChangingName() urlA.setPath(urlA.path() + "a.txt"); fileItemA.setUrl(urlA); - m_model->slotRefreshItems(QList >() << qMakePair(fileItemD, fileItemA)); + m_model->slotRefreshItems({qMakePair(fileItemD, fileItemA)}); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt"); @@ -1060,7 +1060,7 @@ void KFileItemModelTest::testRefreshExpandedItem() QSignalSpy spyItemsChanged(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet))); const KFileItem item = m_model->fileItem(0); - m_model->slotRefreshItems(QList >() << qMakePair(item, item)); + m_model->slotRefreshItems({qMakePair(item, item)}); QVERIFY(!spyItemsChanged.isEmpty()); QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4" @@ -1077,7 +1077,7 @@ void KFileItemModelTest::testRemoveHiddenItems() m_testDir->createDir(".b"); m_testDir->createDir("c"); m_testDir->createDir("d"); - m_testDir->createFiles(QStringList() << ".f" << ".g" << "h" << "i"); + m_testDir->createFiles({".f", ".g", "h", "i"}); QSignalSpy spyItemsInserted(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList))); @@ -1361,7 +1361,7 @@ void KFileItemModelTest::testNameRoleGroups() urlC.setPath(urlC.path() + "c.txt"); fileItemC.setUrl(urlC); - m_model->slotRefreshItems(QList >() << qMakePair(fileItemD, fileItemC)); + m_model->slotRefreshItems({qMakePair(fileItemD, fileItemC)}); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(groupsChanged()), DefaultTimeout)); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt"); @@ -1588,7 +1588,7 @@ void KFileItemModelTest::testRefreshFilteredItems() urlE.setPath(urlE.path() + "e.jpg"); fileItemE.setUrl(urlE); - m_model->slotRefreshItems(QList >() << qMakePair(fileItemC, fileItemE)); + m_model->slotRefreshItems({qMakePair(fileItemC, fileItemE)}); // Show all files again, and verify that the model has updated the file name. m_model->setNameFilter(QString()); diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp index b41b699a9..fb0f4fc2b 100644 --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -369,7 +369,7 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << NoChange - << QList() + << QList{} << (KItemSet() << 2 << 3 << 5 << 6); QTest::newRow("Insert Items") @@ -377,7 +377,7 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << InsertItems - << (QList() << QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))) + << QList{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))} << (KItemSet() << 3 << 4 << 8 << 9); QTest::newRow("Remove Items") @@ -385,7 +385,7 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << RemoveItems - << (QList() << QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))) + << QList{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))} << (KItemSet() << 1 << 2 << 3 << 4); QTest::newRow("Empty Anchored Selection") @@ -393,7 +393,7 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 2 << 2 << KItemSet() << EndAnchoredSelection - << QList() + << QList{} << KItemSet(); QTest::newRow("Toggle selection") @@ -401,7 +401,7 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 6 << 8 << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) << SetSelected - << (QList() << 0 << 10 << QVariant::fromValue(KItemListSelectionManager::Toggle)) + << QList{0, 10, QVariant::fromValue(KItemListSelectionManager::Toggle)} << (KItemSet() << 0 << 2 << 5 << 9); // Swap items 2, 3 and 4, 5 @@ -410,8 +410,8 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << -1 << -1 << (KItemSet() << 0 << 1 << 2 << 3) << MoveItems - << (QList() << QVariant::fromValue(KItemRange(2, 4)) - << QVariant::fromValue(QList() << 4 << 5 << 2 << 3)) + << QList{QVariant::fromValue(KItemRange(2, 4)), + QVariant::fromValue(QList{4, 5, 2, 3})} << (KItemSet() << 0 << 1 << 4 << 5); QTest::newRow("Move items with active anchored selection") @@ -419,8 +419,8 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 0 << 3 << (KItemSet() << 0 << 1 << 2 << 3) << MoveItems - << (QList() << QVariant::fromValue(KItemRange(2, 4)) - << QVariant::fromValue(QList() << 4 << 5 << 2 << 3)) + << QList{QVariant::fromValue(KItemRange(2, 4)), + QVariant::fromValue(QList{4, 5, 2, 3})} << (KItemSet() << 0 << 1 << 4 << 5); // Revert sort order @@ -429,8 +429,8 @@ void KItemListSelectionManagerTest::testChangeSelection_data() << 3 << 4 << (KItemSet() << 0 << 1 << 3 << 4) << MoveItems - << (QList() << QVariant::fromValue(KItemRange(0, 10)) - << QVariant::fromValue(QList() << 9 << 8 << 7 << 6 << 5 << 4 << 3 << 2 << 1 << 0)) + << QList{QVariant::fromValue(KItemRange(0, 10)), + QVariant::fromValue(QList{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})} << (KItemSet() << 5 << 6 << 8 << 9); } @@ -476,7 +476,7 @@ void KItemListSelectionManagerTest::testChangeSelection() break; case MoveItems: m_selectionManager->itemsMoved(data.at(0).value(), - data.at(1).value >()); + data.at(1).value>()); break; case EndAnchoredSelection: m_selectionManager->endAnchoredSelection(); @@ -535,7 +535,7 @@ void KItemListSelectionManagerTest::testAnchoredSelectionAfterMovingItems() m_selectionManager->beginAnchoredSelection(4); // Reverse the items between 0 and 5. - m_selectionManager->itemsMoved(KItemRange(0, 6), QList() << 5 << 4 << 3 << 2 << 1 << 0); + m_selectionManager->itemsMoved(KItemRange(0, 6), {5, 4, 3, 2, 1, 0}); QCOMPARE(m_selectionManager->currentItem(), 1); QCOMPARE(m_selectionManager->m_anchorItem, 1); diff --git a/src/tests/kitemrangetest.cpp b/src/tests/kitemrangetest.cpp index 960530a7b..011f5ae86 100644 --- a/src/tests/kitemrangetest.cpp +++ b/src/tests/kitemrangetest.cpp @@ -40,25 +40,25 @@ void KItemRangeTest::testFromSortedContainer_data() QTest::addColumn >("sortedNumbers"); QTest::addColumn("expected"); - QTest::newRow("empty") << QVector() << KItemRangeList(); - QTest::newRow("[1]") << (QVector() << 1) << (KItemRangeList() << KItemRange(1, 1)); - QTest::newRow("[9]") << (QVector() << 9) << (KItemRangeList() << KItemRange(9, 1)); - QTest::newRow("[1-2]") << (QVector() << 1 << 2) << (KItemRangeList() << KItemRange(1, 2)); - QTest::newRow("[1-3]") << (QVector() << 1 << 2 << 3) << (KItemRangeList() << KItemRange(1, 3)); - QTest::newRow("[1] [4]") << (QVector() << 1 << 4) << (KItemRangeList() << KItemRange(1, 1) << KItemRange(4, 1)); - QTest::newRow("[1-3] [5]") << (QVector() << 1 << 2 << 3 << 5) << (KItemRangeList() << KItemRange(1, 3) << KItemRange(5, 1)); - QTest::newRow("[1] [5-6]") << (QVector() << 1 << 5 << 6) << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2)); - QTest::newRow("duplicates: 1 1") << (QVector() << 1 << 1) << (KItemRangeList() << KItemRange(1, 1)); - QTest::newRow("duplicates: 1 1 1") << (QVector() << 1 << 1 << 1) << (KItemRangeList() << KItemRange(1, 1)); - QTest::newRow("duplicates: 1 1 5") << (QVector() << 1 << 1 << 5) << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); - QTest::newRow("duplicates: 1 5 5") << (QVector() << 1 << 5 << 5) << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); - QTest::newRow("duplicates: 1 1 1 5") << (QVector() << 1 << 1 << 1 << 5) << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); - QTest::newRow("duplicates: 1 5 5 5") << (QVector() << 1 << 5 << 5 << 5) << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); - QTest::newRow("duplicates: 1 1 2") << (QVector() << 1 << 1 << 2) << (KItemRangeList() << KItemRange(1, 2)); - QTest::newRow("duplicates: 1 2 2") << (QVector() << 1 << 2 << 2) << (KItemRangeList() << KItemRange(1, 2)); - QTest::newRow("duplicates: 1 1 2 3") << (QVector() << 1 << 1 << 2 << 3) << (KItemRangeList() << KItemRange(1, 3)); - QTest::newRow("duplicates: 1 2 2 3") << (QVector() << 1 << 2 << 2 << 3) << (KItemRangeList() << KItemRange(1, 3)); - QTest::newRow("duplicates: 1 2 3 3") << (QVector() << 1 << 2 << 3 << 3) << (KItemRangeList() << KItemRange(1, 3)); + QTest::newRow("empty") << QVector{} << KItemRangeList(); + QTest::newRow("[1]") << QVector{1} << (KItemRangeList() << KItemRange(1, 1)); + QTest::newRow("[9]") << QVector{9} << (KItemRangeList() << KItemRange(9, 1)); + QTest::newRow("[1-2]") << QVector{1, 2} << (KItemRangeList() << KItemRange(1, 2)); + QTest::newRow("[1-3]") << QVector{1, 2, 3} << (KItemRangeList() << KItemRange(1, 3)); + QTest::newRow("[1] [4]") << QVector{1, 4} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(4, 1)); + QTest::newRow("[1-3] [5]") << QVector{1, 2, 3, 5} << (KItemRangeList() << KItemRange(1, 3) << KItemRange(5, 1)); + QTest::newRow("[1] [5-6]") << QVector{1, 5, 6} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2)); + QTest::newRow("duplicates: 1 1") << QVector{1, 1} << (KItemRangeList() << KItemRange(1, 1)); + QTest::newRow("duplicates: 1 1 1") << QVector{1, 1, 1} << (KItemRangeList() << KItemRange(1, 1)); + QTest::newRow("duplicates: 1 1 5") << QVector{1, 1, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); + QTest::newRow("duplicates: 1 5 5") << QVector{1, 5, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); + QTest::newRow("duplicates: 1 1 1 5") << QVector{1, 1, 1, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); + QTest::newRow("duplicates: 1 5 5 5") << QVector{1, 5, 5, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); + QTest::newRow("duplicates: 1 1 2") << QVector{1, 1, 2} << (KItemRangeList() << KItemRange(1, 2)); + QTest::newRow("duplicates: 1 2 2") << QVector{1, 2, 2} << (KItemRangeList() << KItemRange(1, 2)); + QTest::newRow("duplicates: 1 1 2 3") << QVector{1, 1, 2, 3} << (KItemRangeList() << KItemRange(1, 3)); + QTest::newRow("duplicates: 1 2 2 3") << QVector{1, 2, 2, 3} << (KItemRangeList() << KItemRange(1, 3)); + QTest::newRow("duplicates: 1 2 3 3") << QVector{1, 2, 3, 3} << (KItemRangeList() << KItemRange(1, 3)); } void KItemRangeTest::testFromSortedContainer() diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 782cc19f2..00281af73 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -125,7 +125,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : m_model = new KFileItemModel(this); m_view = new DolphinItemListView(); m_view->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle()); - m_view->setVisibleRoles(QList() << "text"); + m_view->setVisibleRoles({"text"}); applyModeToView(); KItemListController* controller = new KItemListController(m_model, m_view, this); @@ -1286,7 +1286,7 @@ void DolphinView::observeCreatedItem(const QUrl& url) if (m_active) { clearSelection(); markUrlAsCurrent(url); - markUrlsAsSelected(QList() << url); + markUrlsAsSelected({url}); } } @@ -1513,7 +1513,7 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con KIO::Job * job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, this); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList() << oldUrl, newUrl, job); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->ui()->setAutoErrorHandlingEnabled(true); if (!newNameExistsAlready) { diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index 668623c8c..08d140c01 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -141,7 +141,7 @@ void DolphinViewActionHandler::createActions() // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :) propertiesAction->setText( i18nc("@action:inmenu File", "Properties") ); propertiesAction->setIcon(QIcon::fromTheme("document-properties")); - m_actionCollection->setDefaultShortcuts(propertiesAction, QList() << Qt::ALT + Qt::Key_Return << Qt::ALT + Qt::Key_Enter); + m_actionCollection->setDefaultShortcuts(propertiesAction, {Qt::ALT + Qt::Key_Return, Qt::ALT + Qt::Key_Enter}); connect(propertiesAction, &QAction::triggered, this, &DolphinViewActionHandler::slotProperties); // View menu @@ -211,7 +211,7 @@ void DolphinViewActionHandler::createActions() KToggleAction* showHiddenFiles = m_actionCollection->add("show_hidden_files"); showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - m_actionCollection->setDefaultShortcuts(showHiddenFiles, QList() << Qt::ALT + Qt::Key_Period << Qt::Key_F8); + m_actionCollection->setDefaultShortcuts(showHiddenFiles, {Qt::ALT + Qt::Key_Period, Qt::Key_F8}); connect(showHiddenFiles, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleShowHiddenFiles); QAction* adjustViewProps = m_actionCollection->addAction("view_properties"); diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index 1f3f4ba82..a09faa345 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -47,7 +47,7 @@ KonqOperations* DragAndDropHelper::dropUrls(const KFileItem& destItem, const QUr QDBusMessage message = QDBusMessage::createMethodCall(remoteDBusClient, remoteDBusPath, "org.kde.ark.DndExtract", "extractSelectedFilesTo"); - message.setArguments(QVariantList() << destUrl.toDisplayString(QUrl::PreferLocalFile)); + message.setArguments({destUrl.toDisplayString(QUrl::PreferLocalFile)}); QDBusConnection::sessionBus().call(message); } else if (!destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile())) { // Drop into a directory or a desktop-file diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index 458b9ef79..7fdb486e1 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -159,7 +159,7 @@ void RenameDialog::renameItem(const KFileItem &item, const QString& newName) KIO::Job * job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, widget); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList() << oldUrl, newUrl, job); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->ui()->setAutoErrorHandlingEnabled(true); } diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index 5eb5d23fd..36c6338fe 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -98,7 +98,7 @@ ViewProperties::ViewProperties(const QUrl& url) : if (useDefaultProps) { if (useDetailsViewWithPath) { setViewMode(DolphinView::DetailsView); - setVisibleRoles(QList() << "path"); + setVisibleRoles({"path"}); } else { // The global view-properties act as default for directories without // any view-property configuration. Constructing a ViewProperties @@ -286,8 +286,7 @@ QList ViewProperties::visibleRoles() const // by "CustomizedDetails"), also a details-view with no additional information // is accepted. - QList roles; - roles.append("text"); + QList roles{"text"}; // Iterate through all stored keys and append all roles that match to // the current view mode. -- cgit v1.3 From a07d63d419469592b2600e668795cea2f9bee403 Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Sun, 14 Dec 2014 17:46:58 +0100 Subject: port away from deprecated KFileItem(mode_t mode, mode_t permissions, const QUrl &url, bool delayedMimeTypes = false); --- src/dolphincontextmenu.cpp | 2 +- src/dolphinpart.cpp | 2 +- src/dolphinviewcontainer.cpp | 2 +- src/panels/information/informationpanel.cpp | 6 +++--- src/settings/startup/startupsettingspage.cpp | 2 +- src/tests/kfileitemmodeltest.cpp | 2 +- src/views/dolphinview.cpp | 3 ++- 7 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 0ecd7376d..a7300334f 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -468,7 +468,7 @@ KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const KFileItem DolphinContextMenu::baseFileItem() { if (!m_baseFileItem) { - m_baseFileItem = new KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_baseUrl); + m_baseFileItem = new KFileItem(m_baseUrl); } return *m_baseFileItem; } diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 8484b7ef9..cfde90ada 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -404,7 +404,7 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos, popupFlags |= KParts::BrowserExtension::ShowNavigationItems | KParts::BrowserExtension::ShowUp; item = m_view->rootItem(); if (item.isNull()) - item = KFileItem( S_IFDIR, (mode_t)-1, url() ); + item = KFileItem(url()); else item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799) } diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index f64689d01..3954a12e6 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -479,7 +479,7 @@ void DolphinViewContainer::slotDirectoryLoadingCanceled() void DolphinViewContainer::slotUrlIsFileError(const QUrl& url) { - const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); + const KFileItem item(url); // Find out if the file can be opened in the view (for example, this is the // case if the file is an archive). The mime type must be known for that. diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp index 3d7a05f03..3f778b07a 100644 --- a/src/panels/information/informationpanel.cpp +++ b/src/panels/information/informationpanel.cpp @@ -228,7 +228,7 @@ void InformationPanel::slotFileRenamed(const QString& source, const QString& des { if (m_shownUrl == QUrl::fromLocalFile(source)) { m_shownUrl = QUrl::fromLocalFile(dest); - m_fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); + m_fileItem = KFileItem(m_shownUrl); if ((m_selection.count() == 1) && (m_selection[0].url() == QUrl::fromLocalFile(source))) { m_selection[0] = m_fileItem; @@ -247,7 +247,7 @@ void InformationPanel::slotFilesAdded(const QString& directory) if (m_shownUrl == QUrl::fromLocalFile(directory)) { // If the 'trash' icon changes because the trash has been emptied or got filled, // the signal filesAdded("trash:/") will be emitted. - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, QUrl::fromLocalFile(directory)); + KFileItem item(QUrl::fromLocalFile(directory)); requestDelayedItemInfo(item); } } @@ -277,7 +277,7 @@ void InformationPanel::slotFilesRemoved(const QStringList& files) void InformationPanel::slotEnteredDirectory(const QString& directory) { if (m_shownUrl == QUrl::fromLocalFile(directory)) { - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, QUrl::fromLocalFile(directory)); + KFileItem item(QUrl::fromLocalFile(directory)); requestDelayedItemInfo(item); } } diff --git a/src/settings/startup/startupsettingspage.cpp b/src/settings/startup/startupsettingspage.cpp index f7bcbc685..75ec445df 100644 --- a/src/settings/startup/startupsettingspage.cpp +++ b/src/settings/startup/startupsettingspage.cpp @@ -118,7 +118,7 @@ void StartupSettingsPage::applySettings() GeneralSettings* settings = GeneralSettings::self(); const QUrl url(QUrl::fromLocalFile(m_homeUrl->text())); - KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url); + KFileItem fileItem(url); if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) { settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile)); } else { diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index d224e1a2e..fbe34e2a7 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -1448,7 +1448,7 @@ void KFileItemModelTest::testInconsistentModel() // in the model yet). Otherwise, KFileItemModel::slotItemsAdded() will see that // it receives items that are in the model already and ignore them. QUrl url(m_model->directory().url() + "/a2"); - KFileItem newItem(KFileItem::Unknown, KFileItem::Unknown, url); + KFileItem newItem(url); KFileItemList items; items << newItem << m_model->fileItem(2) << m_model->fileItem(3); diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 00281af73..cb25c6555 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1698,7 +1698,8 @@ void DolphinView::updateWritableState() if (item.isNull()) { // Try to find out if the URL is writable even if the "root item" is // null, see https://bugs.kde.org/show_bug.cgi?id=330001 - item = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url(), true); + item = KFileItem(url()); + item.setDelayedMimeTypes(true); } KFileItemListProperties capabilities(KFileItemList() << item); -- cgit v1.3 From d19d94e60a778d4c19f646224e3b269da515c8fb Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Thu, 18 Dec 2014 14:56:46 +0100 Subject: Ported tests away from KRandomSequence, QTest::kWaitForSignal and KTempDir. All tests passed! --- src/tests/CMakeLists.txt | 4 +- src/tests/dolphinsearchboxtest.cpp | 5 +- src/tests/kfileitemlistviewtest.cpp | 25 +- src/tests/kfileitemmodelbenchmark.cpp | 17 +- src/tests/kfileitemmodeltest.cpp | 518 ++++++++++++----------- src/tests/kitemlistcontrollertest.cpp | 19 +- src/tests/kitemlistkeyboardsearchmanagertest.cpp | 13 +- src/tests/kitemlistselectionmanagertest.cpp | 5 +- src/tests/kitemrangetest.cpp | 3 +- src/tests/kitemsettest.cpp | 3 +- src/tests/kstandarditemmodeltest.cpp | 4 +- src/tests/testdir.cpp | 17 +- src/tests/testdir.h | 8 +- src/tests/viewpropertiestest.cpp | 17 +- 14 files changed, 325 insertions(+), 333 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 60f6517e8..a69400baa 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -52,7 +52,7 @@ set(kitemlistcontrollertest_SRCS ../kitemviews/kitemlistview.cpp ../kitemviews/kitemlistcontainer.cpp ../kitemviews/kitemlistwidget.cpp -# ../kitemviews/kitemlistviewaccessible.cpp # TODO: enable once accessibility is ported to Qt5 + ../kitemviews/kitemlistviewaccessible.cpp ../kitemviews/kitemset.cpp ../kitemviews/kstandarditemlistview.cpp ../kitemviews/kstandarditemlistwidget.cpp @@ -71,7 +71,7 @@ set(kfileitemlistviewtest_SRCS ../kitemviews/kfileitemlistview.cpp ../kitemviews/kitemmodelbase.cpp ../kitemviews/kitemlistview.cpp -# ../kitemviews/kitemlistviewaccessible.cpp # TODO: enable once accessibility is ported to Qt5 + ../kitemviews/kitemlistviewaccessible.cpp ../kitemviews/kitemlistcontainer.cpp ../kitemviews/kitemlistwidget.cpp ../kitemviews/kitemset.cpp diff --git a/src/tests/dolphinsearchboxtest.cpp b/src/tests/dolphinsearchboxtest.cpp index 49bc7e824..862a398a5 100644 --- a/src/tests/dolphinsearchboxtest.cpp +++ b/src/tests/dolphinsearchboxtest.cpp @@ -17,10 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include - #include "search/dolphinsearchbox.h" -#include + +#include class DolphinSearchBoxTest : public QObject { diff --git a/src/tests/kfileitemlistviewtest.cpp b/src/tests/kfileitemlistviewtest.cpp index 696580c0a..9e1add8cf 100644 --- a/src/tests/kfileitemlistviewtest.cpp +++ b/src/tests/kfileitemlistviewtest.cpp @@ -17,18 +17,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include -#include #include "kitemviews/kfileitemlistview.h" #include "kitemviews/kfileitemmodel.h" #include "kitemviews/private/kfileitemmodeldirlister.h" #include "testdir.h" #include - -namespace { - const int DefaultTimeout = 2000; -}; +#include +#include class KFileItemListViewTest : public QObject { @@ -91,27 +87,24 @@ void KFileItemListViewTest::cleanup() */ void KFileItemListViewTest::testGroupedItemChanges() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + m_model->setGroupedSorting(true); m_testDir->createFiles({"1", "3", "5"}); - m_model->loadDirectory(m_testDir->url()); - QSignalSpy psy(m_model, SIGNAL(itemsInserted(KItemRangeList))); - QVERIFY(psy.wait(DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); m_testDir->createFiles({"2", "4"}); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QSignalSpy psyItemsInserted(m_model, SIGNAL(itemsInserted(KItemRangeList))); - QVERIFY(psyItemsInserted.wait(DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 5); - m_testDir->removeFile("1"); - m_testDir->removeFile("3"); - m_testDir->removeFile("5"); + m_testDir->removeFiles({"1", "3", "5"}); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QSignalSpy psyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList))); - QVERIFY(psyItemsRemoved.wait(DefaultTimeout)); + QVERIFY(itemsRemovedSpy.wait()); QCOMPARE(m_model->count(), 2); } diff --git a/src/tests/kfileitemmodelbenchmark.cpp b/src/tests/kfileitemmodelbenchmark.cpp index 43d7173de..c970a7198 100644 --- a/src/tests/kfileitemmodelbenchmark.cpp +++ b/src/tests/kfileitemmodelbenchmark.cpp @@ -18,15 +18,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include +#include #include + +#include +#include + #include "kitemviews/kfileitemmodel.h" #include "kitemviews/private/kfileitemmodelsortalgorithm.h" #include "testdir.h" -#include - void myMessageOutput(QtMsgType type, const char* msg) { switch (type) { @@ -45,10 +47,6 @@ void myMessageOutput(QtMsgType type, const char* msg) } } -namespace { - const int DefaultTimeout = 5000; -}; - Q_DECLARE_METATYPE(KFileItemList) Q_DECLARE_METATYPE(KItemRangeList) @@ -294,8 +292,9 @@ void KFileItemModelBenchmark::insertManyChildItems() } // Bring the items into random order. - KRandomSequence randomSequence(0); - randomSequence.randomize(newItems); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(newItems.begin(), newItems.end(), g); // Measure how long it takes to insert and then remove all files. QBENCHMARK { diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index fbe34e2a7..74b2342c8 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -18,7 +18,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include +#include +#include +#include +#include #include @@ -44,10 +47,6 @@ void myMessageOutput(QtMsgType type, const char* msg) } } -namespace { - const int DefaultTimeout = 5000; -}; - Q_DECLARE_METATYPE(KItemRange) Q_DECLARE_METATYPE(KItemRangeList) Q_DECLARE_METATYPE(QList) @@ -142,15 +141,14 @@ void KFileItemModelTest::testDefaultRoles() void KFileItemModelTest::testDefaultSortRole() { - QCOMPARE(m_model->sortRole(), QByteArray("text")); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QStringList files; - files << "c.txt" << "a.txt" << "b.txt"; + QCOMPARE(m_model->sortRole(), QByteArray("text")); - m_testDir->createFiles(files); + m_testDir->createFiles({"c.txt", "a.txt", "b.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); QCOMPARE(m_model->data(0)["text"].toString(), QString("a.txt")); @@ -165,12 +163,12 @@ void KFileItemModelTest::testDefaultGroupedSorting() void KFileItemModelTest::testNewItems() { - QStringList files; - files << "a.txt" << "b.txt" << "c.txt"; - m_testDir->createFiles(files); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + + m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); @@ -179,30 +177,32 @@ void KFileItemModelTest::testNewItems() void KFileItemModelTest::testRemoveItems() { - m_testDir->createFile("a.txt"); - m_testDir->createFile("b.txt"); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + + m_testDir->createFiles({"a.txt", "b.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 2); QVERIFY(m_model->isConsistent()); m_testDir->removeFile("a.txt"); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsRemovedSpy.wait()); QCOMPARE(m_model->count(), 1); QVERIFY(m_model->isConsistent()); } void KFileItemModelTest::testDirLoadingCompleted() { - QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted())); - QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); - QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); + QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(loadingCompletedSpy.count(), 1); QCOMPARE(itemsInsertedSpy.count(), 1); QCOMPARE(itemsRemovedSpy.count(), 0); @@ -210,7 +210,7 @@ void KFileItemModelTest::testDirLoadingCompleted() m_testDir->createFiles({"d.txt", "e.txt"}); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(loadingCompletedSpy.count(), 2); QCOMPARE(itemsInsertedSpy.count(), 2); QCOMPARE(itemsRemovedSpy.count(), 0); @@ -219,7 +219,7 @@ void KFileItemModelTest::testDirLoadingCompleted() m_testDir->removeFile("a.txt"); m_testDir->createFile("f.txt"); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(loadingCompletedSpy.count(), 3); QCOMPARE(itemsInsertedSpy.count(), 3); QCOMPARE(itemsRemovedSpy.count(), 1); @@ -227,7 +227,7 @@ void KFileItemModelTest::testDirLoadingCompleted() m_testDir->removeFile("b.txt"); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsRemovedSpy.wait()); QCOMPARE(loadingCompletedSpy.count(), 4); QCOMPARE(itemsInsertedSpy.count(), 3); QCOMPARE(itemsRemovedSpy.count(), 2); @@ -238,16 +238,18 @@ void KFileItemModelTest::testDirLoadingCompleted() void KFileItemModelTest::testSetData() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsChangedSpy(m_model, &KFileItemModel::itemsChanged); + m_testDir->createFile("a.txt"); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QHash values; values.insert("customRole1", "Test1"); values.insert("customRole2", "Test2"); - QSignalSpy itemsChangedSpy(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet))); m_model->setData(0, values); QCOMPARE(itemsChangedSpy.count(), 1); @@ -289,18 +291,19 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() QFETCH(int, ratingIndex1); QFETCH(int, ratingIndex2); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + // Changing the value of a sort-role must result in // a reordering of the items. QCOMPARE(m_model->sortRole(), QByteArray("text")); m_model->setSortRole("rating"); QCOMPARE(m_model->sortRole(), QByteArray("rating")); - QStringList files; - files << "a.txt" << "b.txt" << "c.txt"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // Fill the "rating" role of each file: // a.txt -> 2 @@ -330,7 +333,7 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() m_model->setData(changedIndex, rating); if (expectMoveSignal) { - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); + QVERIFY(itemsMovedSpy.wait()); } QCOMPARE(m_model->data(0).value("rating").toInt(), ratingIndex0); @@ -341,14 +344,15 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() void KFileItemModelTest::testChangeSortRole() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + QCOMPARE(m_model->sortRole(), QByteArray("text")); - QStringList files; - files << "a.txt" << "b.jpg" << "c.txt"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a.txt", "b.jpg", "c.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.jpg" << "c.txt"); // Simulate that KFileItemModelRolesUpdater determines the mime type. @@ -359,10 +363,9 @@ void KFileItemModelTest::testChangeSortRole() } // Now: sort by type. - QSignalSpy spyItemsMoved(m_model, SIGNAL(itemsMoved(KItemRange,QList))); m_model->setSortRole("type"); QCOMPARE(m_model->sortRole(), QByteArray("type")); - QVERIFY(!spyItemsMoved.isEmpty()); + QVERIFY(!itemsMovedSpy.isEmpty()); // The actual order of the files might depend on the translation of the // result of KFileItem::mimeComment() in the user's language. @@ -380,16 +383,17 @@ void KFileItemModelTest::testChangeSortRole() void KFileItemModelTest::testResortAfterChangingName() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + // We sort by size in a directory where all files have the same size. // Therefore, the files are sorted by their names. m_model->setSortRole("size"); - QStringList files; - files << "a.txt" << "b.txt" << "c.txt"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt"); // We rename a.txt to d.txt. Even though the size has not changed at all, @@ -398,7 +402,7 @@ void KFileItemModelTest::testResortAfterChangingName() data.insert("text", "d.txt"); m_model->setData(0, data); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); + QVERIFY(itemsMovedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt"); // We rename d.txt back to a.txt using the dir lister's refreshItems() signal. @@ -410,13 +414,13 @@ void KFileItemModelTest::testResortAfterChangingName() m_model->slotRefreshItems({qMakePair(fileItemD, fileItemA)}); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); + QVERIFY(itemsMovedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt"); } void KFileItemModelTest::testModelConsistencyWhenInsertingItems() { - //QSKIP("Temporary disabled", SkipSingle); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); // KFileItemModel prevents that inserting a punch of items sequentially // results in an itemsInserted()-signal for each item. Instead internally @@ -426,14 +430,14 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() // the timeout to 1 millisecond. m_testDir->createFile("1"); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 1); // Insert 10 items for 20 times. After each insert operation the model consistency // is checked. QSet insertedItems; for (int i = 0; i < 20; ++i) { - QSignalSpy spy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + itemsInsertedSpy.clear(); for (int j = 0; j < 10; ++j) { int itemName = qrand(); @@ -446,8 +450,8 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() } m_model->m_dirLister->updateDirectory(m_testDir->url()); - if (spy.count() == 0) { - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + if (itemsInsertedSpy.count() == 0) { + QVERIFY(itemsInsertedSpy.wait()); } QVERIFY(m_model->isConsistent()); @@ -458,18 +462,17 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems() { - QStringList files; - files << "B" << "E" << "G"; - m_testDir->createFiles(files); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + + m_testDir->createFiles({"B", "E", "G"}); // Due to inserting the 3 items one item-range with index == 0 and // count == 3 must be given - QSignalSpy spy1(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(spy1.count(), 1); - QList arguments = spy1.takeFirst(); + QCOMPARE(itemsInsertedSpy.count(), 1); + QList arguments = itemsInsertedSpy.takeFirst(); KItemRangeList itemRangeList = arguments.at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 3)); @@ -485,22 +488,23 @@ void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems() // index: 1, count: 2 for B, C // index: 2, count: 1 for G - files.clear(); - files << "A" << "C" << "D" << "F"; - m_testDir->createFiles(files); + m_testDir->createFiles({"A", "C", "D", "F"}); - QSignalSpy spy2(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_model->m_dirLister->updateDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); - QCOMPARE(spy2.count(), 1); - arguments = spy2.takeFirst(); + QCOMPARE(itemsInsertedSpy.count(), 1); + arguments = itemsInsertedSpy.takeFirst(); itemRangeList = arguments.at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 1) << KItemRange(1, 2) << KItemRange(2, 1)); } void KFileItemModelTest::testExpandItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); + // Test expanding subfolders in a folder with the items "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1". // Besides testing the basic item expansion functionality, the test makes sure that // KFileItemModel::expansionLevelsCompare(const KFileItem& a, const KFileItem& b) @@ -511,18 +515,16 @@ void KFileItemModelTest::testExpandItems() modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/a/1" << "a/a-1/1"; // missing folders are created automatically - m_testDir->createFiles(files); + m_testDir->createFiles({"a/a/1", "a/a-1/1"}); // Store the URLs of all folders in a set. QSet allFolders; - allFolders << QUrl::fromLocalFile(m_testDir->name() + 'a') - << QUrl::fromLocalFile(m_testDir->name() + "a/a") - << QUrl::fromLocalFile(m_testDir->name() + "a/a-1"); + allFolders << QUrl::fromLocalFile(m_testDir->path() + "/a") + << QUrl::fromLocalFile(m_testDir->path() + "/a/a") + << QUrl::fromLocalFile(m_testDir->path() + "/a/a-1"); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // So far, the model contains only "a/" QCOMPARE(m_model->count(), 1); @@ -530,17 +532,19 @@ void KFileItemModelTest::testExpandItems() QVERIFY(!m_model->isExpanded(0)); QVERIFY(m_model->expandedDirectories().empty()); - QSignalSpy spyInserted(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QCOMPARE(itemsInsertedSpy.count(), 1); + KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value(); + QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 1)); // 1 new item "a/" with index 0 // Expand the folder "a/" -> "a/a/" and "a/a-1/" become visible m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/a/", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl::fromLocalFile(m_testDir->name() + 'a')); + QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl::fromLocalFile(m_testDir->path() + "/a")); - QCOMPARE(spyInserted.count(), 1); - KItemRangeList itemRangeList = spyInserted.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 1); + itemRangeList = itemsInsertedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 2)); // 2 new items "a/a/" and "a/a-1/" with indices 1 and 2 QVERIFY(m_model->isExpandable(1)); @@ -551,12 +555,13 @@ void KFileItemModelTest::testExpandItems() // Expand the folder "a/a/" -> "a/a/1" becomes visible m_model->setExpanded(1, true); QVERIFY(m_model->isExpanded(1)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 4); // 4 items: "a/", "a/a/", "a/a/1", "a/a-1/" - QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl::fromLocalFile(m_testDir->name() + 'a') << QUrl::fromLocalFile(m_testDir->name() + "a/a")); + QCOMPARE(m_model->expandedDirectories(), QSet() << QUrl::fromLocalFile(m_testDir->path() + "/a") + << QUrl::fromLocalFile(m_testDir->path() + "/a/a")); - QCOMPARE(spyInserted.count(), 1); - itemRangeList = spyInserted.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 1); + itemRangeList = itemsInsertedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(2, 1)); // 1 new item "a/a/1" with index 2 QVERIFY(!m_model->isExpandable(2)); @@ -565,27 +570,25 @@ void KFileItemModelTest::testExpandItems() // Expand the folder "a/a-1/" -> "a/a-1/1" becomes visible m_model->setExpanded(3, true); QVERIFY(m_model->isExpanded(3)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QCOMPARE(m_model->expandedDirectories(), allFolders); - QCOMPARE(spyInserted.count(), 1); - itemRangeList = spyInserted.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 1); + itemRangeList = itemsInsertedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(4, 1)); // 1 new item "a/a-1/1" with index 4 QVERIFY(!m_model->isExpandable(4)); QVERIFY(!m_model->isExpanded(4)); - QSignalSpy spyRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList))); - // Collapse the top-level folder -> all other items should disappear m_model->setExpanded(0, false); QVERIFY(!m_model->isExpanded(0)); QCOMPARE(m_model->count(), 1); - QVERIFY(!m_model->expandedDirectories().contains(QUrl::fromLocalFile(m_testDir->name() + 'a'))); // TODO: Make sure that child URLs are also removed + QVERIFY(!m_model->expandedDirectories().contains(QUrl::fromLocalFile(m_testDir->path() + "/a"))); // TODO: Make sure that child URLs are also removed - QCOMPARE(spyRemoved.count(), 1); - itemRangeList = spyRemoved.takeFirst().at(0).value(); + QCOMPARE(itemsRemovedSpy.count(), 1); + itemRangeList = itemsRemovedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 4)); // 4 items removed QVERIFY(m_model->isConsistent()); @@ -596,7 +599,7 @@ void KFileItemModelTest::testExpandItems() m_model->loadDirectory(m_testDir->url()); m_model->restoreExpandedDirectories(allFolders); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QVERIFY(m_model->isExpanded(0)); QVERIFY(m_model->isExpanded(1)); @@ -608,30 +611,33 @@ void KFileItemModelTest::testExpandItems() // Move to a sub folder, then call restoreExpandedFolders() *before* going back. // This is how DolphinView restores the expanded folders when navigating in history. - m_model->loadDirectory(QUrl::fromLocalFile(m_testDir->name() + "a/a/")); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + m_model->loadDirectory(QUrl::fromLocalFile(m_testDir->path() + "/a/a/")); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(m_model->count(), 1); // 1 item: "1" m_model->restoreExpandedDirectories(allFolders); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QCOMPARE(m_model->expandedDirectories(), allFolders); // Remove all expanded items by changing the roles - spyRemoved.clear(); + itemsRemovedSpy.clear(); m_model->setRoles(originalModelRoles); QVERIFY(!m_model->isExpanded(0)); QCOMPARE(m_model->count(), 1); - QVERIFY(!m_model->expandedDirectories().contains(QUrl::fromLocalFile(m_testDir->name() + 'a'))); + QVERIFY(!m_model->expandedDirectories().contains(QUrl::fromLocalFile(m_testDir->path() + "/a"))); - QCOMPARE(spyRemoved.count(), 1); - itemRangeList = spyRemoved.takeFirst().at(0).value(); + QCOMPARE(itemsRemovedSpy.count(), 1); + itemRangeList = itemsRemovedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 4)); // 4 items removed QVERIFY(m_model->isConsistent()); } void KFileItemModelTest::testExpandParentItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); + // Create a tree structure of folders: // a 1/ // a 1/b1/ @@ -644,20 +650,18 @@ void KFileItemModelTest::testExpandParentItems() modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a 1/b1/c1/file.txt" << "a2/b2/c2/d2/file.txt"; // missing folders are created automatically - m_testDir->createFiles(files); + m_testDir->createFiles({"a 1/b1/c1/file.txt", "a2/b2/c2/d2/file.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // So far, the model contains only "a 1/" and "a2/". QCOMPARE(m_model->count(), 2); QVERIFY(m_model->expandedDirectories().empty()); // Expand the parents of "a2/b2/c2". - m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->name() + "a2/b2/c2")); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->path() + "a2/b2/c2")); + QVERIFY(loadingCompletedSpy.wait()); // The model should now contain "a 1/", "a2/", "a2/b2/", and "a2/b2/c2/". // It's important that only the parents of "a1/b1/c1" are expanded. @@ -668,8 +672,8 @@ void KFileItemModelTest::testExpandParentItems() QVERIFY(!m_model->isExpanded(3)); // Expand the parents of "a 1/b1". - m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->name() + "a 1/b1")); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->path() + "a 1/b1")); + QVERIFY(loadingCompletedSpy.wait()); // The model should now contain "a 1/", "a 1/b1/", "a2/", "a2/b2", and "a2/b2/c2/". // It's important that only the parents of "a 1/b1/" and "a2/b2/c2/" are expanded. @@ -683,7 +687,7 @@ void KFileItemModelTest::testExpandParentItems() // Expand "a 1/b1/". m_model->setExpanded(1, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout)); + QVERIFY(loadingCompletedSpy.wait()); QCOMPARE(m_model->count(), 6); QVERIFY(m_model->isExpanded(0)); QVERIFY(m_model->isExpanded(1)); @@ -711,28 +715,27 @@ void KFileItemModelTest::testExpandParentItems() */ void KFileItemModelTest::testMakeExpandedItemHidden() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - m_testDir->createFile("1a/2a/3a"); - m_testDir->createFile("1a/2a/3b"); - m_testDir->createFile("1a/2b"); - m_testDir->createFile("1b"); + m_testDir->createFiles({"1a/2a/3a", "1a/2a/3b", "1a/2b", "1b"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // So far, the model contains only "1a/" and "1b". QCOMPARE(m_model->count(), 2); m_model->setExpanded(0, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // Now "1a/2a" and "1a/2b" have appeared. QCOMPARE(m_model->count(), 4); m_model->setExpanded(1, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 6); // Rename "1a/2" and make it hidden. @@ -742,7 +745,7 @@ void KFileItemModelTest::testMakeExpandedItemHidden() KIO::SimpleJob* job = KIO::rename(oldUrl, newUrl, KIO::HideProgressInfo); bool ok = job->exec(); QVERIFY(ok); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsRemovedSpy.wait()); // "1a/2" and its subfolders have disappeared now. QVERIFY(m_model->isConsistent()); @@ -755,17 +758,17 @@ void KFileItemModelTest::testMakeExpandedItemHidden() void KFileItemModelTest::testRemoveFilteredExpandedItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSet originalModelRoles = m_model->roles(); QSet modelRoles = originalModelRoles; modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "folder/child" << "file"; // missing folders are created automatically - m_testDir->createFiles(files); + m_testDir->createFiles({"folder/child", "file"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // So far, the model contains only "folder/" and "file". QCOMPARE(m_model->count(), 2); @@ -778,7 +781,7 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems() // Expand "folder" -> "folder/child" becomes visible. m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "folder" << "child" << "file"); // Add a name filter. @@ -800,6 +803,9 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems() void KFileItemModelTest::testSorting() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + // Create some files with different sizes and modification times to check the different sorting options QDateTime now = QDateTime::currentDateTime(); @@ -822,15 +828,15 @@ void KFileItemModelTest::testSorting() m_testDir->createFile(".f"); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); - int index = m_model->index(QUrl(m_testDir->url().url() + 'c')); + int index = m_model->index(QUrl(m_testDir->url().url() + "/c")); m_model->setExpanded(index, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); - index = m_model->index(QUrl(m_testDir->url().url() + "c/c-2")); + index = m_model->index(QUrl(m_testDir->url().url() + "/c/c-2")); m_model->setExpanded(index, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // Default: Sort by Name, ascending QCOMPARE(m_model->sortRole(), QByteArray("text")); @@ -839,16 +845,14 @@ void KFileItemModelTest::testSorting() QVERIFY(!m_model->showHiddenFiles()); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "d" << "e"); - QSignalSpy spyItemsMoved(m_model, SIGNAL(itemsMoved(KItemRange,QList))); - // Sort by Name, ascending, 'Sort Folders First' disabled m_model->setSortDirectoriesFirst(false); QCOMPARE(m_model->sortRole(), QByteArray("text")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(0, 6)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 2 << 4 << 5 << 3 << 0 << 1); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(0, 6)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 2 << 4 << 5 << 3 << 0 << 1); // Sort by Name, descending m_model->setSortDirectoriesFirst(true); @@ -856,11 +860,11 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortRole(), QByteArray("text")); QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "d" << "b" << "a"); - QCOMPARE(spyItemsMoved.count(), 2); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(0, 6)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 4 << 5 << 0 << 3 << 1 << 2); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(4, 4)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.count(), 2); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(0, 6)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 4 << 5 << 0 << 3 << 1 << 2); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(4, 4)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 7 << 6 << 5 << 4); // Sort by Date, descending m_model->setSortDirectoriesFirst(true); @@ -868,18 +872,18 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortRole(), QByteArray("date")); QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "b" << "d" << "a" << "e"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(4, 4)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 7 << 5 << 4 << 6); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(4, 4)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 7 << 5 << 4 << 6); // Sort by Date, ascending m_model->setSortOrder(Qt::AscendingOrder); QCOMPARE(m_model->sortRole(), QByteArray("date")); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "a" << "d" << "b"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(4, 4)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(4, 4)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 7 << 6 << 5 << 4); // Sort by Date, ascending, 'Sort Folders First' disabled m_model->setSortDirectoriesFirst(false); @@ -887,18 +891,18 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(!m_model->sortDirectoriesFirst()); QCOMPARE(itemsInModel(), QStringList() << "e" << "a" << "c" << "c-1" << "c-2" << "c-3" << "d" << "b"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(0, 6)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 2 << 4 << 5 << 3 << 0 << 1); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(0, 6)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 2 << 4 << 5 << 3 << 0 << 1); // Sort by Name, ascending, 'Sort Folders First' disabled m_model->setSortRole("text"); QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(!m_model->sortDirectoriesFirst()); QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(0, 8)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 7 << 0 << 2 << 3 << 4 << 5 << 6 << 1); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(0, 8)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 7 << 0 << 2 << 3 << 4 << 5 << 6 << 1); // Sort by Size, ascending, 'Sort Folders First' disabled m_model->setSortRole("size"); @@ -906,9 +910,9 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(!m_model->sortDirectoriesFirst()); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "e" << "d"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(0, 8)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 4 << 5 << 0 << 3 << 1 << 2 << 7 << 6); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(0, 8)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 4 << 5 << 0 << 3 << 1 << 2 << 7 << 6); // In 'Sort by Size' mode, folders are always first -> changing 'Sort Folders First' does not resort the model m_model->setSortDirectoriesFirst(true); @@ -916,7 +920,7 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder); QVERIFY(m_model->sortDirectoriesFirst()); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "e" << "d"); - QCOMPARE(spyItemsMoved.count(), 0); + QCOMPARE(itemsMovedSpy.count(), 0); // Sort by Size, descending, 'Sort Folders First' enabled m_model->setSortOrder(Qt::DescendingOrder); @@ -924,21 +928,21 @@ void KFileItemModelTest::testSorting() QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder); QVERIFY(m_model->sortDirectoriesFirst()); QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "d" << "e" << "b" << "a"); - QCOMPARE(spyItemsMoved.count(), 1); - QCOMPARE(spyItemsMoved.first().at(0).value(), KItemRange(4, 4)); - QCOMPARE(spyItemsMoved.takeFirst().at(1).value >(), QList() << 7 << 6 << 5 << 4); + QCOMPARE(itemsMovedSpy.count(), 1); + QCOMPARE(itemsMovedSpy.first().at(0).value(), KItemRange(4, 4)); + QCOMPARE(itemsMovedSpy.takeFirst().at(1).value >(), QList() << 7 << 6 << 5 << 4); // TODO: Sort by other roles; show/hide hidden files } void KFileItemModelTest::testIndexForKeyboardSearch() { - QStringList files; - files << "a" << "aa" << "Image.jpg" << "Image.png" << "Text" << "Text1" << "Text2" << "Text11"; - m_testDir->createFiles(files); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + + m_testDir->createFiles({"a", "aa", "Image.jpg", "Image.png", "Text", "Text1", "Text2", "Text11"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); // Search from index 0 QCOMPARE(m_model->indexForKeyboardSearch("a", 0), 0); @@ -983,12 +987,12 @@ void KFileItemModelTest::testIndexForKeyboardSearch() void KFileItemModelTest::testNameFilter() { - QStringList files; - files << "A1" << "A2" << "Abc" << "Bcd" << "Cde"; - m_testDir->createFiles(files); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + + m_testDir->createFiles({"A1", "A2", "Abc", "Bcd", "Cde"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); m_model->setNameFilter("A"); // Shows A1, A2 and Abc QCOMPARE(m_model->count(), 3); @@ -1040,28 +1044,27 @@ void KFileItemModelTest::testEmptyPath() */ void KFileItemModelTest::testRefreshExpandedItem() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsChangedSpy(m_model, &KFileItemModel::itemsChanged); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/1" << "a/2" << "3" << "4"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a/1", "a/2", "3", "4"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); // "a/", "3", "4" m_model->setExpanded(0, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4" QVERIFY(m_model->isExpanded(0)); - QSignalSpy spyItemsChanged(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet))); - const KFileItem item = m_model->fileItem(0); m_model->slotRefreshItems({qMakePair(item, item)}); - QVERIFY(!spyItemsChanged.isEmpty()); + QVERIFY(!itemsChangedSpy.isEmpty()); QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4" QVERIFY(m_model->isExpanded(0)); @@ -1079,37 +1082,37 @@ void KFileItemModelTest::testRemoveHiddenItems() m_testDir->createDir("d"); m_testDir->createFiles({".f", ".g", "h", "i"}); - QSignalSpy spyItemsInserted(m_model, SIGNAL(itemsInserted(KItemRangeList))); - QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList))); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); m_model->setShowHiddenFiles(true); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i"); - QCOMPARE(spyItemsInserted.count(), 1); - QCOMPARE(spyItemsRemoved.count(), 0); - KItemRangeList itemRangeList = spyItemsInserted.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 1); + QCOMPARE(itemsRemovedSpy.count(), 0); + KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 8)); m_model->setShowHiddenFiles(false); QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i"); - QCOMPARE(spyItemsInserted.count(), 0); - QCOMPARE(spyItemsRemoved.count(), 1); - itemRangeList = spyItemsRemoved.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 0); + QCOMPARE(itemsRemovedSpy.count(), 1); + itemRangeList = itemsRemovedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(4, 2)); m_model->setShowHiddenFiles(true); QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i"); - QCOMPARE(spyItemsInserted.count(), 1); - QCOMPARE(spyItemsRemoved.count(), 0); - itemRangeList = spyItemsInserted.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 1); + QCOMPARE(itemsRemovedSpy.count(), 0); + itemRangeList = itemsInsertedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(2, 2)); m_model->clear(); QCOMPARE(itemsInModel(), QStringList()); - QCOMPARE(spyItemsInserted.count(), 0); - QCOMPARE(spyItemsRemoved.count(), 1); - itemRangeList = spyItemsRemoved.takeFirst().at(0).value(); + QCOMPARE(itemsInsertedSpy.count(), 0); + QCOMPARE(itemsRemovedSpy.count(), 1); + itemRangeList = itemsRemovedSpy.takeFirst().at(0).value(); QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 8)); // Hiding hidden files makes the dir lister emit its itemsDeleted signal. @@ -1122,42 +1125,43 @@ void KFileItemModelTest::testRemoveHiddenItems() */ void KFileItemModelTest::collapseParentOfHiddenItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/1" << "a/b/1" << "a/b/c/1" << "a/b/c/d/1"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a/1", "a/b/1", "a/b/c/1", "a/b/c/d/1"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 1); // Only "a/" // Expand "a/". m_model->setExpanded(0, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/b/", "a/1" // Expand "a/b/". m_model->setExpanded(1, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/b/", "a/b/c", "a/b/1", "a/1" // Expand "a/b/c/". m_model->setExpanded(2, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 7); // 7 items: "a/", "a/b/", "a/b/c", "a/b/c/d/", "a/b/c/1", "a/b/1", "a/1" // Set a name filter that matches nothing -> only the expanded folders remain. m_model->setNameFilter("xyz"); + QCOMPARE(itemsRemovedSpy.count(), 1); QCOMPARE(m_model->count(), 3); QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c"); // Collapse the folder "a/". - QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList))); m_model->setExpanded(0, false); - QCOMPARE(spyItemsRemoved.count(), 1); + QCOMPARE(itemsRemovedSpy.count(), 2); QCOMPARE(m_model->count(), 1); QCOMPARE(itemsInModel(), QStringList() << "a"); @@ -1171,42 +1175,43 @@ void KFileItemModelTest::collapseParentOfHiddenItems() */ void KFileItemModelTest::removeParentOfHiddenItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/1" << "a/b/1" << "a/b/c/1" << "a/b/c/d/1"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a/1", "a/b/1", "a/b/c/1", "a/b/c/d/1"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 1); // Only "a/" // Expand "a/". m_model->setExpanded(0, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/b/", "a/1" // Expand "a/b/". m_model->setExpanded(1, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/b/", "a/b/c", "a/b/1", "a/1" // Expand "a/b/c/". m_model->setExpanded(2, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 7); // 7 items: "a/", "a/b/", "a/b/c", "a/b/c/d/", "a/b/c/1", "a/b/1", "a/1" // Set a name filter that matches nothing -> only the expanded folders remain. m_model->setNameFilter("xyz"); + QCOMPARE(itemsRemovedSpy.count(), 1); QCOMPARE(m_model->count(), 3); QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c"); // Simulate the deletion of the directory "a/b/". - QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList))); m_model->slotItemsDeleted(KFileItemList() << m_model->fileItem(1)); - QCOMPARE(spyItemsRemoved.count(), 1); + QCOMPARE(itemsRemovedSpy.count(), 2); QCOMPARE(m_model->count(), 1); QCOMPARE(itemsInModel(), QStringList() << "a"); @@ -1223,33 +1228,34 @@ void KFileItemModelTest::removeParentOfHiddenItems() */ void KFileItemModelTest::testGeneralParentChildRelationships() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "parent1/realChild1/realGrandChild1" << "parent2/realChild2/realGrandChild2"; - m_testDir->createFiles(files); + m_testDir->createFiles({"parent1/realChild1/realGrandChild1", "parent2/realChild2/realGrandChild2"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "parent2"); // Expand all folders. m_model->setExpanded(0, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2"); m_model->setExpanded(1, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2"); m_model->setExpanded(3, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2"); m_model->setExpanded(4, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2" << "realGrandChild2"); // Add some more children and grand-children. @@ -1279,7 +1285,6 @@ void KFileItemModelTest::testGeneralParentChildRelationships() QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "grandChild2" << "realGrandChild2" << "child2"); // Set a name filter that matches nothing -> only expanded folders remain. - QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); m_model->setNameFilter("xyz"); QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2" << "realChild2"); QCOMPARE(itemsRemovedSpy.count(), 1); @@ -1310,14 +1315,15 @@ void KFileItemModelTest::testGeneralParentChildRelationships() void KFileItemModelTest::testNameRoleGroups() { - QStringList files; - files << "b.txt" << "c.txt" << "d.txt" << "e.txt"; + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + QSignalSpy groupsChangedSpy(m_model, &KFileItemModel::groupsChanged); - m_testDir->createFiles(files); + m_testDir->createFiles({"b.txt", "c.txt", "d.txt", "e.txt"}); m_model->setGroupedSorting(true); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt" << "e.txt"); QList > expectedGroups; @@ -1331,7 +1337,7 @@ void KFileItemModelTest::testNameRoleGroups() QHash data; data.insert("text", "a.txt"); m_model->setData(2, data); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList)), DefaultTimeout)); + QVERIFY(itemsMovedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt"); expectedGroups.clear(); @@ -1344,7 +1350,7 @@ void KFileItemModelTest::testNameRoleGroups() // Rename c.txt to d.txt. data.insert("text", "d.txt"); m_model->setData(2, data); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(groupsChanged()), DefaultTimeout)); + QVERIFY(groupsChangedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.txt" << "e.txt"); expectedGroups.clear(); @@ -1362,7 +1368,7 @@ void KFileItemModelTest::testNameRoleGroups() fileItemC.setUrl(urlC); m_model->slotRefreshItems({qMakePair(fileItemD, fileItemC)}); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(groupsChanged()), DefaultTimeout)); + QVERIFY(groupsChangedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt"); expectedGroups.clear(); @@ -1375,18 +1381,17 @@ void KFileItemModelTest::testNameRoleGroups() void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/b.txt" << "a/c.txt" << "d/e.txt" << "d/f.txt"; - - m_testDir->createFiles(files); + m_testDir->createFiles({"a/b.txt", "a/c.txt", "d/e.txt", "d/f.txt"}); m_model->setGroupedSorting(true); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a" << "d"); QList > expectedGroups; @@ -1401,41 +1406,40 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d"); QCOMPARE(m_model->groups(), expectedGroups); m_model->setExpanded(3, true); QVERIFY(m_model->isExpanded(3)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d" << "e.txt" << "f.txt"); QCOMPARE(m_model->groups(), expectedGroups); } void KFileItemModelTest::testInconsistentModel() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/b/c1.txt" << "a/b/c2.txt"; - - m_testDir->createFiles(files); + m_testDir->createFiles({"a/b/c1.txt", "a/b/c2.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a"); // Expand "a/" and "a/b/". m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a" << "b"); m_model->setExpanded(1, true); QVERIFY(m_model->isExpanded(1)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c1.txt" << "c2.txt"); // Add the files "c1.txt" and "c2.txt" to the model also as top-level items. @@ -1471,16 +1475,16 @@ void KFileItemModelTest::testInconsistentModel() void KFileItemModelTest::testChangeRolesForFilteredItems() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSet modelRoles = m_model->roles(); modelRoles << "owner"; m_model->setRoles(modelRoles); - QStringList files; - files << "a.txt" << "aa.txt" << "aaa.txt"; - m_testDir->createFiles(files); + m_testDir->createFiles({"a.txt", "aa.txt", "aaa.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "aa.txt" << "aaa.txt"); for (int index = 0; index < m_model->count(); ++index) { @@ -1568,12 +1572,12 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering() void KFileItemModelTest::testRefreshFilteredItems() { - QStringList files; - files << "a.txt" << "b.txt" << "c.jpg" << "d.jpg"; - m_testDir->createFiles(files); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + + m_testDir->createFiles({"a.txt", "b.txt", "c.jpg", "d.jpg"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.jpg" << "d.jpg"); const KFileItem fileItemC = m_model->fileItem(2); @@ -1585,7 +1589,7 @@ void KFileItemModelTest::testRefreshFilteredItems() // Rename one of the .jpg files. KFileItem fileItemE = fileItemC; QUrl urlE = fileItemE.url().adjusted(QUrl::RemoveFilename); - urlE.setPath(urlE.path() + "e.jpg"); + urlE.setPath(urlE.path() + "/e.jpg"); fileItemE.setUrl(urlE); m_model->slotRefreshItems({qMakePair(fileItemC, fileItemE)}); @@ -1597,21 +1601,21 @@ void KFileItemModelTest::testRefreshFilteredItems() void KFileItemModelTest::testCreateMimeData() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a/1"; - m_testDir->createFiles(files); + m_testDir->createFile("a/1"); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a"); // Expand "a/". m_model->setExpanded(0, true); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a" << "1"); // Verify that creating the MIME data for a child of an expanded folder does @@ -1624,28 +1628,28 @@ void KFileItemModelTest::testCreateMimeData() void KFileItemModelTest::testCollapseFolderWhileLoading() { + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; m_model->setRoles(modelRoles); - QStringList files; - files << "a2/b/c1.txt"; - m_testDir->createFiles(files); + m_testDir->createFile("a2/b/c1.txt"); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a2"); // Expand "a2/". m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a2" << "b"); // Expand "a2/b/". m_model->setExpanded(1, true); QVERIFY(m_model->isExpanded(1)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a2" << "b" << "c1.txt"); // Simulate that a new item "c2.txt" appears, but that the dir lister's completed() @@ -1677,7 +1681,7 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() // Expand "a2/" again. m_model->setExpanded(0, true); QVERIFY(m_model->isExpanded(0)); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a2" << "b"); // Now simulate that a new folder "a1/" is appears, but that the dir lister's @@ -1702,12 +1706,12 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() void KFileItemModelTest::testDeleteFileMoreThanOnce() { - QStringList files; - files << "a.txt" << "b.txt" << "c.txt" << "d.txt"; - m_testDir->createFiles(files); + QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + + m_testDir->createFiles({"a.txt", "b.txt", "c.txt", "d.txt"}); m_model->loadDirectory(m_testDir->url()); - QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "d.txt"); const KFileItem fileItemB = m_model->fileItem(1); @@ -1730,6 +1734,6 @@ QStringList KFileItemModelTest::itemsInModel() const return items; } -QTEST_KDEMAIN(KFileItemModelTest, NoGUI) +QTEST_MAIN(KFileItemModelTest) #include "kfileitemmodeltest.moc" diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index 42c0a8ed2..cd4d0a681 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -17,10 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include -#include -#include - #include "kitemviews/kitemlistcontainer.h" #include "kitemviews/kfileitemlistview.h" #include "kitemviews/kfileitemmodel.h" @@ -32,13 +28,10 @@ #include #include +#include #include #include -namespace { - const int DefaultTimeout = 2000; -}; - Q_DECLARE_METATYPE(KFileItemListView::ItemLayout); Q_DECLARE_METATYPE(Qt::Orientation); Q_DECLARE_METATYPE(KItemListController::SelectionBehavior); @@ -104,7 +97,7 @@ void KItemListControllerTest::initTestCase() m_testDir->createFiles(files); m_model->loadDirectory(m_testDir->url()); QSignalSpy spyDirectoryLoadingCompleted(m_model, SIGNAL(directoryLoadingCompleted())); - QVERIFY(spyDirectoryLoadingCompleted.wait(DefaultTimeout)); + QVERIFY(spyDirectoryLoadingCompleted.wait()); m_container->show(); QTest::qWaitForWindowShown(m_container); @@ -567,7 +560,7 @@ void KItemListControllerTest::testMouseClickActivation() if (!KGlobalSettings::singleClick()) { // TODO: Try to find a way to make sure that changing the global setting works. - QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!"); } m_view->event(&mousePressEvent); @@ -588,7 +581,7 @@ void KItemListControllerTest::testMouseClickActivation() if (KGlobalSettings::singleClick()) { // TODO: Try to find a way to make sure that changing the global setting works. - QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!"); } m_view->event(&mousePressEvent); @@ -623,7 +616,7 @@ void KItemListControllerTest::testMouseClickActivation() if (!KGlobalSettings::singleClick()) { // TODO: Try to find a way to make sure that changing the global setting works. - QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!"); } m_view->event(&mousePressEvent); @@ -652,7 +645,7 @@ void KItemListControllerTest::testMouseClickActivation() if (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) { // TODO: Try to find a way to make sure that changing the global setting works. - QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!"); } } diff --git a/src/tests/kitemlistkeyboardsearchmanagertest.cpp b/src/tests/kitemlistkeyboardsearchmanagertest.cpp index 373f4f301..41475660d 100644 --- a/src/tests/kitemlistkeyboardsearchmanagertest.cpp +++ b/src/tests/kitemlistkeyboardsearchmanagertest.cpp @@ -17,10 +17,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include -#include #include "kitemviews/private/kitemlistkeyboardsearchmanager.h" +#include +#include + class KItemListKeyboardSearchManagerTest : public QObject { Q_OBJECT @@ -45,7 +46,7 @@ void KItemListKeyboardSearchManagerTest::init() void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch() { - QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool))); + QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); m_keyboardSearchManager.addKeys("f"); QCOMPARE(spy.count(), 1); @@ -70,7 +71,7 @@ void KItemListKeyboardSearchManagerTest::testAbortedKeyboardSearch() // to save time when running this test. m_keyboardSearchManager.setTimeout(100); - QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool))); + QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); m_keyboardSearchManager.addKeys("f"); QCOMPARE(spy.count(), 1); @@ -101,7 +102,7 @@ void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress() // 1. the string contains the repeated key only once, and // 2. the bool searchFromNextItem is true. - QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool))); + QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); m_keyboardSearchManager.addKeys("p"); QCOMPARE(spy.count(), 1); @@ -128,7 +129,7 @@ void KItemListKeyboardSearchManagerTest::testPressShift() // string. Make sure that this does not reset the current search. See // https://bugs.kde.org/show_bug.cgi?id=321286 - QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool))); + QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); // Simulate that the user enters "a_b". m_keyboardSearchManager.addKeys("a"); diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp index fb0f4fc2b..8403de701 100644 --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -18,11 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include -#include #include "kitemviews/kitemmodelbase.h" #include "kitemviews/kitemlistselectionmanager.h" +#include +#include + class DummyModel : public KItemModelBase { public: diff --git a/src/tests/kitemrangetest.cpp b/src/tests/kitemrangetest.cpp index 011f5ae86..882cd66e7 100644 --- a/src/tests/kitemrangetest.cpp +++ b/src/tests/kitemrangetest.cpp @@ -17,10 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include - #include "kitemviews/kitemrange.h" +#include #include Q_DECLARE_METATYPE(QVector); diff --git a/src/tests/kitemsettest.cpp b/src/tests/kitemsettest.cpp index 9cc02d060..ed683e1a8 100644 --- a/src/tests/kitemsettest.cpp +++ b/src/tests/kitemsettest.cpp @@ -17,10 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include - #include "kitemviews/kitemset.h" +#include #include Q_DECLARE_METATYPE(KItemRangeList); diff --git a/src/tests/kstandarditemmodeltest.cpp b/src/tests/kstandarditemmodeltest.cpp index f7e61ce90..e83e2031d 100644 --- a/src/tests/kstandarditemmodeltest.cpp +++ b/src/tests/kstandarditemmodeltest.cpp @@ -18,11 +18,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include - #include "kitemviews/kstandarditem.h" #include "kitemviews/kstandarditemmodel.h" +#include + class KStandardItemModelTest : public QObject { Q_OBJECT diff --git a/src/tests/testdir.cpp b/src/tests/testdir.cpp index dcc4c87a5..b84b344b7 100644 --- a/src/tests/testdir.cpp +++ b/src/tests/testdir.cpp @@ -28,7 +28,7 @@ #endif TestDir::TestDir(const QString& directoryPrefix) : - KTempDir(directoryPrefix) + QTemporaryDir(directoryPrefix) { } @@ -38,7 +38,7 @@ TestDir::~TestDir() QUrl TestDir::url() const { - return QUrl::fromLocalFile(name()); + return QUrl::fromLocalFile(path()); } /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */ @@ -85,7 +85,7 @@ void TestDir::createDir(const QString& path, const QDateTime& time) { QString absolutePath = path; makePathAbsoluteAndCreateParents(absolutePath); - QDir(name()).mkdir(absolutePath); + QDir(TestDir::path()).mkdir(absolutePath); if (time.isValid()) { setTimeStamp(absolutePath, time); @@ -94,12 +94,19 @@ void TestDir::createDir(const QString& path, const QDateTime& time) Q_ASSERT(QFile::exists(absolutePath)); } +void TestDir::removeFiles(const QStringList& files) +{ + foreach (const QString& path, files) { + removeFile(path); + } +} + void TestDir::removeFile(const QString& path) { QString absolutePath = path; QFileInfo fileInfo(absolutePath); if (!fileInfo.isAbsolute()) { - absolutePath = name() + path; + absolutePath = TestDir::path() + QLatin1Char('/') + path; } QFile::remove(absolutePath); } @@ -108,7 +115,7 @@ void TestDir::makePathAbsoluteAndCreateParents(QString& path) { QFileInfo fileInfo(path); if (!fileInfo.isAbsolute()) { - path = name() + path; + path = TestDir::path() + QLatin1Char('/') + path; fileInfo.setFile(path); } diff --git a/src/tests/testdir.h b/src/tests/testdir.h index 24c4d77b0..3f244448c 100644 --- a/src/tests/testdir.h +++ b/src/tests/testdir.h @@ -20,16 +20,15 @@ #ifndef TESTDIR_H #define TESTDIR_H -#include #include - +#include #include /** - * TestDir provides a temporary directory. In addition to KTempDir, it has + * TestDir provides a temporary directory. In addition to QTemporaryDir, it has * methods that create files and subdirectories inside the directory. */ -class TestDir : public KTempDir +class TestDir : public QTemporaryDir { public: @@ -50,6 +49,7 @@ public: void createDir(const QString& path, const QDateTime& time = QDateTime()); void removeFile(const QString& path); + void removeFiles(const QStringList& files); private: void makePathAbsoluteAndCreateParents(QString& path); diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp index d5584ce82..ba2ca307c 100644 --- a/src/tests/viewpropertiestest.cpp +++ b/src/tests/viewpropertiestest.cpp @@ -17,12 +17,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ -#include - #include "dolphin_generalsettings.h" #include "views/viewproperties.h" #include "testdir.h" +#include #include class ViewPropertiesTest : public QObject @@ -68,29 +67,27 @@ void ViewPropertiesTest::cleanup() */ void ViewPropertiesTest::testReadOnlyBehavior() { - QString dotDirectoryFile = m_testDir->url().toLocalFile() + ".directory"; + QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory"; QVERIFY(!QFile::exists(dotDirectoryFile)); - ViewProperties* props = new ViewProperties(m_testDir->url()); + QScopedPointer props(new ViewProperties(m_testDir->url())); QVERIFY(props->isAutoSaveEnabled()); const QByteArray sortRole = props->sortRole(); Q_UNUSED(sortRole); - delete props; - props = 0; + props.reset(); QVERIFY(!QFile::exists(dotDirectoryFile)); } void ViewPropertiesTest::testAutoSave() { - QString dotDirectoryFile = m_testDir->url().toLocalFile() + ".directory"; + QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory"; QVERIFY(!QFile::exists(dotDirectoryFile)); - ViewProperties* props = new ViewProperties(m_testDir->url()); + QScopedPointer props(new ViewProperties(m_testDir->url())); QVERIFY(props->isAutoSaveEnabled()); props->setSortRole("someNewSortRole"); - delete props; - props = 0; + props.reset(); QVERIFY(QFile::exists(dotDirectoryFile)); } -- cgit v1.3 From 7c695cd709aff2cc7cc5d36784ac53ad7b6435cf Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 24 Dec 2014 08:49:47 +0100 Subject: Fix compilation with Qt 5.2 and 5.3; QSignalSpy can't take a function pointer yet --- src/tests/kfileitemlistviewtest.cpp | 6 +- src/tests/kfileitemmodeltest.cpp | 113 +++++++++++++---------- src/tests/kitemlistkeyboardsearchmanagertest.cpp | 12 ++- 3 files changed, 76 insertions(+), 55 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/src/tests/kfileitemlistviewtest.cpp b/src/tests/kfileitemlistviewtest.cpp index 9e1add8cf..5c40abba3 100644 --- a/src/tests/kfileitemlistviewtest.cpp +++ b/src/tests/kfileitemlistviewtest.cpp @@ -87,8 +87,10 @@ void KFileItemListViewTest::cleanup() */ void KFileItemListViewTest::testGroupedItemChanges() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QVERIFY(itemsInsertedSpy.isValid()); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); + QVERIFY(itemsRemovedSpy.isValid()); m_model->setGroupedSorting(true); diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 74b2342c8..cf50db02a 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -141,7 +141,8 @@ void KFileItemModelTest::testDefaultRoles() void KFileItemModelTest::testDefaultSortRole() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QVERIFY(itemsInsertedSpy.isValid()); QCOMPARE(m_model->sortRole(), QByteArray("text")); @@ -163,7 +164,7 @@ void KFileItemModelTest::testDefaultGroupedSorting() void KFileItemModelTest::testNewItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); @@ -177,8 +178,8 @@ void KFileItemModelTest::testNewItems() void KFileItemModelTest::testRemoveItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); m_testDir->createFiles({"a.txt", "b.txt"}); m_model->loadDirectory(m_testDir->url()); @@ -195,9 +196,9 @@ void KFileItemModelTest::testRemoveItems() void KFileItemModelTest::testDirLoadingCompleted() { - QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted())); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); m_testDir->createFiles({"a.txt", "b.txt", "c.txt"}); @@ -238,8 +239,10 @@ void KFileItemModelTest::testDirLoadingCompleted() void KFileItemModelTest::testSetData() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsChangedSpy(m_model, &KFileItemModel::itemsChanged); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QVERIFY(itemsInsertedSpy.isValid()); + QSignalSpy itemsChangedSpy(m_model, SIGNAL(itemsChanged(KItemRangeList, QSet))); + QVERIFY(itemsChangedSpy.isValid()); m_testDir->createFile("a.txt"); @@ -291,8 +294,10 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() QFETCH(int, ratingIndex1); QFETCH(int, ratingIndex2); - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QVERIFY(itemsInsertedSpy.isValid()); + QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList))); + QVERIFY(itemsMovedSpy.isValid()); // Changing the value of a sort-role must result in // a reordering of the items. @@ -344,8 +349,9 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() void KFileItemModelTest::testChangeSortRole() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList))); + QVERIFY(itemsMovedSpy.isValid()); QCOMPARE(m_model->sortRole(), QByteArray("text")); @@ -383,8 +389,9 @@ void KFileItemModelTest::testChangeSortRole() void KFileItemModelTest::testResortAfterChangingName() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList))); + QVERIFY(itemsMovedSpy.isValid()); // We sort by size in a directory where all files have the same size. // Therefore, the files are sorted by their names. @@ -420,7 +427,7 @@ void KFileItemModelTest::testResortAfterChangingName() void KFileItemModelTest::testModelConsistencyWhenInsertingItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); // KFileItemModel prevents that inserting a punch of items sequentially // results in an itemsInserted()-signal for each item. Instead internally @@ -462,7 +469,7 @@ void KFileItemModelTest::testModelConsistencyWhenInsertingItems() void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_testDir->createFiles({"B", "E", "G"}); @@ -501,9 +508,12 @@ void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems() void KFileItemModelTest::testExpandItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); - QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QVERIFY(itemsInsertedSpy.isValid()); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); + QVERIFY(itemsRemovedSpy.isValid()); + QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted())); + QVERIFY(loadingCompletedSpy.isValid()); // Test expanding subfolders in a folder with the items "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1". // Besides testing the basic item expansion functionality, the test makes sure that @@ -635,8 +645,9 @@ void KFileItemModelTest::testExpandItems() void KFileItemModelTest::testExpandParentItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted())); + QVERIFY(loadingCompletedSpy.isValid()); // Create a tree structure of folders: // a 1/ @@ -715,8 +726,8 @@ void KFileItemModelTest::testExpandParentItems() */ void KFileItemModelTest::testMakeExpandedItemHidden() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -758,7 +769,7 @@ void KFileItemModelTest::testMakeExpandedItemHidden() void KFileItemModelTest::testRemoveFilteredExpandedItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSet originalModelRoles = m_model->roles(); QSet modelRoles = originalModelRoles; @@ -803,8 +814,9 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems() void KFileItemModelTest::testSorting() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList))); + QVERIFY(itemsMovedSpy.isValid()); // Create some files with different sizes and modification times to check the different sorting options QDateTime now = QDateTime::currentDateTime(); @@ -937,7 +949,7 @@ void KFileItemModelTest::testSorting() void KFileItemModelTest::testIndexForKeyboardSearch() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_testDir->createFiles({"a", "aa", "Image.jpg", "Image.png", "Text", "Text1", "Text2", "Text11"}); @@ -987,7 +999,7 @@ void KFileItemModelTest::testIndexForKeyboardSearch() void KFileItemModelTest::testNameFilter() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_testDir->createFiles({"A1", "A2", "Abc", "Bcd", "Cde"}); @@ -1044,8 +1056,9 @@ void KFileItemModelTest::testEmptyPath() */ void KFileItemModelTest::testRefreshExpandedItem() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsChangedSpy(m_model, &KFileItemModel::itemsChanged); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsChangedSpy(m_model, SIGNAL(itemsChanged(KItemRangeList, QSet))); + QVERIFY(itemsChangedSpy.isValid()); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1082,8 +1095,8 @@ void KFileItemModelTest::testRemoveHiddenItems() m_testDir->createDir("d"); m_testDir->createFiles({".f", ".g", "h", "i"}); - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); m_model->setShowHiddenFiles(true); m_model->loadDirectory(m_testDir->url()); @@ -1125,8 +1138,8 @@ void KFileItemModelTest::testRemoveHiddenItems() */ void KFileItemModelTest::collapseParentOfHiddenItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1175,8 +1188,8 @@ void KFileItemModelTest::collapseParentOfHiddenItems() */ void KFileItemModelTest::removeParentOfHiddenItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1228,8 +1241,8 @@ void KFileItemModelTest::removeParentOfHiddenItems() */ void KFileItemModelTest::testGeneralParentChildRelationships() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1315,9 +1328,11 @@ void KFileItemModelTest::testGeneralParentChildRelationships() void KFileItemModelTest::testNameRoleGroups() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); - QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved); - QSignalSpy groupsChangedSpy(m_model, &KFileItemModel::groupsChanged); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); + QSignalSpy itemsMovedSpy(m_model, SIGNAL(itemsMoved(KItemRange,QList))); + QVERIFY(itemsMovedSpy.isValid()); + QSignalSpy groupsChangedSpy(m_model, SIGNAL(groupsChanged())); + QVERIFY(groupsChangedSpy.isValid()); m_testDir->createFiles({"b.txt", "c.txt", "d.txt", "e.txt"}); @@ -1381,7 +1396,7 @@ void KFileItemModelTest::testNameRoleGroups() void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1419,7 +1434,7 @@ void KFileItemModelTest::testNameRoleGroupsWithExpandedItems() void KFileItemModelTest::testInconsistentModel() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1475,7 +1490,7 @@ void KFileItemModelTest::testInconsistentModel() void KFileItemModelTest::testChangeRolesForFilteredItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "owner"; @@ -1572,7 +1587,7 @@ void KFileItemModelTest::testChangeSortRoleWhileFiltering() void KFileItemModelTest::testRefreshFilteredItems() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_testDir->createFiles({"a.txt", "b.txt", "c.jpg", "d.jpg"}); @@ -1601,7 +1616,7 @@ void KFileItemModelTest::testRefreshFilteredItems() void KFileItemModelTest::testCreateMimeData() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1628,7 +1643,7 @@ void KFileItemModelTest::testCreateMimeData() void KFileItemModelTest::testCollapseFolderWhileLoading() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); QSet modelRoles = m_model->roles(); modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount"; @@ -1706,7 +1721,7 @@ void KFileItemModelTest::testCollapseFolderWhileLoading() void KFileItemModelTest::testDeleteFileMoreThanOnce() { - QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted); + QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList))); m_testDir->createFiles({"a.txt", "b.txt", "c.txt", "d.txt"}); diff --git a/src/tests/kitemlistkeyboardsearchmanagertest.cpp b/src/tests/kitemlistkeyboardsearchmanagertest.cpp index 41475660d..6720b9fc3 100644 --- a/src/tests/kitemlistkeyboardsearchmanagertest.cpp +++ b/src/tests/kitemlistkeyboardsearchmanagertest.cpp @@ -46,7 +46,8 @@ void KItemListKeyboardSearchManagerTest::init() void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch() { - QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); + QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool))); + QVERIFY(spy.isValid()); m_keyboardSearchManager.addKeys("f"); QCOMPARE(spy.count(), 1); @@ -71,7 +72,8 @@ void KItemListKeyboardSearchManagerTest::testAbortedKeyboardSearch() // to save time when running this test. m_keyboardSearchManager.setTimeout(100); - QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); + QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool))); + QVERIFY(spy.isValid()); m_keyboardSearchManager.addKeys("f"); QCOMPARE(spy.count(), 1); @@ -102,7 +104,8 @@ void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress() // 1. the string contains the repeated key only once, and // 2. the bool searchFromNextItem is true. - QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); + QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool))); + QVERIFY(spy.isValid()); m_keyboardSearchManager.addKeys("p"); QCOMPARE(spy.count(), 1); @@ -129,7 +132,8 @@ void KItemListKeyboardSearchManagerTest::testPressShift() // string. Make sure that this does not reset the current search. See // https://bugs.kde.org/show_bug.cgi?id=321286 - QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem); + QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString, bool))); + QVERIFY(spy.isValid()); // Simulate that the user enters "a_b". m_keyboardSearchManager.addKeys("a"); -- cgit v1.3 From 832e157ecd1a1640b82425358b20fff416a2f8b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Pescosta Date: Thu, 26 Feb 2015 17:40:06 +0100 Subject: Port away from KDELibs4Support (we only use KDELibs4Support when baloo isn't present, because KFileMetaDataWidget is in KDELibs4Support) Reviewed-By: Vishesh Handa --- CMakeLists.txt | 10 +++++- src/CMakeLists.txt | 47 ++++++++++++++++++------- src/dolphinmainwindow.cpp | 6 ++-- src/dolphinmainwindow.h | 4 +-- src/dolphinpart.cpp | 7 ++-- src/kitemviews/kitemlistcontroller.cpp | 7 ++-- src/panels/folders/folderspanel.cpp | 4 +-- src/panels/folders/treeviewcontextmenu.cpp | 3 +- src/panels/places/placesitemeditdialog.cpp | 1 - src/panels/places/placesitemmodel.cpp | 2 -- src/search/dolphinsearchbox.cpp | 18 ++++++---- src/settings/startup/startupsettingspage.cpp | 4 +-- src/settings/viewmodes/dolphinfontrequester.cpp | 10 +++--- src/settings/viewpropertiesdialog.cpp | 1 - src/tests/kfileitemlistviewtest.cpp | 2 +- src/tests/kfileitemmodelbenchmark.cpp | 10 +++--- src/tests/kfileitemmodeltest.cpp | 10 +++--- src/tests/kitemlistcontrollertest.cpp | 4 +-- src/views/dolphinview.cpp | 1 - src/views/renamedialog.cpp | 1 - 20 files changed, 96 insertions(+), 56 deletions(-) (limited to 'src/tests/kfileitemmodeltest.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index f31def98e..9c2b109af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS DocTools Init KCMUtils - KDELibs4Support NewStuff CoreAddons I18n @@ -53,6 +52,11 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS KIO Parts Solid + IconThemes + Completion + TextEditor + WindowSystem + Notifications ) find_package(KF5 ${KF5_MIN_VERSION} COMPONENTS Activities @@ -83,6 +87,10 @@ set_package_properties(KF5FileMetaData PROPERTIES if (KF5Baloo_FOUND AND KF5BalooWidgets_FOUND AND KF5FileMetaData_FOUND) message(STATUS "Baloo packages are found") set(HAVE_BALOO TRUE) +else() + find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS + KDELibs4Support # for KFileMetaDataWidget + ) endif() add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b04a642b..9ea45e34b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,8 +3,18 @@ configure_file(config-baloo.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-baloo.h) configure_file(config-dolphin.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-dolphin.h) -add_definitions(-DTRANSLATION_DOMAIN=\"dolphin\" -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) -remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_URL_CAST_FROM_STRING) +add_definitions( + -DTRANSLATION_DOMAIN=\"dolphin\" + -DQT_USE_FAST_CONCATENATION + -DQT_USE_FAST_OPERATOR_PLUS +) +remove_definitions( + -DQT_NO_CAST_FROM_BYTEARRAY + -DQT_NO_URL_CAST_FROM_STRING + -DQT_NO_SIGNALS_SLOTS_KEYWORDS + -DQT_NO_CAST_FROM_ASCII + -DQT_NO_CAST_TO_ASCII +) if(X11_Xrender_FOUND) set(HAVE_XRENDER TRUE) @@ -132,7 +142,16 @@ add_library(dolphinprivate ${dolphinprivate_LIB_SRCS}) target_link_libraries( dolphinprivate PUBLIC dolphinvcs - KF5::KDELibs4Support + Qt5::Gui + KF5::I18n + KF5::IconThemes + KF5::KIOCore + KF5::KIOWidgets + KF5::KIOFileWidgets + KF5::Completion + KF5::TextEditor + KF5::WindowSystem + KF5::ConfigCore KF5::NewStuff ) @@ -143,6 +162,11 @@ if(HAVE_BALOO) KF5::Baloo KF5::BalooWidgets ) +else() + target_link_libraries( + dolphinprivate PUBLIC + KF5::KDELibs4Support # for KFileMetaDataWidget + ) endif() if(X11_Xrender_FOUND) @@ -168,7 +192,6 @@ add_library(dolphinpart MODULE ${dolphinpart_SRCS}) target_link_libraries(dolphinpart dolphinprivate - KF5::KDELibs4Support ) install(TARGETS dolphinpart DESTINATION ${PLUGIN_INSTALL_DIR}) @@ -261,16 +284,14 @@ target_include_directories(kdeinit_dolphin PRIVATE ${PHONON_INCLUDES}) target_link_libraries(kdeinit_dolphin dolphinprivate - KF5::NewStuff KF5::Parts KF5::KCMUtils KF5::Solid - KF5::KIOFileWidgets - Phonon::phonon4qt5 - KF5::KDELibs4Support - KF5::I18n KF5::CoreAddons KF5::DBusAddons + KF5::Bookmarks + KF5::Notifications + Phonon::phonon4qt5 ) if (KF5Activities_FOUND) @@ -338,10 +359,10 @@ add_library(kcm_dolphinnavigation MODULE ${kcm_dolphinnavigation_PART_SRCS}) add_library(kcm_dolphinservices MODULE ${kcm_dolphinservices_PART_SRCS}) add_library(kcm_dolphingeneral MODULE ${kcm_dolphingeneral_PART_SRCS}) -target_link_libraries(kcm_dolphinviewmodes KF5::KDELibs4Support dolphinprivate) -target_link_libraries(kcm_dolphinnavigation KF5::KDELibs4Support dolphinprivate) -target_link_libraries(kcm_dolphinservices KF5::KDELibs4Support dolphinprivate) -target_link_libraries(kcm_dolphingeneral KF5::KDELibs4Support dolphinprivate) +target_link_libraries(kcm_dolphinviewmodes dolphinprivate) +target_link_libraries(kcm_dolphinnavigation dolphinprivate) +target_link_libraries(kcm_dolphinservices dolphinprivate) +target_link_libraries(kcm_dolphingeneral dolphinprivate) install(TARGETS kcm_dolphinviewmodes DESTINATION ${PLUGIN_INSTALL_DIR} ) install(TARGETS kcm_dolphinnavigation DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 0ee6e5c2c..1eda03e3c 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -687,7 +686,10 @@ void DolphinMainWindow::openTerminal() // If the given directory is not local, it can still be the URL of an // ioslave using UDS_LOCAL_PATH which to be converted first. - QUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this); + KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url()); + KJobWidgets::setWindow(statJob, this); + statJob->exec(); + QUrl url = statJob->mostLocalUrl(); //If the URL is local after the above conversion, set the directory. if (url.isLocalFile()) { diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index e3188aee5..5066657ef 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -31,7 +31,7 @@ #include #include -#include +#include typedef KIO::FileUndoManager::CommandType CommandType; @@ -493,7 +493,7 @@ private: DolphinViewActionHandler* m_actionHandler; DolphinRemoteEncoding* m_remoteEncoding; - QWeakPointer m_settingsDialog; + QPointer m_settingsDialog; // Members for the toolbar menu that is shown when the menubar is hidden: QToolButton* m_controlButton; diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 35f328be5..ea0ffd92c 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include #include "dolphinpart_ext.h" #include "dolphinnewfilemenu.h" @@ -541,7 +541,10 @@ void DolphinPart::slotOpenTerminal() // If the given directory is not local, it can still be the URL of an // ioslave using UDS_LOCAL_PATH which to be converted first. - u = KIO::NetAccess::mostLocalUrl(u, widget()); + KIO::StatJob* statJob = KIO::mostLocalUrl(u); + KJobWidgets::setWindow(statJob, widget()); + statJob->exec(); + u = statJob->mostLocalUrl(); //If the URL is local after the above conversion, set the directory. if (u.isLocalFile()) { diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 6c32e4b37..a9ebf97af 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -917,7 +917,8 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT emit itemDropEvent(m_view->itemAt(pos), event); } - QAccessible::updateAccessibility(view(), 0, QAccessible::DragDropEnd); + QAccessibleEvent accessibilityEvent(view(), QAccessible::DragDropEnd); + QAccessible::updateAccessibility(&accessibilityEvent); return true; } @@ -1171,7 +1172,9 @@ void KItemListController::startDragging() drag->setHotSpot(hotSpot); drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction); - QAccessible::updateAccessibility(view(), 0, QAccessible::DragDropStart); + + QAccessibleEvent accessibilityEvent(view(), QAccessible::DragDropStart); + QAccessible::updateAccessibility(&accessibilityEvent); } KItemListWidget* KItemListController::hoveredWidget() const diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index e99c673bc..13df9019b 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -208,7 +208,7 @@ void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos) const KFileItem fileItem = m_model->fileItem(index); - QWeakPointer contextMenu = new TreeViewContextMenu(this, fileItem); + QPointer contextMenu = new TreeViewContextMenu(this, fileItem); contextMenu.data()->open(); if (contextMenu.data()) { delete contextMenu.data(); @@ -219,7 +219,7 @@ void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos) { Q_UNUSED(pos); - QWeakPointer contextMenu = new TreeViewContextMenu(this, KFileItem()); + QPointer contextMenu = new TreeViewContextMenu(this, KFileItem()); contextMenu.data()->open(); if (contextMenu.data()) { delete contextMenu.data(); diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index bbdf783cd..e45fcd67e 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -42,6 +42,7 @@ #include #include #include +#include TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo) : @@ -148,7 +149,7 @@ void TreeViewContextMenu::open() } } - QWeakPointer popupPtr = popup; + QPointer popupPtr = popup; popup->exec(QCursor::pos()); if (popupPtr.data()) { popupPtr.data()->deleteLater(); diff --git a/src/panels/places/placesitemeditdialog.cpp b/src/panels/places/placesitemeditdialog.cpp index d5ca4bf4f..d035b0403 100644 --- a/src/panels/places/placesitemeditdialog.cpp +++ b/src/panels/places/placesitemeditdialog.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 354d4a43e..bc7c2b7d3 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -26,13 +26,11 @@ #include "dolphin_generalsettings.h" #include -#include #include #include "dolphindebug.h" #include #include #include -#include #include #include #include diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index d4ebba8c0..524c4462f 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #ifdef HAVE_BALOO @@ -130,9 +131,11 @@ QUrl DolphinSearchBox::urlForSearching() const url = balooUrlForSearching(); } else { url.setScheme("filenamesearch"); - url.addQueryItem("search", m_searchInput->text()); + + QUrlQuery query; + query.addQueryItem("search", m_searchInput->text()); if (m_contentButton->isChecked()) { - url.addQueryItem("checkContent", "yes"); + query.addQueryItem("checkContent", "yes"); } QString encodedUrl; @@ -144,7 +147,9 @@ QUrl DolphinSearchBox::urlForSearching() const } else { encodedUrl = m_searchPath.url(); } - url.addQueryItem("url", encodedUrl); + query.addQueryItem("url", encodedUrl); + + url.setQuery(query); } return url; @@ -155,9 +160,10 @@ void DolphinSearchBox::fromSearchUrl(const QUrl& url) if (url.scheme() == "baloosearch") { fromBalooSearchUrl(url); } else if (url.scheme() == "filenamesearch") { - setText(url.queryItemValue("search")); - setSearchPath(QUrl::fromUserInput(url.queryItemValue("url"), QString(), QUrl::AssumeLocalFile)); - m_contentButton->setChecked(url.queryItemValue("checkContent") == "yes"); + const QUrlQuery query(url); + setText(query.queryItemValue("search")); + setSearchPath(QUrl::fromUserInput(query.queryItemValue("url"), QString(), QUrl::AssumeLocalFile)); + m_contentButton->setChecked(query.queryItemValue("checkContent") == "yes"); } else { setText(QString()); setSearchPath(url); diff --git a/src/settings/startup/startupsettingspage.cpp b/src/settings/startup/startupsettingspage.cpp index baba7f8a1..21b213cd5 100644 --- a/src/settings/startup/startupsettingspage.cpp +++ b/src/settings/startup/startupsettingspage.cpp @@ -24,7 +24,6 @@ #include "dolphin_generalsettings.h" -#include #include #include #include @@ -36,6 +35,7 @@ #include #include #include +#include #include "views/dolphinview.h" @@ -165,7 +165,7 @@ void StartupSettingsPage::slotSettingsChanged() void StartupSettingsPage::selectHomeUrl() { const QString homeUrl = m_homeUrl->text(); - QUrl url = KFileDialog::getExistingDirectoryUrl(QUrl::fromLocalFile(homeUrl), this); + QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString(), QUrl::fromLocalFile(homeUrl)); if (!url.isEmpty()) { m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); slotSettingsChanged(); diff --git a/src/settings/viewmodes/dolphinfontrequester.cpp b/src/settings/viewmodes/dolphinfontrequester.cpp index 4d8b4813c..b9c5d97cf 100644 --- a/src/settings/viewmodes/dolphinfontrequester.cpp +++ b/src/settings/viewmodes/dolphinfontrequester.cpp @@ -19,13 +19,13 @@ #include "dolphinfontrequester.h" -#include #include #include #include #include #include +#include DolphinFontRequester::DolphinFontRequester(QWidget* parent) : QWidget(parent), @@ -86,11 +86,9 @@ QFont DolphinFontRequester::customFont() const void DolphinFontRequester::openFontDialog() { - QFont font = m_customFont; - const int result = KFontDialog::getFont(font, - KFontChooser::NoDisplayFlags, - this); - if (result == KFontDialog::Accepted) { + bool ok = false; + const QFont font = QFontDialog::getFont(&ok, this); + if (ok) { m_customFont = font; m_modeCombo->setFont(m_customFont); emit changed(); diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp index aa7e4b4a0..be7fe0d86 100644 --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #include #include diff --git a/src/tests/kfileitemlistviewtest.cpp b/src/tests/kfileitemlistviewtest.cpp index 5c40abba3..cac4f7a58 100644 --- a/src/tests/kfileitemlistviewtest.cpp +++ b/src/tests/kfileitemlistviewtest.cpp @@ -56,7 +56,7 @@ void KFileItemListViewTest::init() m_graphicsView = new QGraphicsView(); m_graphicsView->show(); - QTest::qWaitForWindowShown(m_graphicsView); + QTest::qWaitForWindowExposed(m_graphicsView); } void KFileItemListViewTest::cleanup() diff --git a/src/tests/kfileitemmodelbenchmark.cpp b/src/tests/kfileitemmodelbenchmark.cpp index c970a7198..b73485efb 100644 --- a/src/tests/kfileitemmodelbenchmark.cpp +++ b/src/tests/kfileitemmodelbenchmark.cpp @@ -29,18 +29,20 @@ #include "testdir.h" -void myMessageOutput(QtMsgType type, const char* msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) { + Q_UNUSED(context); + switch (type) { case QtDebugMsg: break; case QtWarningMsg: break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s\n", msg); + fprintf(stderr, "Critical: %s\n", msg.toLocal8Bit().data()); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s\n", msg); + fprintf(stderr, "Fatal: %s\n", msg.toLocal8Bit().data()); abort(); default: break; @@ -317,7 +319,7 @@ void KFileItemModelBenchmark::insertManyChildItems() KFileItemList KFileItemModelBenchmark::createFileItemList(const QStringList& fileNames, const QString& prefix) { // Suppress 'file does not exist anymore' messages from KFileItemPrivate::init(). - qInstallMsgHandler(myMessageOutput); + qInstallMessageHandler(myMessageOutput); KFileItemList result; foreach (const QString& name, fileNames) { diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index cf50db02a..eba32e1e1 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -29,18 +29,20 @@ #include "kitemviews/private/kfileitemmodeldirlister.h" #include "testdir.h" -void myMessageOutput(QtMsgType type, const char* msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) { + Q_UNUSED(context); + switch (type) { case QtDebugMsg: break; case QtWarningMsg: break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s\n", msg); + fprintf(stderr, "Critical: %s\n", msg.toLocal8Bit().data()); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s\n", msg); + fprintf(stderr, "Fatal: %s\n", msg.toLocal8Bit().data()); abort(); default: break; @@ -107,7 +109,7 @@ void KFileItemModelTest::init() { // The item-model tests result in a huge number of debugging // output from kdelibs. Only show critical and fatal messages. - qInstallMsgHandler(myMessageOutput); + qInstallMessageHandler(myMessageOutput); qRegisterMetaType("KItemRange"); qRegisterMetaType("KItemRangeList"); diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index dafb9f854..e34731fa4 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -142,7 +142,7 @@ void KItemListControllerTest::initTestCase() QVERIFY(spyDirectoryLoadingCompleted.wait()); m_container->show(); - QTest::qWaitForWindowShown(m_container); + QTest::qWaitForWindowExposed(m_container); } void KItemListControllerTest::cleanupTestCase() @@ -460,7 +460,7 @@ void KItemListControllerTest::testKeyboardNavigation_data() selectionBehaviorNames[selectionBehavior] + ", " + groupingEnabledNames[groupingEnabled]; - const QByteArray testNameAscii = testName.toAscii(); + const QByteArray testNameAscii = testName.toLatin1(); QTest::newRow(testNameAscii.data()) << layout diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 4129cc217..191cd6511 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index 6d009ba9a..be9e34c4a 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -23,7 +23,6 @@ #include #include #include -#include //TODO port to QCollator #include #include -- cgit v1.3