Skip to content
Snippets Groups Projects
Commit d3d8a45d authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

Fix a nullptr issue with CollectionManagers

Refs #65367
parent 166d0346
No related branches found
No related tags found
No related merge requests found
...@@ -139,7 +139,8 @@ QObject* BookmarkTopLevelItem::getSelf() const ...@@ -139,7 +139,8 @@ QObject* BookmarkTopLevelItem::getSelf() const
return nullptr; 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"); setObjectName("BookmarkModel");
reloadCategories(); reloadCategories();
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <collectionmediator.h> #include <collectionmediator.h>
class CommonCollectionModel; class CommonCollectionModel;
class QAbstractItemModel;
enum LoadOptions { enum LoadOptions {
NONE = 0x0 , NONE = 0x0 ,
...@@ -68,7 +69,15 @@ template <class T> class LIB_EXPORT CollectionManagerInterface { ...@@ -68,7 +69,15 @@ template <class T> class LIB_EXPORT CollectionManagerInterface {
friend class CollectionMediator<T>; friend class CollectionMediator<T>;
public: 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() {}; virtual ~CollectionManagerInterface() {};
/** /**
......
...@@ -20,14 +20,17 @@ template <class T> ...@@ -20,14 +20,17 @@ template <class T>
class CollectionManagerInterfacePrivate class CollectionManagerInterfacePrivate
{ {
public: 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(); ~CollectionManagerInterfacePrivate();
QVector< CollectionInterface* > m_lBackends; QVector< CollectionInterface* > m_lBackends;
QVector< CollectionInterface* > m_lEnabledBackends; QVector< CollectionInterface* > m_lEnabledBackends;
mutable CollectionMediator<T>* m_pMediator; mutable CollectionMediator<T>* m_pMediator;
CollectionManagerInterface<T>* q_ptr; QAbstractItemModel* q_ptr;
CollectionManagerInterface<T>* i_ptr;
CollectionMediator<T>* itemMediator() const; CollectionMediator<T>* itemMediator() const;
}; };
...@@ -36,7 +39,7 @@ template<class T> ...@@ -36,7 +39,7 @@ template<class T>
CollectionMediator<T>* CollectionManagerInterfacePrivate<T>::itemMediator() const CollectionMediator<T>* CollectionManagerInterfacePrivate<T>::itemMediator() const
{ {
if (!m_pMediator) { if (!m_pMediator) {
m_pMediator = new CollectionMediator<T>(q_ptr,nullptr); m_pMediator = new CollectionMediator<T>(i_ptr,q_ptr);
} }
return m_pMediator; return m_pMediator;
} }
...@@ -71,7 +74,7 @@ T2* CollectionManagerInterface<T>::addBackend(Ts... args, const LoadOptions opti ...@@ -71,7 +74,7 @@ T2* CollectionManagerInterface<T>::addBackend(Ts... args, const LoadOptions opti
} }
template<class T> template<class T>
CollectionManagerInterface<T>::CollectionManagerInterface() : d_ptr(new CollectionManagerInterfacePrivate<T>(this)) CollectionManagerInterface<T>::CollectionManagerInterface(QAbstractItemModel* self) : d_ptr(new CollectionManagerInterfacePrivate<T>(self,this))
{ {
} }
......
...@@ -187,7 +187,8 @@ m_Role(Call::Role::FuzzyDate) ...@@ -187,7 +187,8 @@ m_Role(Call::Role::FuzzyDate)
} }
///Constructor ///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; m_spInstance = this;
d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER << RingMimes::HISTORYID; d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER << RingMimes::HISTORYID;
......
...@@ -67,7 +67,8 @@ m_pBackendModel(nullptr) ...@@ -67,7 +67,8 @@ m_pBackendModel(nullptr)
} }
///Constructor ///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))
{ {
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment