Commit f0529c1c authored by Jekyll Wu's avatar Jekyll Wu
Browse files

Prefer foreach(..) over iterating manually for readability

parent 97ce14af
......@@ -522,18 +522,16 @@ void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
model->clear();
QList<const ColorScheme*> schemeList = ColorSchemeManager::instance()->allColorSchemes();
QListIterator<const ColorScheme*> schemeIter(schemeList);
QStandardItem* selectedItem = 0;
while (schemeIter.hasNext()) {
const ColorScheme* colors = schemeIter.next();
QStandardItem* item = new QStandardItem(colors->description());
item->setData(QVariant::fromValue(colors) , Qt::UserRole + 1);
QList<const ColorScheme*> schemeList = ColorSchemeManager::instance()->allColorSchemes();
foreach ( const ColorScheme* scheme, schemeList) {
QStandardItem* item = new QStandardItem(scheme->description());
item->setData(QVariant::fromValue(scheme) , Qt::UserRole + 1);
item->setFlags(item->flags());
if (currentScheme == colors)
if (currentScheme == scheme)
selectedItem = item;
model->appendRow(item);
......
......@@ -70,13 +70,9 @@ KeyBindingEditor::~KeyBindingEditor()
void KeyBindingEditor::removeSelectedEntry()
{
QList<QTableWidgetItem*> selectedList = _ui->keyBindingTable->selectedItems();
QList<QTableWidgetItem*> uniqueList;
//Filter unique items
QListIterator<QTableWidgetItem*> iter(selectedList);
while (iter.hasNext()) {
QTableWidgetItem* item = iter.next();
foreach ( QTableWidgetItem* item, _ui->keyBindingTable->selectedItems() ) {
if (item->column() == 1) //Select item at the first column
item = _ui->keyBindingTable->item(item->row(), 0);
......@@ -84,10 +80,8 @@ void KeyBindingEditor::removeSelectedEntry()
uniqueList.append(item);
}
iter = QListIterator<QTableWidgetItem*>(uniqueList);
while (iter.hasNext()) {
foreach ( QTableWidgetItem* item, uniqueList ) {
// get the first item in the row which has the entry
QTableWidgetItem* item = iter.next();
KeyboardTranslator::Entry existing = item->data(Qt::UserRole).
value<KeyboardTranslator::Entry>();
......
......@@ -67,9 +67,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
QStringListIterator listIter(list);
while (listIter.hasNext()) {
QString translatorPath = listIter.next();
foreach ( const QString& translatorPath, list) {
QString name = QFileInfo(translatorPath).baseName();
......@@ -116,9 +114,8 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla
KeyboardTranslatorWriter writer(&destination);
writer.writeHeader(translator->description());
QListIterator<KeyboardTranslator::Entry> iter(translator->entries());
while (iter.hasNext())
writer.writeEntry(iter.next());
foreach ( const KeyboardTranslator::Entry& entry, translator->entries() )
writer.writeEntry(entry);
}
destination.close();
......
......@@ -659,8 +659,6 @@ void Session::onViewSizeChange(int /*height*/, int /*width*/)
void Session::updateTerminalSize()
{
QListIterator<TerminalDisplay*> viewIter(_views);
int minLines = -1;
int minColumns = -1;
......@@ -671,8 +669,7 @@ void Session::updateTerminalSize()
const int VIEW_COLUMNS_THRESHOLD = 2;
//select largest number of lines and columns that will fit in all visible views
while (viewIter.hasNext()) {
TerminalDisplay* view = viewIter.next();
foreach ( TerminalDisplay* view, _views ) {
if (view->isHidden() == false &&
view->lines() >= VIEW_LINES_THRESHOLD &&
view->columns() >= VIEW_COLUMNS_THRESHOLD) {
......@@ -1447,9 +1444,7 @@ void SessionGroup::forwardData(const char* data, int size)
}
_inForwardData = true;
QListIterator<Session*> iter(_sessions.keys());
while (iter.hasNext()) {
Session* other = iter.next();
foreach ( Session* other, _sessions.keys() ) {
if (!_sessions[other]) {
other->emulation()->sendString(data, size);
}
......
......@@ -711,9 +711,7 @@ static const KXmlGuiWindow* findWindow(const QObject* object)
static bool hasTerminalDisplayInSameWindow(const Session* session, const KXmlGuiWindow* window)
{
// Iterate all TerminalDisplays of this Session ...
QListIterator<TerminalDisplay*> terminalDisplayIterator(session->views());
while (terminalDisplayIterator.hasNext()) {
const TerminalDisplay* terminalDisplay = terminalDisplayIterator.next();
foreach ( const TerminalDisplay* terminalDisplay, session->views() ) {
// ... and check whether a TerminalDisplay has the same
// window as given in the parameter
if (window == findWindow(terminalDisplay)) {
......@@ -1269,8 +1267,6 @@ SaveHistoryTask::~SaveHistoryTask()
void SaveHistoryTask::execute()
{
QListIterator<SessionPtr> iter(sessions());
// TODO - think about the UI when saving multiple history sessions, if there are more than two or
// three then providing a URL for each one will be tedious
......@@ -1290,8 +1286,7 @@ 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
while (iter.hasNext()) {
SessionPtr session = iter.next();
foreach ( const SessionPtr& session, sessions() ) {
dialog->setCaption(i18n("Save Output From %1", session->title(Session::NameRole)));
......
......@@ -391,9 +391,7 @@ void SessionManager::changeProfile(Profile::Ptr profile,
Q_ASSERT(profile);
// insert the changes into the existing Profile instance
QListIterator<Profile::Property> iter(propertyMap.keys());
while (iter.hasNext()) {
const Profile::Property property = iter.next();
foreach ( const Profile::Property& property, propertyMap.keys() ) {
profile->setProperty(property, propertyMap[property]);
}
......
......@@ -1206,9 +1206,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
// and draw appropriate visuals to indicate the presence of the hotspot
QList<Filter::HotSpot*> spots = _filterChain->hotSpots();
QListIterator<Filter::HotSpot*> iter(spots);
while (iter.hasNext()) {
Filter::HotSpot* spot = iter.next();
foreach ( Filter::HotSpot* spot, spots ) {
QRegion region;
if (_underlineLinks && spot->type() == Filter::HotSpot::Link) {
......
......@@ -235,12 +235,9 @@ ViewContainer* ViewSplitter::activeContainer() const
ViewContainer* focusContainer = 0;
while (focusW != 0) {
QListIterator<ViewContainer*> containerIter(_containers);
while (containerIter.hasNext()) {
ViewContainer* nextContainer = containerIter.next();
if (nextContainer->containerWidget() == focusW) {
focusContainer = nextContainer;
foreach ( ViewContainer* container, _containers ) {
if (container->containerWidget() == focusW) {
focusContainer = container;
break;
}
}
......
......@@ -434,9 +434,7 @@ void Vt102Emulation::processWindowAttributeChange()
void Vt102Emulation::updateTitle()
{
QListIterator<int> iter( _pendingTitleUpdates.keys() );
while (iter.hasNext()) {
int arg = iter.next();
foreach ( const int& arg, _pendingTitleUpdates.keys() ) {
emit titleChanged( arg , _pendingTitleUpdates[arg] );
}
_pendingTitleUpdates.clear();
......
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