mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Code layout changes
Tomaz convinced me (with help from Linus) that it might be a good idea to go with the compacter "single line" case statements in some specific instances where this makes the code much more compact and easier to read. While doing that I changed Linus' code to do 'retVal = ...; break;' instead of just 'return ...;' - this is more consistent and makes debugging a little easier. And while doing all that, I also cleaned up divelistview.cpp a little bit. And removed an unused variable. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
94c3545c18
commit
f037b9e13f
2 changed files with 56 additions and 127 deletions
|
@ -46,10 +46,9 @@ void DiveListView::headerClicked(int i )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
|
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
|
||||||
if (d){
|
if (d)
|
||||||
currentSelectedDives.push_back(d);
|
currentSelectedDives.push_back(d);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// clear the model, repopulate with new indexes.
|
// clear the model, repopulate with new indexes.
|
||||||
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST, false);
|
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST, false);
|
||||||
|
@ -72,7 +71,6 @@ void DiveListView::headerClicked(int i )
|
||||||
|
|
||||||
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
||||||
{
|
{
|
||||||
DiveTripModel::Layout oldLayout = currentLayout;
|
|
||||||
currentLayout = layout;
|
currentLayout = layout;
|
||||||
|
|
||||||
header()->setClickable(true);
|
header()->setClickable(true);
|
||||||
|
@ -176,12 +174,11 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
|
||||||
selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0));
|
selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0));
|
||||||
selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
|
selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
|
||||||
if (!isExpanded(index)) {
|
if (!isExpanded(index))
|
||||||
expand(index);
|
expand(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
|
||||||
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
|
||||||
|
|
162
qt-ui/models.cpp
162
qt-ui/models.cpp
|
@ -32,27 +32,13 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in
|
||||||
return font;
|
return font;
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
switch(section) {
|
switch(section) {
|
||||||
case TYPE:
|
case TYPE: ret = tr("Type"); break;
|
||||||
ret = tr("Type");
|
case SIZE: ret = tr("Size"); break;
|
||||||
break;
|
case WORKINGPRESS: ret = tr("WorkPress"); break;
|
||||||
case SIZE:
|
case START: ret = tr("StartPress"); break;
|
||||||
ret = tr("Size");
|
case END: ret = tr("EndPress "); break;
|
||||||
break;
|
case O2: ret = tr("O2% "); break;
|
||||||
case WORKINGPRESS:
|
case HE: ret = tr("He% "); break;
|
||||||
ret = tr("WorkPress");
|
|
||||||
break;
|
|
||||||
case START:
|
|
||||||
ret = tr("StartPress");
|
|
||||||
break;
|
|
||||||
case END:
|
|
||||||
ret = tr("EndPress ");
|
|
||||||
break;
|
|
||||||
case O2:
|
|
||||||
ret = tr("O2% ");
|
|
||||||
break;
|
|
||||||
case HE:
|
|
||||||
ret = tr("He% ");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -767,48 +753,20 @@ QVariant TreeItemDT::data(int column, int role) const
|
||||||
{
|
{
|
||||||
QVariant ret;
|
QVariant ret;
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case NR:
|
case NR: ret = tr("#"); break;
|
||||||
ret = tr("#");
|
case DATE: ret = tr("Date"); break;
|
||||||
break;
|
case RATING: ret = UTF8_BLACKSTAR; break;
|
||||||
case DATE:
|
case DEPTH: ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft"); break;
|
||||||
ret = tr("Date");
|
case DURATION: ret = tr("min"); break;
|
||||||
break;
|
case TEMPERATURE: ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break;
|
||||||
case RATING:
|
case TOTALWEIGHT: ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs"); break;
|
||||||
ret = UTF8_BLACKSTAR;
|
case SUIT: ret = tr("Suit"); break;
|
||||||
break;
|
case CYLINDER: ret = tr("Cyl"); break;
|
||||||
case DEPTH:
|
case NITROX: ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2); break;
|
||||||
ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft");
|
case SAC: ret = tr("SAC"); break;
|
||||||
break;
|
case OTU: ret = tr("OTU"); break;
|
||||||
case DURATION:
|
case MAXCNS: ret = tr("maxCNS"); break;
|
||||||
ret = tr("min");
|
case LOCATION: ret = tr("Location"); break;
|
||||||
break;
|
|
||||||
case TEMPERATURE:
|
|
||||||
ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F");
|
|
||||||
break;
|
|
||||||
case TOTALWEIGHT:
|
|
||||||
ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs");
|
|
||||||
break;
|
|
||||||
case SUIT:
|
|
||||||
ret = tr("Suit");
|
|
||||||
break;
|
|
||||||
case CYLINDER:
|
|
||||||
ret = tr("Cyl");
|
|
||||||
break;
|
|
||||||
case NITROX:
|
|
||||||
ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2);
|
|
||||||
break;
|
|
||||||
case SAC:
|
|
||||||
ret = tr("SAC");
|
|
||||||
break;
|
|
||||||
case OTU:
|
|
||||||
ret = tr("OTU");
|
|
||||||
break;
|
|
||||||
case MAXCNS:
|
|
||||||
ret = tr("maxCNS");
|
|
||||||
break;
|
|
||||||
case LOCATION:
|
|
||||||
ret = tr("Location");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -877,62 +835,36 @@ QVariant DiveItem::data(int column, int role) const
|
||||||
break;
|
break;
|
||||||
case SORT_ROLE:
|
case SORT_ROLE:
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case NR: return dive->number;
|
case NR: retVal = dive->number; break;
|
||||||
case DATE: return (qulonglong) dive->when;
|
case DATE: retVal = (qulonglong) dive->when; break;
|
||||||
case DEPTH: return dive->maxdepth.mm;
|
case DEPTH: retVal = dive->maxdepth.mm; break;
|
||||||
case DURATION: return dive->duration.seconds;
|
case DURATION: retVal = dive->duration.seconds; break;
|
||||||
case TEMPERATURE: return dive->watertemp.mkelvin;
|
case TEMPERATURE: retVal = dive->watertemp.mkelvin; break;
|
||||||
case TOTALWEIGHT: return total_weight(dive);
|
case TOTALWEIGHT: retVal = total_weight(dive); break;
|
||||||
case SUIT: return QString(dive->suit);
|
case SUIT: retVal = QString(dive->suit); break;
|
||||||
case CYLINDER: return QString(dive->cylinder[0].type.description);
|
case CYLINDER: retVal = QString(dive->cylinder[0].type.description); break;
|
||||||
case NITROX: return nitrox_sort_value(dive);
|
case NITROX: retVal = nitrox_sort_value(dive); break;
|
||||||
case SAC: return dive->sac;
|
case SAC: retVal = dive->sac; break;
|
||||||
case OTU: return dive->otu;
|
case OTU: retVal = dive->otu; break;
|
||||||
case MAXCNS: return dive->maxcns;
|
case MAXCNS: retVal = dive->maxcns; break;
|
||||||
case LOCATION: return QString(dive->location);
|
case LOCATION: retVal = QString(dive->location); break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case NR:
|
case NR: retVal = dive->number; break;
|
||||||
retVal = dive->number;
|
case DATE: retVal = QString(get_dive_date_string(dive->when)); break;
|
||||||
break;
|
case DEPTH: retVal = displayDepth(); break;
|
||||||
case DATE:
|
case DURATION: retVal = displayDuration(); break;
|
||||||
retVal = QString(get_dive_date_string(dive->when));
|
case TEMPERATURE: retVal = displayTemperature(); break;
|
||||||
break;
|
case TOTALWEIGHT: retVal = displayWeight(); break;
|
||||||
case DEPTH:
|
case SUIT: retVal = QString(dive->suit); break;
|
||||||
retVal = displayDepth();
|
case CYLINDER: retVal = QString(dive->cylinder[0].type.description); break;
|
||||||
break;
|
case NITROX: retVal = QString(get_nitrox_string(dive)); break;
|
||||||
case DURATION:
|
case SAC: retVal = displaySac(); break;
|
||||||
retVal = displayDuration();
|
case OTU: retVal = dive->otu; break;
|
||||||
break;
|
case MAXCNS: retVal = dive->maxcns; break;
|
||||||
case TEMPERATURE:
|
case LOCATION: retVal = QString(dive->location); break;
|
||||||
retVal = displayTemperature();
|
|
||||||
break;
|
|
||||||
case TOTALWEIGHT:
|
|
||||||
retVal = displayWeight();
|
|
||||||
break;
|
|
||||||
case SUIT:
|
|
||||||
retVal = QString(dive->suit);
|
|
||||||
break;
|
|
||||||
case CYLINDER:
|
|
||||||
retVal = QString(dive->cylinder[0].type.description);
|
|
||||||
break;
|
|
||||||
case NITROX:
|
|
||||||
retVal = QString(get_nitrox_string(dive));
|
|
||||||
break;
|
|
||||||
case SAC:
|
|
||||||
retVal = displaySac();
|
|
||||||
break;
|
|
||||||
case OTU:
|
|
||||||
retVal = dive->otu;
|
|
||||||
break;
|
|
||||||
case MAXCNS:
|
|
||||||
retVal = dive->maxcns;
|
|
||||||
break;
|
|
||||||
case LOCATION:
|
|
||||||
retVal = QString(dive->location);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue