mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Use the existing current_dive macro in Qt code
Replicating this with the currentDive member seems to make no sense. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
0794f03b5e
commit
730e055e5a
2 changed files with 23 additions and 23 deletions
|
@ -59,9 +59,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
||||||
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
|
if (!index.isValid() || index.row() >= MAX_CYLINDERS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
cylinder_t& cyl = current_dive->cylinder[index.row()];
|
||||||
struct dive *d = get_dive(selected_dive);
|
|
||||||
cylinder_t& cyl = d->cylinder[index.row()];
|
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
switch(index.column()) {
|
switch(index.column()) {
|
||||||
|
@ -93,57 +91,60 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
int CylindersModel::rowCount(const QModelIndex& parent) const
|
int CylindersModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return usedRows[currentDive];
|
return usedRows[current_dive];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::add(cylinder_t* cyl)
|
void CylindersModel::add(cylinder_t* cyl)
|
||||||
{
|
{
|
||||||
if (usedRows[currentDive] >= MAX_CYLINDERS) {
|
if (usedRows[current_dive] >= MAX_CYLINDERS) {
|
||||||
free(cyl);
|
free(cyl);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.end.mbar = cyl->end.mbar;
|
||||||
cylinder.start.mbar = cyl->start.mbar;
|
cylinder.start.mbar = cyl->start.mbar;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
usedRows[currentDive]++;
|
usedRows[current_dive]++;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::update()
|
void CylindersModel::update()
|
||||||
{
|
{
|
||||||
if (usedRows[currentDive] > 0) {
|
if (usedRows[current_dive] > 0) {
|
||||||
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
if (usedRows[current_dive] > 0) {
|
||||||
currentDive = get_dive(selected_dive);
|
beginInsertRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
if (usedRows[currentDive] > 0) {
|
|
||||||
beginInsertRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::clear()
|
void CylindersModel::clear()
|
||||||
{
|
{
|
||||||
if (usedRows[currentDive] > 0) {
|
if (usedRows[current_dive] > 0) {
|
||||||
beginRemoveRows(QModelIndex(), 0, usedRows[currentDive]-1);
|
beginRemoveRows(QModelIndex(), 0, usedRows[current_dive]-1);
|
||||||
usedRows[currentDive] = 0;
|
usedRows[current_dive] = 0;
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeightModel::clear()
|
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
|
int WeightModel::columnCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
QVariant WeightModel::data(const QModelIndex& index, int role) const
|
||||||
|
@ -153,7 +154,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
int WeightModel::rowCount(const QModelIndex& parent) const
|
int WeightModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return rows;
|
return usedRows[current_dive];
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
|
|
@ -47,12 +47,10 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
dive *currentDive;
|
|
||||||
|
|
||||||
/* Since the dive doesn`t stores the number of cylinders that
|
/* Since the dive doesn`t stores the number of cylinders that
|
||||||
* it has ( max 8 ) and since I don`t want to make a
|
* it has ( max 8 ) and since I don`t want to make a
|
||||||
* model-for-each-dive, let`s hack this here instead. */
|
* model-for-each-dive, let`s hack this here instead. */
|
||||||
QMap<dive*, int> usedRows;
|
QMap<struct dive *, int> usedRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Encapsulation of the Weight Model, that represents
|
/* Encapsulation of the Weight Model, that represents
|
||||||
|
@ -68,7 +66,8 @@ class WeightModel : public QAbstractTableModel {
|
||||||
void clear();
|
void clear();
|
||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
int rows;
|
/* Remember the number of rows in a dive */
|
||||||
|
QMap<struct dive *, int> usedRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
/*! An AbstractItemModel for recording dive trip information such as a list of dives.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue