Skip to content

Commit 8eb7f52

Browse files
committed
Refactor various output classes to improve code readability and maintainability
- Replaced `emit` with direct calls for `beginResetModel`, `endResetModel`, `dataChanged`, `beginInsertRows`, `endInsertRows`, `beginRemoveRows`, and `endRemoveRows` in `AbstractOutput`, `ConfiningStressTableModel`, `CrustalAmplification`, `CrustalModel`, `MotionLibrary`, `ResponseSpectrum`, `SoilProfile`, and `TimeSeriesOutputCatalog`. - Updated string formatting in `AbstractRatioOutput`, `AbstractTimeSeriesOutput`, `AccelTransferFunctionOutput`, `AriasIntensityProfileOutput`, `MainWindow`, `NonlinearPropertyOutput`, `ResultsPage`, `SpectralRatioOutput`, and `StrainTransferFunctionOutput` to use multiple arguments in `arg()`. - Changed loops to use `std::as_const` for better const-correctness in `MotionLibrary`, `SoilProfile`, `SpectraOutputCatalog`, and others. - Improved JSON handling in `fromJson` methods across multiple classes to use local variables for arrays. - Removed unnecessary variable declarations and improved code clarity in various locations.
1 parent 8863ddb commit 8eb7f52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+143
-152
lines changed

source/AbstractLocationOutput.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ auto AbstractLocationOutput::needsOutputConditions() const -> bool {
3636
}
3737

3838
auto AbstractLocationOutput::fullName() const -> QString {
39-
return tr("Location -- %1 -- %2").arg(prefix()).arg(name());
39+
return tr("Location -- %1 -- %2").arg(prefix(), name());
4040
}
4141

4242
auto AbstractLocationOutput::depth() const -> double { return _depth; }
@@ -74,9 +74,8 @@ auto AbstractLocationOutput::fileName(int motion) const -> QString {
7474
}
7575

7676
auto AbstractLocationOutput::prefix() const -> const QString {
77-
return QString("%1 (%3)")
78-
.arg(locationToString(_depth))
79-
.arg(AbstractMotion::typeList().at(_type));
77+
return QString("%1 (%2)").arg(locationToString(_depth),
78+
AbstractMotion::typeList().at(_type));
8079
}
8180

