mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
CylindersModel: test for CHANGED() outside of switch statement
A small code consolidation: With one exception, all targets of the switch statement would test for CHANGED(). Instead do the test once and exit early. This changes the behavior of the function: if not changed, there will be no more dataChanged-signal. However, this appears to be the correct thing to do anyway. And it is easily changed if it matters after all. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
a4a06c48bf
commit
a75360f58f
1 changed files with 30 additions and 40 deletions
|
@ -321,17 +321,18 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool changed = CHANGED();
|
||||||
|
if (index.column() != TYPE && !changed)
|
||||||
|
return false;
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case TYPE: {
|
case TYPE:
|
||||||
QString type = value.toString();
|
if (!same_string(qPrintable(vString), cyl->type.description)) {
|
||||||
if (!same_string(qPrintable(type), cyl->type.description)) {
|
|
||||||
free((void *)cyl->type.description);
|
free((void *)cyl->type.description);
|
||||||
cyl->type.description = strdup(qPrintable(type));
|
cyl->type.description = strdup(qPrintable(vString));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SIZE:
|
case SIZE: {
|
||||||
if (CHANGED()) {
|
|
||||||
TankInfoModel *tanks = TankInfoModel::instance();
|
TankInfoModel *tanks = TankInfoModel::instance();
|
||||||
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
||||||
|
|
||||||
|
@ -340,8 +341,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
|
tanks->setData(tanks->index(matches.first().row(), TankInfoModel::ML), cyl->type.size.mliter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WORKINGPRESS:
|
case WORKINGPRESS: {
|
||||||
if (CHANGED()) {
|
|
||||||
TankInfoModel *tanks = TankInfoModel::instance();
|
TankInfoModel *tanks = TankInfoModel::instance();
|
||||||
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, cyl->type.description);
|
||||||
cyl->type.workingpressure = string_to_pressure(qPrintable(vString));
|
cyl->type.workingpressure = string_to_pressure(qPrintable(vString));
|
||||||
|
@ -350,16 +350,13 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case START:
|
case START:
|
||||||
if (CHANGED())
|
|
||||||
cyl->start = string_to_pressure(qPrintable(vString));
|
cyl->start = string_to_pressure(qPrintable(vString));
|
||||||
break;
|
break;
|
||||||
case END:
|
case END:
|
||||||
if (CHANGED())
|
//if (!cyl->start.mbar || string_to_pressure(qPrintable(vString)).mbar <= cyl->start.mbar) {
|
||||||
//&& (!cyl->start.mbar || string_to_pressure(qPrintable(vString)).mbar <= cyl->start.mbar)) {
|
|
||||||
cyl->end = string_to_pressure(qPrintable(vString));
|
cyl->end = string_to_pressure(qPrintable(vString));
|
||||||
break;
|
break;
|
||||||
case O2:
|
case O2: {
|
||||||
if (CHANGED()) {
|
|
||||||
cyl->gasmix.o2 = string_to_fraction(qPrintable(vString));
|
cyl->gasmix.o2 = string_to_fraction(qPrintable(vString));
|
||||||
// fO2 + fHe must not be greater than 1
|
// fO2 + fHe must not be greater than 1
|
||||||
if (get_o2(cyl->gasmix) + get_he(cyl->gasmix) > 1000)
|
if (get_o2(cyl->gasmix) + get_he(cyl->gasmix) > 1000)
|
||||||
|
@ -375,20 +372,16 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HE:
|
case HE:
|
||||||
if (CHANGED()) {
|
|
||||||
cyl->gasmix.he = string_to_fraction(qPrintable(vString));
|
cyl->gasmix.he = string_to_fraction(qPrintable(vString));
|
||||||
// fO2 + fHe must not be greater than 1
|
// fO2 + fHe must not be greater than 1
|
||||||
if (get_o2(cyl->gasmix) + get_he(cyl->gasmix) > 1000)
|
if (get_o2(cyl->gasmix) + get_he(cyl->gasmix) > 1000)
|
||||||
cyl->gasmix.o2.permille = 1000 - get_he(cyl->gasmix);
|
cyl->gasmix.o2.permille = 1000 - get_he(cyl->gasmix);
|
||||||
cyl->bestmix_he = false;
|
cyl->bestmix_he = false;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case DEPTH:
|
case DEPTH:
|
||||||
if (CHANGED())
|
|
||||||
cyl->depth = string_to_depth(qPrintable(vString));
|
cyl->depth = string_to_depth(qPrintable(vString));
|
||||||
break;
|
break;
|
||||||
case MOD:
|
case MOD: {
|
||||||
if (CHANGED()) {
|
|
||||||
if (QString::compare(qPrintable(vString), "*") == 0) {
|
if (QString::compare(qPrintable(vString), "*") == 0) {
|
||||||
cyl->bestmix_o2 = true;
|
cyl->bestmix_o2 = true;
|
||||||
// Calculate fO2 for max. depth
|
// Calculate fO2 for max. depth
|
||||||
|
@ -404,7 +397,6 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MND:
|
case MND:
|
||||||
if (CHANGED()) {
|
|
||||||
if (QString::compare(qPrintable(vString), "*") == 0) {
|
if (QString::compare(qPrintable(vString), "*") == 0) {
|
||||||
cyl->bestmix_he = true;
|
cyl->bestmix_he = true;
|
||||||
// Calculate fO2 for max. depth
|
// Calculate fO2 for max. depth
|
||||||
|
@ -414,10 +406,8 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
// Calculate fHe for input depth
|
// Calculate fHe for input depth
|
||||||
cyl->gasmix.he = best_he(string_to_depth(qPrintable(vString)), d, prefs.o2narcotic, cyl->gasmix.o2);
|
cyl->gasmix.he = best_he(string_to_depth(qPrintable(vString)), d, prefs.o2narcotic, cyl->gasmix.o2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case USE:
|
case USE: {
|
||||||
if (CHANGED()) {
|
|
||||||
int use = vString.toInt();
|
int use = vString.toInt();
|
||||||
if (use > NUM_GAS_USE - 1 || use < 0)
|
if (use > NUM_GAS_USE - 1 || use < 0)
|
||||||
use = 0;
|
use = 0;
|
||||||
|
|
Loading…
Reference in a new issue