Commit c83bb19a authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Port away from deprecated foreach, use for-range instead, first take

The code compiles and konsole loads and seems to work as before.
parent 59ff5d37
......@@ -57,7 +57,7 @@ Application::Application(QSharedPointer<QCommandLineParser> parser,
void Application::populateCommandLineParser(QCommandLineParser *parser)
{
auto options = QVector<QCommandLineOption> {
const auto options = QVector<QCommandLineOption> {
{ { QStringLiteral("profile") },
i18nc("@info:shell", "Name of profile to use for new Konsole instance"),
QStringLiteral("name")
......@@ -118,7 +118,7 @@ void Application::populateCommandLineParser(QCommandLineParser *parser)
QStringLiteral("cmd")
}
};
foreach(const auto& option, options) {
for (const auto &option : options) {
parser->addOption(option);
}
......@@ -187,7 +187,8 @@ void Application::detachTerminals(ViewSplitter *splitter,const QHash<TerminalDis
MainWindow *window = newMainWindow();
ViewManager *manager = window->viewManager();
foreach(TerminalDisplay* terminal, splitter->findChildren<TerminalDisplay*>()) {
const QList<TerminalDisplay *> displays = splitter->findChildren<TerminalDisplay *>();
for (TerminalDisplay* terminal : displays) {
manager->attachView(terminal, sessionsMap[terminal]);
}
manager->activeContainer()->addSplitter(splitter);
......@@ -472,9 +473,9 @@ bool Application::processHelpArgs()
void Application::listAvailableProfiles()
{
QStringList paths = ProfileManager::instance()->availableProfilePaths();
const QStringList paths = ProfileManager::instance()->availableProfilePaths();
foreach (const QString &path, paths) {
for (const QString &path : paths) {
QFileInfo info(path);
printf("%s\n", info.completeBaseName().toLocal8Bit().constData());
}
......@@ -485,7 +486,7 @@ void Application::listProfilePropertyInfo()
Profile::Ptr tempProfile = ProfileManager::instance()->defaultProfile();
const QStringList names = tempProfile->propertiesInfoList();
foreach (const QString &name, names) {
for (const QString &name : names) {
printf("%s\n", name.toLocal8Bit().constData());
}
}
......@@ -505,7 +506,7 @@ Profile::Ptr Application::processProfileChangeArgs(Profile::Ptr baseProfile)
// temporary changes to profile options specified on the command line
const QStringList profileProperties = m_parser->values(QStringLiteral("p"));
foreach (const QString &value, profileProperties) {
for (const QString &value : profileProperties) {
ProfileCommandParser parser;
QHashIterator<Profile::Property, QVariant> iter(parser.parse(value));
......
......@@ -58,8 +58,8 @@ void ColorSchemeManager::loadAllColorSchemes()
int success = 0;
int failed = 0;
QStringList nativeColorSchemes = listColorSchemes();
foreach (const QString &colorScheme, nativeColorSchemes) {
const QStringList nativeColorSchemes = listColorSchemes();
for (const QString &colorScheme : nativeColorSchemes) {
if (loadColorScheme(colorScheme)) {
success++;
} else {
......
......@@ -121,10 +121,10 @@ void CopyInputDialog::setSelectionChecked(bool checked)
QAbstractItemModel *model = _ui->sessionList->model();
int rows = model->rowCount();
QModelIndexList selected = _ui->sessionList->selectionModel()->selectedIndexes();
const QModelIndexList selected = _ui->sessionList->selectionModel()->selectedIndexes();
if (selected.count() > 1) {
foreach (const QModelIndex &index, selected) {
for (const QModelIndex &index : selected) {
setRowChecked(index.row(), checked);
}
} else {
......
......@@ -307,7 +307,7 @@ bool EditProfileDialog::isValidProfileName()
const QList<Profile::Ptr> existingProfiles = ProfileManager::instance()->allProfiles();
QStringList otherExistingProfileNames;
foreach(auto existingProfile, existingProfiles) {
for (const Profile::Ptr &existingProfile : existingProfiles) {
if (existingProfile->name() != _profile->name()) {
otherExistingProfileNames.append(existingProfile->name());
}
......@@ -866,9 +866,9 @@ void EditProfileDialog::updateColorSchemeList(const QString &selectedColorScheme
QStandardItem *selectedItem = nullptr;
QList<const ColorScheme *> schemeList = ColorSchemeManager::instance()->allColorSchemes();
const QList<const ColorScheme *> schemeList = ColorSchemeManager::instance()->allColorSchemes();
foreach (const ColorScheme *scheme, schemeList) {
for (const ColorScheme *scheme : schemeList) {
QStandardItem *item = new QStandardItem(scheme->description());
item->setData(QVariant::fromValue(scheme), Qt::UserRole + 1);
item->setData(QVariant::fromValue(_profile->font()), Qt::UserRole + 2);
......@@ -1325,7 +1325,8 @@ void EditProfileDialog::enableIfNonEmptySelection(QWidget *widget, QItemSelectio
void EditProfileDialog::updateTransparencyWarning()
{
// zero or one indexes can be selected
foreach (const QModelIndex &index, _appearanceUi->colorSchemeList->selectionModel()->selectedIndexes()) {
const QModelIndexList selected = _appearanceUi->colorSchemeList->selectionModel()->selectedIndexes();
for (const QModelIndex &index : selected) {
bool needTransparency = index.data(Qt::UserRole + 1).value<const ColorScheme *>()->opacity() < 1.0;
if (!needTransparency) {
......
......@@ -109,7 +109,7 @@ void Emulation::checkSelectedText()
Emulation::~Emulation()
{
foreach (ScreenWindow *window, _windows) {
for (ScreenWindow *window : qAsConst(_windows)) {
delete window;
}
......@@ -124,7 +124,7 @@ void Emulation::setScreen(int index)
_currentScreen = _screen[index & 1];
if (_currentScreen != oldScreen) {
// tell all windows onto this emulation to switch to the newly active screen
foreach (ScreenWindow *window, _windows) {
for (ScreenWindow *window : qAsConst(_windows)) {
window->setScreen(_currentScreen);
}
......
......@@ -74,10 +74,11 @@ uint ExtendedCharTable::createExtendedChar(const uint *unicodePoints, ushort len
// All the hashes are full, go to all Screens and try to free any
// This is slow but should happen very rarely
QSet<uint> usedExtendedChars;
const SessionManager *sm = SessionManager::instance();
foreach (const Session *s, sm->sessions()) {
foreach (const TerminalDisplay *td, s->views()) {
usedExtendedChars += td->screenWindow()->screen()->usedExtendedChars();
const QList<Session *> sessionsList = SessionManager::instance()->sessions();
for (const Session *s : sessionsList) {
const QList<TerminalDisplay *> displayList = s->views();
for (const TerminalDisplay *display : displayList) {
usedExtendedChars += display->screenWindow()->screen()->usedExtendedChars();
}
}
......
......@@ -254,9 +254,9 @@ QList<Filter::HotSpot *> Filter::hotSpots() const
Filter::HotSpot *Filter::hotSpotAt(int line, int column) const
{
QList<HotSpot *> hotspots = _hotspots.values(line);
const QList<HotSpot *> hotspots = _hotspots.values(line);
foreach (HotSpot *spot, hotspots) {
for (HotSpot *spot : hotspots) {
if (spot->startLine() == line && spot->startColumn() > column) {
continue;
}
......
......@@ -123,8 +123,8 @@ void KeyBindingEditor::filterRows(const QString &text)
void KeyBindingEditor::removeSelectedEntry()
{
QList<QTableWidgetItem *> uniqueList;
foreach (QTableWidgetItem *item, _ui->keyBindingTable->selectedItems()) {
const QList<QTableWidgetItem *> selectedItems = _ui->keyBindingTable->selectedItems();
for (QTableWidgetItem *item : selectedItems) {
if (item->column() == 1) { //Select item at the first column
item = _ui->keyBindingTable->item(item->row(), 0);
}
......@@ -134,7 +134,7 @@ void KeyBindingEditor::removeSelectedEntry()
}
}
foreach (QTableWidgetItem *item, uniqueList) {
for (QTableWidgetItem *item : qAsConst(uniqueList)) {
// get the first item in the row which has the entry
KeyboardTranslator::Entry existing = item->data(Qt::UserRole).
......
......@@ -112,7 +112,7 @@ void KeyboardTranslatorManager::findTranslators()
// add the name of each translator to the list and associated
// the name with a null pointer to indicate that the translator
// has not yet been loaded from disk
foreach (const QString &translatorPath, list) {
for (const QString &translatorPath : qAsConst(list)) {
QString name = QFileInfo(translatorPath).completeBaseName();
if (!_translators.contains(name)) {
......@@ -163,8 +163,8 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator *transla
{
KeyboardTranslatorWriter writer(&destination);
writer.writeHeader(translator->description());
foreach (const KeyboardTranslator::Entry &entry, translator->entries()) {
const QList<KeyboardTranslator::Entry> entriesList = translator->entries();
for (const KeyboardTranslator::Entry &entry : entriesList) {
writer.writeEntry(entry);
}
}
......
......@@ -623,7 +623,7 @@ void Session::silenceTimerDone()
}
bool hasFocus = false;
foreach(TerminalDisplay *display, _views) {
for (const TerminalDisplay *display : qAsConst(_views)) {
if (display->hasFocus()) {
hasFocus = true;
break;
......@@ -646,14 +646,14 @@ void Session::updateFlowControlState(bool suspended)
{
if (suspended) {
if (flowControlEnabled()) {
foreach(TerminalDisplay * display, _views) {
for (TerminalDisplay *display : qAsConst(_views)) {
if (display->flowControlWarningEnabled()) {
display->outputSuspended(true);
}
}
}
} else {
foreach(TerminalDisplay * display, _views) {
for (TerminalDisplay *display : qAsConst(_views)) {
display->outputSuspended(false);
}
}
......@@ -695,7 +695,7 @@ void Session::activityStateSet(int state)
} else if (state == NOTIFYACTIVITY) {
// Don't notify if the terminal is active
bool hasFocus = false;
foreach(TerminalDisplay *display, _views) {
for (const TerminalDisplay *display : qAsConst(_views)) {
if (display->hasFocus()) {
hasFocus = true;
break;
......@@ -746,7 +746,7 @@ void Session::updateTerminalSize()
const int VIEW_COLUMNS_THRESHOLD = 2;
//select largest number of lines and columns that will fit in all visible views
foreach(TerminalDisplay* view, _views) {
for (TerminalDisplay *view : qAsConst(_views)) {
if (!view->isHidden() &&
view->lines() >= VIEW_LINES_THRESHOLD &&
view->columns() >= VIEW_COLUMNS_THRESHOLD) {
......@@ -1604,7 +1604,7 @@ QString Session::profile()
void Session::setProfile(const QString &profileName)
{
const QList<Profile::Ptr> profiles = ProfileManager::instance()->allProfiles();
foreach (const Profile::Ptr &profile, profiles) {
for (const Profile::Ptr &profile : profiles) {
if (profile->name() == profileName) {
SessionManager::instance()->setSessionProfile(this, profile);
}
......@@ -1785,7 +1785,7 @@ void SessionGroup::forwardData(const QByteArray& data)
_inForwardData = true;
const QList<Session*> sessionsKeys = _sessions.keys();
foreach(Session* other, sessionsKeys) {
for (Session *other : sessionsKeys) {
if (!_sessions[other]) {
other->emulation()->sendString(data);
}
......
......@@ -61,7 +61,7 @@ SessionManager::~SessionManager()
<<"session(s) still alive";
// ensure that the Session doesn't later try to call back and do things to the
// SessionManager
foreach (Session *session, _sessions) {
for (Session *session : qAsConst(_sessions)) {
disconnect(session, nullptr, this, nullptr);
}
}
......@@ -81,7 +81,7 @@ bool SessionManager::isClosingAllSessions() const
void SessionManager::closeAllSessions()
{
_isClosingAllSessions = true;
foreach (Session *session, _sessions) {
for (Session *session : qAsConst(_sessions)) {
session->close();
}
_sessions.clear();
......@@ -142,7 +142,7 @@ void SessionManager::sessionTerminated(Session *session)
void SessionManager::applyProfile(const Profile::Ptr &profile, bool modifiedPropertiesOnly)
{
foreach (Session *session, _sessions) {
for (Session *session : qAsConst(_sessions)) {
if (_sessionProfiles[session] == profile) {
applyProfile(session, profile, modifiedPropertiesOnly);
}
......@@ -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;
foreach (TerminalDisplay *view, session->views()) {
const QList<TerminalDisplay *> views = session->views();
for (TerminalDisplay *view : views) {
const QFont &viewCurFont = view->getVTFont();
if (viewCurFont != _sessionProfiles[session]->font()) {
zoomFontSizes.insert(view, viewCurFont);
......@@ -337,7 +337,7 @@ void SessionManager::saveSessions(KConfig *config)
int n = 1;
_restoreMapping.clear();
foreach (Session *session, _sessions) {
for (Session *session : qAsConst(_sessions)) {
QString name = QLatin1String("Session") + QString::number(n);
KConfigGroup group(config, name);
......@@ -379,7 +379,7 @@ void SessionManager::restoreSessions(KConfig *config)
Session *SessionManager::idToSession(int id)
{
foreach (Session *session, _sessions) {
for (Session *session : qAsConst(_sessions)) {
if (session->sessionId() == id) {
return session;
}
......
......@@ -1292,7 +1292,9 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
// Determine which characters should be repainted (1 region unit = 1 character)
QRegion dirtyImageRegion;
foreach(const QRect & rect, (pe->region() & contentsRect())) {
const QRegion region = pe->region() & contentsRect();
for (const QRect &rect : region) {
dirtyImageRegion += widgetToImage(rect);
drawBackground(paint, rect, getBackgroundColor(), true /* use opacity setting */);
}
......@@ -1301,7 +1303,7 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
// set https://bugreports.qt.io/browse/QTBUG-66036
paint.setRenderHint(QPainter::TextAntialiasing, _antialiasText);
foreach(const QRect & rect, dirtyImageRegion) {
for (const QRect &rect : qAsConst(dirtyImageRegion)) {
drawContents(paint, rect);
}
drawCurrentResultRect(paint);
......@@ -1310,7 +1312,7 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
const bool drawDimmed = _dimWhenInactive && !hasFocus();
const QColor dimColor(0, 0, 0, 128);
foreach(const QRect & rect, (pe->region() & contentsRect())) {
for (const QRect &rect : region) {
if (drawDimmed) {
paint.fillRect(rect, dimColor);
}
......
......@@ -196,9 +196,8 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char *argv[])
if (!targetDir.exists()) {
QDir().mkpath(targetBasePath);
}
QStringList fileNames = sourceDir.entryList(
QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
foreach (const QString &fileName, fileNames) {
const QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
for (const QString &fileName : fileNames) {
targetFilePath = targetBasePath + fileName;
if (!QFile::exists(targetFilePath)) {
QFile::copy(sourceBasePath + fileName, targetFilePath);
......@@ -259,7 +258,7 @@ bool shouldUseNewProcess(int argc, char *argv[])
qtProblematicOptions << QStringLiteral("--display")
<< QStringLiteral("--visual");
#endif
foreach (const QString &option, qtProblematicOptions) {
for (const QString &option : qAsConst(qtProblematicOptions)) {
if (arguments.contains(option)) {
return true;
}
......@@ -273,7 +272,7 @@ bool shouldUseNewProcess(int argc, char *argv[])
kdeProblematicOptions << QStringLiteral("--waitforwm");
#endif
foreach (const QString &option, kdeProblematicOptions) {
for (const QString &option : qAsConst(kdeProblematicOptions)) {
if (arguments.contains(option)) {
return true;
}
......
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