Commit 4b47bea2 authored by Camilo higuita's avatar Camilo higuita

modeling fices and some issues with control style under android

parent 12a65d17
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.1, 2019-03-01T22:41:41. -->
<!-- Written by QtCreator 4.8.2, 2019-03-08T09:09:18. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -78,9 +78,17 @@ bool DBActions::removeContact(const QString &id)
return this->execQuery(queryTxt);
}
bool DBActions::updateContact(const FMH::MODEL &con)
{
auto contact = con;
contact.insert(FMH::MODEL_KEY::MODIFIED, QDateTime::currentDateTime().toString(Qt::TextDate));
QVariantMap where = {{FMH::MODEL_NAME[FMH::MODEL_KEY::ID], con[FMH::MODEL_KEY::ID]}};
return this->update(UNI::TABLEMAP[UNI::TABLE::CONTACTS], con, where);
}
bool DBActions::favContact(const QString &id, const bool &fav )
{
if(!this->checkExistance("contacts", "id", id))
if(!this->checkExistance(UNI::TABLEMAP[UNI::TABLE::CONTACTS], FMH::MODEL_NAME[FMH::MODEL_KEY::ID], id))
return false;
const FMH::MODEL faved = {{FMH::MODEL_KEY::FAV, fav ? "1" : "0"}};
......
......@@ -41,6 +41,7 @@ public:
bool insertContact(const FMH::MODEL &con);
bool removeContact(const QString &id);
bool updateContact(const FMH::MODEL &con);
/* utils */
FMH::MODEL_LIST getDBData(const QString &queryTxt);
......
#include "synchroniser.h"
#include "./../db/dbactions.h"
#include "vcardproperty.h"
#include "vcard.h"
Synchroniser::Synchroniser(QObject *parent) : QObject (parent)
{
......@@ -15,10 +14,20 @@ FMH::MODEL_LIST Synchroniser::getContacts(const QString &query)
}
bool Synchroniser::insertContact(const FMH::MODEL &contact)
{
return this->dba->insertContact(contact);
}
bool Synchroniser::updateContact(const FMH::MODEL &contact)
{
return this->dba->updateContact(contact);
}
vCard Synchroniser::tovCard(const FMH::MODEL &contact)
{
Q_UNUSED(contact);
vCard vcard;
vCardProperty name_prop = vCardProperty::createName("Emanuele", "Bertoldi");
vcard.addProperty(name_prop);
return this->dba->insertContact(contact);
return vcard;
}
......@@ -8,6 +8,9 @@
#include <MauiKit/fmh.h>
#endif
#include "vcard.h"
class DBActions;
class Synchroniser : public QObject
{
......@@ -17,9 +20,12 @@ public:
FMH::MODEL_LIST getContacts(const QString &query);
bool insertContact(const FMH::MODEL &contact);
bool updateContact(const FMH::MODEL &contact);
private:
DBActions *dba;
vCard tovCard(const FMH::MODEL &contact);
signals:
public slots:
......
......@@ -2,7 +2,7 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
// #include <QQuickStyle>
#include <QQuickStyle>
#include <QIcon>
#include <QCommandLineParser>
#include <QFileInfo>
......@@ -46,6 +46,7 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
// QQuickStyle::setStyle("Material");
#ifdef STATIC_KIRIGAMI
KirigamiPlugin::getInstance().registerTypes();
......@@ -53,6 +54,7 @@ int main(int argc, char *argv[])
#ifdef STATIC_MAUIKIT
MauiKit::getInstance().registerTypes();
#endif
qmlRegisterUncreatableType<BaseList>("UnionModels", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
......
......@@ -105,7 +105,12 @@ Maui.ApplicationWindow
EditContactDialog
{
id: _newContactDialog
onNewContact: _contacsView.list.insert(contact)
onNewContact:
{
var con = contact;
con["id"] = Math.random();
_contacsView.list.insert(con)
}
}
Maui.FileDialog
......
......@@ -144,6 +144,31 @@ bool ContactsModel::insert(const QVariantMap &map)
return true;
}
bool ContactsModel::update(const QVariantMap &map, const int &index)
{
if(index >= this->list.size() || index < 0)
return false;
const auto newItem = FM::toModel(map);
const auto oldItem = this->list[index];
if(this->syncer->updateContact(newItem))
{
QVector<int> roles;
for(auto key : newItem.keys())
if(newItem[key] != oldItem[key])
roles << key;
this->list[index] = newItem;
emit this->updateModel(index, roles);
return true;
}
return false;
}
void ContactsModel::append(const QVariantMap &item)
{
if(item.isEmpty())
......
......@@ -58,6 +58,8 @@ signals:
public slots:
QVariantMap get(const int &index) const override;
bool insert(const QVariantMap &map) override;
bool update(const QVariantMap &map, const int &index) override;
void append(const QVariantMap &item, const int &at);
void append(const QVariantMap &item);
void appendQuery(const QString &query);
......
......@@ -73,7 +73,7 @@ ItemDelegate
smooth: true
asynchronous: true
source: "file://"+ model.photo
source: /*"file://"+ */model.photo
layer.enabled: true
layer.effect: OpacityMask
......
......@@ -16,13 +16,23 @@ Maui.Dialog
property var contact : ({})
acceptButton.text: qsTr("Edit")
rejectButton.visible: false
onAccepted: _editContactDialog.open()
onAccepted: _editContactDialog.show()
EditContactDialog
{
id: _editContactDialog
contact: control.contact
onNewContact:
{
var con = contact
var id = control.contact.id
con["id"] = id
console.log("trying to edit contact", id)
if(_contacsView.list.update(con, _contacsView.listView.currentIndex))
control.contact = _contacsView.list.get(_contacsView.listView.currentIndex)
}
}
ColumnLayout
......@@ -77,7 +87,7 @@ Maui.Dialog
smooth: true
asynchronous: true
source: "file://"+ contact.photo
source: contact.photo
layer.enabled: true
layer.effect: OpacityMask
......@@ -174,6 +184,7 @@ Maui.Dialog
{
anchors.fill: parent
contentHeight: _formLayout.implicitHeight
clip: true
ColumnLayout
{
id: _formLayout
......@@ -201,7 +212,7 @@ Maui.Dialog
Layout.fillWidth: true
width: parent.width
text: contact.n
text: contact.n.split(" ")[0]
font.pointSize: fontSizes.big
font.weight: Font.Bold
color: textColor
......@@ -228,7 +239,7 @@ Maui.Dialog
{
Layout.fillHeight: true
Layout.fillWidth: true
text: contact.n.split(" ")[1]
text: contact.n.split(" ")[1] ? contact.n.split(" ")[1] : ""
font.pointSize: fontSizes.big
font.weight: Font.Bold
color: textColor
......
......@@ -10,6 +10,7 @@ Maui.Page
colorScheme.accentColor: "#615f7d"
property alias list : _contactsList
property alias listView : _listView
// floatingBar: true
// footBarMargins: space.huge
......
......@@ -24,13 +24,12 @@ Maui.Dialog
onAccepted:
{
var contact =({
id: Math.random(),
n: _nameField.text +" "+ _lastNameField.text,
tel: _telField.text,
email: _emailField.text,
org: _orgField.text,
adr: _adrField.text,
gender: _genreField.currentText,
gender: _genderField.currentText,
photo: _img.source
})
newContact(contact)
......@@ -133,10 +132,13 @@ Maui.Dialog
{
anchors.fill: parent
contentHeight: _formLayout.implicitHeight
clip: true
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ColumnLayout
{
id: _formLayout
width: parent.width
width: _layout.width * 0.95
// implicitHeight: control.height
spacing: space.large
Column
......@@ -155,8 +157,7 @@ Maui.Dialog
{
id: _nameField
width: parent.width
height: rowHeight
text: contact.n
text: contact.n.split(" ")[0]
}
}
......@@ -177,7 +178,7 @@ Maui.Dialog
{
id: _lastNameField
width: parent.width
text: contact.n.split(" ")[1]
text: contact.n.split(" ")[1] ? contact.n.split(" ")[1] : ""
}
}
......@@ -195,8 +196,11 @@ Maui.Dialog
ComboBox
{
id: _genreField
id: _genderField
width: parent.width
model: ["Male", "Female", "Other"]
popup.z: control.z+1
// currentText: contact.gender
}
}
......@@ -216,6 +220,7 @@ Maui.Dialog
{
id: _orgField
width: parent.width
text: contact.org
}
}
......@@ -236,6 +241,7 @@ Maui.Dialog
{
id: _telField
width: parent.width
text: contact.tel
}
}
......@@ -254,6 +260,7 @@ Maui.Dialog
Maui.TextField
{
width: parent.width
text: contact.tel
}
}
......@@ -273,6 +280,7 @@ Maui.Dialog
{
id: _emailField
width: parent.width
text: contact.email
}
}
......@@ -292,6 +300,7 @@ Maui.Dialog
{
id: _adrField
width: parent.width
text: contact.adr
}
}
}
......
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