|
|
|
#include "campwizard.h"
|
|
|
|
#include "ui_campwizard.h"
|
|
|
|
#include "campservice.h"
|
|
|
|
#include <core.h>
|
|
|
|
#include <addressbookservice.h>
|
|
|
|
|
|
|
|
AddressHelper::AddressHelper(QObject *parent)
|
|
|
|
:QObject(parent)
|
|
|
|
{
|
|
|
|
m_address = AddressbookDataPtr(new AddressbookData);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<QObject> AddressHelper::address() const
|
|
|
|
{
|
|
|
|
return m_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressHelper::setAddress(const QSharedPointer<QObject> &address)
|
|
|
|
{
|
|
|
|
if (qobject_cast<AddressbookData*>(address.data()) != NULL)
|
|
|
|
{
|
|
|
|
m_address = qSharedPointerDynamicCast<AddressbookData, QObject>(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressbookDataPtr AddressHelper::addr() const
|
|
|
|
{
|
|
|
|
return m_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressHelper::setAddr(const AddressbookDataPtr &address)
|
|
|
|
{
|
|
|
|
m_address = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressbookDataPtr AddressHelper::newAddress()
|
|
|
|
{
|
|
|
|
AddressBookService adbSrv;
|
|
|
|
m_copyAddress = adbSrv.copyAddress(m_address);
|
|
|
|
|
|
|
|
return m_copyAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressbookDataPtr AddressHelper::copyAddress()
|
|
|
|
{
|
|
|
|
if (m_copyAddress.isNull())
|
|
|
|
{
|
|
|
|
m_copyAddress = AddressbookDataPtr(new AddressbookData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_copyAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
/// \brief CampWizard::CampWizard
|
|
|
|
/// \param parent
|
|
|
|
///
|
|
|
|
CampWizard::CampWizard(QWidget *parent) :
|
|
|
|
QWizard(parent),
|
|
|
|
ui(new Ui::CampWizard)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
m_peopleModel = new AutoTableModel<AddressItem>(this);
|
|
|
|
ui->tablePeople->setModel(m_peopleModel);
|
|
|
|
ui->tablePeople->hideColumn(2);
|
|
|
|
ui->tablePeople->hideColumn(3);
|
|
|
|
ui->tablePeople->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
ui->tablePeople->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
|
|
|
connect(ui->tablePeople->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex, QModelIndex){
|
|
|
|
ui->btnRemove->setEnabled(!m_data->people().isEmpty());
|
|
|
|
ui->btnOwner->setEnabled(!m_data->people().isEmpty());
|
|
|
|
});
|
|
|
|
|
|
|
|
m_dataBinder = new ObjectBinder(this);
|
|
|
|
m_dataBinder->registerBinding(ui->start);
|
|
|
|
m_dataBinder->registerBinding(ui->end);
|
|
|
|
|
|
|
|
m_addrHelper = new AddressHelper(this);
|
|
|
|
|
|
|
|
Service<AddressbookData> addrSrv;
|
|
|
|
m_addrHelperBinder = new ObjectBinder(this);
|
|
|
|
m_addrHelperBinder->registerBinding(ui->address, ComboData::createComboData(addrSrv.all()));
|
|
|
|
m_addrHelperBinder->setData(m_addrHelper);
|
|
|
|
|
|
|
|
m_addressBinder = new ObjectBinder(this);
|
|
|
|
m_addressBinder->registerBinding(ui->title);
|
|
|
|
m_addressBinder->registerBinding(ui->firstName);
|
|
|
|
m_addressBinder->registerBinding(ui->lastName);
|
|
|
|
m_addressBinder->registerBinding(ui->birthDate);
|
|
|
|
m_addressBinder->registerBinding(ui->idCardNumber);
|
|
|
|
m_addressBinder->registerBinding(ui->ztp);
|
|
|
|
m_addressBinder->registerBinding(ui->addressStreet);
|
|
|
|
m_addressBinder->registerBinding(ui->addressHouseNumber);
|
|
|
|
m_addressBinder->registerBinding(ui->addressZipCode);
|
|
|
|
m_addressBinder->registerBinding(ui->addressCity);
|
|
|
|
|
|
|
|
Service<CountryData> coutrySrv;
|
|
|
|
m_addressBinder->registerBinding(ui->country, ComboData::createComboData(coutrySrv.all()));
|
|
|
|
|
|
|
|
m_addressBinder->setData(m_addrHelper->copyAddress().data());
|
|
|
|
m_addressBinder->bindToUi();
|
|
|
|
|
|
|
|
m_bindAddrCombo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CampWizard::~CampWizard()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CampWizard::setData(const CampDataPtr &data)
|
|
|
|
{
|
|
|
|
m_data = data;
|
|
|
|
|
|
|
|
m_dataBinder->setData(data.data());
|
|
|
|
m_dataBinder->bindToUi();
|
|
|
|
m_addrHelperBinder->bindToUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CampWizard::on_btnAdd_clicked()
|
|
|
|
{
|
|
|
|
m_addressBinder->bindToData();
|
|
|
|
|
|
|
|
CampService srv;
|
|
|
|
AddressBookService adbSrv;
|
|
|
|
|
|
|
|
if (ui->groupNew->isChecked())
|
|
|
|
{
|
|
|
|
AddressbookDataPtr newAddr = adbSrv.copyAddress(m_addrHelper->copyAddress());
|
|
|
|
adbSrv.save(newAddr);
|
|
|
|
srv.addPerson(m_data, newAddr);
|
|
|
|
|
|
|
|
m_bindAddrCombo = false;
|
|
|
|
m_addrHelperBinder->registerBinding(ui->address, ComboData::createComboData(adbSrv.all()));
|
|
|
|
m_addrHelperBinder->bindToUi();
|
|
|
|
m_bindAddrCombo = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
srv.addPerson(m_data, m_addrHelper->addr());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_peopleModel->setData(m_data->people());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CampWizard::on_address_currentIndexChanged(int)
|
|
|
|
{
|
|
|
|
if (m_bindAddrCombo)
|
|
|
|
{
|
|
|
|
AddressBookService adbSrv;
|
|
|
|
m_addrHelperBinder->bindToData();
|
|
|
|
m_addressBinder->setData(m_addrHelper->newAddress().data());
|
|
|
|
m_addressBinder->bindToUi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CampWizard::on_btnRemove_clicked()
|
|
|
|
{
|
|
|
|
AddressItemPtr selAddr = m_peopleModel->itemFromIndex(ui->tablePeople->currentIndex());
|
|
|
|
m_data->removePerson(selAddr);
|
|
|
|
m_peopleModel->setData(m_data->people());
|
|
|
|
|
|
|
|
ui->btnOwner->setEnabled(false);
|
|
|
|
ui->btnRemove->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CampWizard::on_btnOwner_clicked()
|
|
|
|
{
|
|
|
|
CampService srv;
|
|
|
|
AddressItemPtr selAddr = m_peopleModel->itemFromIndex(ui->tablePeople->currentIndex());
|
|
|
|
srv.setOwner(m_data, selAddr);
|
|
|
|
|
|
|
|
QModelIndex currIndex = ui->tablePeople->currentIndex();
|
|
|
|
m_peopleModel->setData(m_data->people());
|
|
|
|
ui->tablePeople->setCurrentIndex(currIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CampWizard::on_groupNew_clicked(bool checked)
|
|
|
|
{
|
|
|
|
if (checked)
|
|
|
|
{
|
|
|
|
ui->address->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->address->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CampWizard::on_CampWizard_currentIdChanged(int id)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|