Commit 9dd9a305 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to delete address

parent eec05d20
Pipeline #51017 passed with stage
in 15 minutes and 23 seconds
......@@ -22,13 +22,13 @@ using namespace ContactEditor;
AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
: QSplitter(parent)
, mAddressLocationWidget(new AddressLocationWidget(this))
, mAddressesLocationView(new QTreeView(this))
, mAddressModel(new AddressModel(this))
{
mAddressLocationWidget = new AddressLocationWidget(this);
mAddressLocationWidget->setObjectName(QStringLiteral("addresslocationwidget"));
addWidget(mAddressLocationWidget);
mAddressesLocationView = new QTreeView(this);
mAddressesLocationView->setRootIsDecorated(false);
mAddressesLocationView->setHeaderHidden(true);
mAddressesLocationView->setModel(mAddressModel);
......@@ -49,6 +49,7 @@ AddressesLocationWidget::AddressesLocationWidget(QWidget *parent)
mAddressLocationWidget->slotModifyAddress(idx.data(Qt::UserRole).value<KContacts::Address>(), idx.row());
});
connect(mAddressLocationWidget, &AddressLocationWidget::addNewAddress, mAddressModel, &AddressModel::addAddress);
connect(mAddressLocationWidget, &AddressLocationWidget::removeAddress, mAddressModel, &AddressModel::removeAddress);
connect(mAddressLocationWidget,
&AddressLocationWidget::updateAddressCanceled,
mAddressesLocationView->selectionModel(),
......
......@@ -33,8 +33,8 @@ public:
Q_REQUIRED_RESULT bool hasNoSavedData() const;
private:
AddressLocationWidget *mAddressLocationWidget = nullptr;
QTreeView *mAddressesLocationView = nullptr;
AddressLocationWidget *const mAddressLocationWidget;
QTreeView *const mAddressesLocationView;
AddressModel *const mAddressModel;
bool mReadOnly = false;
};
......
......@@ -13,6 +13,7 @@
#include <KComboBox>
#include <KLineEdit>
#include <KLocalizedString>
#include <KMessageBox>
#include <QCheckBox>
#include <QLabel>
......@@ -132,6 +133,11 @@ AddressLocationWidget::AddressLocationWidget(QWidget *parent)
modifyButtonWidgetLayout->setContentsMargins(0, 0, 0, 0);
mButtonStack->addWidget(modifyButtonWidget);
mRemoveAddress = new QPushButton(i18n("Remove Address"), this);
mRemoveAddress->setObjectName(QStringLiteral("removebuttonaddress"));
modifyButtonWidgetLayout->addWidget(mRemoveAddress);
connect(mRemoveAddress, &QPushButton::clicked, this, &AddressLocationWidget::slotRemoveAddress);
mModifyAddress = new QPushButton(i18n("Update Address"), this);
mModifyAddress->setObjectName(QStringLiteral("modifybuttonaddress"));
modifyButtonWidgetLayout->addWidget(mModifyAddress);
......@@ -285,6 +291,17 @@ void AddressLocationWidget::slotUpdateAddress()
}
}
void AddressLocationWidget::slotRemoveAddress()
{
if (mCurrentMode == ModifyAddress) {
const auto result = KMessageBox::questionYesNo(this, i18n("Do you really want to delete this address?"));
if (result == KMessageBox::Yes) {
Q_EMIT removeAddress(mCurrentAddress);
reset();
}
}
}
void AddressLocationWidget::reset()
{
Q_EMIT updateAddressCanceled();
......
......@@ -46,11 +46,13 @@ Q_SIGNALS:
void addNewAddress(const KContacts::Address &address);
void updateAddress(const KContacts::Address &address, int index);
void updateAddressCanceled();
void removeAddress(int index);
private:
void slotChanged();
void slotAddAddress();
void slotUpdateAddress();
void slotRemoveAddress();
void slotCancelModifyAddress();
void fillCountryCombo();
void switchMode();
......@@ -64,6 +66,7 @@ private:
KLineEdit *mStreetEdit = nullptr;
KComboBox *mCountryCombo = nullptr;
QPushButton *mAddAddress = nullptr;
QPushButton *mRemoveAddress = nullptr;
QPushButton *mModifyAddress = nullptr;
QPushButton *mCancelAddress = nullptr;
QStackedWidget *mButtonStack = nullptr;
......
......@@ -7,4 +7,4 @@ set(addresslocationwidget_SRCS addresslocationwidgettest.cpp ../addresslocationw
add_executable(addresslocationwidget ${addresslocationwidget_SRCS})
add_test(NAME addresslocationwidget COMMAND addresslocationwidget)
ecm_mark_as_test(addresslocationwidget)
target_link_libraries(addresslocationwidget Qt5::Test Qt5::Widgets KF5::ContactEditor KF5::Contacts KF5::I18n KF5::Completion)
target_link_libraries(addresslocationwidget Qt5::Test Qt5::Widgets KF5::ContactEditor KF5::Contacts KF5::I18n KF5::Completion KF5::WidgetsAddons)
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