Replace Q_FOREACH with C++11 range-for
ClosedPublic

Authored by jeanv on Jul 15 2017, 5:57 PM.

Details

Summary

The use of Q_FOREACH is advised against (https://doc.qt.io/qt-5/qtglobal.html#Q_FOREACH) since Qt 5.7 and will eventually be removed from Qt.

I replaced all occurrences with the range-for loop introduced in C++11 (except for the one in daemon.cpp in deviceIdByName which might have a bug / typo in it).

I added const to the container or casted it with qAsConst when appropriate to avoid unnecessary copies.

(This is my first submission. I did all the unit tests, and they all passed but I don't know how to show it here.)

Diff Detail

Repository
R224 KDE Connect
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jeanv created this revision.Jul 15 2017, 5:57 PM
jeanv added a reviewer: KDE Connect.
jeanv edited the summary of this revision. (Show Details)Jul 15 2017, 6:03 PM
nicolasfella accepted this revision.Jul 15 2017, 6:29 PM
nicolasfella added a subscriber: nicolasfella.

Looks good to me :) As you probably don't have a developer account Albert will push the changes for you

This revision is now accepted and ready to land.Jul 15 2017, 6:29 PM

except for the one in daemon.cpp in deviceIdByName which might have a bug / typo in it

This seems to be just really bad naming. d is also the name of a member variable. The Device* should be renamed to avoid such confusion

jeanv added a comment.Jul 15 2017, 7:19 PM

except for the one in daemon.cpp in deviceIdByName which might have a bug / typo in it

This seems to be just really bad naming. d is also the name of a member variable. The Device* should be renamed to avoid such confusion

That's what I thought, but I wasn't sure so I didn't touch it. Thanks for clarifying

I'll update the diff with the Q_FOREACH removed (and the name changed).

jeanv updated this revision to Diff 16756.Jul 15 2017, 7:22 PM

Remove the remaining Q_FOREACH in daemon.cpp in deviceIdByName and rename the variable d to device to avoid confusion.

apol accepted this revision.Jul 15 2017, 11:32 PM
apol added a subscriber: apol.

Looks good to me.

Can you give me your email, so I can push this on your behalf?

jeanv added a comment.Jul 20 2017, 3:13 PM

Can you give me your email, so I can push this on your behalf?

Sure: jean.vincent@posteo.net

This revision was automatically updated to reflect the committed changes.