8281
void AbstractLocationOutput::fromJson(const QJsonObject &json) {

source/AbstractMotion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ auto AbstractMotion::variantToType(QVariant variant, bool *ok)
7373

7474
// Need to split about the type because when advance options are turned on
7575
// the name includes the wave parts
76-
for (const QString &possibleType : typeList()) {
76+
const QStringList types = typeList();
77+
for (const QString &possibleType : types) {
7778
if (possibleType.startsWith(s))
7879
break;
7980

source/AbstractNonlinearPropertyFactory.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ auto AbstractNonlinearPropertyFactory::setData(const QModelIndex &index,
6969

7070
if (cnp) {
7171
cnp->setName(value.toString());
72-
dataChanged(index, index);
72+
emit dataChanged(index, index);
7373
return true;
7474
} else {
7575
return false;
@@ -108,12 +108,12 @@ auto AbstractNonlinearPropertyFactory::insertRows(int row, int count,
108108
if (!count)
109109
return false;
110110

111-
emit beginInsertRows(parent, row, row + count - 1);
111+
beginInsertRows(parent, row, row + count - 1);
112112

113113
for (int i = 0; i < count; ++i)
114114
_models.insert(row, new CustomNonlinearProperty(_type, true));
115115

116-
emit endInsertRows();
116+
endInsertRows();
117117
return true;
118118
}
119119

@@ -125,9 +125,9 @@ auto AbstractNonlinearPropertyFactory::removeRows(int row, int count,
125125

126126
for (int i = 0; i < count; ++i) {
127127
if (flags(index(row)) & Qt::ItemIsEditable) {
128-
emit beginRemoveRows(parent, row, row);
128+
beginRemoveRows(parent, row, row);
129129
_models.takeAt(row)->deleteLater();
130-
emit endRemoveRows();
130+
endRemoveRows();
131131
} else {
132132
return false;
133133
}
@@ -181,7 +181,8 @@ auto AbstractNonlinearPropertyFactory::duplicateAt(QVariant value) const
181181
}
182182

183183
void AbstractNonlinearPropertyFactory::fromJson(const QJsonObject &json) {
184-
for (const QJsonValue &v : json["models"].toArray()) {
184+
const QJsonArray models = json["models"].toArray();
185+
for (const QJsonValue &v : models) {
185186
auto *np = new CustomNonlinearProperty(_type, true);
186187
np->fromJson(v.toObject());
187188
_models << np;

source/AbstractOutput.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ auto AbstractOutput::intToMotion(int i) const -> int {
286286
}
287287

288288
void AbstractOutput::clear() {
289-
emit beginResetModel();
289+
beginResetModel();
290290
_data.clear();
291291
_motionIndex = 0;
292292
_maxSize = 0;
293-
emit endResetModel();
293+
endResetModel();
294294
}
295295

296296
auto AbstractOutput::seriesEnabled(int site, int motion) -> bool {
@@ -410,12 +410,14 @@ auto AbstractOutput::suffix() const -> const QString { return ""; }
410410
void AbstractOutput::fromJson(const QJsonObject &json) {
411411
_exportEnabled = json["exportEnabled"].toBool();
412412

413-
QJsonArray data = json["data"].toArray();
413+
const QJsonArray data = json["data"].toArray();
414414
for (const QJsonValue &site : data) {
415415
QList<QVector<double>> l;
416-
for (const QJsonValue &motion : site.toArray()) {
416+
const QJsonArray siteArray = site.toArray();
417+
for (const QJsonValue &motion : siteArray) {
417418
QVector<double> v;
418-
for (const QJsonValue &qjv : motion.toArray()) {
419+
const QJsonArray motionArray = motion.toArray();
420+
for (const QJsonValue &qjv : motionArray) {
419421
v << qjv.toDouble();
420422
}
421423
l << v;
@@ -426,7 +428,7 @@ void AbstractOutput::fromJson(const QJsonObject &json) {
426428
}
427429

428430
_maxSize = 0;
429-
for (const QList<QVector<double>> &l : _data) {
431+
for (const QList<QVector<double>> &l : std::as_const(_data)) {
430432
for (const QVector<double> &v : l) {
431433
if (_maxSize < v.size())
432434
_maxSize = v.size();
@@ -472,7 +474,7 @@ auto operator>>(QDataStream &in, AbstractOutput *ao) -> QDataStream & {
472474
in >> ao->_exportEnabled >> ao->_data;
473475

474476
// Find the maximum length of all data vectors
475-
for (const QList<QVector<double>> &l : ao->_data) {
477+
for (const QList<QVector<double>> &l : std::as_const(ao->_data)) {
476478
for (const QVector<double> &v : l) {
477479
if (ao->_maxSize < v.size())
478480
ao->_maxSize = v.size();

source/AbstractRatioOutput.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AbstractRatioOutput::AbstractRatioOutput(OutputCatalog *catalog)
4040
}
4141

4242
auto AbstractRatioOutput::fullName() const -> QString {
43-
return tr("Ratio -- %1 -- %2").arg(prefix()).arg(name());
43+
return tr("Ratio -- %1 -- %2").arg(prefix(), name());
4444
}
4545

4646
auto AbstractRatioOutput::inDepth() const -> double { return _inDepth; }
@@ -107,10 +107,8 @@ auto AbstractRatioOutput::fileName(int motion) const -> QString {
107107

108108
auto AbstractRatioOutput::prefix() const -> const QString {
109109
return QString("%1 (%2) from %3 (%4)")
110-
.arg(locationToString(_outDepth))
111-
.arg(AbstractMotion::typeList().at(_outType))
112-
.arg(locationToString(_inDepth))
113-
.arg(AbstractMotion::typeList().at(_inType));
110+
.arg(locationToString(_outDepth), AbstractMotion::typeList().at(_outType),
111+
locationToString(_inDepth), AbstractMotion::typeList().at(_inType));
114112
}
115113

116114
void AbstractRatioOutput::fromJson(const QJsonObject &json) {

source/AbstractTimeSeriesOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ AbstractTimeSeriesOutput::AbstractTimeSeriesOutput(OutputCatalog *catalog)
3030
: AbstractLocationOutput(catalog) {}
3131

3232
auto AbstractTimeSeriesOutput::fullName() const -> QString {
33-
QString s = tr("Time Series -- %1 -- %2").arg(prefix()).arg(name());
33+
QString s = tr("Time Series -- %1 -- %2").arg(prefix(), name());
3434

3535
if (!suffix().isEmpty())
3636
s += " -- " + suffix();

source/AccelTransferFunctionOutput.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ auto AccelTransferFunctionOutput::xLabel() const -> const QString {
6161

6262
auto AccelTransferFunctionOutput::yLabel() const -> const QString {
6363
return tr("FAS (accel) at %1 / FAS (accel) at %2")
64-
.arg(locationToString(_outDepth))
65-
.arg(locationToString(_inDepth));
64+
.arg(locationToString(_outDepth), locationToString(_inDepth));
6665
}
6766

6867
auto AccelTransferFunctionOutput::ref(int motion) const

source/AriasIntensityProfileOutput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void AriasIntensityProfileOutput::extract(AbstractCalculator *const calculator,
6868
data << tsm->ariasIntensity(
6969
calculator->calcAccelTf(site->inputLocation(), tsm->type(),
7070
site->depthToLocation(depth), type))
71-
.last();
71+
.constLast();
7272
type = AbstractMotion::Within;
7373
}
7474
}

source/BooreThompsonPeakCalculator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ BooreThompsonPeakCalculator::BooreThompsonPeakCalculator() {
4545
_lnDistAcc = gsl_interp_accel_alloc();
4646

4747
// Load the model coefficients
48-
for (QString region : {"cena", "wna"}) {
48+
for (const QString &region : {QString("cena"), QString("wna")}) {
4949
// Load the JSON and convert to vectors
5050
QString fileName =
5151
QString(":/data/%1_bt15_trms4osc.json").arg(region).toUtf8();
@@ -61,7 +61,8 @@ BooreThompsonPeakCalculator::BooreThompsonPeakCalculator() {
6161
QJsonObject json = jsonDoc.object();
6262

6363
QMap<QString, QVector<double>> paramMap;
64-
for (QString key : json.keys()) {
64+
const QStringList keys = json.keys();
65+
for (const QString &key : keys) {
6566
Serialize::toDoubleVector(json[key], paramMap[key]);
6667
}
6768

source/CompatibleRvtMotion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ auto CompatibleRvtMotion::vanmarckeInversion() const -> QVector<double> {
338338
if (_targetRespSpec->sa().size() < 10) {
339339
// Loglog interpolate prior to performing the inversion
340340
QVector<double> targetPeriod = _targetRespSpec->period();
341-
QVector<double> targetSa = _targetRespSpec->sa();
342341
const double decades = log10(targetPeriod.last() / targetPeriod.first());
343342

344343
QVector<double> period = Dimension::logSpace(

0 commit comments

Comments
 (0)