| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 2.1 or version 3 as published by the Free |
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
| 22 | ** following information to ensure the GNU Lesser General Public License |
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 25 | ** |
| 26 | ** As a special exception, The Qt Company gives you certain additional |
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception |
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 29 | ** |
| 30 | ** $QT_END_LICENSE$ |
| 31 | ** |
| 32 | ****************************************************************************/ |
| 33 | |
| 34 | #include "qdeclarativecontactrelationship_p.h" |
| 35 | |
| 36 | #include <QtQml/qqmlinfo.h> |
| 37 | |
| 38 | QTCONTACTS_USE_NAMESPACE |
| 39 | |
| 40 | QT_BEGIN_NAMESPACE |
| 41 | |
| 42 | /*! |
| 43 | \qmltype Relationship |
| 44 | \instantiates QDeclarativeContactRelationship |
| 45 | \brief The Relationship element describes a one-to-one relationship |
| 46 | between a locally-stored contact and another (possibly remote) contact. |
| 47 | |
| 48 | \ingroup qml-contacts-main |
| 49 | \inqmlmodule QtContacts |
| 50 | This element is part of the \b{QtContacts} module. |
| 51 | |
| 52 | \sa QContactRelationship |
| 53 | \sa RelationshipModel |
| 54 | */ |
| 55 | |
| 56 | QDeclarativeContactRelationship::QDeclarativeContactRelationship(QObject* parent) |
| 57 | :QObject(parent) |
| 58 | { |
| 59 | |
| 60 | } |
| 61 | |
| 62 | |
| 63 | /*! |
| 64 | \qmlproperty int Relationship::first |
| 65 | |
| 66 | This property holds the locally-stored contact which has a relationship of the given type with the second contact. |
| 67 | */ |
| 68 | QString QDeclarativeContactRelationship::first() const |
| 69 | { |
| 70 | const QContactId contactId(m_relationship.first()); |
| 71 | if (!contactId.isNull()) |
| 72 | return contactId.toString(); |
| 73 | return QString(); |
| 74 | } |
| 75 | |
| 76 | /*! |
| 77 | \qmlproperty int Relationship::second |
| 78 | |
| 79 | This property holds the contact with which the first contact has a relationship of the given type. |
| 80 | */ |
| 81 | QString QDeclarativeContactRelationship::second() const |
| 82 | { |
| 83 | const QContactId contactId(m_relationship.second()); |
| 84 | if (!contactId.isNull()) |
| 85 | return contactId.toString(); |
| 86 | return QString(); |
| 87 | } |
| 88 | |
| 89 | /*! |
| 90 | \qmlproperty string Relationship::type |
| 91 | |
| 92 | This property holds the type of relationship which the source contact has with the destination contacts. |
| 93 | The value for this property can be one of: |
| 94 | \list |
| 95 | \li HasMember |
| 96 | \li Aggregates |
| 97 | \li IsSameAs |
| 98 | \li HasAssistant |
| 99 | \li HasManager |
| 100 | \li HasSpouse |
| 101 | \endlist |
| 102 | or any other customized relationship type string. |
| 103 | */ |
| 104 | |
| 105 | QVariant QDeclarativeContactRelationship::relationshipType() const |
| 106 | { |
| 107 | return m_relationship.relationshipType(); |
| 108 | } |
| 109 | |
| 110 | void QDeclarativeContactRelationship::setFirst(const QString& firstContactId) |
| 111 | { |
| 112 | m_relationship.setFirst(QContactId::fromString(idString: firstContactId)); |
| 113 | } |
| 114 | |
| 115 | void QDeclarativeContactRelationship::setSecond(const QString& secondContactId) |
| 116 | { |
| 117 | m_relationship.setSecond(QContactId::fromString(idString: secondContactId)); |
| 118 | } |
| 119 | |
| 120 | void QDeclarativeContactRelationship::setRelationshipType(const QVariant& relationshipType) |
| 121 | { |
| 122 | if (relationshipType.type() == QVariant::Int) { |
| 123 | switch (relationshipType.toInt()) { |
| 124 | case QDeclarativeContactRelationship::HasMember: |
| 125 | m_relationship.setRelationshipType(QContactRelationship::HasMember()); |
| 126 | break; |
| 127 | case QDeclarativeContactRelationship::Aggregates: |
| 128 | m_relationship.setRelationshipType(QContactRelationship::Aggregates()); |
| 129 | break; |
| 130 | case QDeclarativeContactRelationship::IsSameAs: |
| 131 | m_relationship.setRelationshipType(QContactRelationship::IsSameAs()); |
| 132 | break; |
| 133 | case QDeclarativeContactRelationship::HasAssistant: |
| 134 | m_relationship.setRelationshipType(QContactRelationship::HasAssistant()); |
| 135 | break; |
| 136 | case QDeclarativeContactRelationship::HasManager: |
| 137 | m_relationship.setRelationshipType(QContactRelationship::HasManager()); |
| 138 | break; |
| 139 | case QDeclarativeContactRelationship::HasSpouse: |
| 140 | m_relationship.setRelationshipType(QContactRelationship::HasSpouse()); |
| 141 | break; |
| 142 | default: |
| 143 | //unknown type |
| 144 | qmlInfo(me: this) << tr(s: "unknown relationship type:") << relationshipType; |
| 145 | break; |
| 146 | } |
| 147 | } else { |
| 148 | m_relationship.setRelationshipType(relationshipType.toString()); |
| 149 | } |
| 150 | |
| 151 | } |
| 152 | |
| 153 | |
| 154 | QContactRelationship QDeclarativeContactRelationship::relationship() const |
| 155 | { |
| 156 | return m_relationship; |
| 157 | } |
| 158 | void QDeclarativeContactRelationship::setRelationship(const QContactRelationship& relationship) |
| 159 | { |
| 160 | m_relationship = relationship; |
| 161 | emit valueChanged(); |
| 162 | } |
| 163 | |
| 164 | #include "moc_qdeclarativecontactrelationship_p.cpp" |
| 165 | |
| 166 | QT_END_NAMESPACE |
| 167 |
