...
 
Commits (3)
......@@ -105,19 +105,26 @@ Kirigami.ScrollablePage {
id: phoneNumber
Kirigami.FormData.label: i18n("Phone:")
Repeater {
id: rep
model: addressee.phoneNumbers
delegate: Controls.TextField {
id: phoneField
text: display
onAccepted: {
display = text
console.log("accepted", text)
}
Connections {
target: root;
onSave: phoneField.accepted()
delegate: RowLayout {
Controls.TextField {
id: phoneField
text: display
onAccepted: {
display = text
}
Connections {
target: root;
onSave: phoneField.accepted()
}
}
Controls.Button {
icon.name: "list-remove"
onClicked: {
addressee.phoneNumbers.removePhoneNumber(phoneField.text)
}
}
}
}
......@@ -126,10 +133,24 @@ Kirigami.ScrollablePage {
id: toAddPhone
placeholderText: i18n("+1 555 2368")
}
// add last text field on save()
Connections {
target: root;
onSave: {
if (toAddPhone.text !== "")
addressee.phoneNumbers.addPhoneNumber(toAddPhone.text)
}
}
// button to add additional text field
Controls.Button {
icon.name: "list-add"
enabled: toAddPhone.text.length > 0
onClicked: addressee.phoneNumbers.addPhoneNumber(toAddPhone.text)
onClicked: {
addressee.phoneNumbers.addPhoneNumber(toAddPhone.text)
toAddPhone.text = ""
}
}
}
}
......@@ -143,32 +164,50 @@ Kirigami.ScrollablePage {
Kirigami.FormData.label: i18n("E-mail:")
Repeater {
model: addressee.emails
Binding {
target: parent
property: "model"
value: addressee.emails
when: addressee.dataChanged
}
delegate: Row {
delegate: RowLayout {
Controls.TextField {
id: textField
text: modelData
}
Controls.Button {
icon.name: "list-remove"
onClicked: parent.destroy()
onClicked: addressee.removeEmail(textField.text)
}
}
}
RowLayout {
Controls.TextField {
id: toAddEmail
placeholderText: i18n("user@example.org")
}
// add last text field on save()
Connections {
target: root;
onSave: {
if (toAddEmail.text !== "")
addressee.insertEmail(toAddEmail.text)
}
}
Controls.TextField {
id: toAdd
placeholderText: i18n("user@example.org")
// button to add additional text field
Controls.Button {
icon.name: "list-add"
enabled: toAddEmail.text.length > 0
onClicked: {
addressee.insertEmail(toAddEmail.text)
toAddEmail.text = ""
}
}
}
}
Controls.Button {
icon.name: "list-add"
onClicked: addressee.insertEmail(toAdd.text)
}
}
}
......@@ -107,7 +107,6 @@ Flickable {
text: model.display
icon: model.iconName
onClicked: personActions.triggerAction(model.action)
Component.onCompleted: console.log(model.actionType)
}
}
}
......@@ -66,7 +66,6 @@ Kirigami.ScrollablePage {
iconName: "document-edit"
text: "Edit"
onTriggered: {
console.log(page.personUri)
pageStack.push(Qt.resolvedUrl("AddContactPage.qml"), {state: "update", person: personData.person})
}
}
......@@ -75,14 +74,13 @@ Kirigami.ScrollablePage {
iconName: "document-edit"
text: "Edit"
onTriggered: {
console.log(page.personUri)
pageStack.push(Qt.resolvedUrl("AddContactPage.qml"), {state: "update", person: personData.person})
}
},
Kirigami.Action {
iconName: "delete"
text: "Delete contact"
onTriggered: phonebook.deleteContact(page.personUri)
onTriggered: KPeople.PersonPluginManager.deleteContact(page.personUri)
}
]
}
......
......@@ -58,6 +58,11 @@ public:
Q_EMIT emailsChanged(emails());
}
Q_SCRIPTABLE void removeEmail(const QString &email) {
m_addressee.removeEmail(email);
Q_EMIT emailsChanged(emails());
}
QByteArray raw() const;
void setRaw(const QByteArray &raw);
......
......@@ -57,7 +57,7 @@ bool PhonesModel::setData(const QModelIndex& index, const QVariant& value, int r
numbers[index.row()].setNumber(value.toString());
m_addressee->m_addressee.setPhoneNumbers(numbers);
dataChanged(index, index, {Qt::DisplayRole});
} return true;
} return true;
}
return false;
}
......@@ -74,3 +74,22 @@ void PhonesModel::addPhoneNumber(const QString& number)
m_addressee->m_addressee.insertPhoneNumber(number);
endInsertRows();
}
void PhonesModel::removePhoneNumber(const QString &number)
{
for (int i = 0; 0 < m_addressee->m_addressee.phoneNumbers().count(); i++) {
if (m_addressee->m_addressee.phoneNumbers()[i].number() == number) {
beginRemoveRows({}, i, i);
break;
}
}
for (const auto &phoneNumber : m_addressee->m_addressee.phoneNumbers()) {
if (phoneNumber.number() == number) {
m_addressee->m_addressee.removePhoneNumber(phoneNumber);
break;
}
}
endRemoveRows();
}
......@@ -36,6 +36,7 @@ public:
int rowCount(const QModelIndex & parent = {}) const override;
Q_SCRIPTABLE void addPhoneNumber(const QString &number);
Q_SCRIPTABLE void removePhoneNumber(const QString &number);
private:
Addressee* m_addressee;
......