repay some desbt in ActivityListModel::data
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 13 Feb 2023 18:12:58 +0000 (19:12 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Wed, 17 May 2023 16:16:08 +0000 (18:16 +0200)
only valid index are sent to QAbstractItemModel::data

we may want to do more checks in debug mode, let's do it

if we are going to show data, let's use a const variable to contain the
current activity item

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/gui/tray/activitylistmodel.cpp

index 7b152a9842b04e0f5b113e0e8f3c0c7e65c32b63..e7b7b38f55d3d506e07625fa49d68b6a90363d11 100644 (file)
@@ -130,12 +130,9 @@ void ActivityListModel::setDisplayActions(bool value)
 
 QVariant ActivityListModel::data(const QModelIndex &index, int role) const
 {
-    Activity a;
+    Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid));
 
-    if (!index.isValid())
-        return QVariant();
-
-    a = _finalList.at(index.row());
+    const auto a = _finalList.at(index.row());
     AccountStatePtr ast = AccountManager::instance()->account(a._accName);
     if (!ast && _accountState != ast.data())
         return QVariant();