diff --git a/src/categorizedcontactmodel.cpp b/src/categorizedcontactmodel.cpp index dec3f572d3ddfa90c537187e52a7b2fc23eb7ba7..d4805e3a1877e40e543390d0f2baaaf0bbefe54e 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 808c2b8a1aa95fe7a2f772d9dba3e7fc7da4410b..024d827ec79c90341e8d0f4ac7d96cea1832c327 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 ff7c946d506604a39bd6a550a3af3337214598fd..5bf5aae4f382ddee105d642a037c638f56d65d69 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 0224e83034bdc7a400893847c6c8e29f2ece0c71..98f443da76ae54c026045ba72b688a4f4f338706 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 cb60f660911755201229a56d0cb1e8ff5c8b8a3b..834caa587987765ac1b3b529c193219bcdb94263 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 07df784123980b4c46912612fa59262965875792..51b1f7717f913bc073682bc943814c461f2d7bbb 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)