Commit e6b63889 authored by Tom Titcombe's avatar Tom Titcombe
Browse files

clang-tidy modernize-loop-convert on qt/widgets

parent d70285f2
......@@ -382,11 +382,11 @@ bool AlgorithmDialog::setPropertyValues(const QStringList &skipList) {
// But only if the individual validation passed
if (allValid) {
std::map<std::string, std::string> errs = m_algorithm->validateInputs();
for (auto it = errs.begin(); it != errs.end(); it++) {
for (auto & err : errs) {
// only count as an error if the named property exists
if (m_algorithm->existsProperty(it->first)) {
const QString pName = QString::fromStdString(it->first);
const QString value = QString::fromStdString(it->second);
if (m_algorithm->existsProperty(err.first)) {
const QString pName = QString::fromStdString(err.first);
const QString value = QString::fromStdString(err.second);
if (m_errors.contains(pName)) {
if (!m_errors[pName].isEmpty())
m_errors[pName] += "\n";
......@@ -761,8 +761,8 @@ void AlgorithmDialog::executeAlgorithmAsync() {
try {
// Add any custom AlgorithmObservers to the algorithm
for (auto it = m_observers.begin(); it != m_observers.end(); ++it) {
(*it)->observeAll(algToExec);
for (auto & m_observer : m_observers) {
m_observer->observeAll(algToExec);
}
// Only need to observe finish events if we are staying open
......
......@@ -496,8 +496,8 @@ void AlgorithmHistoryWindow::copytoClipboard() {
}
void AlgorithmHistoryWindow::doUnroll(const std::vector<int> &unrollIndicies) {
for (auto it = unrollIndicies.begin(); it != unrollIndicies.end(); ++it) {
m_view->unroll(*it);
for (std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<int> > >::value_type unrollIndicie : unrollIndicies) {
m_view->unroll(unrollIndicie);
}
}
......@@ -749,15 +749,14 @@ void AlgHistoryTreeWidget::populateNestedHistory(
parentWidget->setCheckState(1, Qt::Unchecked);
}
for (auto algHistIter = entries.begin(); algHistIter != entries.end();
++algHistIter) {
int nAlgVersion = (*algHistIter)->version();
algName = concatVersionwithName((*algHistIter)->name(), nAlgVersion);
for (const auto & entrie : entries) {
int nAlgVersion = entrie->version();
algName = concatVersionwithName(entrie->name(), nAlgVersion);
AlgHistoryItem *item =
new AlgHistoryItem(QStringList(algName), *algHistIter, parentWidget);
new AlgHistoryItem(QStringList(algName), entrie, parentWidget);
parentWidget->addChild(item);
populateNestedHistory(item, *algHistIter);
populateNestedHistory(item, entrie);
}
}
......
......@@ -178,8 +178,8 @@ void AlgorithmPropertiesWidget::initLayout() {
// This also deletes the PropertyWidget, which does not actually
// contain the sub-widgets because they are shared in the grid layout
for (auto it = m_propWidgets.begin(); it != m_propWidgets.end(); it++)
(*it)->deleteLater();
for (auto & m_propWidget : m_propWidgets)
m_propWidget->deleteLater();
QCoreApplication::processEvents();
m_propWidgets.clear();
......@@ -196,9 +196,7 @@ void AlgorithmPropertiesWidget::initLayout() {
// Each property is on its own row
int row = 0;
for (std::vector<Property *>::const_iterator pIter = prop_list.begin();
pIter != prop_list.end(); ++pIter) {
Property *prop = *pIter;
for (auto prop : prop_list) {
QString propName = QString::fromStdString(prop->name());
// Are we entering a new group?
......
......@@ -128,9 +128,8 @@ bool BatchAlgorithmRunner::executeAlgo(ConfiguredAlgorithm algorithm) {
m_currentAlgorithm = algorithm.first;
// Assign the properties to be set at runtime
for (auto it = algorithm.second.begin(); it != algorithm.second.end();
++it) {
m_currentAlgorithm->setProperty(it->first, it->second);
for (auto & it : algorithm.second) {
m_currentAlgorithm->setProperty(it.first, it.second);
}
g_log.information() << "Starting next algorithm in queue: "
......
......@@ -38,8 +38,8 @@ CatalogHelper::getInstrumentList(const std::vector<std::string> &sessionIDs) {
return catalogAlgorithm->getProperty("InstrumentList");
} else {
// Use catalogs for the specified sessions.
for (unsigned i = 0; i < sessionIDs.size(); ++i) {
catalogAlgorithm->setProperty("Session", sessionIDs.at(i));
for (const auto & sessionID : sessionIDs) {
catalogAlgorithm->setProperty("Session", sessionID);
executeAsynchronously(catalogAlgorithm);
}
// Return the vector containing the list of instruments available.
......@@ -63,8 +63,8 @@ const std::vector<std::string> CatalogHelper::getInvestigationTypeList(
executeAsynchronously(catalogAlgorithm);
return catalogAlgorithm->getProperty("InvestigationTypes");
} else {
for (unsigned i = 0; i < sessionIDs.size(); ++i) {
catalogAlgorithm->setProperty("Session", sessionIDs.at(i));
for (const auto & sessionID : sessionIDs) {
catalogAlgorithm->setProperty("Session", sessionID);
executeAsynchronously(catalogAlgorithm);
}
return catalogAlgorithm->getProperty("InvestigationTypes");
......@@ -97,8 +97,8 @@ void CatalogHelper::executeSearch(
if (session.size() == sessionIDs.size()) {
executeAsynchronously(catalogAlgorithm);
} else {
for (unsigned i = 0; i < sessionIDs.size(); ++i) {
catalogAlgorithm->setProperty("Session", sessionIDs.at(i));
for (const auto & sessionID : sessionIDs) {
catalogAlgorithm->setProperty("Session", sessionID);
executeAsynchronously(catalogAlgorithm);
}
}
......@@ -126,8 +126,8 @@ int64_t CatalogHelper::getNumberOfSearchResults(
executeAsynchronously(catalogAlgorithm);
return catalogAlgorithm->getProperty("NumberOfSearchResults");
} else {
for (unsigned i = 0; i < sessionIDs.size(); ++i) {
catalogAlgorithm->setProperty("Session", sessionIDs.at(i));
for (const auto & sessionID : sessionIDs) {
catalogAlgorithm->setProperty("Session", sessionID);
executeAsynchronously(catalogAlgorithm);
}
return catalogAlgorithm->getProperty("NumberOfSearchResults");
......@@ -175,10 +175,9 @@ const std::vector<std::string> CatalogHelper::downloadDataFiles(
// For each pair in userSelectedFiles we want to add them to their related
// vector to pass to the algorithm.
for (auto it = userSelectedFiles.begin(); it != userSelectedFiles.end();
++it) {
fileIDs.push_back(it->first);
fileNames.push_back(it->second);
for (const auto & userSelectedFile : userSelectedFiles) {
fileIDs.push_back(userSelectedFile.first);
fileNames.push_back(userSelectedFile.second);
}
// End of the ugly!
......@@ -211,17 +210,17 @@ const std::map<std::string, std::string> CatalogHelper::validateProperties(
std::map<std::string, std::string> errors;
// Validate all input elements in the map.
for (auto iter = inputFields.begin(); iter != inputFields.end(); ++iter) {
for (const auto & inputField : inputFields) {
try {
catalogAlgorithm->setProperty(iter->first, iter->second);
catalogAlgorithm->setProperty(inputField.first, inputField.second);
} catch (std::invalid_argument &) {
std::string documentation =
propertyDocumentation(catalogAlgorithm->getProperties(), iter->first);
propertyDocumentation(catalogAlgorithm->getProperties(), inputField.first);
// Add the input name + "_err" (to indicate the error marker in the GUI,
// rather than the input field) as the key, and the related error as the
// value.
errors.emplace(iter->first + "_err", documentation);
errors.emplace(inputField.first + "_err", documentation);
}
}
// catch invalid date formats
......@@ -296,9 +295,9 @@ void CatalogHelper::showPublishDialog() {
const std::string CatalogHelper::propertyDocumentation(
const std::vector<Mantid::Kernel::Property *> &properties,
const std::string &name) {
for (unsigned i = 0; i < properties.size(); i++) {
if (properties.at(i)->name() == name) {
return properties.at(i)->documentation();
for (auto propertie : properties) {
if (propertie->name() == name) {
return propertie->documentation();
}
}
return "";
......@@ -344,13 +343,13 @@ void CatalogHelper::setSearchProperties(
// isn't empty (e.g. a value was input by the user)
// then we will set the algorithm property with the key and value of that
// specific value.
for (auto it = userInputFields.begin(); it != userInputFields.end(); it++) {
std::string value = it->second;
for (const auto & userInputField : userInputFields) {
std::string value = userInputField.second;
// If the user has input any search terms.
if (!value.empty()) {
// Set the property that the search algorithm uses to: (key => FieldName,
// value => FieldValue) (e.g., (Keywords, bob))
catalogAlgorithm->setProperty(it->first, value);
catalogAlgorithm->setProperty(userInputField.first, value);
}
}
}
......
......@@ -702,13 +702,13 @@ void CatalogSearch::searchClicked() {
*/
void CatalogSearch::showErrorLabels(
std::map<std::string, std::string> &errors) {
for (auto iter = errors.begin(); iter != errors.end(); ++iter) {
for (auto & error : errors) {
QLabel *label = m_icatUiForm.searchFrame->findChild<QLabel *>(
QString::fromStdString(iter->first));
QString::fromStdString(error.first));
if (label) {
// Update the tooltip of the element and then show it.
correctedToolTip(iter->second, label);
correctedToolTip(error.second, label);
label->show();
}
}
......@@ -1262,15 +1262,15 @@ void CatalogSearch::loadDataFiles() {
loadAlgorithm->initialize();
// For all the files downloaded (or in archive) we want to load them.
for (unsigned i = 0; i < filePaths.size(); i++) {
if (filePaths.at(i).empty())
for (auto & filePath : filePaths) {
if (filePath.empty())
return;
// Set the filename (path) of the algorithm to load from.
loadAlgorithm->setPropertyValue("Filename", filePaths.at(i));
loadAlgorithm->setPropertyValue("Filename", filePath);
// Sets the output workspace to be the name of the file.
loadAlgorithm->setPropertyValue(
"OutputWorkspace",
Poco::Path(Poco::Path(filePaths.at(i)).getFileName()).getBaseName());
Poco::Path(Poco::Path(filePath).getFileName()).getBaseName());
Poco::ActiveResult<bool> result(loadAlgorithm->executeAsync());
while (!result.available()) {
......
......@@ -387,8 +387,8 @@ void QDataProcessorWidget::saveSettings(
const std::map<QString, QVariant> &options) {
QSettings settings;
settings.beginGroup(DataProcessorSettingsGroup);
for (auto it = options.begin(); it != options.end(); ++it)
settings.setValue(it->first, it->second);
for (const auto & option : options)
settings.setValue(option.first, option.second);
settings.endGroup();
}
......@@ -400,8 +400,8 @@ void QDataProcessorWidget::loadSettings(std::map<QString, QVariant> &options) {
QSettings settings;
settings.beginGroup(DataProcessorSettingsGroup);
QStringList keys = settings.childKeys();
for (auto it = keys.begin(); it != keys.end(); ++it)
options[*it] = settings.value(*it);
for (auto & key : keys)
options[key] = settings.value(key);
settings.endGroup();
}
......@@ -440,8 +440,8 @@ void QDataProcessorWidget::setSelection(const std::set<int> &groups) {
ui.viewTable->clearSelection();
auto selectionModel = ui.viewTable->selectionModel();
for (auto group = groups.begin(); group != groups.end(); ++group) {
selectionModel->select(ui.viewTable->model()->index((*group), 0),
for (std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<int> > >::value_type group : groups) {
selectionModel->select(ui.viewTable->model()->index(group, 0),
QItemSelectionModel::Select |
QItemSelectionModel::Rows);
}
......@@ -458,8 +458,8 @@ void QDataProcessorWidget::setInstrumentList(const QString &instruments,
ui.comboProcessInstrument->clear();
QStringList instrList = instruments.split(",");
for (auto it = instrList.begin(); it != instrList.end(); ++it) {
ui.comboProcessInstrument->addItem((*it).trimmed());
for (auto & it : instrList) {
ui.comboProcessInstrument->addItem(it.trimmed());
}
int index =
......@@ -510,10 +510,10 @@ std::map<int, std::set<int>> QDataProcessorWidget::getSelectedChildren() const {
auto selectionModel = ui.viewTable->selectionModel();
if (selectionModel) {
auto selectedRows = selectionModel->selectedRows();
for (auto it = selectedRows.begin(); it != selectedRows.end(); ++it) {
if (it->parent().isValid()) {
int children = it->row();
int parent = it->parent().row();
for (auto & selectedRow : selectedRows) {
if (selectedRow.parent().isValid()) {
int children = selectedRow.row();
int parent = selectedRow.parent().row();
rows[parent].insert(children);
}
}
......@@ -530,9 +530,9 @@ std::set<int> QDataProcessorWidget::getSelectedParents() const {
auto selectionModel = ui.viewTable->selectionModel();
if (selectionModel) {
auto selectedRows = selectionModel->selectedRows();
for (auto it = selectedRows.begin(); it != selectedRows.end(); ++it) {
if (!it->parent().isValid()) {
parents.insert(it->row());
for (auto & selectedRow : selectedRows) {
if (!selectedRow.parent().isValid()) {
parents.insert(selectedRow.row());
}
}
}
......@@ -650,8 +650,8 @@ void QDataProcessorWidget::transfer(const QList<QString> &runs) {
for (auto it = runs.constBegin(); it != runs.constEnd(); ++it) {
QStringList map = (*it).split(",");
for (auto jt = map.begin(); jt != map.end(); ++jt) {
QStringList pair = (*jt).split(":");
for (auto & jt : map) {
QStringList pair = jt.split(":");
// The entry can be of the for "key:value" or of the form "key:" if
// nothing is to be set in the column.
......
......@@ -38,10 +38,10 @@ void QtDataProcessorOptionsDialog::initBindings() {
// Check all the widgets for the "reflOptionName" property.
// If it exists, bind the named option to that widget.
QList<QWidget *> widgets = findChildren<QWidget *>();
for (auto it = widgets.begin(); it != widgets.end(); ++it) {
QVariant binding = (*it)->property("reflOptionName");
for (auto & widget : widgets) {
QVariant binding = widget->property("reflOptionName");
if (binding.isValid())
m_bindings[binding.toString()] = (*it)->objectName();
m_bindings[binding.toString()] = widget->objectName();
}
}
......@@ -51,20 +51,20 @@ void QtDataProcessorOptionsDialog::saveOptions() {
// Iterate through all our bound widgets, pushing their value into the options
// map
for (auto it = m_bindings.begin(); it != m_bindings.end(); ++it) {
QString widgetName = it->second;
for (auto & m_binding : m_bindings) {
QString widgetName = m_binding.second;
if (widgetName.isEmpty())
continue;
QCheckBox *checkbox = findChild<QCheckBox *>(widgetName);
if (checkbox) {
options[it->first] = checkbox->isChecked();
options[m_binding.first] = checkbox->isChecked();
continue;
}
QSpinBox *spinbox = findChild<QSpinBox *>(widgetName);
if (spinbox) {
options[it->first] = spinbox->value();
options[m_binding.first] = spinbox->value();
continue;
}
}
......@@ -78,20 +78,20 @@ void QtDataProcessorOptionsDialog::loadOptions() {
std::map<QString, QVariant> options = m_presenter->options();
// Set the values from the options
for (auto it = options.begin(); it != options.end(); ++it) {
QString widgetName = m_bindings[it->first];
for (auto & option : options) {
QString widgetName = m_bindings[option.first];
if (widgetName.isEmpty())
continue;
QCheckBox *checkbox = findChild<QCheckBox *>(widgetName);
if (checkbox) {
checkbox->setChecked(it->second.toBool());
checkbox->setChecked(option.second.toBool());
continue;
}
QSpinBox *spinbox = findChild<QSpinBox *>(widgetName);
if (spinbox) {
spinbox->setValue(it->second.toInt());
spinbox->setValue(option.second.toInt());
continue;
}
}
......
......@@ -276,8 +276,8 @@ std::set<int> TwoLevelTreeManager::expandSelection() {
if (items.empty())
return groupIds;
for (auto group = items.begin(); group != items.end(); ++group)
groupIds.insert(group->first);
for (auto & item : items)
groupIds.insert(item.first);
return groupIds;
}
......@@ -369,9 +369,9 @@ void TwoLevelTreeManager::pasteSelected(const QString &text) {
// Iterate over rows and lines simultaneously, stopping when we reach the
// end of either
auto lineIt = lines.begin();
for (auto it = selectedRows.begin(); it != selectedRows.end(); ++it) {
const int groupId = it->first;
auto rows = it->second;
for (const auto & selectedRow : selectedRows) {
const int groupId = selectedRow.first;
auto rows = selectedRow.second;
auto rowIt = rows.begin();
for (; rowIt != rows.end() && lineIt != lines.end(); rowIt++, lineIt++) {
auto values = (*lineIt).split("\t");
......
......@@ -55,8 +55,7 @@ DiagResults::DiagResults(QWidget *parent)
addRow("Test", "Number of failed spectra");
// make one row for each set of results
int row = 0;
for (int i = 0; i < NUMTESTS; i++) {
QString col1 = TESTS[i];
for (auto col1 : TESTS) {
QString col2 = "N/A";
row = addRow(col1, col2);
}
......
......@@ -91,11 +91,10 @@ void DoubleSpinBox::interpretText(bool notify) {
emit valueChanged(d_value);
} else {
// Check for any registered test strings that map to a given value
for (auto it = m_specialTextMappings.begin();
it != m_specialTextMappings.end(); ++it) {
if (it->first == text()) {
for (auto & m_specialTextMapping : m_specialTextMappings) {
if (m_specialTextMapping.first == text()) {
// Found a matching string, try to set the value
if (setValue(it->second)) {
if (setValue(m_specialTextMapping.second)) {
lineEdit()->setText(text());
if (notify)
emit valueChanged(d_value);
......
......@@ -80,8 +80,8 @@ void FindFilesWorker::run() {
else if (m_parameters.isForRunFiles) {
filenames = fileSearcher.findRuns(m_parameters.searchText);
valueForProperty = "";
for (auto cit = filenames.begin(); cit != filenames.end(); ++cit) {
valueForProperty += QString::fromStdString(*cit) + ",";
for (auto & filename : filenames) {
valueForProperty += QString::fromStdString(filename) + ",";
}
valueForProperty.chop(1);
}
......
......@@ -162,9 +162,8 @@ void FitOptionsBrowser::createCommonProperties() {
QStringList minimizers;
// Store them in the m_minimizer enum property
for (auto it = minimizerOptions.begin(); it != minimizerOptions.end();
++it) {
minimizers << QString::fromStdString(*it);
for (auto & minimizerOption : minimizerOptions) {
minimizers << QString::fromStdString(minimizerOption);
}
m_enumManager->setEnumNames(m_minimizer, minimizers);
int i =
......@@ -185,8 +184,8 @@ void FitOptionsBrowser::createCommonProperties() {
Mantid::API::CostFunctionFactory::Instance().getKeys();
QStringList costFunctions;
// Store them in the m_minimizer enum property
for (auto it = costOptions.begin(); it != costOptions.end(); ++it) {
costFunctions << QString::fromStdString(*it);
for (auto & costOption : costOptions) {
costFunctions << QString::fromStdString(costOption);
}
m_enumManager->setEnumNames(m_costFunction, costFunctions);
m_browser->addProperty(m_costFunction);
......@@ -381,10 +380,9 @@ void FitOptionsBrowser::updateMinimizer() {
// Create and add properties to the minimizer group
auto minimizerProperties = minimizer->getProperties();
for (auto property = minimizerProperties.begin();
property != minimizerProperties.end(); ++property) {
auto prop = createPropertyProperty(*property);
if (!*property)
for (auto & minimizerPropertie : minimizerProperties) {
auto prop = createPropertyProperty(minimizerPropertie);
if (!minimizerPropertie)
continue;
m_minimizerGroup->addSubProperty(prop);
}
......
......@@ -1751,8 +1751,8 @@ void FitPropertyBrowser::populateWorkspaceNames() {
QStringList tmp;
auto sv = Mantid::API::AnalysisDataService::Instance().getObjectNames();
for (auto it = sv.begin(); it != sv.end(); ++it) {
auto const &name = QString::fromStdString(*it);
for (auto & it : sv) {
auto const &name = QString::fromStdString(it);
if (allAreAllowed || m_allowedSpectra.contains(name)) {
tmp << name;
}
......@@ -1907,13 +1907,13 @@ QtBrowserItem *FitPropertyBrowser::findItem(QtBrowserItem *parent,
QtProperty *prop) const {
QList<QtBrowserItem *> children = parent->children();
QtBrowserItem *res = nullptr;
for (int i = 0; i < children.size(); i++) {
if (children[i]->property() == prop) {
return children[i];
for (auto & i : children) {
if (i->property() == prop) {
return i;
}
QList<QtBrowserItem *> grand_children = children[i]->children();
QList<QtBrowserItem *> grand_children = i->children();
if (grand_children.size() > 0)
res = findItem(children[i], prop);
res = findItem(i, prop);
if (res)
return res;
}
......@@ -2222,14 +2222,14 @@ void FitPropertyBrowser::hasConstraints(QtProperty *parProp, bool &hasTie,
hasTie = false;
hasBounds = false;
QList<QtProperty *> subs = parProp->subProperties();
for (int i = 0; i < subs.size(); i++) {
if (subs[i]->propertyName() == "Tie") {
for (auto & sub : subs) {
if (sub->propertyName() == "Tie") {
hasTie = true;
}
if (subs[i]->propertyName() == "LowerBound") {
if (sub->propertyName() == "LowerBound") {
hasBounds = true;
}
if (subs[i]->propertyName() == "UpperBound") {
if (sub->propertyName() == "UpperBound") {
hasBounds = true;
}
}
......@@ -2240,9 +2240,9 @@ void FitPropertyBrowser::hasConstraints(QtProperty *parProp, bool &hasTie,
*/
QtProperty *FitPropertyBrowser::getTieProperty(QtProperty *parProp) const {
QList<QtProperty *> subs = parProp->subProperties();
for (int i = 0; i < subs.size(); i++) {
if (subs[i]->propertyName() == "Tie") {
return subs[i];
for (auto & sub : subs) {
if (sub->propertyName() == "Tie") {
return sub;
}
}
return nullptr;
......@@ -3050,17 +3050,17 @@ void FitPropertyBrowser::setWorkspaceProperties() {
QString errName;
auto names = tws->getColumnNames();
QStringList columns;
for (size_t i = 0; i < names.size(); ++i) {
columns << QString::fromStdString(names[i]);
auto col = tws->getColumn(names[i]);
for (const auto & name : names) {
columns << QString::fromStdString(name);
auto col = tws->getColumn(name);
if (xName.isEmpty() && col->getPlotType() == 1 /*X*/) {