Commit 17bd1ee9 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Implement deleting phone numbers again

parent 3488cff3
......@@ -105,8 +105,8 @@ Kirigami.ScrollablePage {
id: phoneNumber
Kirigami.FormData.label: i18n("Phone:")
Repeater {
id: rep
model: addressee.phoneNumbers
delegate: RowLayout {
Controls.TextField {
id: phoneField
......@@ -123,7 +123,7 @@ Kirigami.ScrollablePage {
Controls.Button {
icon.name: "list-remove"
onClicked: {
addressee.phoneNumbers.removePhoneNumber(edit)
addressee.phoneNumbers.removePhoneNumber(phoneField.text)
}
}
}
......@@ -133,6 +133,17 @@ 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
......@@ -177,6 +188,17 @@ Kirigami.ScrollablePage {
id: toAddEmail
placeholderText: i18n("user@example.org")
}
// add last text field on save()
Connections {
target: root;
onSave: {
if (toAddEmail.text !== "")
addressee.insertEmail(toAddEmail.text)
}
}
// button to add additional text field
Controls.Button {
icon.name: "list-add"
enabled: toAddEmail.text.length > 0
......
......@@ -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,7 +74,6 @@ Kirigami.ScrollablePage {
iconName: "document-edit"
text: "Edit"
onTriggered: {
console.log(page.personUri)
pageStack.push(Qt.resolvedUrl("AddContactPage.qml"), {state: "update", person: personData.person})
}
},
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment