Verified Commit e0f24ab2 authored by Jonah Brüchert's avatar Jonah Brüchert 🌳

Fix removing phone numbers / instant messenger contacts

parent a20f951d
...@@ -140,10 +140,10 @@ Kirigami.ScrollablePage { ...@@ -140,10 +140,10 @@ Kirigami.ScrollablePage {
delegate: RowLayout { delegate: RowLayout {
Controls.TextField { Controls.TextField {
id: phoneField id: phoneField
text: display text: model.display
Layout.fillWidth: true Layout.fillWidth: true
onAccepted: { onAccepted: {
display = text model.display = text
} }
Connections { Connections {
...@@ -155,7 +155,7 @@ Kirigami.ScrollablePage { ...@@ -155,7 +155,7 @@ Kirigami.ScrollablePage {
icon.name: "list-remove" icon.name: "list-remove"
implicitWidth: implicitHeight implicitWidth: implicitHeight
onClicked: { onClicked: {
addressee.phoneNumbers.removePhoneNumber(display) addressee.phoneNumbers.removePhoneNumber(model.display)
} }
} }
} }
...@@ -264,10 +264,10 @@ Kirigami.ScrollablePage { ...@@ -264,10 +264,10 @@ Kirigami.ScrollablePage {
delegate: RowLayout { delegate: RowLayout {
Controls.TextField { Controls.TextField {
id: imppField id: imppField
text: display text: model.display
Layout.fillWidth: true Layout.fillWidth: true
onAccepted: { onAccepted: {
display = text model.display = text
} }
Connections { Connections {
...@@ -279,7 +279,8 @@ Kirigami.ScrollablePage { ...@@ -279,7 +279,8 @@ Kirigami.ScrollablePage {
icon.name: "list-remove" icon.name: "list-remove"
implicitWidth: implicitHeight implicitWidth: implicitHeight
onClicked: { onClicked: {
addressee.impps.removeImpp(display) print("remove", model.display)
addressee.impps.removeImpp(model.display)
} }
} }
} }
......
...@@ -84,17 +84,17 @@ void ImppModel::addImpp(const QString &address) ...@@ -84,17 +84,17 @@ void ImppModel::addImpp(const QString &address)
void ImppModel::removeImpp(const QString &address) void ImppModel::removeImpp(const QString &address)
{ {
// Find Impp object belonging to the address and remove it.
for (int i = 0; i < m_addressee->m_addressee.imppList().count(); i++) { for (int i = 0; i < m_addressee->m_addressee.imppList().count(); i++) {
if (m_addressee->m_addressee.imppList()[i].address().toString().contains(address)) { if (m_addressee->m_addressee.imppList().at(i).address().toString() == address) {
beginRemoveRows({}, i, i); beginRemoveRows({}, i, i);
auto imppList = m_addressee->m_addressee.imppList(); auto imppList = m_addressee->m_addressee.imppList();
imppList.remove(i); imppList.remove(i);
m_addressee->m_addressee.setImppList(imppList); m_addressee->m_addressee.setImppList(imppList);
endRemoveRows();
break; break;
} }
} }
endRemoveRows();
} }
...@@ -78,19 +78,16 @@ void PhonesModel::addPhoneNumber(const QString &number) ...@@ -78,19 +78,16 @@ void PhonesModel::addPhoneNumber(const QString &number)
void PhonesModel::removePhoneNumber(const QString &number) void PhonesModel::removePhoneNumber(const QString &number)
{ {
for (int i = 0; i < m_addressee->m_addressee.phoneNumbers().count(); i++) { const auto phoneNumbers = m_addressee->m_addressee.phoneNumbers();
if (m_addressee->m_addressee.phoneNumbers()[i].number() == number) {
beginRemoveRows({}, i, i);
break;
}
}
for (const auto &phoneNumber : m_addressee->m_addressee.phoneNumbers()) { // Find PhoneNumber object that belongs to the number and remove it
for (const auto &phoneNumber : phoneNumbers) {
if (phoneNumber.number() == number) { if (phoneNumber.number() == number) {
int index = phoneNumbers.indexOf(phoneNumber);
beginRemoveRows({}, index, index);
m_addressee->m_addressee.removePhoneNumber(phoneNumber); m_addressee->m_addressee.removePhoneNumber(phoneNumber);
endRemoveRows();
break; break;
} }
} }
endRemoveRows();
} }
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