diff options
author | Erik Verbruggen <erik@verbruggen.consulting> | 2021-10-15 15:05:01 +0300 |
---|---|---|
committer | Erik Verbruggen <Erik.Verbruggen@Me.com> | 2021-12-03 12:45:08 +0300 |
commit | 470bf76e6362a4379e6548e466971e3a2e532ccd (patch) | |
tree | f697e03da9fde7e1d97394d867c6c3eed7f314d9 /src/gui/folderstatusmodel.cpp | |
parent | ed603153da4fdc385f90982c88660fe0cec2f7ea (diff) |
Use the refcounted AccountStatePtr as much as possible
The AccountManager creates AccountState objects, and stores them in a
shared pointer.
Previously, the raw pointer was given out, and stored in other objects.
That made removal very tricky: when an account gets removed, the
underlying object gets deleted, and then all classes that listen get
notified of the deletion. Those classes would sometimes put a nullptr
into the AccountState pointer they stored, and in each usage would
(hopefully) check for a nullptr. The problem was that a number of checks
were missing, which the clang static analyser pointed out.
This patch changes nearly all uses of a raw pointer into the shared
pointer, thereby making sure all usages have a valid reference, even
when account deletion happens. The two places where a raw pointer is
still used, now put it into a refcounted pointer as soon as possible.
Diffstat (limited to 'src/gui/folderstatusmodel.cpp')
-rw-r--r-- | src/gui/folderstatusmodel.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 06f64118b..f3a2630e6 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -62,7 +62,7 @@ static bool sortByFolderHeader(const FolderStatusModel::SubFolderInfo &lhs, cons < 0; } -void FolderStatusModel::setAccountState(const AccountState *accountState) +void FolderStatusModel::setAccountState(AccountStatePtr accountState) { beginResetModel(); _dirty = false; @@ -106,7 +106,7 @@ void FolderStatusModel::setAccountState(const AccountState *accountState) Qt::ItemFlags FolderStatusModel::flags(const QModelIndex &index) const { if (!_accountState) { - return nullptr; + return Qt::NoItemFlags; } // Always enable the item. If it isn't enabled, it cannot be in the selection model, so all |