From d3d8a45d919a1c9325f516d58bd7e6c3bed2b2bc Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> Date: Fri, 13 Feb 2015 16:42:17 +0000 Subject: [PATCH] Fix a nullptr issue with CollectionManagers Refs #65367 --- src/bookmarkmodel.cpp | 3 ++- src/collectionmanagerinterface.h | 11 ++++++++++- src/collectionmanagerinterface.hpp | 11 +++++++---- src/historymodel.cpp | 3 ++- src/personmodel.cpp | 3 ++- src/tlsmethodmodel.cpp | 2 +- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/bookmarkmodel.cpp b/src/bookmarkmodel.cpp index 837e3db9..c841a925 100644 --- a/src/bookmarkmodel.cpp +++ b/src/bookmarkmodel.cpp @@ -139,7 +139,8 @@ QObject* BookmarkTopLevelItem::getSelf() const return nullptr; } -BookmarkModel::BookmarkModel(QObject* parent) : QAbstractItemModel(parent), d_ptr(new BookmarkModelPrivate(this)) +BookmarkModel::BookmarkModel(QObject* parent) : QAbstractItemModel(parent), CollectionManagerInterface<ContactMethod>(this), +d_ptr(new BookmarkModelPrivate(this)) { setObjectName("BookmarkModel"); reloadCategories(); diff --git a/src/collectionmanagerinterface.h b/src/collectionmanagerinterface.h index 8744b94e..572a354b 100644 --- a/src/collectionmanagerinterface.h +++ b/src/collectionmanagerinterface.h @@ -31,6 +31,7 @@ #include <collectionmediator.h> class CommonCollectionModel; +class QAbstractItemModel; enum LoadOptions { NONE = 0x0 , @@ -68,7 +69,15 @@ template <class T> class LIB_EXPORT CollectionManagerInterface { friend class CollectionMediator<T>; public: - CollectionManagerInterface(); + /** + * Extend a QAbstractItemModel to have the collection management interface. + * This will add the addBackend and a few other methods. + * + * This interface need to be used on a QAbstractItemModel derived class + * + * @param in self: "this" + */ + explicit CollectionManagerInterface(QAbstractItemModel* self); virtual ~CollectionManagerInterface() {}; /** diff --git a/src/collectionmanagerinterface.hpp b/src/collectionmanagerinterface.hpp index b82ca28f..9f77c5d8 100644 --- a/src/collectionmanagerinterface.hpp +++ b/src/collectionmanagerinterface.hpp @@ -20,14 +20,17 @@ template <class T> class CollectionManagerInterfacePrivate { public: - CollectionManagerInterfacePrivate(CollectionManagerInterface<T>* p) : m_pMediator(nullptr),q_ptr(p) + ///All manager should be QAbstractItemModel, this wont compile (on purpose) if the aren't + CollectionManagerInterfacePrivate(QAbstractItemModel* p2, CollectionManagerInterface<T>* p) : + m_pMediator(nullptr),q_ptr(p2),i_ptr(p) {} ~CollectionManagerInterfacePrivate(); QVector< CollectionInterface* > m_lBackends; QVector< CollectionInterface* > m_lEnabledBackends; mutable CollectionMediator<T>* m_pMediator; - CollectionManagerInterface<T>* q_ptr; + QAbstractItemModel* q_ptr; + CollectionManagerInterface<T>* i_ptr; CollectionMediator<T>* itemMediator() const; }; @@ -36,7 +39,7 @@ template<class T> CollectionMediator<T>* CollectionManagerInterfacePrivate<T>::itemMediator() const { if (!m_pMediator) { - m_pMediator = new CollectionMediator<T>(q_ptr,nullptr); + m_pMediator = new CollectionMediator<T>(i_ptr,q_ptr); } return m_pMediator; } @@ -71,7 +74,7 @@ T2* CollectionManagerInterface<T>::addBackend(Ts... args, const LoadOptions opti } template<class T> -CollectionManagerInterface<T>::CollectionManagerInterface() : d_ptr(new CollectionManagerInterfacePrivate<T>(this)) +CollectionManagerInterface<T>::CollectionManagerInterface(QAbstractItemModel* self) : d_ptr(new CollectionManagerInterfacePrivate<T>(self,this)) { } diff --git a/src/historymodel.cpp b/src/historymodel.cpp index 9023b683..c305d01f 100644 --- a/src/historymodel.cpp +++ b/src/historymodel.cpp @@ -187,7 +187,8 @@ m_Role(Call::Role::FuzzyDate) } ///Constructor -HistoryModel::HistoryModel():QAbstractItemModel(QCoreApplication::instance()),d_ptr(new HistoryModelPrivate(this)) +HistoryModel::HistoryModel():QAbstractItemModel(QCoreApplication::instance()),CollectionManagerInterface<Call>(this), +d_ptr(new HistoryModelPrivate(this)) { m_spInstance = this; d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER << RingMimes::HISTORYID; diff --git a/src/personmodel.cpp b/src/personmodel.cpp index 67f816ec..ccac3685 100644 --- a/src/personmodel.cpp +++ b/src/personmodel.cpp @@ -67,7 +67,8 @@ m_pBackendModel(nullptr) } ///Constructor -PersonModel::PersonModel(QObject* par) : QAbstractItemModel(par?par:QCoreApplication::instance()), d_ptr(new PersonModelPrivate(this)) +PersonModel::PersonModel(QObject* par) : QAbstractItemModel(par?par:QCoreApplication::instance()), CollectionManagerInterface<Person>(this), +d_ptr(new PersonModelPrivate(this)) { } diff --git a/src/tlsmethodmodel.cpp b/src/tlsmethodmodel.cpp index bf7f589a..55dfb4f0 100644 --- a/src/tlsmethodmodel.cpp +++ b/src/tlsmethodmodel.cpp @@ -133,7 +133,7 @@ QItemSelectionModel* TlsMethodModel::selectionModel() const { if (!d_ptr->m_pSelectionModel) { d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<TlsMethodModel*>(this)); - const QString value = d_ptr->m_pAccount->d_ptr->accountDetail(DRing::Account::ConfProperties::TLS::METHOD); + const QString value = d_ptr->m_pAccount->d_ptr->accountDetail(DRing::Account::ConfProperties::TLS::METHOD); const QModelIndex& idx = toIndex(TlsMethodModelPrivate::fromDaemonName(value)); d_ptr->m_pSelectionModel->setCurrentIndex(idx,QItemSelectionModel::ClearAndSelect); -- GitLab