Skip to content
Snippets Groups Projects
Commit 87b747cd authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by Stepan Salenikovich
Browse files

person: Allow copies to be created

Useful for migration between collections without using vCard
serialization.

Issue: #81136
Change-Id: If52e19692c2a5022e484f855ee475ed192cf068a
parent fc541131
Branches
Tags
No related merge requests found
...@@ -224,6 +224,40 @@ Person::Person(const QByteArray& content, Person::Encoding encoding, CollectionI ...@@ -224,6 +224,40 @@ Person::Person(const QByteArray& content, Person::Encoding encoding, CollectionI
}; };
} }
/**
* Copy constructor, useful when transferring a contact between collections
*
* For example, converting a trust request to GMail contact without forcing
* a slow vCard conversion.
*
* This create a COPY of the person details, using shared attributes between
* multiple person with multiple collection is currently not supported (but
* would be easy to enable if the need arise).
*/
Person::Person(const Person& other) noexcept : ItemBase(nullptr),
d_ptr(new PersonPrivate(this))
{
d_ptr->m_FirstName = other.d_ptr->m_FirstName ;
d_ptr->m_SecondName = other.d_ptr->m_SecondName ;
d_ptr->m_NickName = other.d_ptr->m_NickName ;
d_ptr->m_vPhoto = other.d_ptr->m_vPhoto ;
d_ptr->m_FormattedName = other.d_ptr->m_FormattedName ;
d_ptr->m_PreferredEmail = other.d_ptr->m_PreferredEmail ;
d_ptr->m_Organization = other.d_ptr->m_Organization ;
d_ptr->m_Uid = other.d_ptr->m_Uid ;
d_ptr->m_Group = other.d_ptr->m_Group ;
d_ptr->m_Department = other.d_ptr->m_Department ;
d_ptr->m_DisplayPhoto = other.d_ptr->m_DisplayPhoto ;
d_ptr->m_Numbers = other.d_ptr->m_Numbers ;
d_ptr->m_Active = other.d_ptr->m_Active ;
d_ptr->m_isPlaceHolder = other.d_ptr->m_isPlaceHolder ;
d_ptr->m_lAddresses = other.d_ptr->m_lAddresses ;
d_ptr->m_lCustomAttributes = other.d_ptr->m_lCustomAttributes ;
d_ptr->m_LastUsed = other.d_ptr->m_LastUsed ;
d_ptr->m_LastUsedInit = other.d_ptr->m_LastUsedInit ;
d_ptr->m_HiddenContactMethods = other.d_ptr->m_HiddenContactMethods;
}
///Updates an existing contact from vCard info ///Updates an existing contact from vCard info
void Person::updateFromVCard(const QByteArray& content) void Person::updateFromVCard(const QByteArray& content)
{ {
......
...@@ -122,6 +122,7 @@ public: ...@@ -122,6 +122,7 @@ public:
//Constructors & Destructors //Constructors & Destructors
explicit Person(CollectionInterface* parent = nullptr, const QByteArray& uid = QByteArray()); explicit Person(CollectionInterface* parent = nullptr, const QByteArray& uid = QByteArray());
Person(const QByteArray& content, Person::Encoding encoding = Encoding::UID, CollectionInterface* parent = nullptr); Person(const QByteArray& content, Person::Encoding encoding = Encoding::UID, CollectionInterface* parent = nullptr);
Person(const Person& other) noexcept;
virtual ~Person(); virtual ~Person();
//Getters //Getters
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
#include "person.h" #include "person.h"
class ContactMethod; class ContactMethod;
class PersonPrivate : public QObject class PersonPrivate final : public QObject
{ {
Q_OBJECT Q_OBJECT
friend class ContactMethod; friend class ContactMethod;
public: public:
PersonPrivate(Person* contact); explicit PersonPrivate(Person* contact);
~PersonPrivate(); ~PersonPrivate();
QString m_FirstName ; QString m_FirstName ;
QString m_SecondName ; QString m_SecondName ;
...@@ -54,6 +54,14 @@ public: ...@@ -54,6 +54,14 @@ public:
bool m_LastUsedInit ; bool m_LastUsedInit ;
QList<ContactMethod*> m_HiddenContactMethods; QList<ContactMethod*> m_HiddenContactMethods;
/*
* NOTE If new attributes are added, please update the explicit Person copy
* constructor as Qt force QObject copy via serialization (to force developers
* to use references, copy-on-write based containers and smart pointers
* instead), which is overkill for this scenario and would detach all the
* containers causing useless increase in memory usage.
*/
//Cache //Cache
QString m_CachedFilterString; QString m_CachedFilterString;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment