Skip to content

Commit

Permalink
Modernize for cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
kecsap committed Jun 3, 2018
1 parent 48e8cc7 commit 6569077
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 183 deletions.
20 changes: 11 additions & 9 deletions datahandlers/ksparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ QHash<QString, QVariant> KSParser::ReadFixedWidthRow()
continue;

int curr_width = 0;
for (int n_split = 0; n_split < width_sequence_.length(); n_split++)
for (int split : width_sequence_)
{
// Build separated stringlist. Then assign it afterwards.
QString temp_split;
temp_split = next_line.mid(curr_width, width_sequence_[n_split]);

temp_split = next_line.mid(curr_width, split);
// Don't use at(), because it crashes on invalid index
curr_width += width_sequence_[n_split];
curr_width += split;
separated.append(temp_split.trimmed());
}
separated.append(next_line.mid(curr_width).trimmed()); // Append last segment
Expand Down Expand Up @@ -211,21 +212,22 @@ QHash<QString, QVariant> KSParser::DummyRow()
{
// qWarning() << "File named " << filename_ << " encountered an error while reading";
QHash<QString, QVariant> newRow;
for (int i = 0; i < name_type_sequence_.length(); ++i)

for (auto &item : name_type_sequence_)
{
switch (name_type_sequence_[i].second)
switch (item.second)
{
case D_QSTRING:
newRow[name_type_sequence_[i].first] = EBROKEN_QSTRING;
newRow[item.first] = EBROKEN_QSTRING;
break;
case D_DOUBLE:
newRow[name_type_sequence_[i].first] = EBROKEN_DOUBLE;
newRow[item.first] = EBROKEN_DOUBLE;
break;
case D_INT:
newRow[name_type_sequence_[i].first] = EBROKEN_INT;
newRow[item.first] = EBROKEN_INT;
break;
case D_FLOAT:
newRow[name_type_sequence_[i].first] = EBROKEN_FLOAT;
newRow[item.first] = EBROKEN_FLOAT;
break;
case D_SKIP:
default:
Expand Down
11 changes: 6 additions & 5 deletions kstars/auxiliary/binfilehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,12 @@ QString BinFileHelper::getError()
struct dataElement BinFileHelper::getField(const QString &fieldName) const
{
dataElement de;
for (int i = 0; i < fields.size(); ++i)

for (auto &field : fields)
{
if (fields[i]->name == fieldName)
if (field->name == fieldName)
{
de = *fields[i];
de = *field;
return de;
}
}
Expand All @@ -321,9 +322,9 @@ struct dataElement BinFileHelper::getField(const QString &fieldName) const

bool BinFileHelper::isField(const QString &fieldName) const
{
for (int i = 0; i < fields.size(); ++i)
for (auto &field : fields)
{
if (fields[i]->name == fieldName)
if (field->name == fieldName)
return true;
}
return false;
Expand Down
7 changes: 4 additions & 3 deletions kstars/auxiliary/ksuserdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,12 +1807,13 @@ void KSUserDB::AddHorizon(ArtificialHorizonEntity *horizon)

SkyList *skyList = horizon->list()->points();

for (int i = 0; i < skyList->size(); i++)
for (const auto &item : *skyList)
{
points.select();
QSqlRecord rec(points.record());
rec.setValue("Az", skyList->at(i)->az().Degrees());
rec.setValue("Alt", skyList->at(i)->alt().Degrees());

rec.setValue("Az", item->az().Degrees());
rec.setValue("Alt", item->alt().Degrees());
points.insertRecord(-1, rec);
}

Expand Down
6 changes: 3 additions & 3 deletions kstars/auxiliary/kswizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ void KSWizard::slotChangeCity()
{
if (location->CityListBox->currentItem())
{
for (int i = 0; i < filteredCityList.size(); ++i)
for (auto &city : filteredCityList)
{
if (filteredCityList[i]->fullName() == location->CityListBox->currentItem()->text())
if (city->fullName() == location->CityListBox->currentItem()->text())
{
Geo = filteredCityList[i];
Geo = city;
break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions kstars/auxiliary/schememanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,9 @@ void SchemeManagerPrivate::init(const KSharedConfigPtr& config,
{
StateEffects effects(state, config);

for (int i = 0; i < 8; i++)
for (auto &brush : _brushes.fg)
{
_brushes.fg[i] = effects.brush(_brushes.fg[i], _brushes.bg[0]);
brush = effects.brush(brush, _brushes.bg[0]);
}

_brushes.deco[0] = effects.brush(_brushes.deco[0], _brushes.bg[0]);
Expand Down Expand Up @@ -1092,9 +1092,8 @@ QPalette SchemeManager::createApplicationPalette(const KSharedConfigPtr& config)
// TT thinks tooltips shouldn't use active, so we use our active colors for all states
SchemeManager schemeTooltip(QPalette::Active, SchemeManager::Tooltip, config);

for (int i = 0; i < 3; i++)
for (auto &state : states)
{
QPalette::ColorGroup state = states[i];
SchemeManager schemeView(state, SchemeManager::View, config);
SchemeManager schemeWindow(state, SchemeManager::Window, config);
SchemeManager schemeButton(state, SchemeManager::Button, config);
Expand Down
4 changes: 2 additions & 2 deletions kstars/dialogs/locationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ void LocationDialog::filterCity()
void LocationDialog::changeCity()
{
KStarsData *data = KStarsData::Instance();

//when the selected city changes, set newCity, and redraw map
SelectedCity = nullptr;
if (ld->GeoBox->currentItem())
{
for (int i = 0; i < filteredCityList.size(); ++i)
for (auto &loc : filteredCityList)
{
GeoLocation *loc = filteredCityList.at(i);
if (loc->fullName() == ld->GeoBox->currentItem()->text())
{
SelectedCity = loc;
Expand Down
8 changes: 4 additions & 4 deletions kstars/ekos/guide/externalguide/phd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ void PHD2::processPHD2Event(const QJsonObject &jsonEvent)
emit newAxisDelta(diff_ra_arcsecs, diff_de_arcsecs);
emit newAxisPulse(pulse_ra, pulse_dec);

double total_sqr_RA_error=0.0;
double total_sqr_DE_error=0.0;
for(int i=0;i<errorLog.size();i++)
double total_sqr_RA_error = 0.0;
double total_sqr_DE_error = 0.0;

for (auto &point : errorLog)
{
QPointF point=errorLog.at(i);
total_sqr_RA_error+=point.x()*point.x();
total_sqr_DE_error+=point.y()*point.y();
}
Expand Down
20 changes: 13 additions & 7 deletions kstars/ekos/guide/internalguide/matr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
//---------------------------------------------------------------------------
#include "matr.h"

#include <cmath>
#include "vect.h"

#include <cmath>

//---------------------------------------------------------------------------

namespace Ekos
Expand All @@ -29,9 +30,12 @@ Matrix ::Matrix(double v)

Matrix ::Matrix()
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
x[i][j] = 0.0;
for (auto &row : x)
for (double &item : row)
{
item = 0.0;
}

x[3][3] = 1;
}

Expand Down Expand Up @@ -108,9 +112,11 @@ Matrix &Matrix ::operator-=(const Matrix &A)

Matrix &Matrix ::operator*=(double v)
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
x[i][j] *= v;
for (auto &row : x)
for (double &item : row)
{
item *= v;
}

return *this;
}
Expand Down
8 changes: 4 additions & 4 deletions kstars/hips/hipsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,22 @@ bool HIPSRenderer::renderPix(bool allsky, int level, int pix, QImage *pDest)
m_HEALpix->getPixChilds(pix, childPixelID);

int j = 0;
for (int q = 0; q < 4; q++)
for (int id : childPixelID)
{
int grandChildPixelID[4];
// Find the children of this child (i.e. grand child)
// Then we have 4x4 pixels under the primary pixel
// The image is interpolated and rendered over these pixels
// coordinate to minimize any distortions due to the projection
// system.
m_HEALpix->getPixChilds(childPixelID[q], grandChildPixelID);
m_HEALpix->getPixChilds(id, grandChildPixelID);

QPointF fineScreenCoords[4];

for (int w = 0; w < 4; w++)
for (int id2 : grandChildPixelID)
{
SkyPoint fineSkyPoints[4];
m_HEALpix->getCornerPoints(level + 2, grandChildPixelID[w], fineSkyPoints);
m_HEALpix->getCornerPoints(level + 2, id2, fineSkyPoints);

for (int i = 0; i < 4; i++)
fineScreenCoords[i] = m_projector->toScreen(&fineSkyPoints[i]);
Expand Down
8 changes: 4 additions & 4 deletions kstars/indi/indidbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "indidbus.h"

#include <basedevice.h>

#include "indiadaptor.h"
#include "nan.h"
#include "indi/drivermanager.h"
Expand All @@ -22,6 +20,8 @@

#include "kstars_debug.h"

#include <basedevice.h>

INDIDBus::INDIDBus(QObject *parent) : QObject(parent)
{
new INDIAdaptor(this);
Expand Down Expand Up @@ -149,9 +149,9 @@ QStringList INDIDBus::getProperties(const QString &device)
INDI::Property *prop;

// Let's print a list of all device properties
for (unsigned int i = 0; i < pAll->size(); i++)
for (auto &property : *pAll)
{
prop = pAll->at(i);
prop = property;

switch (prop->getType())
{
Expand Down
9 changes: 4 additions & 5 deletions kstars/indi/indilistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

#include "auxiliary/ksnotification.h"

#include <basedevice.h>
#include <knotification.h>

#include <basedevice.h>
#include <indi_debug.h>

#include <knotification.h>

#define NINDI_STD 35

/* INDI standard property used across all clients to enable interoperability. */
Expand Down Expand Up @@ -106,9 +105,9 @@ INDIListener::~INDIListener()

bool INDIListener::isStandardProperty(const QString &name)
{
for (int i = 0; i < NINDI_STD; i++)
for (auto &item : indi_std)
{
if (!strcmp(name.toLatin1().constData(), indi_std[i]))
if (!strcmp(name.toLatin1().constData(), item))
return true;
}
return false;
Expand Down
10 changes: 5 additions & 5 deletions kstars/ksnumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,20 +361,20 @@ void KSNumbers::updateValues(long double jd)
// Vearth Z component
vearth[2] = 0.;

for (unsigned int i = 0; i < 36; i++)
for (auto &item : vondrak)
{
anglev.setRadians(vondrak[i][0]);
anglev.setRadians(item[0]);
anglev.SinCos(sa, ca);
for (unsigned int j = 0; j < 3; j++)
{
vearth[j] += vondrak[i][2 * j + 1] * sa + vondrak[i][2 * j + 2] * ca;
vearth[j] += item[2 * j + 1] * sa + item[2 * j + 2] * ca;
}
}

const double UA2km = 1.49597870 / 86400.; // 10^{-8}*UA/dia -> km/s

for (unsigned int j = 0; j < 3; j++)
for (double &item : vearth)
{
vearth[j] = vearth[j] * UA2km;
item *= UA2km;
}
}
16 changes: 8 additions & 8 deletions kstars/skycomponents/catalogcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ void CatalogComponent::_loadData(bool includeCatalogDesignation)
QList<QPair<int, QString>> names;

KStarsData::Instance()->catalogdb()->GetAllObjects(m_catName, m_ObjectList, names, this, includeCatalogDesignation);
for (int iter = 0; iter < names.size(); ++iter)

for (const auto &name : names)
{
if (names.at(iter).first <= SkyObject::TYPE_UNKNOWN)
if (name.first <= SkyObject::TYPE_UNKNOWN)
{
//FIXME JM 2016-06-02: inefficient and costly check
// Need better way around this
Expand All @@ -88,14 +89,13 @@ void CatalogComponent::_loadData(bool includeCatalogDesignation)
// very large such that the filtering in Find Dialog takes
// too long. -- AS

objectNames(names.at(iter).first).append(names.at(iter).second);
objectNames(name.first).append(name.second);
}
}

//FIXME - get rid of objectNames completely. For now only KStars Lite uses objectLists
for (int iter = 0; iter < m_ObjectList.size(); ++iter)
for (auto obj : m_ObjectList)
{
SkyObject *obj = m_ObjectList[iter];
Q_ASSERT(obj);
if (obj->type() <= SkyObject::TYPE_UNKNOWN)
{
Expand All @@ -116,11 +116,11 @@ void CatalogComponent::_loadData(bool includeCatalogDesignation)
// miscellaneous catalog), then disabling one catalog
// removes the name entirely from the list.

for (int i = 0; i < objects.size(); ++i)
for (const auto &object : objects)
{
if (name == objects.at(i).first)
if (name == object.first)
dupName = true;
if (longname == objects.at(i).first)
if (longname == object.first)
dupLongname = true;
}

Expand Down
4 changes: 2 additions & 2 deletions kstars/skycomponents/constellationboundarylines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ PolyList *ConstellationBoundaryLines::ContainingPoly(SkyPoint *p)

//printf(" size: %d\n", polyListList->size() );

for (int i = 0; i < polyListList->size(); i++)
for (const auto &item : *polyListList)
{
polyHash.insert(polyListList->at(i).get(), true);
polyHash.insert(item.get(), true);
}
}

Expand Down
Loading

0 comments on commit 6569077

Please sign in to comment.