Skip to content

Commit

Permalink
Gui: modernize C++: use range-based for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 14, 2023
1 parent 26f16f7 commit 2725c3a
Show file tree
Hide file tree
Showing 42 changed files with 234 additions and 240 deletions.
26 changes: 15 additions & 11 deletions src/Gui/AutoSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ using namespace Gui;
namespace sp = std::placeholders;

AutoSaver* AutoSaver::self = nullptr;
const int AutoSaveTimeout = 900000;

AutoSaver::AutoSaver(QObject* parent)
: QObject(parent), timeout(900000), compressed(true)
: QObject(parent)
, timeout(AutoSaveTimeout)
, compressed(true)
{
//NOLINTBEGIN
App::GetApplication().signalNewDocument.connect(std::bind(&AutoSaver::slotCreateDocument, this, sp::_1));
Expand All @@ -69,8 +72,9 @@ AutoSaver::~AutoSaver()

AutoSaver* AutoSaver::instance()
{
if (!self)
if (!self) {
self = new AutoSaver(QApplication::instance());
}
return self;
}

Expand All @@ -88,11 +92,11 @@ void AutoSaver::setTimeout(int ms)
timeout = Base::clamp<int>(ms, 0, 3600000); // between 0 and 60 min

// go through the attached documents and apply the new timeout
for (std::map<std::string, AutoSaveProperty*>::iterator it = saverMap.begin(); it != saverMap.end(); ++it) {
if (it->second->timerId > 0)
killTimer(it->second->timerId);
for (auto & it : saverMap) {
if (it.second->timerId > 0)
killTimer(it.second->timerId);
int id = timeout > 0 ? startTimer(timeout) : 0;
it->second->timerId = id;
it.second->timerId = id;
}
}

Expand Down Expand Up @@ -227,15 +231,15 @@ void AutoSaver::saveDocument(const std::string& name, AutoSaveProperty& saver)
void AutoSaver::timerEvent(QTimerEvent * event)
{
int id = event->timerId();
for (std::map<std::string, AutoSaveProperty*>::iterator it = saverMap.begin(); it != saverMap.end(); ++it) {
if (it->second->timerId == id) {
for (auto & it : saverMap) {
if (it.second->timerId == id) {
try {
saveDocument(it->first, *it->second);
it->second->touched.clear();
saveDocument(it.first, *it.second);
it.second->touched.clear();
break;
}
catch (...) {
Base::Console().Error("Failed to auto-save document '%s'\n", it->first.c_str());
Base::Console().Error("Failed to auto-save document '%s'\n", it.first.c_str());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/CommandTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ void Std_TestQM::activated(int iMsg)
if (!files.empty()) {
Translator::instance()->activateLanguage("English");
QList<QTranslator*> i18n = qApp->findChildren<QTranslator*>();
for (QList<QTranslator*>::Iterator it = i18n.begin(); it != i18n.end(); ++it)
qApp->removeTranslator(*it);
for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) {
for (QTranslator* it : i18n)
qApp->removeTranslator(it);
for (const QString& it : files) {
auto translator = new QTranslator(qApp);
if (translator->load(*it)) {
if (translator->load(it)) {
qApp->installTranslator(translator);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DAGView/DAGModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,9 @@ void Model::mousePressEvent(QGraphicsSceneMouseEvent* event)
QPointF currentPickPoint = event->scenePos();
QGraphicsLineItem intersectionLine(QLineF(lastPick, currentPickPoint));
QList<QGraphicsItem *>selection = collidingItems(&intersectionLine);
for (auto currentItem = selection.begin(); currentItem != selection.end(); ++currentItem)
for (auto currentItem : selection)
{
auto rect = dynamic_cast<RectItem *>(*currentItem);
auto rect = dynamic_cast<RectItem *>(currentItem);
if (!rect) continue;
const GraphLinkRecord &selectionRecord = findRecord(rect, *graphLink);
Gui::Selection().addSelection(selectionRecord.DObject->getDocument()->getName(),
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/DlgActivateWindowImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ DlgActivateWindowImp::DlgActivateWindowImp(QWidget* parent, Qt::WindowFlags fl)

QWidget* activeWnd = getMainWindow()->activeWindow();

for (QList<QWidget*>::Iterator it = windows.begin(); it != windows.end(); ++it) {
for (QWidget* it : windows) {
auto item = new QTreeWidgetItem(ui->treeWidget);
QString title = (*it)->windowTitle();
QString title = it->windowTitle();
title.replace(QLatin1String("[*]"), QLatin1String(""));
if ((*it)->isWindowModified())
if (it->isWindowModified())
title += QLatin1String("*");
item->setText(0, title);
if (*it == activeWnd)
if (it == activeWnd)
active = item;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DlgCustomizeImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ DlgCustomizeImp::DlgCustomizeImp(QWidget* parent, Qt::WindowFlags fl)

// make sure that pages are ready to create
GetWidgetFactorySupplier();
for (QList<QByteArray>::Iterator it = _pages.begin(); it!=_pages.end(); ++it)
for (const QByteArray& it : _pages)
{
addPage(WidgetFactory().createWidget((*it).constData()));
addPage(WidgetFactory().createWidget(it.constData()));
}

customLayout->addWidget(tabWidget, 0, 0);
Expand Down
11 changes: 5 additions & 6 deletions src/Gui/DlgKeyboardImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ void DlgCustomKeyboardImp::populatePriorityList(QTreeWidget *priorityList,

auto actionList = ShortcutManager::instance()->getActionsByShortcut(sc);
QTreeWidgetItem *currentItem = nullptr;
for (size_t i=0; i<actionList.size(); ++i) {
const auto &info = actionList[i];
for (const auto &info : actionList) {
if (!info.second)
continue;
QTreeWidgetItem* item = new QTreeWidgetItem(priorityList);
Expand Down Expand Up @@ -397,10 +396,10 @@ void DlgCustomKeyboardImp::populateCommandGroups(QComboBox *combo)
}
groupMap.push_back(std::make_pair(QLatin1String("All"), tr("All")));

for (GroupMap::iterator it = groupMap.begin(); it != groupMap.end(); ++it) {
if (combo->findData(it->first) < 0) {
combo->addItem(it->second);
combo->setItemData(combo->count()-1, QVariant(it->first), Qt::UserRole);
for (const auto & it : groupMap) {
if (combo->findData(it.first) < 0) {
combo->addItem(it.second);
combo->setItemData(combo->count()-1, QVariant(it.first), Qt::UserRole);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DlgUnitsCalculatorImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WindowFlags fl )
<< Base::Unit::VolumeFlowRate
<< Base::Unit::VolumetricThermalExpansionCoefficient
<< Base::Unit::Work;
for (QList<Base::Unit>::iterator it = units.begin(); it != units.end(); ++it) {
ui->unitsBox->addItem(it->getTypeString());
for (const Base::Unit& it : units) {
ui->unitsBox->addItem(it.getTypeString());
}

ui->quantitySpinBox->setValue(1.0);
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,8 +2438,8 @@ void Document::handleChildren3D(ViewProvider* viewProvider, bool deleting)
backGroup->addChild(childBackNode);

// cycling to all views of the document to remove the viewprovider from the viewer itself
for (std::list<Gui::BaseView*>::iterator vIt = d->baseViews.begin();vIt != d->baseViews.end();++vIt) {
auto activeView = dynamic_cast<View3DInventor *>(*vIt);
for (Gui::BaseView* vIt : d->baseViews) {
auto activeView = dynamic_cast<View3DInventor *>(vIt);
if (activeView && activeView->getViewer()->hasViewProvider(ChildViewProvider)) {
// @Note hasViewProvider()
// remove the viewprovider serves the purpose of detaching the inventor nodes from the
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DocumentPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ PyObject* DocumentPy::mdiViewsOfType(PyObject *args)
PY_TRY {
std::list<Gui::MDIView*> views = getDocumentPtr()->getMDIViewsOfType(type);
Py::List list;
for (auto it = views.begin(); it != views.end(); ++it)
list.append(Py::asObject((*it)->getPyObject()));
for (auto it : views)
list.append(Py::asObject(it->getPyObject()));
return Py::new_reference_to(list);
}
PY_CATCH;
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ QUrl DownloadManager::redirectUrl(const QUrl& url) const
if (url.host() == QLatin1String("www.dropbox.com")) {
QUrlQuery urlQuery(url);
QList< QPair<QString, QString> > query = urlQuery.queryItems();
for (QList< QPair<QString, QString> >::iterator it = query.begin(); it != query.end(); ++it) {
if (it->first == QLatin1String("dl")) {
if (it->second == QLatin1String("0\r\n")) {
for (const auto & it : query) {
if (it.first == QLatin1String("dl")) {
if (it.second == QLatin1String("0\r\n")) {
urlQuery.removeQueryItem(QLatin1String("dl"));
urlQuery.addQueryItem(QLatin1String("dl"), QLatin1String("1\r\n"));
}
else if (it->second == QLatin1String("0")) {
else if (it.second == QLatin1String("0")) {
urlQuery.removeQueryItem(QLatin1String("dl"));
urlQuery.addQueryItem(QLatin1String("dl"), QLatin1String("1"));
}
Expand Down
9 changes: 3 additions & 6 deletions src/Gui/Flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ void FlagLayout::setGeometry(const QRect &rect)
QLayout::setGeometry(rect);

// left side
for (int i = 0; i < list.size(); ++i) {
ItemWrapper *wrapper = list.at(i);
for (ItemWrapper *wrapper : list) {
QLayoutItem *item = wrapper->item;
Position position = wrapper->position;

Expand All @@ -275,8 +274,7 @@ void FlagLayout::setGeometry(const QRect &rect)
// right side
topHeight = 0;
bottomHeight = 0;
for (int i = 0; i < list.size(); ++i) {
ItemWrapper *wrapper = list.at(i);
for (ItemWrapper *wrapper : list) {
QLayoutItem *item = wrapper->item;
Position position = wrapper->position;

Expand Down Expand Up @@ -318,8 +316,7 @@ QSize FlagLayout::calculateSize(SizeType sizeType) const
{
QSize totalSize;

for (int i = 0; i < list.size(); ++i) {
ItemWrapper *wrapper = list.at(i);
for (ItemWrapper *wrapper : list) {
QSize itemSize;

if (sizeType == MinimumSize)
Expand Down
10 changes: 5 additions & 5 deletions src/Gui/GLPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ void Polyline::paintGL()
if (closed && !stippled) {
glBegin(GL_LINE_LOOP);

for (std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
glVertex2i(it->x(), it->y());
for (const QPoint& it : _cNodeVector) {
glVertex2i(it.x(), it.y());
}

glEnd();
Expand All @@ -439,10 +439,10 @@ void Polyline::paintGL()
glBegin(GL_LINES);

QPoint start = _cNodeVector.front();
for (std::vector<QPoint>::iterator it = _cNodeVector.begin(); it != _cNodeVector.end(); ++it) {
for (const QPoint& it : _cNodeVector) {
glVertex2i(start.x(), start.y());
start = *it;
glVertex2i(it->x(), it->y());
start = it;
glVertex2i(it.x(), it.y());
}

glEnd();
Expand Down
10 changes: 5 additions & 5 deletions src/Gui/GraphvizView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,16 @@ bool GraphvizView::onMsg(const char* pMsg,const char**)
//formatMap << qMakePair(tr("VRML format (*.vrml)"), QString::fromLatin1("vrml"));

QStringList filter;
for (QList< QPair<QString, QString> >::iterator it = formatMap.begin(); it != formatMap.end(); ++it)
filter << it->first;
for (const auto & it : formatMap)
filter << it.first;

QString selectedFilter;
QString fn = Gui::FileDialog::getSaveFileName(this, tr("Export graph"), QString(), filter.join(QLatin1String(";;")), &selectedFilter);
if (!fn.isEmpty()) {
QString format;
for (QList< QPair<QString, QString> >::iterator it = formatMap.begin(); it != formatMap.end(); ++it) {
if (selectedFilter == it->first) {
format = it->second;
for (const auto & it : formatMap) {
if (selectedFilter == it.first) {
format = it.second;
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/Inventor/MarkerBitmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ int MarkerBitmaps::getMarkerIndex(const std::string& name, int px)
std::list<int> MarkerBitmaps::getSupportedSizes(const std::string& name)
{
std::list<int> sizes;
for (std::map<Marker, int>::iterator it = markerIndex.begin(); it != markerIndex.end(); ++it) {
if (it->first.first == name)
sizes.push_back(it->first.second);
for (const auto & it : markerIndex) {
if (it.first.first == name)
sizes.push_back(it.first.second);
}
return sizes;
}
10 changes: 5 additions & 5 deletions src/Gui/Language/Translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ void Translator::refresh()
std::map<std::string, std::string>::iterator tld = d->mapLanguageTopLevelDomain.find(d->activatedLanguage);
if (tld == d->mapLanguageTopLevelDomain.end())
return; // no language activated
for (QStringList::iterator it = d->paths.begin(); it != d->paths.end(); ++it) {
QDir dir(*it);
for (const QString& it : d->paths) {
QDir dir(it);
installQMFiles(dir, tld->second.c_str());
}
}
Expand All @@ -356,9 +356,9 @@ void Translator::refresh()
*/
void Translator::removeTranslators()
{
for (std::list<QTranslator*>::iterator it = d->translators.begin(); it != d->translators.end(); ++it) {
qApp->removeTranslator(*it);
delete *it;
for (QTranslator* it : d->translators) {
qApp->removeTranslator(it);
delete it;
}

d->translators.clear();
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/MergeDocuments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ MergeDocuments::importObjects(std::istream& input)
void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Base::XMLReader & r)
{
objects = o;
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) {
Gui::ViewProvider* vp = document->getViewProvider(*it);
for (auto it : objects) {
Gui::ViewProvider* vp = document->getViewProvider(it);
if (vp) vp->hide();
}
Restore(r);
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/PrefWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,9 @@ void PrefQuantitySpinBox::contextMenuEvent(QContextMenuEvent *event)

// data structure to remember actions for values
QStringList history = d->history.asStringList();
for (QStringList::const_iterator it = history.cbegin();it != history.cend(); ++it) {
QAction* action = menu->addAction(*it);
action->setProperty("history_value", *it);
for (const auto & it : history) {
QAction* action = menu->addAction(it);
action->setProperty("history_value", it);
}

// add the save value portion of the menu
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/PythonConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ void PythonConsole::runSource(const QString& line)
PySys_SetObject("stdout", default_stdout);
PySys_SetObject("stderr", default_stderr);
d->interactive = false;
for (QStringList::Iterator it = d->statements.begin(); it != d->statements.end(); ++it) {
printStatement(*it);
for (const auto & it : d->statements) {
printStatement(it);
}
d->statements.clear();
}
Expand Down
Loading

0 comments on commit 2725c3a

Please sign in to comment.