mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 00:33:24 +00:00
cleanup: use begin/endResetModel in ExtraDataModel
As we do in most other models, use begin/endResetModel() to reset the model. This is distinctly less errorprone than the add/removeRows() version as we don't have to check for empty ranges, etc. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
1cd9229ae0
commit
6790e07a4c
1 changed files with 5 additions and 9 deletions
|
@ -13,10 +13,9 @@ ExtraDataModel::ExtraDataModel(QObject *parent) : CleanerTableModel(parent),
|
|||
|
||||
void ExtraDataModel::clear()
|
||||
{
|
||||
if (rows > 0) {
|
||||
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
||||
endRemoveRows();
|
||||
}
|
||||
beginResetModel();
|
||||
rows = 0;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant ExtraDataModel::data(const QModelIndex &index, int role) const
|
||||
|
@ -57,15 +56,12 @@ int ExtraDataModel::rowCount(const QModelIndex&) const
|
|||
|
||||
void ExtraDataModel::updateDive()
|
||||
{
|
||||
clear();
|
||||
beginResetModel();
|
||||
rows = 0;
|
||||
struct extra_data *ed = get_dive_dc(&displayed_dive, dc_number)->extra_data;
|
||||
while (ed) {
|
||||
rows++;
|
||||
ed = ed->next;
|
||||
}
|
||||
if (rows > 0) {
|
||||
beginInsertRows(QModelIndex(), 0, rows - 1);
|
||||
endInsertRows();
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue