1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

bookmarks: port foreach -> range-based for

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-12-30 19:50:58 +01:00
parent 40c06eaaae
commit c4b6ae9019
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
13 changed files with 54 additions and 32 deletions

View File

@ -322,7 +322,7 @@ void Bookmarks::readBookmarks(const QVariantList &list, BookmarkItem* parent)
{
Q_ASSERT(parent);
foreach (const QVariant &entry, list) {
for (const QVariant &entry : list) {
const QVariantMap map = entry.toMap();
BookmarkItem::Type type = BookmarkItem::typeFromString(map.value(QSL("type")).toString());
@ -364,7 +364,8 @@ QVariantList Bookmarks::writeBookmarks(BookmarkItem* parent)
QVariantList list;
foreach (BookmarkItem* child, parent->children()) {
const auto children = parent->children();
for (BookmarkItem* child : children) {
QVariantMap map;
map.insert(QSL("type"), BookmarkItem::typeToString(child->type()));
@ -405,11 +406,13 @@ void Bookmarks::search(QList<BookmarkItem*>* items, BookmarkItem* parent, const
switch (parent->type()) {
case BookmarkItem::Root:
case BookmarkItem::Folder:
foreach (BookmarkItem* child, parent->children()) {
case BookmarkItem::Folder: {
const auto children = parent->children();
for (BookmarkItem* child : children) {
search(items, child, url);
}
break;
}
case BookmarkItem::Url:
if (parent->url() == url) {
@ -433,11 +436,13 @@ void Bookmarks::search(QList<BookmarkItem*>* items, BookmarkItem* parent, const
switch (parent->type()) {
case BookmarkItem::Root:
case BookmarkItem::Folder:
foreach (BookmarkItem* child, parent->children()) {
case BookmarkItem::Folder: {
const auto children = parent->children();
for (BookmarkItem* child : children) {
search(items, child, string, limit, sensitive);
}
break;
}
case BookmarkItem::Url:
if (parent->title().contains(string, sensitive) ||
@ -461,10 +466,12 @@ void Bookmarks::searchKeyword(QList<BookmarkItem*>* items, BookmarkItem* parent,
switch (parent->type()) {
case BookmarkItem::Root:
case BookmarkItem::Folder:
foreach (BookmarkItem* child, parent->children())
case BookmarkItem::Folder: {
const auto children = parent->children();
for (BookmarkItem* child : children)
searchKeyword(items, child, keyword);
break;
}
case BookmarkItem::Url:
if (parent->keyword() == keyword)

View File

@ -72,7 +72,7 @@ void BookmarksExportDialog::init()
{
m_exporters.append(new HtmlExporter(this));
foreach (BookmarksExporter* exporter, m_exporters) {
for (BookmarksExporter* exporter : qAsConst(m_exporters)) {
ui->format->addItem(exporter->name());
}

View File

@ -79,26 +79,30 @@ void HtmlExporter::writeBookmark(BookmarkItem* item, QTextStream &stream, int le
stream << indent << "<HR>" << endl;
break;
case BookmarkItem::Folder:
case BookmarkItem::Folder: {
stream << indent << "<DT><H3>" << item->title() << "</H3>" << endl;
stream << indent << "<DL><p>" << endl;
foreach (BookmarkItem* child, item->children()) {
const auto children = item->children();
for (BookmarkItem* child : children) {
writeBookmark(child, stream, level + 1);
}
stream << indent << "</DL><p>" << endl;
break;
}
case BookmarkItem::Root:
case BookmarkItem::Root: {
stream << indent << "<DL><p>" << endl;
foreach (BookmarkItem* child, item->children()) {
const auto children = item->children();
for (BookmarkItem* child : children) {
writeBookmark(child, stream, level + 1);
}
stream << indent << "</DL><p>" << endl;
break;
}
default:
break;

View File

@ -101,7 +101,7 @@ void ChromeImporter::readBookmarks(const QVariantList &list, BookmarkItem* paren
{
Q_ASSERT(parent);
foreach (const QVariant &entry, list) {
for (const QVariant &entry : list) {
const QVariantMap map = entry.toMap();
const QString typeString = map.value(QSL("type")).toString();
BookmarkItem::Type type;

View File

@ -126,7 +126,7 @@ BookmarkItem* FirefoxImporter::importBookmarks()
QHash<int, BookmarkItem*> hash;
foreach (const Item &item, items) {
for (const Item &item : qAsConst(items)) {
BookmarkItem* parent = hash.value(item.parent);
BookmarkItem* bookmark = new BookmarkItem(item.type, parent ? parent : root);
bookmark->setTitle(item.title.isEmpty() ? item.url.toString() : item.title);

View File

@ -67,7 +67,8 @@ BookmarkItem* IeImporter::importBookmarks()
void IeImporter::readDir(const QDir &dir, BookmarkItem *parent)
{
foreach (const QFileInfo &file, dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) {
const auto files = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
for (const QFileInfo &file : files) {
if (file.isDir()) {
BookmarkItem* folder = new BookmarkItem(BookmarkItem::Folder, parent);
folder->setTitle(file.baseName());

View File

@ -119,9 +119,9 @@ void BookmarksManager::createContextMenu(const QPoint &pos)
connect(actDelete, &QAction::triggered, this, &BookmarksManager::deleteBookmarks);
bool canBeDeleted = false;
QList<BookmarkItem*> items = ui->tree->selectedBookmarks();
const QList<BookmarkItem*> items = ui->tree->selectedBookmarks();
foreach (BookmarkItem* item, items) {
for (BookmarkItem* item : items) {
if (m_bookmarks->canBeModified(item)) {
canBeDeleted = true;
break;
@ -194,9 +194,9 @@ void BookmarksManager::addSeparator()
void BookmarksManager::deleteBookmarks()
{
QList<BookmarkItem*> items = ui->tree->selectedBookmarks();
const QList<BookmarkItem*> items = ui->tree->selectedBookmarks();
foreach (BookmarkItem* item, items) {
for (BookmarkItem* item : items) {
if (m_bookmarks->canBeModified(item)) {
m_bookmarks->removeBookmark(item);
}

View File

@ -84,7 +84,8 @@ void BookmarksMenu::menuAboutToShow()
Q_ASSERT(qobject_cast<Menu*>(sender()));
Menu *menu = static_cast<Menu*>(sender());
foreach (QAction *action, menu->actions()) {
const auto menuActions = menu->actions();
for (QAction *action : menuActions) {
BookmarkItem *item = static_cast<BookmarkItem*>(action->data().value<void*>());
if (item && item->type() == BookmarkItem::Url && action->icon().isNull()) {
action->setIcon(item->icon());
@ -188,7 +189,8 @@ void BookmarksMenu::refresh()
BookmarksTools::addActionToMenu(this, this, mApp->bookmarks()->toolbarFolder());
addSeparator();
foreach (BookmarkItem* child, mApp->bookmarks()->menuFolder()->children()) {
const auto children = mApp->bookmarks()->menuFolder()->children();
for (BookmarkItem* child : children) {
BookmarksTools::addActionToMenu(this, this, child);
}

View File

@ -200,7 +200,7 @@ QMimeData* BookmarksModel::mimeData(const QModelIndexList &indexes) const
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (const QModelIndex &index, indexes) {
for (const QModelIndex &index : indexes) {
// If item's parent (=folder) is also selected, we will just move the whole folder
if (index.isValid() && index.column() == 0 && !indexes.contains(index.parent())) {
stream << index.row() << (quintptr) index.internalPointer();
@ -252,7 +252,7 @@ bool BookmarksModel::dropMimeData(const QMimeData* data, Qt::DropAction action,
row = qMax(row, 0);
foreach (BookmarkItem* itm, items) {
for (BookmarkItem* itm : qAsConst(items)) {
// If we are moving an item through the folder and item is above the row to insert,
// we must decrease row by one (by the dropped folder)
if (itm->parent() == parentItm && itm->parent()->children().indexOf(itm) < row) {

View File

@ -115,7 +115,8 @@ void BookmarksToolbar::refresh()
BookmarkItem* folder = mApp->bookmarks()->toolbarFolder();
foreach (BookmarkItem* child, folder->children()) {
const auto children = folder->children();
for (BookmarkItem* child : children) {
addItem(child);
}

View File

@ -140,7 +140,8 @@ void BookmarksToolbarButton::menuAboutToShow()
Q_ASSERT(qobject_cast<Menu*>(sender()));
Menu *menu = static_cast<Menu*>(sender());
foreach (QAction *action, menu->actions()) {
const auto menuActions = menu->actions();
for (QAction *action : menuActions) {
BookmarkItem *item = static_cast<BookmarkItem*>(action->data().value<void*>());
if (item && item->type() == BookmarkItem::Url && action->icon().isNull()) {
action->setIcon(item->icon());

View File

@ -79,7 +79,8 @@ void BookmarksFoldersMenu::createMenu(QMenu* menu, BookmarkItem* parent)
menu->addSeparator();
foreach (BookmarkItem* child, parent->children()) {
const auto children = parent->children();
for (BookmarkItem* child : children) {
if (child->isFolder()) {
QMenu* m = menu->addMenu(child->icon(), child->title());
createMenu(m, child);
@ -205,7 +206,8 @@ bool BookmarksTools::bookmarkAllTabsDialog(QWidget* parent, TabWidget* tabWidget
return false;
}
foreach (WebTab* tab, tabWidget->allTabs(false)) {
const auto allTabs = tabWidget->allTabs(false);
for (WebTab* tab : allTabs) {
if (!tab->url().isEmpty()) {
BookmarkItem* bookmark = new BookmarkItem(BookmarkItem::Url);
bookmark->setTitle(tab->title());
@ -326,9 +328,11 @@ void BookmarksTools::openFolderInTabs(BrowserWindow* window, BookmarkItem* folde
Q_ASSERT(window);
Q_ASSERT(folder->isFolder());
const auto children = folder->children();
bool showWarning = folder->children().size() > 10;
if (!showWarning) {
foreach (BookmarkItem* child, folder->children()) {
for (BookmarkItem* child : children) {
if (child->isFolder()) {
showWarning = true;
break;
@ -345,7 +349,7 @@ void BookmarksTools::openFolderInTabs(BrowserWindow* window, BookmarkItem* folde
}
}
foreach (BookmarkItem* child, folder->children()) {
for (BookmarkItem* child : children) {
if (child->isUrl()) {
openBookmarkInNewTab(window, child);
}
@ -427,7 +431,8 @@ void BookmarksTools::addFolderContentsToMenu(QObject *receiver, Menu *menu, Book
QObject::connect(menu, SIGNAL(aboutToShow()), receiver, SLOT(menuAboutToShow()));
QObject::connect(menu, SIGNAL(menuMiddleClicked(Menu*)), receiver, SLOT(menuMiddleClicked(Menu*)));
foreach (BookmarkItem* child, folder->children()) {
const auto children = folder->children();
for (BookmarkItem* child : children) {
addActionToMenu(receiver, menu, child);
}

View File

@ -85,7 +85,8 @@ QList<BookmarkItem*> BookmarksTreeView::selectedBookmarks() const
{
QList<BookmarkItem*> items;
foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
const auto indexes = selectionModel()->selectedRows();
for (const QModelIndex &index : indexes) {
BookmarkItem* item = m_model->item(m_filter->mapToSource(index));
items.append(item);
}