Implemented first page of camp wizard.

master
Josef Rokos 8 years ago
parent 9c30d416e0
commit 6a042c46a1

@ -10,9 +10,22 @@ AddressBookService::~AddressBookService()
{
}
QList<QSharedPointer<AddressbookData> > AddressBookService::all(const QString &where)
AddressbookDataPtr AddressBookService::copyAddress(AddressbookDataPtr address)
{
Service<AddressbookData> srv;
return srv.all(where);
AddressbookDataPtr newAddress(new AddressbookData());
newAddress->setTitle(address->title());
newAddress->setFirstName(address->firstName());
newAddress->setLastName(address->lastName());
newAddress->setBirthDate(address->birthDate());
newAddress->setIdCardNumber(address->idCardNumber());
newAddress->setZtp(address->ztp());
newAddress->setAddressStreet(address->addressStreet());
newAddress->setAddressHouseNumber(address->addressHouseNumber());
newAddress->setAddressZipCode(address->addressZipCode());
newAddress->setAddressCity(address->addressCity());
newAddress->setCountry(address->country());
return newAddress;
}

@ -3,17 +3,18 @@
#include <QList>
#include <QSharedPointer>
#include <service.h>
#include "data/addressbookdata.h"
#include "addressbook_global.h"
class ADDRESSBOOKSHARED_EXPORT AddressBookService
class ADDRESSBOOKSHARED_EXPORT AddressBookService : public Service<AddressbookData>
{
public:
AddressBookService();
~AddressBookService();
QList<QSharedPointer<AddressbookData> > all(const QString &where = "");
AddressbookDataPtr copyAddress(AddressbookDataPtr address);
};
#endif // ADDRESSBOOKSERVICE_H

@ -8,7 +8,7 @@
"default" : "",
"CZ" : ""
},
"schemaVersion" : 2,
"schemaVersion" : 3,
"sql" : [
"CREATE TABLE \"CampData\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
@ -77,6 +77,9 @@ CREATE TABLE \"PersonPrice\" (
",
"ALTER TABLE Sale ADD \"description\" TEXT NULL;
",
"ALTER TABLE AddressItem ADD \"owner\" INTEGER NULL;
"
],

@ -1,5 +1,6 @@
#include "campgrid.h"
#include "campwizard.h"
#include "campservice.h"
CampGrid::CampGrid(QWidget *parent) : GridForm<CampData>(parent)
{
@ -8,8 +9,10 @@ CampGrid::CampGrid(QWidget *parent) : GridForm<CampData>(parent)
void CampGrid::handleNewRecord()
{
CampService srv;
CampWizard *wizard = new CampWizard();
wizard->setAttribute(Qt::WA_DeleteOnClose);
wizard->setData(srv.create());
wizard->show();
}

@ -14,5 +14,32 @@ void CampService::addPerson(CampDataPtr data, AddressbookDataPtr address)
addrItem->setLastName(address->lastName());
addrItem->setCampData(data);
if (data->people().isEmpty())
{
setOwner(data, addrItem);
}
data->addPerson(addrItem);
}
void CampService::setOwner(CampDataPtr data, AddressItemPtr person)
{
foreach (AddressItemPtr p, data->people()) {
p->setOwner(false);
}
person->setOwner(true);
data->setOwnerFirstame(person->firstName());
data->setOwnerLastname(person->lastName());
data->setOwnerAddress(person->address());
}
CampDataPtr CampService::create()
{
CampDataPtr data(new CampData);
data->setStart(QDate::currentDate());
data->setEnd(QDate::currentDate());
return data;
}

@ -1,11 +1,18 @@
#ifndef CAMPSERVICE_H
#define CAMPSERVICE_H
#include <core.h>
#include <addressbookdata.h>
#include "data/camp-data.h"
#include "camp-odb.hxx"
class CampService
class CampService : public Service<CampData>
{
public:
CampService();
void addPerson(CampDataPtr data, AddressbookDataPtr address);
void setOwner(CampDataPtr data, AddressItemPtr person);
CampDataPtr create();
};
#endif // CAMPSERVICE_H

@ -1,15 +1,100 @@
#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()
{
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_bindAddrCombo = true;
}
CampWizard::~CampWizard()
@ -22,9 +107,77 @@ 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);
}
}

@ -4,6 +4,30 @@
#include <QWizard>
#include "data/camp-data.h"
#include <objectbinder.h>
#include <data/addressbookdata.h>
#include <core.h>
class AddressHelper : public QObject
{
Q_OBJECT
Q_PROPERTY(QSharedPointer<QObject> address READ address WRITE setAddress)
public:
AddressHelper(QObject *parent = NULL);
QSharedPointer<QObject> address() const;
void setAddress(const QSharedPointer<QObject> &address);
AddressbookDataPtr addr() const;
void setAddr(const AddressbookDataPtr &address);
AddressbookDataPtr newAddress();
AddressbookDataPtr copyAddress();
private:
AddressbookDataPtr m_address;
AddressbookDataPtr m_copyAddress;
};
namespace Ui {
class CampWizard;
@ -22,10 +46,24 @@ public:
private slots:
void on_btnAdd_clicked();
void on_address_currentIndexChanged(int index);
void on_btnRemove_clicked();
void on_btnOwner_clicked();
void on_groupNew_clicked(bool checked);
private:
Ui::CampWizard *ui;
CampDataPtr m_data;
ObjectBinder *m_dataBinder;
ObjectBinder *m_addrHelperBinder;
ObjectBinder *m_addressBinder;
AddressHelper *m_addrHelper;
AutoTableModel<AddressItem> *m_peopleModel;
bool m_bindAddrCombo;
};
#endif // CAMPWIZARD_H

@ -89,6 +89,12 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QWidget" name="widget_3" native="true">
<property name="maximumSize">
<size>
<width>450</width>
<height>16777215</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
@ -118,12 +124,12 @@
</property>
<property name="minimumSize">
<size>
<width>450</width>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="title">
<string>New address</string>
<string>&amp;New address</string>
</property>
<property name="checkable">
<bool>true</bool>
@ -245,6 +251,12 @@
</item>
<item row="10" column="1">
<widget class="QComboBox" name="country">
<property name="maximumSize">
<size>
<width>450</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
@ -354,7 +366,7 @@
</size>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
@ -378,12 +390,22 @@
</widget>
</item>
<item>
<widget class="QTableView" name="tablePeople"/>
<widget class="QTableView" name="tablePeople">
<property name="minimumSize">
<size>
<width>380</width>
<height>0</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
<zorder>widget_9</zorder>
<zorder>tableView</zorder>
<zorder>tablePeople</zorder>
</widget>
</item>
</layout>

@ -5,6 +5,7 @@ AddressItem::AddressItem(QObject *parent) : QObject(parent)
{
m_id = 0;
m_price = 0;
m_owner = false;
}
int AddressItem::id() const
@ -86,3 +87,13 @@ void AddressItem::setAdbItem(const AddressbookDataPtr &adbItem)
{
m_adbItem = adbItem;
}
bool AddressItem::owner() const
{
return m_owner;
}
void AddressItem::setOwner(bool owner)
{
m_owner = owner;
}

@ -20,6 +20,7 @@ class AddressItem : public QObject
Q_PROPERTY(QString lastName READ lastName WRITE setLastName)
Q_PROPERTY(QString address READ address WRITE setAddress)
Q_PROPERTY(QDecDouble price READ price WRITE setPrice)
Q_PROPERTY(bool owner READ owner WRITE setOwner)
public:
explicit AddressItem(QObject *parent = 0);
@ -48,6 +49,9 @@ public:
AddressbookDataPtr adbItem() const;
void setAdbItem(const AddressbookDataPtr &adbItem);
bool owner() const;
void setOwner(bool owner);
private:
friend class odb::access;
#pragma db id auto
@ -60,6 +64,7 @@ private:
#pragma db not_null
QWeakPointer<CampData> m_campData;
PersonPricePtr m_personPrice;
bool m_owner;
};
#endif // ADDRESSITEM_H

@ -84,6 +84,11 @@ void CampData::addServiceItem(ServiceItemPtr serviceItem)
m_services.append(serviceItem);
}
void CampData::removeServiceItem(ServiceItemPtr serviceItem)
{
m_services.removeOne(serviceItem);
}
QOdbList<AddressItemPtr> CampData::people() const
{
return m_people;
@ -99,6 +104,11 @@ void CampData::addPerson(AddressItemPtr person)
m_people.append(person);
}
void CampData::removePerson(AddressItemPtr person)
{
m_people.removeOne(person);
}
QDecDouble CampData::totalPrice() const
{
return TO_DEC(m_totalPrice);

@ -48,10 +48,12 @@ public:
QOdbList<QSharedPointer<ServiceItem> > services() const;
void setServices(const QOdbList<QSharedPointer<ServiceItem> > &services);
void addServiceItem(ServiceItemPtr serviceItem);
void removeServiceItem(ServiceItemPtr serviceItem);
QOdbList<AddressItemPtr> people() const;
void setPeople(const QOdbList<AddressItemPtr> &people);
void addPerson(AddressItemPtr person);
void removePerson(AddressItemPtr person);
QDecDouble totalPrice() const;
void setTotalPrice(QDecDouble totalPrice);

Loading…
Cancel
Save