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

api: Move isActive to ItemBase

Refs #68848
parent bfd5f5e8
No related branches found
No related tags found
No related merge requests found
...@@ -309,8 +309,6 @@ QVariant CategorizedContactModel::data( const QModelIndex& index, int role) cons ...@@ -309,8 +309,6 @@ QVariant CategorizedContactModel::data( const QModelIndex& index, int role) cons
return static_cast<const ContactTreeNode*>(modelItem)->m_Name; return static_cast<const ContactTreeNode*>(modelItem)->m_Name;
case (int)Person::Role::IndexedLastUsed: case (int)Person::Role::IndexedLastUsed:
return index.child(0,0).data((int)Person::Role::IndexedLastUsed); return index.child(0,0).data((int)Person::Role::IndexedLastUsed);
case (int)Person::Role::Active:
return true;
default: default:
break; break;
} }
...@@ -327,10 +325,6 @@ QVariant CategorizedContactModel::data( const QModelIndex& index, int role) cons ...@@ -327,10 +325,6 @@ QVariant CategorizedContactModel::data( const QModelIndex& index, int role) cons
break; break;
} }
case ContactTreeNode::NodeType::CONTACTMETHOD: /* && (role == Qt::DisplayRole)) {*/ case ContactTreeNode::NodeType::CONTACTMETHOD: /* && (role == Qt::DisplayRole)) {*/
switch (role) {
case (int)Person::Role::Active:
return true;
}
return modelItem->m_pContactMethod->roleData(role); return modelItem->m_pContactMethod->roleData(role);
} }
return QVariant(); return QVariant();
...@@ -402,7 +396,13 @@ Qt::ItemFlags CategorizedContactModel::flags( const QModelIndex& index ) const ...@@ -402,7 +396,13 @@ Qt::ItemFlags CategorizedContactModel::flags( const QModelIndex& index ) const
{ {
if (!index.isValid()) if (!index.isValid())
return Qt::NoItemFlags; 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 int CategorizedContactModel::columnCount ( const QModelIndex& parent) const
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
bool save() const; bool save() const;
bool edit() ; bool edit() ;
bool remove() ; bool remove() ;
bool isActive() ;
//Setter //Setter
void setCollection(CollectionInterface* backend); void setCollection(CollectionInterface* backend);
......
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
class ItemBasePrivate class ItemBasePrivate
{ {
public: public:
ItemBasePrivate() : m_pBackend(nullptr){} ItemBasePrivate() : m_pBackend(nullptr),m_isActive(true){}
CollectionInterface* m_pBackend; CollectionInterface* m_pBackend;
bool m_isActive;
}; };
template<typename Base> template<typename Base>
...@@ -76,3 +77,9 @@ bool ItemBase<Base>::remove() ...@@ -76,3 +77,9 @@ bool ItemBase<Base>::remove()
// else // else
// qDebug() << "Cannot save, invalid item type"; // qDebug() << "Cannot save, invalid item type";
} }
template<typename Base>
bool ItemBase<Base>::isActive()
{
return d_ptr->m_pBackend->isEnabled() && d_ptr->m_isActive;
}
...@@ -389,14 +389,6 @@ void Person::setDepartment(const QString& name) ...@@ -389,14 +389,6 @@ void Person::setDepartment(const QString& name)
d_ptr->changed(); 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 ///Return if one of the ContactMethod is present
bool Person::isPresent() const bool Person::isPresent() const
{ {
...@@ -417,12 +409,6 @@ bool Person::isTracked() const ...@@ -417,12 +409,6 @@ bool Person::isTracked() const
return false; 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 /** Get the last time this person was contacted
* @warning This method complexity is O(N) * @warning This method complexity is O(N)
*/ */
...@@ -473,8 +459,6 @@ QVariant Person::roleData(int role) const ...@@ -473,8 +459,6 @@ QVariant Person::roleData(int role) const
return QVariant((int)HistoryTimeCategoryModel::timeToHistoryConst(lastUsedTime())); return QVariant((int)HistoryTimeCategoryModel::timeToHistoryConst(lastUsedTime()));
case (int)Person::Role::Object: case (int)Person::Role::Object:
return QVariant::fromValue(const_cast<Person*>(this)); return QVariant::fromValue(const_cast<Person*>(this));
case (int)Person::Role::Active:
return isActive();
case (int)Person::Role::DatedLastUsed: case (int)Person::Role::DatedLastUsed:
return QVariant(QDateTime::fromTime_t( lastUsedTime())); return QVariant(QDateTime::fromTime_t( lastUsedTime()));
case (int)Person::Role::Filter: case (int)Person::Role::Filter:
......
...@@ -52,7 +52,6 @@ public: ...@@ -52,7 +52,6 @@ public:
FormattedLastUsed = 104, FormattedLastUsed = 104,
IndexedLastUsed = 105, IndexedLastUsed = 105,
DatedLastUsed = 106, DatedLastUsed = 106,
Active = 107,
Object = 108, Object = 108,
Filter = 200, //All roles, all at once Filter = 200, //All roles, all at once
DropState = 300, //State for drag and drop DropState = 300, //State for drag and drop
...@@ -96,9 +95,7 @@ public: ...@@ -96,9 +95,7 @@ public:
Q_PROPERTY( QString preferredEmail READ preferredEmail WRITE setPreferredEmail ) Q_PROPERTY( QString preferredEmail READ preferredEmail WRITE setPreferredEmail )
Q_PROPERTY( QVariant photo READ photo WRITE setPhoto ) Q_PROPERTY( QVariant photo READ photo WRITE setPhoto )
Q_PROPERTY( QString group READ group WRITE setGroup ) Q_PROPERTY( QString group READ group WRITE setGroup )
Q_PROPERTY( QString department READ department WRITE setDepartment ) Q_PROPERTY( QString department READ department WRITE setDepartment ) Q_PROPERTY( time_t lastUsedTime READ lastUsedTime )
Q_PROPERTY( bool active READ isActive WRITE setActive NOTIFY statusChanged )
Q_PROPERTY( time_t lastUsedTime READ lastUsedTime )
//Mutator //Mutator
Q_INVOKABLE void addAddress(Address* addr); Q_INVOKABLE void addAddress(Address* addr);
...@@ -129,7 +126,6 @@ public: ...@@ -129,7 +126,6 @@ public:
const QVariant photo () const; const QVariant photo () const;
const QString& group () const; const QString& group () const;
const QString& department () const; const QString& department () const;
bool isActive () const;
time_t lastUsedTime () const; time_t lastUsedTime () const;
QVariant roleData(int role) const; QVariant roleData(int role) const;
...@@ -154,7 +150,6 @@ public: ...@@ -154,7 +150,6 @@ public:
void setDepartment ( const QString& name ); void setDepartment ( const QString& name );
void setUid ( const QByteArray& id ); void setUid ( const QByteArray& id );
void setPhoto ( const QVariant& photo ); void setPhoto ( const QVariant& photo );
void setActive ( bool active );
//Operator //Operator
bool operator==(const Person* other) const; bool operator==(const Person* other) const;
......
...@@ -135,16 +135,15 @@ QHash<int,QByteArray> PersonModel::roleNames() const ...@@ -135,16 +135,15 @@ QHash<int,QByteArray> PersonModel::roleNames() const
static bool initRoles = false; static bool initRoles = false;
if (!initRoles) { if (!initRoles) {
initRoles = true; initRoles = true;
roles[ (int)Person::Role::Organization ] = "Organization"; roles[ (int)Person::Role::Organization ] = "organization";
roles[ (int)Person::Role::Group ] = "Group"; roles[ (int)Person::Role::Group ] = "group";
roles[ (int)Person::Role::Department ] = "Department"; roles[ (int)Person::Role::Department ] = "department";
roles[ (int)Person::Role::PreferredEmail ] = "PreferredEmail"; roles[ (int)Person::Role::PreferredEmail ] = "preferredEmail";
roles[ (int)Person::Role::FormattedLastUsed ] = "FormattedLastUsed"; roles[ (int)Person::Role::FormattedLastUsed ] = "formattedLastUsed";
roles[ (int)Person::Role::IndexedLastUsed ] = "IndexedLastUsed"; roles[ (int)Person::Role::IndexedLastUsed ] = "indexedLastUsed";
roles[ (int)Person::Role::DatedLastUsed ] = "DatedLastUsed"; 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::Filter ] = "Filter"; //All roles, all at once roles[ (int)Person::Role::DropState ] = "dropState"; //State for drag and drop
roles[ (int)Person::Role::DropState ] = "DropState"; //State for drag and drop
} }
return roles; return roles;
} }
...@@ -323,8 +322,9 @@ bool PersonModel::addPerson(Person* c) ...@@ -323,8 +322,9 @@ bool PersonModel::addPerson(Person* c)
void PersonModel::disablePerson(Person* c) void PersonModel::disablePerson(Person* c)
{ {
if (c) Q_UNUSED(c) //TODO re-implement
c->setActive(false); // if (c)
// c->setActive(false);
} }
bool PersonModel::addNewPerson(Person* c, CollectionInterface* backend) bool PersonModel::addNewPerson(Person* c, CollectionInterface* backend)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment