Gui: Use auto and range-based for (#7481)

* On lines where the variable type is obvious from inspection, avoid repeating the type using auto. 
* When possible use a ranged for loop instead of begin() and end() iterators
This commit is contained in:
berniev
2022-09-15 04:25:13 +10:00
committed by GitHub
parent d7792826b4
commit 75acacd1b7
175 changed files with 2051 additions and 2057 deletions

View File

@@ -219,7 +219,7 @@ void TaskBox::actionEvent (QActionEvent* e)
switch (e->type()) {
case QEvent::ActionAdded:
{
QSint::ActionLabel *label = new QSint::ActionLabel(action, this);
auto label = new QSint::ActionLabel(action, this);
this->addActionLabel(label, true, false);
break;
}
@@ -327,7 +327,7 @@ bool TaskView::event(QEvent* event)
bool isSpinBox = qobject_cast<QAbstractSpinBox*>(focusWidget);
if (isLineEdit || isSpinBox) {
QKeyEvent * kevent = static_cast<QKeyEvent*>(event);
auto kevent = static_cast<QKeyEvent*>(event);
Qt::KeyboardModifiers ShiftKeypadModifier = Qt::ShiftModifier | Qt::KeypadModifier;
if (kevent->modifiers() == Qt::NoModifier ||
kevent->modifiers() == Qt::ShiftModifier ||
@@ -356,8 +356,7 @@ void TaskView::keyPressEvent(QKeyEvent* ke)
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
// get all buttons of the complete task dialog
QList<QPushButton*> list = this->findChildren<QPushButton*>();
for (int i=0; i<list.size(); ++i) {
QPushButton *pb = list.at(i);
for (auto pb : list) {
if (pb->isDefault() && pb->isVisible()) {
if (pb->isEnabled()) {
#if defined(FC_OS_MACOSX)
@@ -378,8 +377,7 @@ void TaskView::keyPressEvent(QKeyEvent* ke)
// get only the buttons of the button box
QDialogButtonBox* box = ActiveCtrl->standardButtons();
QList<QAbstractButton*> list = box->buttons();
for (int i=0; i<list.size(); ++i) {
QAbstractButton *pb = list.at(i);
for (auto pb : list) {
if (box->buttonRole(pb) == QDialogButtonBox::RejectRole) {
if (pb->isEnabled()) {
#if defined(FC_OS_MACOSX)
@@ -399,7 +397,7 @@ void TaskView::keyPressEvent(QKeyEvent* ke)
// In case a task panel has no Close or Cancel button
// then invoke resetEdit() directly
// See also ViewProvider::eventCallback
Gui::TimerFunction* func = new Gui::TimerFunction();
auto func = new Gui::TimerFunction();
func->setAutoDelete(true);
Gui::Document* doc = Gui::Application::Instance->getDocument(ActiveDialog->getDocumentName().c_str());
if (doc) {
@@ -499,13 +497,13 @@ void TaskView::showDialog(TaskDialog *dlg)
if (dlg->buttonPosition() == TaskDialog::North) {
taskPanel->addWidget(ActiveCtrl);
for (std::vector<QWidget*>::const_iterator it=cont.begin();it!=cont.end();++it){
taskPanel->addWidget(*it);
for (const auto & it : cont){
taskPanel->addWidget(it);
}
}
else {
for (std::vector<QWidget*>::const_iterator it=cont.begin();it!=cont.end();++it){
taskPanel->addWidget(*it);
for (const auto & it : cont){
taskPanel->addWidget(it);
}
taskPanel->addWidget(ActiveCtrl);
}
@@ -538,8 +536,8 @@ void TaskView::removeDialog()
// See 'accept' and 'reject'
if (ActiveDialog->property("taskview_accept_or_reject").isNull()) {
const std::vector<QWidget*> &cont = ActiveDialog->getDialogContent();
for(std::vector<QWidget*>::const_iterator it=cont.begin();it!=cont.end();++it){
taskPanel->removeWidget(*it);
for(const auto & it : cont){
taskPanel->removeWidget(it);
}
remove = ActiveDialog;
ActiveDialog = nullptr;
@@ -581,14 +579,14 @@ void TaskView::updateWatcher()
}
// add all widgets for all watcher to the task view
for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) {
bool match = (*it)->shouldShow();
std::vector<QWidget*> &cont = (*it)->getWatcherContent();
for (std::vector<QWidget*>::iterator it2=cont.begin();it2!=cont.end();++it2) {
for (const auto & it : ActiveWatcher) {
bool match = it->shouldShow();
std::vector<QWidget*> &cont = it->getWatcherContent();
for (auto & it2 : cont) {
if (match)
(*it2)->show();
it2->show();
else
(*it2)->hide();
it2->hide();
}
}
@@ -622,7 +620,7 @@ void TaskView::addTaskWatcher()
for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it){
std::vector<QWidget*> &cont = (*it)->getWatcherContent();
for (std::vector<QWidget*>::iterator it2=cont.begin();it2!=cont.end();++it2){
taskPanel->addWidget(*it2);
taskPanel->addWidget(*it2);
}
}
@@ -636,7 +634,7 @@ void TaskView::addTaskWatcher()
//
// Notify the button box about a style change so that it can
// safely delete the style animation of its push buttons.
QDialogButtonBox* box = taskPanel->findChild<QDialogButtonBox*>();
auto box = taskPanel->findChild<QDialogButtonBox*>();
if (box) {
QEvent event(QEvent::StyleChange);
QApplication::sendEvent(box, &event);