diff --git a/src/bookmarkmodel.cpp b/src/bookmarkmodel.cpp index 837e3db9b75837a72cb900e99302981450e4854b..c841a9259f37a937bdf8f10e774d998ec478a7f4 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 8744b94e9a23c1ea30fc415c4bd04f66ec161276..572a354b7e0724ce42cdb2a077c56e78d1120e10 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 b82ca28fe021310938346a2722fe55b131bb8a7f..9f77c5d8fad62e9bb8ea8c4a6cbab1e35019a079 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 9023b683d5e4e8b9b74480ddb1b0465ee2d47ca6..c305d01f86f078794af76eb76ab8b62ebc62beb2 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 67f816ec1d7320ec8679f23a9614f521e6ed25c0..ccac3685849e411a88febc9193e5482268f7cf91 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 bf7f589aa75bc1d7799c2c85b90029303ecdca1e..55dfb4f0c28b027122db873b85b4a4350cf205a6 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);