Skip to content

Commit

Permalink
Improve our use of qAsConst.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jun 30, 2021
1 parent 9832a20 commit c5c26c1
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 40 deletions.
Expand Up @@ -230,12 +230,12 @@ void CellmlAnnotationViewMetadataNormalViewDetailsWidget::updateGui(iface::cellm

// Populate our Web view, but only if there is at least one RDF triple

CellMLSupport::CellmlFileRdfTriples rdfTriples = mCellmlFile->rdfTriples(pElement);
const CellMLSupport::CellmlFileRdfTriples rdfTriples = mCellmlFile->rdfTriples(pElement);

if (!rdfTriples.isEmpty()) {
// Add the RDF triples

for (auto rdfTriple : qAsConst(rdfTriples)) {
for (auto rdfTriple : rdfTriples) {
addRdfTriple(rdfTriple, false);
}
} else {
Expand Down
Expand Up @@ -648,7 +648,7 @@ void CellMLTextViewConverter::processCommentNode(const QDomNode &pDomNode)
{
// Process the given comment node

QStringList commentLines = pDomNode.nodeValue().remove('\r').split('\n');
const QStringList commentLines = pDomNode.nodeValue().remove('\r').split('\n');
// Note #1: we don't know which end of line string is used by the file, so
// the above code ensures that we can handle both "\r\n" on Windows
// and "\n" on Linux/macOS...
Expand All @@ -664,7 +664,7 @@ void CellMLTextViewConverter::processCommentNode(const QDomNode &pDomNode)
outputString();
}

for (const auto &commentLine : qAsConst(commentLines)) {
for (const auto &commentLine : commentLines) {
outputString(Output::Comment, QString("//%1").arg(processCommentString(commentLine)));
}
}
Expand Down
Expand Up @@ -194,9 +194,9 @@ bool CellmlTextViewParser::execute(const QString &pCellmlText,
// being referenced all over the place, which is really not what we
// want since that unnecessarily pollutes things...

QStringList keys = mNamespaces.keys();
const QStringList keys = mNamespaces.keys();

for (const auto &key : qAsConst(keys)) {
for (const auto &key : keys) {
mDomDocument.documentElement().setAttribute(QString("xmlns:%1").arg(key), mNamespaces.value(key));
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/miscellaneous/Core/src/centralwidget.cpp
Expand Up @@ -336,9 +336,9 @@ void CentralWidget::loadSettings(QSettings &pSettings)
// Note: if a file is not a remote file then openRemoteFile() will open it
// as a normal file...

QStringList fileNamesOrUrls = pSettings.value(SettingsFileNamesOrUrls).toStringList();
const QStringList fileNamesOrUrls = pSettings.value(SettingsFileNamesOrUrls).toStringList();

for (const auto &fileNameOrUrl : qAsConst(fileNamesOrUrls)) {
for (const auto &fileNameOrUrl : fileNamesOrUrls) {
openRemoteFile(fileNameOrUrl, false);
}

Expand Down Expand Up @@ -1554,13 +1554,13 @@ void CentralWidget::showEnableActions(const QList<QAction *> &pActions)
QMenu *actionMenu = action->menu();

if (actionMenu != nullptr) {
QList<QAction *> actionMenuActions = actionMenu->actions();
const QList<QAction *> actionMenuActions = actionMenu->actions();

showEnableActions(actionMenuActions);

bool showEnable = false;

for (auto actionMenuAction : qAsConst(actionMenuActions)) {
for (auto actionMenuAction : actionMenuActions) {
if ( !actionMenuAction->isSeparator()
&& actionMenuAction->isVisible()) {
showEnable = true;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/miscellaneous/Core/src/corecliutils.cpp
Expand Up @@ -1002,9 +1002,9 @@ QByteArray serialiseDomDocument(const QDomDocument &pDomDocument)

// Manually serialise the elements' attributes

QStringList elementAttributeKeys = elementsAttributes.keys();
const QStringList elementAttributeKeys = elementsAttributes.keys();

for (const auto &elementAttribute : qAsConst(elementAttributeKeys)) {
for (const auto &elementAttribute : elementAttributeKeys) {
res.replace(elementAttribute+R"(="")", elementsAttributes.value(elementAttribute));
}

Expand Down
Expand Up @@ -911,15 +911,15 @@ QString PmrWorkspacesWindowSynchronizeDialog::diffHtml(const QString &pOld,
static const QRegularExpression AfterNumberOfLinesRegEx = QRegularExpression(" .*");

QString html;
QStringList differencesList = differences.split('\n');
const QStringList differencesList = differences.split('\n');
int differenceNumber = 0;
int differenceMaxNumber = differencesList.count()-1;
int addLineNumber = 0;
int addMaxLineNumber = 0;
int removeLineNumber = 0;
PmrWorkspacesWindowSynchronizeDialogDifferencesData differencesData;

for (const auto &difference : qAsConst(differencesList)) {
for (const auto &difference : differencesList) {
++differenceNumber;

if (difference.startsWith("@@") && difference.endsWith("@@")) {
Expand Down
Expand Up @@ -1421,11 +1421,11 @@ void PmrWorkspacesWindowWidget::refreshWorkspaces()
return;
}

PMRSupport::PmrWorkspaces workspaces = PMRSupport::PmrWorkspaceManager::instance()->workspaces();
const PMRSupport::PmrWorkspaces workspaces = PMRSupport::PmrWorkspaceManager::instance()->workspaces();
int workspacesCount = workspaces.count();
int workspaceNb = 0;

for (auto workspace : qAsConst(workspaces)) {
for (auto workspace : workspaces) {
refreshWorkspace(workspace, ++workspaceNb == workspacesCount);
}
}
Expand Down
Expand Up @@ -1653,9 +1653,9 @@ void SimulationExperimentViewSimulationWidget::addSedmlSimulationAlgorithm(libse
// properties

if (pSolverInterface != nullptr) {
QStringList solverPropertyKeys = pSolverProperties.keys();
const QStringList solverPropertyKeys = pSolverProperties.keys();

for (const auto &solverProperty : qAsConst(solverPropertyKeys)) {
for (const auto &solverProperty : solverPropertyKeys) {
QString kisaoId = pSolverInterface->kisaoId(solverProperty);
QVariant solverPropertyValue = pSolverProperties.value(solverProperty);
QString value = (solverPropertyValue.type() == QVariant::Double)?
Expand Down Expand Up @@ -1697,10 +1697,10 @@ void SimulationExperimentViewSimulationWidget::addSedmlSimulation(libsedml::SedD

if ((runtime != nullptr) && runtime->needNlaSolver()) {
Solver::Solver::Properties nlaSolverProperties = mSimulation->data()->nlaSolverProperties();
QStringList nlaSolverPropertyKeys = nlaSolverProperties.keys();
const QStringList nlaSolverPropertyKeys = nlaSolverProperties.keys();
QString nlaSolverAnnotation;

for (const auto &nlaSolverProperty : qAsConst(nlaSolverPropertyKeys)) {
for (const auto &nlaSolverProperty : nlaSolverPropertyKeys) {
nlaSolverAnnotation += QString(R"(<%1 %2="%3" %4="%5"/>)").arg(SEDMLSupport::SolverProperty,
SEDMLSupport::Id,
nlaSolverProperty,
Expand Down
Expand Up @@ -764,9 +764,9 @@ void SimulationExperimentViewWidget::updateContentsInformationGui(SimulationExpe
informationWidget->parametersWidget()->setColumnWidth(i, (i == iMax-1)?0:mParametersColumnWidths[i]);
}

QIntList sectionKeys = mGraphPanelSectionsExpanded.keys();
const QIntList sectionKeys = mGraphPanelSectionsExpanded.keys();

for (auto section : qAsConst(sectionKeys)) {
for (auto section : sectionKeys) {
informationWidget->graphPanelAndGraphsWidget()->setGraphPanelSectionExpanded(section, mGraphPanelSectionsExpanded.value(section));
}
}
Expand Down
25 changes: 13 additions & 12 deletions src/plugins/support/SimulationSupport/src/simulation.cpp
Expand Up @@ -942,9 +942,9 @@ void SimulationResults::createDataStore()
// Reimport our data, if any, and update their array so that it contains the
// computed values for our start point

QList<double *> dataKeys = mDataDataStores.keys();
const QList<double *> dataKeys = mDataDataStores.keys();

for (auto data : qAsConst(dataKeys)) {
for (auto data : dataKeys) {
DataStore::DataStore *importDataStore = mDataDataStores.value(data);
DataStore::DataStoreVariables variables = mDataStore->addVariables(data, importDataStore->variables().count());

Expand Down Expand Up @@ -1207,10 +1207,10 @@ void SimulationResults::addPoint(double pPoint)
// Make sure that we have the correct imported data values for the given
// point, keeping in mind that we may have several runs

QList<double *> dataKeys = mDataDataStores.keys();
const QList<double *> dataKeys = mDataDataStores.keys();
double realPoint = SimulationResults::realPoint(pPoint);

for (auto data : qAsConst(dataKeys)) {
for (auto data : dataKeys) {
DataStore::DataStore *dataStore = mDataDataStores.value(data);
DataStore::DataStoreVariable *voi = dataStore->voi();
DataStore::DataStoreVariables variables = dataStore->variables();
Expand Down Expand Up @@ -1604,18 +1604,15 @@ void Simulation::checkIssues()

// Determine whether we have issues with our SED-ML and our COMBINE archive

SEDMLSupport::SedmlFileIssues sedmlFileIssues = (mSedmlFile != nullptr)?
mSedmlFile->issues():
SEDMLSupport::SedmlFileIssues();
COMBINESupport::CombineArchiveIssues combineArchiveIssues = (mCombineArchive != nullptr)?
mCombineArchive->issues():
COMBINESupport::CombineArchiveIssues();
const COMBINESupport::CombineArchiveIssues combineArchiveIssues = (mCombineArchive != nullptr)?
mCombineArchive->issues():
COMBINESupport::CombineArchiveIssues();

if (!combineArchiveIssues.isEmpty()) {
// There is one or several issues with our COMBINE archive, so list
// it/them

for (const auto &combineArchiveIssue : qAsConst(combineArchiveIssues)) {
for (const auto &combineArchiveIssue : combineArchiveIssues) {
SimulationIssue::Type issueType = SimulationIssue::Type::Fatal;

switch (combineArchiveIssue.type()) {
Expand Down Expand Up @@ -1645,10 +1642,14 @@ void Simulation::checkIssues()
}
}

const SEDMLSupport::SedmlFileIssues sedmlFileIssues = (mSedmlFile != nullptr)?
mSedmlFile->issues():
SEDMLSupport::SedmlFileIssues();

if (!sedmlFileIssues.isEmpty()) {
// There is one or several issues with our SED-ML file, so list it/them

for (const auto &sedmlFileIssue : qAsConst(sedmlFileIssues)) {
for (const auto &sedmlFileIssue : sedmlFileIssues) {
SimulationIssue::Type issueType = SimulationIssue::Type::Fatal;

switch (sedmlFileIssue.type()) {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/widget/GraphPanelWidget/src/graphpanelplotwidget.cpp
Expand Up @@ -3355,10 +3355,10 @@ void GraphPanelPlotWidget::doUpdateGui(bool pForceAlignment)
{
// Resize our legend and that of our neighbours

GraphPanelPlotWidgets selfPlusNeighbors = GraphPanelPlotWidgets() << this << mNeighbors;
const GraphPanelPlotWidgets selfPlusNeighbors = GraphPanelPlotWidgets() << this << mNeighbors;
int legendWidth = 0;

for (auto plot : qAsConst(selfPlusNeighbors)) {
for (auto plot : selfPlusNeighbors) {
auto legend = static_cast<GraphPanelPlotLegendWidget *>(plot->legend());

if (legend != nullptr) {
Expand All @@ -3371,7 +3371,7 @@ void GraphPanelPlotWidget::doUpdateGui(bool pForceAlignment)
}
}

for (auto plot : qAsConst(selfPlusNeighbors)) {
for (auto plot : selfPlusNeighbors) {
auto legend = static_cast<GraphPanelPlotLegendWidget *>(plot->legend());

if (legend != nullptr) {
Expand Down Expand Up @@ -3920,7 +3920,7 @@ void GraphPanelPlotWidget::alignWithNeighbors(bool pCanReplot,
|| mSynchronizeXAxisAction->isChecked()
|| mSynchronizeYAxisAction->isChecked();

GraphPanelPlotWidgets selfPlusNeighbors = GraphPanelPlotWidgets() << this << mNeighbors;
const GraphPanelPlotWidgets selfPlusNeighbors = GraphPanelPlotWidgets() << this << mNeighbors;
int oldMinBorderDistStartX = 0;
int oldMinBorderDistEndX = 0;
int newMinBorderDistStartX = 0;
Expand All @@ -3930,7 +3930,7 @@ void GraphPanelPlotWidget::alignWithNeighbors(bool pCanReplot,

axisWidget(QwtPlot::xBottom)->getMinBorderDist(oldMinBorderDistStartX, oldMinBorderDistEndX);

for (auto plot : qAsConst(selfPlusNeighbors)) {
for (auto plot : selfPlusNeighbors) {
// Determine how much space we should have directly to the left and
// right of the X axis

Expand Down Expand Up @@ -3976,7 +3976,7 @@ void GraphPanelPlotWidget::alignWithNeighbors(bool pCanReplot,
|| !qFuzzyCompare(newMinExtentY, oldMinExtentY);
bool alignmentChanged = xAlignmentChanged || yAlignmentChanged;

for (auto plot : qAsConst(selfPlusNeighbors)) {
for (auto plot : selfPlusNeighbors) {
auto xScaleWidget = static_cast<GraphPanelPlotScaleWidget *>(plot->axisWidget(QwtPlot::xBottom));

xScaleWidget->setMinBorderDist(newMinBorderDistStartX, newMinBorderDistEndX);
Expand Down

0 comments on commit c5c26c1

Please sign in to comment.