From 3fedf9f77eabce50ba8e87ff6c706b0ba114bdb6 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> Date: Mon, 6 Apr 2015 12:29:04 -0400 Subject: [PATCH] contact: Add CategorizedContactModel singleton Refs #70196 --- src/categorizedcontactmodel.cpp | 13 ++++++++++++- src/categorizedcontactmodel.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/categorizedcontactmodel.cpp b/src/categorizedcontactmodel.cpp index f3d6ebcd..121e5619 100644 --- a/src/categorizedcontactmodel.cpp +++ b/src/categorizedcontactmodel.cpp @@ -71,7 +71,6 @@ public: void slotContactMethodCountChanged (int,int); void slotContactMethodCountAboutToChange(int,int); }; - class CategorizedContactModelPrivate : public QObject { Q_OBJECT @@ -94,6 +93,9 @@ public: ContactTreeNode* getContactTopLevelItem(const QString& category); QModelIndex getIndex(int row, int column, ContactTreeNode* parent); + //Singleton + static CategorizedContactModel* m_spInstance; + private: CategorizedContactModel* q_ptr; @@ -102,6 +104,8 @@ public Q_SLOTS: void slotContactAdded(const Person* c); }; +CategorizedContactModel* CategorizedContactModelPrivate::m_spInstance = nullptr; + ContactTreeNode::ContactTreeNode(const Person* ct, CategorizedContactModel* parent) : CategorizedCompositeNode(CategorizedCompositeNode::Type::CONTACT), m_pContact(ct),m_Index(-1),m_pContactMethod(nullptr),m_Type(ContactTreeNode::NodeType::PERSON),m_pParent(nullptr),m_pModel(parent) { @@ -204,6 +208,13 @@ CategorizedContactModel::~CategorizedContactModel() } } +CategorizedContactModel* CategorizedContactModel::instance() +{ + if (!CategorizedContactModelPrivate::m_spInstance) + CategorizedContactModelPrivate::m_spInstance = new CategorizedContactModel(); + return CategorizedContactModelPrivate::m_spInstance; +} + QHash<int,QByteArray> CategorizedContactModel::roleNames() const { static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); diff --git a/src/categorizedcontactmodel.h b/src/categorizedcontactmodel.h index b1b7664a..25093d5c 100644 --- a/src/categorizedcontactmodel.h +++ b/src/categorizedcontactmodel.h @@ -68,6 +68,9 @@ public: bool isSortAlphabetical () const; QString defaultCategory () const; + //Singleton + static CategorizedContactModel* instance(); + private: QScopedPointer<CategorizedContactModelPrivate> d_ptr; Q_DECLARE_PRIVATE(CategorizedContactModel) -- GitLab