mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'Qt' into RenderStarsOnTable
This commit is contained in:
commit
e5ad47e459
12 changed files with 342 additions and 56 deletions
|
@ -60,9 +60,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
|||
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct dive *d = get_dive(selected_dive);
|
||||
cylinder_t& cyl = d->cylinder[index.row()];
|
||||
cylinder_t& cyl = current_dive->cylinder[index.row()];
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(index.column()) {
|
||||
|
@ -94,67 +92,93 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
int CylindersModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return usedRows[currentDive];
|
||||
return usedRows[current_dive];
|
||||
}
|
||||
|
||||
void CylindersModel::add(cylinder_t* cyl)
|
||||
{
|
||||
if (usedRows[currentDive] >= MAX_CYLINDERS) {
|
||||
if (usedRows[current_dive] >= MAX_CYLINDERS) {
|
||||
free(cyl);
|
||||
return;
|
||||
}
|
||||
|
||||
int row = usedRows[currentDive];
|
||||
int row = usedRows[current_dive];
|
||||
|
||||
cylinder_t& cylinder = currentDive->cylinder[row];
|
||||
cylinder_t& cylinder = current_dive->cylinder[row];
|
||||
|
||||
cylinder.end.mbar = cyl->end.mbar;
|
||||
cylinder.start.mbar = cyl->start.mbar;
|
||||
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
usedRows[currentDive]++;
|
||||
usedRows[current_dive]++;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void CylindersModel::update()
|
||||
{
|
||||
if (usedRows[currentDive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
currentDive = get_dive(selected_dive);
|
||||
if (usedRows[currentDive] > 0) {
|
||||
beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
void CylindersModel::clear()
|
||||
{
|
||||
if (usedRows[currentDive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
||||
usedRows[currentDive] = 0;
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
usedRows[current_dive] = 0;
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
void WeightModel::clear()
|
||||
{
|
||||
if (usedRows[current_dive] > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||
usedRows[current_dive] = 0;
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
int WeightModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
return QVariant();
|
||||
QVariant ret;
|
||||
if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS) {
|
||||
return ret;
|
||||
}
|
||||
weightsystem_t *ws = ¤t_dive->weightsystem[index.row()];
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(index.column()) {
|
||||
case TYPE:
|
||||
ret = QString(ws->description);
|
||||
break;
|
||||
case WEIGHT:
|
||||
if (get_units()->weight == units::KG) {
|
||||
int gr = ws->weight.grams % 1000;
|
||||
int kg = ws->weight.grams / 1000;
|
||||
ret = QString("%1.%2").arg(kg).arg((unsigned)(gr + 500) / 100);
|
||||
} else {
|
||||
ret = QString("%1").arg((unsigned)(grams_to_lbs(ws->weight.grams) + 0.5));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WeightModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return rows;
|
||||
return usedRows[current_dive];
|
||||
}
|
||||
|
||||
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
@ -164,19 +188,36 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
|
|||
return ret;
|
||||
}
|
||||
|
||||
switch(section) {
|
||||
case TYPE:
|
||||
ret = tr("Type");
|
||||
break;
|
||||
case WEIGHT:
|
||||
ret = tr("Weight");
|
||||
break;
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch(section) {
|
||||
case TYPE:
|
||||
ret = tr("Type");
|
||||
break;
|
||||
case WEIGHT:
|
||||
ret = tr("Weight");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void WeightModel::add(weight_t* weight)
|
||||
void WeightModel::add(weightsystem_t* weight)
|
||||
{
|
||||
if (usedRows[current_dive] >= MAX_WEIGHTSYSTEMS) {
|
||||
free(weight);
|
||||
return;
|
||||
}
|
||||
|
||||
int row = usedRows[current_dive];
|
||||
|
||||
weightsystem_t *ws = ¤t_dive->weightsystem[row];
|
||||
|
||||
ws->description = weight->description;
|
||||
ws->weight.grams = weight->weight.grams;
|
||||
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
usedRows[current_dive]++;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void WeightModel::update()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue