[C++11] `foreach` to `for`, const/const& where possible

Qt foreach macro is unnecessary in most cases with C++11's new
range-based for loop syntax.  **However**, foreach makes a copy and for
does not, and for cannot change something it is looping over.  I left
foreach loops in some places.

I also moved to const and const reference where possible, which are good
optimizations.