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