Qt: Fix CredentialsModel::clear()

The last parameter to beginRemoveRows() is the last row index, not the
number of rows. The QAbstractItemModel::beginRemoveRows() source code
expliticly checks if the value is smaller than row count.

Do not emit beginRemoveRows() if the model is empty as it does not make
sense and it is impossible to pass the QAbstractItemModel assertions
in such case.

Emit endRemoveRows() when finished instead of endInsertRows().

Change-Id: I93be4820b1ea0fbb5c0f3cd28edca329b4017814
Reviewed-on: https://code.wireshark.org/review/34318
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Tomasz Moń 2019-08-18 14:13:34 +02:00 committed by Gerald Combs
parent 97a9c7a12e
commit 22b5495485
1 changed files with 9 additions and 7 deletions

View File

@ -117,14 +117,16 @@ void CredentialsModel::addRecord(tap_credential_t* auth)
void CredentialsModel::clear()
{
emit beginRemoveRows(QModelIndex(), 0, rowCount());
for (QList<tap_credential_t*>::iterator itr = credentials_.begin(); itr != credentials_.end(); ++itr) {
g_free((*itr)->username);
g_free((*itr)->info);
delete *itr;
if (!credentials_.isEmpty()) {
emit beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
for (QList<tap_credential_t*>::iterator itr = credentials_.begin(); itr != credentials_.end(); ++itr) {
g_free((*itr)->username);
g_free((*itr)->info);
delete *itr;
}
credentials_.clear();
emit endRemoveRows();
}
credentials_.clear();
emit endInsertRows();
}
QVariant CredentialsModel::headerData(int section, Qt::Orientation orientation, int role) const