mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: implement proper Qt-model semantics in TankInfoModel
- Use a beginResetModel()/endResetModel() pair instead of distinct addRows / removeRows pairs. - Reuse the update function in the constructor(). - Let "rows" be the number of rows, not the number of rows minus one. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4f0fd86d35
commit
36d8dcc3bf
1 changed files with 7 additions and 22 deletions
|
@ -79,35 +79,20 @@ QVariant TankInfoModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
int TankInfoModel::rowCount(const QModelIndex&) const
|
int TankInfoModel::rowCount(const QModelIndex&) const
|
||||||
{
|
{
|
||||||
return rows + 1;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
TankInfoModel::TankInfoModel() : rows(-1)
|
TankInfoModel::TankInfoModel()
|
||||||
{
|
{
|
||||||
setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
|
setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
|
||||||
struct tank_info_t *info = tank_info;
|
update();
|
||||||
for (info = tank_info; info->name && info < tank_info + MAX_TANK_INFO; info++, rows++)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (rows > -1) {
|
|
||||||
beginInsertRows(QModelIndex(), 0, rows);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TankInfoModel::update()
|
void TankInfoModel::update()
|
||||||
{
|
{
|
||||||
if (rows > -1) {
|
beginResetModel();
|
||||||
beginRemoveRows(QModelIndex(), 0, rows);
|
rows = 0;
|
||||||
endRemoveRows();
|
for (struct tank_info_t *info = tank_info; info->name && info < tank_info + MAX_TANK_INFO; info++, rows++)
|
||||||
rows = -1;
|
|
||||||
}
|
|
||||||
struct tank_info_t *info = tank_info;
|
|
||||||
for (info = tank_info; info->name && info < tank_info + MAX_TANK_INFO; info++, rows++)
|
|
||||||
;
|
;
|
||||||
|
endResetModel();
|
||||||
if (rows > -1) {
|
|
||||||
beginInsertRows(QModelIndex(), 0, rows);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue