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
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -39,6 +39,7 @@ public:
bool save() const;
bool edit() ;
bool remove() ;
bool isActive() ;
//Setter
void setCollection(CollectionInterface* backend);
......
......@@ -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;
}
......@@ -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:
......
......@@ -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;
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment