Commit 5f60bc5a authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Replace foreach (deprecated) with range-for

The code compiles and konsole seems to work as bofore.
parent 686a14da
......@@ -154,7 +154,8 @@ void MainWindow::updateUseTransparency()
void MainWindow::rememberMenuAccelerators()
{
foreach (QAction *menuItem, menuBar()->actions()) {
const QList<QAction *> actions = menuBar()->actions();
for (QAction *menuItem : actions) {
QString itemText = menuItem->text();
menuItem->setData(itemText);
}
......@@ -170,14 +171,16 @@ void MainWindow::rememberMenuAccelerators()
// can then be redefined there to exclude the standard accelerators
void MainWindow::removeMenuAccelerators()
{
foreach (QAction *menuItem, menuBar()->actions()) {
const QList<QAction *> actions = menuBar()->actions();
for (QAction *menuItem : actions) {
menuItem->setText(menuItem->text().replace(QLatin1Char('&'), QString()));
}
}
void MainWindow::restoreMenuAccelerators()
{
foreach (QAction *menuItem, menuBar()->actions()) {
const QList<QAction *> actions = menuBar()->actions();
for (QAction *menuItem : actions) {
QString itemText = menuItem->data().toString();
menuItem->setText(itemText);
}
......@@ -406,7 +409,7 @@ void MainWindow::profileListChanged(const QList<QAction *> &sessionActions)
} else {
_newTabMenuAction->setMenu(new QMenu());
}
foreach (QAction *sessionAction, sessionActions) {
for (QAction *sessionAction : sessionActions) {
_newTabMenuAction->menu()->addAction(sessionAction);
// NOTE: defaultProfile seems to not work here, sigh.
......@@ -558,7 +561,7 @@ bool MainWindow::queryClose()
QStringList processesRunning;
const auto uniqueSessions = QSet<Session*>::fromList(_viewManager->sessions());
foreach (Session *session, uniqueSessions) {
for (Session *session : uniqueSessions) {
if ((session == nullptr) || !session->isForegroundProcessActive()) {
continue;
}
......@@ -693,7 +696,8 @@ void MainWindow::readGlobalProperties(KConfig *config)
void MainWindow::syncActiveShortcuts(KActionCollection *dest, const KActionCollection *source)
{
foreach (QAction *qAction, source->actions()) {
const QList<QAction *> actionsList = source->actions();
for (QAction *qAction : actionsList) {
if (QAction *destQAction = dest->action(qAction->objectName())) {
destQAction->setShortcut(qAction->shortcut());
}
......@@ -706,13 +710,15 @@ void MainWindow::showShortcutsDialog()
KShortcutsEditor::LetterShortcutsDisallowed, this);
// add actions from this window and the current session controller
foreach (KXMLGUIClient *client, guiFactory()->clients()) {
const QList<KXMLGUIClient *> clientsList = guiFactory()->clients();
for (KXMLGUIClient *client : clientsList) {
dialog.addCollection(client->actionCollection());
}
if (dialog.configure()) {
// sync shortcuts for non-session actions (defined in "konsoleui.rc") in other main windows
foreach (QWidget *mainWindowWidget, QApplication::topLevelWidgets()) {
const QList<QWidget *> widgets = QApplication::topLevelWidgets();
for (QWidget *mainWindowWidget : widgets) {
auto *mainWindow = qobject_cast<MainWindow *>(mainWindowWidget);
if ((mainWindow != nullptr) && mainWindow != this) {
syncActiveShortcuts(mainWindow->actionCollection(), actionCollection());
......@@ -722,7 +728,8 @@ void MainWindow::showShortcutsDialog()
// Controllers which are currently plugged in (ie. their actions are part of the current menu)
// must be updated immediately via syncActiveShortcuts(). Other controllers will be updated
// when they are plugged into a main window.
foreach (SessionController *controller, SessionController::allControllers()) {
const QSet<SessionController *> allControllers = SessionController::allControllers();
for (SessionController *controller : allControllers) {
controller->reloadXML();
if ((controller->factory() != nullptr) && controller != _pluggedController) {
syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection());
......
......@@ -72,7 +72,8 @@ Part::Part(QWidget *parentWidget, QObject *parent, const QVariantList &) :
setWidget(_viewManager->widget());
actionCollection()->addAssociatedWidget(_viewManager->widget());
foreach (QAction *action, actionCollection()->actions()) {
const QList<QAction *> actionsList = actionCollection()->actions();
for (QAction *action : actionsList) {
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
}
......
......@@ -582,7 +582,7 @@ private:
const QStringList &argList = data.split(QLatin1Char('\0'));
foreach (const QString &entry, argList) {
for (const QString &entry : argList) {
if (!entry.isEmpty()) {
addArgument(entry);
}
......@@ -709,8 +709,8 @@ private:
}
// len holds the length of the string
QString qargs = QString::fromLocal8Bit(args, len);
foreach (const QString &value, qargs.split(QLatin1Char('\u0000'))) {
const QStringList argurments = QString::fromLocal8Bit(args, len).split(QLatin1Char('\u0000'));
for (const QString &value : argurments) {
if (!value.isEmpty()) {
addArgument(value);
}
......
......@@ -388,7 +388,7 @@ void ProfileGroup::setProperty(Property p, const QVariant& value)
}
Profile::setProperty(p, value);
foreach(Profile::Ptr profile, _profiles) {
for (const Profile::Ptr &profile : qAsConst(_profiles)) {
profile->setProperty(p, value);
}
}
......
......@@ -49,9 +49,9 @@ ProfileList::ProfileList(bool addShortcuts , QObject* parent)
// TODO - Handle re-sorts when user changes profile names
ProfileManager* manager = ProfileManager::instance();
QList<Profile::Ptr> favoriteProfiles = manager->sortedFavorites();
const QList<Profile::Ptr> favoriteProfiles = manager->sortedFavorites();
foreach(const Profile::Ptr& profile, favoriteProfiles) {
for (const Profile::Ptr &profile : favoriteProfiles) {
favoriteChanged(profile, true);
}
......@@ -76,7 +76,8 @@ void ProfileList::updateEmptyAction()
}
QAction* ProfileList::actionForProfile(const Profile::Ptr &profile) const
{
foreach(QAction* action, _group->actions()) {
const QList<QAction *> actionsList = _group->actions();
for (QAction *action : actionsList) {
if (action->data().value<Profile::Ptr>() == profile) {
return action;
}
......@@ -122,7 +123,7 @@ void ProfileList::syncWidgetActions(QWidget* widget, bool sync)
_registeredWidgets.insert(widget);
const QList<QAction*> currentActions = widget->actions();
foreach(QAction * currentAction, currentActions) {
for (QAction *currentAction : currentActions) {
widget->removeAction(currentAction);
}
......@@ -142,7 +143,7 @@ void ProfileList::addShortcutAction(const Profile::Ptr &profile)
updateAction(action, profile);
foreach(QWidget * widget, _registeredWidgets) {
for (QWidget *widget : qAsConst(_registeredWidgets)) {
widget->addAction(action);
}
emit actionsChanged(_group->actions());
......@@ -156,7 +157,7 @@ void ProfileList::removeShortcutAction(const Profile::Ptr &profile)
if (action != nullptr) {
_group->removeAction(action);
foreach(QWidget * widget, _registeredWidgets) {
for (QWidget *widget : qAsConst(_registeredWidgets)) {
widget->removeAction(action);
}
emit actionsChanged(_group->actions());
......
......@@ -161,7 +161,7 @@ Profile::Ptr ProfileManager::loadProfile(const QString& shortPath)
}
// check that we have not already loaded this profile
foreach(const Profile::Ptr& profile, _profiles) {
for (const Profile::Ptr &profile : qAsConst(_profiles)) {
if (profile->path() == path) {
return profile;
}
......@@ -221,7 +221,8 @@ QStringList ProfileManager::availableProfileNames() const
{
QStringList names;
foreach(Profile::Ptr profile, ProfileManager::instance()->allProfiles()) {
const QList<Profile::Ptr> allProfiles = ProfileManager::instance()->allProfiles();
for (const Profile::Ptr &profile : allProfiles) {
if (!profile->isHidden()) {
names.push_back(profile->name());
}
......@@ -239,7 +240,7 @@ void ProfileManager::loadAllProfiles()
}
const QStringList& paths = availableProfilePaths();
foreach(const QString& path, paths) {
for (const QString &path : paths) {
loadProfile(path);
}
......@@ -369,9 +370,9 @@ void ProfileManager::changeProfile(Profile::Ptr profile,
// Generate a new name, so it is obvious what is actually built-in
// in the profile manager
QList<Profile::Ptr> existingProfiles = allProfiles();
QStringList existingProfileNames;
foreach(Profile::Ptr existingProfile, existingProfiles) {
const QList<Profile::Ptr> profiles = allProfiles();
for (const Profile::Ptr &existingProfile : profiles) {
existingProfileNames.append(existingProfile->name());
}
......@@ -415,7 +416,8 @@ void ProfileManager::changeProfile(Profile::Ptr profile,
// is saved to disk
ProfileGroup::Ptr group = newProfile->asGroup();
if (group) {
foreach(const Profile::Ptr & groupProfile, group->profiles()) {
const QList<Profile::Ptr> profiles = group->profiles();
for (const Profile::Ptr &groupProfile : profiles) {
changeProfile(groupProfile, propertyMap, persistent);
}
return;
......@@ -435,7 +437,7 @@ void ProfileManager::changeProfile(Profile::Ptr profile,
// this is needed to include the old profile too
_loadedAllProfiles = false;
const QList<Profile::Ptr> availableProfiles = ProfileManager::instance()->allProfiles();
foreach(auto oldProfile, availableProfiles) {
for (const Profile::Ptr &oldProfile : availableProfiles) {
if (oldProfile->path() == origPath) {
// assign the same shortcut of the old profile to
// the newly renamed profile
......@@ -599,7 +601,7 @@ void ProfileManager::saveFavorites()
KConfigGroup favoriteGroup = appConfig->group("Favorite Profiles");
QStringList paths;
foreach(const Profile::Ptr& profile, _favorites) {
for (const Profile::Ptr &profile : qAsConst(_favorites)) {
Q_ASSERT(_profiles.contains(profile) && profile);
paths << normalizePath(profile->path());
}
......@@ -643,7 +645,7 @@ void ProfileManager::loadFavorites()
}
// look for favorites among those already loaded
foreach(const Profile::Ptr& profile, _profiles) {
for (const Profile::Ptr &profile : qAsConst(_profiles)) {
const QString& path = profile->path();
if (favoriteSet.contains(path)) {
_favorites.insert(profile);
......@@ -651,7 +653,7 @@ void ProfileManager::loadFavorites()
}
}
// load any remaining favorites
foreach(const QString& favorite, favoriteSet) {
for (const QString &favorite : qAsConst(favoriteSet)) {
Profile::Ptr profile = loadProfile(favorite);
if (profile) {
_favorites.insert(profile);
......
......@@ -211,7 +211,7 @@ void Pty::addEnvironmentVariables(const QStringList &environmentVariables)
{
bool isTermEnvAdded = false;
foreach (const QString &pair, environmentVariables) {
for (const QString &pair : environmentVariables) {
// split on the first '=' character
const int separator = pair.indexOf(QLatin1Char('='));
......
......@@ -76,7 +76,8 @@ void SaveHistoryTask::execute()
// iterate over each session in the task and display a dialog to allow the user to choose where
// to save that session's history.
// then start a KIO job to transfer the data from the history to the chosen URL
foreach(const auto& session, sessions()) {
const QList<QPointer<Session>> sessionsList = sessions();
for (const auto &session : sessionsList) {
dialog->setWindowTitle(i18n("Save Output From %1", session->title(Session::NameRole)));
int result = dialog->exec();
......
......@@ -139,7 +139,9 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
}
actionCollection()->addAssociatedWidget(view);
foreach(QAction * action, actionCollection()->actions()) {
const QList<QAction *> actionsList = actionCollection()->actions();
for (QAction *action : actionsList) {
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
}
......@@ -431,7 +433,7 @@ void SessionController::updateWebSearchMenu()
QAction* action = nullptr;
foreach(const QString& searchProvider, searchProviders) {
for (const QString &searchProvider : searchProviders) {
action = new QAction(searchProvider, _webSearchMenu);
action->setIcon(QIcon::fromTheme(filterData.iconNameForPreferredSearchProvider(searchProvider)));
action->setData(filterData.queryForPreferredSearchProvider(searchProvider));
......@@ -828,12 +830,12 @@ EditProfileDialog* SessionController::profileDialogPointer()
void SessionController::editCurrentProfile()
{
// Searching for Edit profile dialog opened with the same profile
const QList<SessionController*> allSessionsControllers = _allControllers.values();
foreach (SessionController* session, allSessionsControllers) {
if ((session->profileDialogPointer() != nullptr)
&& session->profileDialogPointer()->isVisible()
&& session->profileDialogPointer()->lookupProfile() == SessionManager::instance()->sessionProfile(_session)) {
session->profileDialogPointer()->close();
for (SessionController *controller : qAsConst(_allControllers)) {
if ( (controller->profileDialogPointer() != nullptr)
&& controller->profileDialogPointer()->isVisible()
&& (controller->profileDialogPointer()->lookupProfile()
== SessionManager::instance()->sessionProfile(_session)) ) {
controller->profileDialogPointer()->close();
}
}
......@@ -1019,7 +1021,8 @@ static const KXmlGuiWindow* findWindow(const QObject* object)
static bool hasTerminalDisplayInSameWindow(const Session* session, const KXmlGuiWindow* window)
{
// Iterate all TerminalDisplays of this Session ...
foreach(const TerminalDisplay* terminalDisplay, session->views()) {
const QList<TerminalDisplay *> views = session->views();
for (const TerminalDisplay *terminalDisplay : views) {
// ... and check whether a TerminalDisplay has the same
// window as given in the parameter
if (window == findWindow(terminalDisplay)) {
......@@ -1102,8 +1105,8 @@ void SessionController::copyInputToSelectedTabs()
QSet<Session*> newGroup = dialog->chosenSessions();
newGroup.remove(_session);
QSet<Session*> completeGroup = newGroup | currentGroup;
foreach(Session * session, completeGroup) {
const QSet<Session *> completeGroup = newGroup | currentGroup;
for (Session *session : completeGroup) {
if (newGroup.contains(session) && !currentGroup.contains(session)) {
_copyToGroup->addSession(session);
} else if (!newGroup.contains(session) && currentGroup.contains(session)) {
......@@ -1646,9 +1649,10 @@ void SessionController::sessionReadOnlyChanged() {
updateReadOnlyActionStates();
// Update all views
foreach (TerminalDisplay* view, session()->views()) {
if (view != _view.data()) {
view->updateReadOnlyState(isReadOnly());
const QList<TerminalDisplay *> viewsList = session()->views();
for (TerminalDisplay *terminalDisplay : viewsList) {
if (terminalDisplay != _view.data()) {
terminalDisplay->updateReadOnlyState(isReadOnly());
}
}
}
......
......@@ -44,7 +44,7 @@ void SessionListModel::setSessions(const QList<Session *> &sessions)
beginResetModel();
_sessions = sessions;
foreach (Session *session, sessions) {
for (Session *session : sessions) {
connect(session, &Konsole::Session::finished, this,
&Konsole::SessionListModel::sessionFinished);
}
......
......@@ -292,8 +292,8 @@ void SessionManager::sessionProfileCommandReceived(const QString &text)
// store the font for each view if zoom was applied so that they can
// be restored after applying the new profile
QHash<TerminalDisplay *, QFont> zoomFontSizes;
const QList<TerminalDisplay *> views = session->views();
for (TerminalDisplay *view : views) {
const QList<TerminalDisplay *> viewsList = session->views();
for (TerminalDisplay *view : viewsList) {
const QFont &viewCurFont = view->getVTFont();
if (viewCurFont != _sessionProfiles[session]->font()) {
zoomFontSizes.insert(view, viewCurFont);
......
......@@ -76,7 +76,7 @@ QStringList ShellCommand::expand(const QStringList &items)
QStringList result;
result.reserve(items.size());
foreach (const QString &item, items) {
for (const QString &item : items) {
result << expand(item);
}
......
......@@ -1393,7 +1393,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
// iterate over hotspots identified by the display's currently active filters
// and draw appropriate visuals to indicate the presence of the hotspot
QList<Filter::HotSpot*> spots = _filterChain->hotSpots();
const QList<Filter::HotSpot*> spots = _filterChain->hotSpots();
int urlNumber, urlNumInc;
if (_reverseUrlHints) {
urlNumber = spots.size() + 1;
......@@ -1402,7 +1402,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
urlNumber = 0;
urlNumInc = 1;
}
foreach(Filter::HotSpot* spot, spots) {
for (const Filter::HotSpot *spot : spots) {
urlNumber += urlNumInc;
QRegion region;
......
......@@ -163,7 +163,8 @@ void TabbedViewContainer::moveTabToWindow(int index, QWidget *window)
QHash<TerminalDisplay*, Session*> sessionsMap = _connectedViewManager->forgetAll(splitter);
foreach(TerminalDisplay* terminal, splitter->findChildren<TerminalDisplay*>()) {
const QList<TerminalDisplay *> displays = splitter->findChildren<TerminalDisplay*>();
for (TerminalDisplay *terminal : displays) {
manager->attachView(terminal, sessionsMap[terminal]);
}
auto container = manager->activeContainer();
......@@ -322,8 +323,8 @@ void TabbedViewContainer::addSplitter(ViewSplitter *viewSplitter, int index) {
disconnect(viewSplitter, &ViewSplitter::terminalDisplayDropped, nullptr, nullptr);
connect(viewSplitter, &ViewSplitter::terminalDisplayDropped, this, &TabbedViewContainer::terminalDisplayDropped);
auto terminalDisplays = viewSplitter->findChildren<TerminalDisplay*>();
foreach(TerminalDisplay* terminal, terminalDisplays) {
const auto terminalDisplays = viewSplitter->findChildren<TerminalDisplay*>();
for (TerminalDisplay *terminal : terminalDisplays) {
connectTerminalDisplay(terminal);
}
if (terminalDisplays.count() > 0) {
......
......@@ -261,7 +261,7 @@ void ViewManager::setupActions()
void ViewManager::toggleActionsBasedOnState() {
const int count = _viewContainer->count();
foreach(QAction *tabOnlyAction, _multiTabOnlyActions) {
for (QAction *tabOnlyAction : qAsConst(_multiTabOnlyActions)) {
tabOnlyAction->setEnabled(count > 1);
}
......@@ -272,7 +272,7 @@ void ViewManager::toggleActionsBasedOnState() {
->findChildren<TerminalDisplay*>()
.count();
foreach (QAction *action, _multiSplitterOnlyActions) {
for (QAction *action : qAsConst(_multiSplitterOnlyActions)) {
action->setEnabled(splitCount > 1);
}
}
......@@ -422,7 +422,8 @@ void ViewManager::detachTab(int tabIdx)
QHash<TerminalDisplay*, Session*> ViewManager::forgetAll(ViewSplitter* splitter) {
splitter->setParent(nullptr);
QHash<TerminalDisplay*, Session*> detachedSessions;
foreach(TerminalDisplay* terminal, splitter->findChildren<TerminalDisplay*>()) {
const QList<TerminalDisplay *> displays = splitter->findChildren<TerminalDisplay*>();
for (TerminalDisplay *terminal : displays) {
Session* session = forgetTerminal(terminal);
detachedSessions[terminal] = session;
}
......@@ -826,7 +827,7 @@ void ViewManager::updateViewsForSession(Session *session)
const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
const QList<TerminalDisplay *> sessionMapKeys = _sessionMap.keys(session);
foreach (TerminalDisplay *view, sessionMapKeys) {
for (TerminalDisplay *view : sessionMapKeys) {
applyProfileToView(view, profile);
}
}
......@@ -960,7 +961,8 @@ void ViewManager::restoreSessions(const KConfigGroup &group)
TerminalDisplay *display = nullptr;
int tab = 1;
foreach (int id, ids) {
for (auto it = ids.cbegin(); it != ids.cend(); ++it) {
const int &id = *it;
Session *session = SessionManager::instance()->idToSession(id);
if (session == nullptr) {
......
......@@ -241,7 +241,7 @@ void ProfileSettings::populateTable()
QList<Profile::Ptr> profiles = ProfileManager::instance()->allProfiles();
ProfileManager::instance()->sortProfiles(profiles);
foreach(const Profile::Ptr& profile, profiles) {
for (const Profile::Ptr &profile : qAsConst(profiles)) {
addItems(profile);
}
updateDefaultItem();
......@@ -303,7 +303,8 @@ void ProfileSettings::tableSelectionChanged(const QItemSelection&)
}
void ProfileSettings::deleteSelected()
{
foreach(const Profile::Ptr & profile, selectedProfiles()) {
const QList<Profile::Ptr> profiles = selectedProfiles();
for (const Profile::Ptr &profile : profiles) {
if (profile != ProfileManager::instance()->defaultProfile()) {
ProfileManager::instance()->deleteProfile(profile);
}
......@@ -349,27 +350,30 @@ void ProfileSettings::createProfile()
}
void ProfileSettings::editSelected()
{
QList<Profile::Ptr> profiles(selectedProfiles());
foreach (Session* session, SessionManager::instance()->sessions()) {
foreach (TerminalDisplay* terminal, session->views()) {
// Searching for opened profiles
if (terminal->sessionController()->profileDialogPointer() != nullptr) {
foreach (const Profile::Ptr & profile, profiles) {
if (profile->name() == terminal->sessionController()->profileDialogPointer()->lookupProfile()->name()
&& terminal->sessionController()->profileDialogPointer()->isVisible()) {
// close opened edit dialog
terminal->sessionController()->profileDialogPointer()->close();
}
}
}
const QList<Profile::Ptr> profiles = selectedProfiles();
EditProfileDialog *profileDialog = nullptr;
// sessions() returns a const QList
for (const Session *session : SessionManager::instance()->sessions()) {
const QList<TerminalDisplay *> viewsList = session->views();
for (TerminalDisplay *terminalDisplay : viewsList) {
// Searching for opened profiles
profileDialog = terminalDisplay->sessionController()->profileDialogPointer();
if (profileDialog != nullptr) {
for (const Profile::Ptr &profile : profiles) {
if (profile->name() == profileDialog->lookupProfile()->name()
&& profileDialog->isVisible()) {
// close opened edit dialog
profileDialog->close();
}
}
}
}
}
EditProfileDialog dialog(this);
// the dialog will delete the profile group when it is destroyed
ProfileGroup* group = new ProfileGroup;
foreach (const Profile::Ptr & profile, profiles) {
for (const Profile::Ptr &profile : profiles) {
group->addProfile(profile);
}
group->updateValues();
......@@ -385,7 +389,8 @@ QList<Profile::Ptr> ProfileSettings::selectedProfiles() const
return list;
}
foreach(const QModelIndex & index, selection->selectedIndexes()) {
const QList<QModelIndex> selectedIndexes = selection->selectedIndexes();
for (const QModelIndex &index : selectedIndexes) {
if (index.column() == ProfileColumn) {
list << index.data(ProfilePtrRole).value<Profile::Ptr>();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment