From a7f869380f2ddd8f6762d8853442eb90ba28beee Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> Date: Fri, 20 Mar 2015 19:18:35 -0400 Subject: [PATCH] api: Move isActive to ItemBase Refs #68848 --- src/categorizedcontactmodel.cpp | 14 +++++++------- src/itembase.h | 1 + src/itembase.hpp | 9 ++++++++- src/person.cpp | 16 ---------------- src/person.h | 7 +------ src/personmodel.cpp | 24 ++++++++++++------------ 6 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/categorizedcontactmodel.cpp b/src/categorizedcontactmodel.cpp index dec3f572..d4805e3a 100644 --- a/src/categorizedcontactmodel.cpp +++ b/src/categorizedcontactmodel.cpp @@ -309,8 +309,6 @@ QVariant CategorizedContactModel::data( const QModelIndex& index, int role) cons return static_cast<const ContactTreeNode*>(modelItem)->m_Name; case (int)Person::Role::IndexedLastUsed: return index.child(0,0).data((int)Person::Role::IndexedLastUsed); - case (int)Person::Role::Active: - return true; default: break; } @@ -327,10 +325,6 @@ QVariant CategorizedContactModel::data( const QModelIndex& index, int role) cons break; } case ContactTreeNode::NodeType::CONTACTMETHOD: /* && (role == Qt::DisplayRole)) {*/ - switch (role) { - case (int)Person::Role::Active: - return true; - } return modelItem->m_pContactMethod->roleData(role); } return QVariant(); @@ -402,7 +396,13 @@ Qt::ItemFlags CategorizedContactModel::flags( const QModelIndex& index ) const { if (!index.isValid()) return Qt::NoItemFlags; - return Qt::ItemIsEnabled | Qt::ItemIsSelectable | (index.parent().isValid()?Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled:Qt::ItemIsEnabled); + + const ContactTreeNode* modelNode = static_cast<ContactTreeNode*>(index.internalPointer()); + + return (modelNode->m_pContact && modelNode->m_pContact->isActive() ? Qt::NoItemFlags : Qt::ItemIsEnabled) + | Qt::ItemIsSelectable + | (modelNode->m_pParent? (Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled) : Qt::ItemIsEnabled + ); } int CategorizedContactModel::columnCount ( const QModelIndex& parent) const diff --git a/src/itembase.h b/src/itembase.h index 808c2b8a..024d827e 100644 --- a/src/itembase.h +++ b/src/itembase.h @@ -39,6 +39,7 @@ public: bool save() const; bool edit() ; bool remove() ; + bool isActive() ; //Setter void setCollection(CollectionInterface* backend); diff --git a/src/itembase.hpp b/src/itembase.hpp index ff7c946d..5bf5aae4 100644 --- a/src/itembase.hpp +++ b/src/itembase.hpp @@ -23,8 +23,9 @@ class ItemBasePrivate { public: - ItemBasePrivate() : m_pBackend(nullptr){} + ItemBasePrivate() : m_pBackend(nullptr),m_isActive(true){} CollectionInterface* m_pBackend; + bool m_isActive; }; template<typename Base> @@ -76,3 +77,9 @@ bool ItemBase<Base>::remove() // else // qDebug() << "Cannot save, invalid item type"; } + +template<typename Base> +bool ItemBase<Base>::isActive() +{ + return d_ptr->m_pBackend->isEnabled() && d_ptr->m_isActive; +} diff --git a/src/person.cpp b/src/person.cpp index 0224e830..98f443da 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -389,14 +389,6 @@ void Person::setDepartment(const QString& name) d_ptr->changed(); } -///If the contact have been deleted or not yet fully created -void Person::setActive( bool active) -{ - d_ptr->m_Active = active; - d_ptr->statusChanged(d_ptr->m_Active); - d_ptr->changed(); -} - ///Return if one of the ContactMethod is present bool Person::isPresent() const { @@ -417,12 +409,6 @@ bool Person::isTracked() const return false; } -///Have this contact been deleted or doesn't exist yet -bool Person::isActive() const -{ - return d_ptr->m_Active; -} - /** Get the last time this person was contacted * @warning This method complexity is O(N) */ @@ -473,8 +459,6 @@ QVariant Person::roleData(int role) const return QVariant((int)HistoryTimeCategoryModel::timeToHistoryConst(lastUsedTime())); case (int)Person::Role::Object: return QVariant::fromValue(const_cast<Person*>(this)); - case (int)Person::Role::Active: - return isActive(); case (int)Person::Role::DatedLastUsed: return QVariant(QDateTime::fromTime_t( lastUsedTime())); case (int)Person::Role::Filter: diff --git a/src/person.h b/src/person.h index cb60f660..834caa58 100644 --- a/src/person.h +++ b/src/person.h @@ -52,7 +52,6 @@ public: FormattedLastUsed = 104, IndexedLastUsed = 105, DatedLastUsed = 106, - Active = 107, Object = 108, Filter = 200, //All roles, all at once DropState = 300, //State for drag and drop @@ -96,9 +95,7 @@ public: Q_PROPERTY( QString preferredEmail READ preferredEmail WRITE setPreferredEmail ) Q_PROPERTY( QVariant photo READ photo WRITE setPhoto ) Q_PROPERTY( QString group READ group WRITE setGroup ) - Q_PROPERTY( QString department READ department WRITE setDepartment ) - Q_PROPERTY( bool active READ isActive WRITE setActive NOTIFY statusChanged ) - Q_PROPERTY( time_t lastUsedTime READ lastUsedTime ) + Q_PROPERTY( QString department READ department WRITE setDepartment ) Q_PROPERTY( time_t lastUsedTime READ lastUsedTime ) //Mutator Q_INVOKABLE void addAddress(Address* addr); @@ -129,7 +126,6 @@ public: const QVariant photo () const; const QString& group () const; const QString& department () const; - bool isActive () const; time_t lastUsedTime () const; QVariant roleData(int role) const; @@ -154,7 +150,6 @@ public: void setDepartment ( const QString& name ); void setUid ( const QByteArray& id ); void setPhoto ( const QVariant& photo ); - void setActive ( bool active ); //Operator bool operator==(const Person* other) const; diff --git a/src/personmodel.cpp b/src/personmodel.cpp index 07df7841..51b1f771 100644 --- a/src/personmodel.cpp +++ b/src/personmodel.cpp @@ -135,16 +135,15 @@ QHash<int,QByteArray> PersonModel::roleNames() const static bool initRoles = false; if (!initRoles) { initRoles = true; - roles[ (int)Person::Role::Organization ] = "Organization"; - roles[ (int)Person::Role::Group ] = "Group"; - roles[ (int)Person::Role::Department ] = "Department"; - roles[ (int)Person::Role::PreferredEmail ] = "PreferredEmail"; - roles[ (int)Person::Role::FormattedLastUsed ] = "FormattedLastUsed"; - roles[ (int)Person::Role::IndexedLastUsed ] = "IndexedLastUsed"; - roles[ (int)Person::Role::DatedLastUsed ] = "DatedLastUsed"; - roles[ (int)Person::Role::Active ] = "Active"; - roles[ (int)Person::Role::Filter ] = "Filter"; //All roles, all at once - roles[ (int)Person::Role::DropState ] = "DropState"; //State for drag and drop + roles[ (int)Person::Role::Organization ] = "organization"; + roles[ (int)Person::Role::Group ] = "group"; + roles[ (int)Person::Role::Department ] = "department"; + roles[ (int)Person::Role::PreferredEmail ] = "preferredEmail"; + roles[ (int)Person::Role::FormattedLastUsed ] = "formattedLastUsed"; + roles[ (int)Person::Role::IndexedLastUsed ] = "indexedLastUsed"; + roles[ (int)Person::Role::DatedLastUsed ] = "datedLastUsed"; + roles[ (int)Person::Role::Filter ] = "filter"; //All roles, all at once + roles[ (int)Person::Role::DropState ] = "dropState"; //State for drag and drop } return roles; } @@ -323,8 +322,9 @@ bool PersonModel::addPerson(Person* c) void PersonModel::disablePerson(Person* c) { - if (c) - c->setActive(false); + Q_UNUSED(c) //TODO re-implement +// if (c) +// c->setActive(false); } bool PersonModel::addNewPerson(Person* c, CollectionInterface* backend) -- GitLab