Fix UI to work better on smaller screens. Implement first version of data import from carfax json.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
set(vehiclevoyage_SRCS
|
set(vehiclevoyage_SRCS
|
||||||
db/sqlvehicle.cpp
|
db/sqlvehicle.cpp
|
||||||
db/sqlservicerecord.cpp
|
db/sqlservicerecord.cpp
|
||||||
|
jsonio.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import QtQuick 2.9
|
import QtQuick 2.14
|
||||||
import org.kde.kirigami 2.12 as Kirigami
|
import org.kde.kirigami 2.12 as Kirigami
|
||||||
import QtQuick.Controls 2.9 as Controls
|
import QtQuick.Controls 2.14 as Controls
|
||||||
import QtQuick.Layouts 1.12 as Layouts
|
import QtQuick.Layouts 1.14 as Layouts
|
||||||
import QtQuick.Controls 1.4 as Old
|
import QtQuick.Controls 1.4 as Old
|
||||||
|
import QtQuick.Dialogs 1.3 as Dialogs
|
||||||
|
|
||||||
Kirigami.ApplicationWindow {
|
Kirigami.ApplicationWindow {
|
||||||
id: root
|
id: root
|
||||||
@@ -38,6 +39,13 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
contextualActions: [
|
contextualActions: [
|
||||||
|
Kirigami.Action {
|
||||||
|
iconName: "application-javascript"
|
||||||
|
text: qsTr("Import From Carfax")
|
||||||
|
onTriggered: {
|
||||||
|
importDialog.visible = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
iconName: "help-about"
|
iconName: "help-about"
|
||||||
text: qsTr("About")
|
text: qsTr("About")
|
||||||
@@ -47,6 +55,14 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
title: "Vehicles"
|
title: "Vehicles"
|
||||||
|
Dialogs.FileDialog {
|
||||||
|
id: importDialog
|
||||||
|
title: qsTr("Select Carfax Json file to import...")
|
||||||
|
nameFilters: ["Carfax Vehicle Json (*.json)"]
|
||||||
|
onAccepted: {
|
||||||
|
jsonConverter.importCarfaxJsonToDB(importDialog.fileUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
Kirigami.CardsListView {
|
Kirigami.CardsListView {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
id: vehicleView
|
id: vehicleView
|
||||||
@@ -56,21 +72,34 @@ Kirigami.ApplicationWindow {
|
|||||||
banner {
|
banner {
|
||||||
title: name
|
title: name
|
||||||
}
|
}
|
||||||
header: Row {
|
header: Row{
|
||||||
layoutDirection: Qt.RightToLeft
|
|
||||||
topPadding: 10.0
|
topPadding: 10.0
|
||||||
rightPadding: 10.0
|
rightPadding: 10.0
|
||||||
|
leftPadding: 10.0
|
||||||
|
layoutDirection: Qt.RightToLeft
|
||||||
spacing: 5
|
spacing: 5
|
||||||
Controls.Label {
|
Controls.Label {
|
||||||
text: vin
|
text: vin
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
visible: root.wideScreen && mainPage.width > 550
|
||||||
}
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
Image {
|
}
|
||||||
source: "qrc:/license.svg"
|
Image {
|
||||||
sourceSize.width: 32
|
id: vinIcon
|
||||||
sourceSize.height: 32
|
source: "qrc:/license.svg"
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
sourceSize.width: 32
|
||||||
}
|
sourceSize.height: 32
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
MouseArea {
|
||||||
|
id: vinMouse
|
||||||
|
hoverEnabled: true
|
||||||
|
anchors.fill: vinIcon
|
||||||
|
}
|
||||||
|
Controls.ToolTip {
|
||||||
|
id: vinTip
|
||||||
|
text: vin
|
||||||
|
visible: vinMouse.containsMouse
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
contentItem: Item{
|
contentItem: Item{
|
||||||
implicitHeight: Kirigami.Units.gridUnit * 4
|
implicitHeight: Kirigami.Units.gridUnit * 4
|
||||||
|
|||||||
@@ -52,9 +52,14 @@ QVariant SqlServiceRecord::data ( const QModelIndex& index, int role ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SqlServiceRecord::addNewRecord(QString serviceProvider, int serviceType, QString serviceTypeName, QString dateISO, int miles, QString notes)
|
void SqlServiceRecord::addNewRecord(QString serviceProvider, int serviceType, QString serviceTypeName, QString dateISO, int miles, QString notes)
|
||||||
|
{
|
||||||
|
this->addNewRecord(this->currentVehicleID, serviceProvider, serviceType, serviceTypeName, dateISO, miles, notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SqlServiceRecord::addNewRecord(int vehicleId, QString serviceProvider, int serviceType, QString serviceTypeName, QString dateISO, int miles, QString notes)
|
||||||
{
|
{
|
||||||
QSqlRecord newItem = this->record();
|
QSqlRecord newItem = this->record();
|
||||||
newItem.setValue("vehicle", this->currentVehicleID);
|
newItem.setValue("vehicle", vehicleId);
|
||||||
newItem.setValue("serviceprovider", serviceProvider);
|
newItem.setValue("serviceprovider", serviceProvider);
|
||||||
newItem.setValue("servicetype", serviceType);
|
newItem.setValue("servicetype", serviceType);
|
||||||
newItem.setValue("servicetypename", serviceTypeName);
|
newItem.setValue("servicetypename", serviceTypeName);
|
||||||
@@ -63,12 +68,12 @@ void SqlServiceRecord::addNewRecord(QString serviceProvider, int serviceType, QS
|
|||||||
newItem.setValue("notes", notes);
|
newItem.setValue("notes", notes);
|
||||||
this->insertRecord(-1, newItem);
|
this->insertRecord(-1, newItem);
|
||||||
if(this->submitAll()) {
|
if(this->submitAll()) {
|
||||||
printf("inserted new service record");
|
printf("inserted new service record\n");
|
||||||
this->database().commit();
|
this->database().commit();
|
||||||
this->select();
|
this->select();
|
||||||
} else {
|
} else {
|
||||||
this->database().rollback();
|
this->database().rollback();
|
||||||
printf("database error");
|
printf("database error\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,12 +81,12 @@ void SqlServiceRecord::removeRecord(int index)
|
|||||||
{
|
{
|
||||||
this->removeRow(index);
|
this->removeRow(index);
|
||||||
if(this->submitAll()) {
|
if(this->submitAll()) {
|
||||||
printf("removed service record");
|
printf("removed service record\n");
|
||||||
this->database().commit();
|
this->database().commit();
|
||||||
this->select();
|
this->select();
|
||||||
} else {
|
} else {
|
||||||
this->database().rollback();
|
this->database().rollback();
|
||||||
printf("database error");
|
printf("database error\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ class SqlServiceRecord : public QSqlTableModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SqlServiceRecord(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
SqlServiceRecord(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
|
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
Q_INVOKABLE void addNewRecord(int vehicleId, QString serviceProvider, int serviceType, QString serviceTypeName, QString dateISO, int miles, QString notes);
|
||||||
Q_INVOKABLE void addNewRecord(QString serviceProvider, int serviceType, QString serviceTypeName, QString dateISO, int miles, QString notes);
|
Q_INVOKABLE void addNewRecord(QString serviceProvider, int serviceType, QString serviceTypeName, QString dateISO, int miles, QString notes);
|
||||||
Q_INVOKABLE void removeRecord(int index);
|
Q_INVOKABLE void removeRecord(int index);
|
||||||
Q_INVOKABLE void changeVehicleFilter(int id);
|
Q_INVOKABLE void changeVehicleFilter(int id);
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ void SqlVehicle::addNewVehicle ( const QString name, const QString maker, const
|
|||||||
newItem.setValue("vin", vin);
|
newItem.setValue("vin", vin);
|
||||||
this->insertRecord(-1, newItem);
|
this->insertRecord(-1, newItem);
|
||||||
if(this->submitAll()) {
|
if(this->submitAll()) {
|
||||||
printf("inserted new vehicle record");
|
printf("inserted new vehicle record\n");
|
||||||
this->database().commit();
|
this->database().commit();
|
||||||
this->select();
|
this->select();
|
||||||
} else {
|
} else {
|
||||||
this->database().rollback();
|
this->database().rollback();
|
||||||
printf("database error");
|
printf("database error\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@ void SqlVehicle::removeVehicle(int index)
|
|||||||
this->database().exec("DELETE FROM records WHERE records.vehicle="+this->record(index).value("id").toString());
|
this->database().exec("DELETE FROM records WHERE records.vehicle="+this->record(index).value("id").toString());
|
||||||
this->removeRow(index);
|
this->removeRow(index);
|
||||||
if(this->submitAll()) {
|
if(this->submitAll()) {
|
||||||
printf("removed vehicle record");
|
printf("removed vehicle record\n");
|
||||||
this->database().commit();
|
this->database().commit();
|
||||||
this->select();
|
this->select();
|
||||||
} else {
|
} else {
|
||||||
this->database().rollback();
|
this->database().rollback();
|
||||||
printf("database error");
|
printf("database error\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class SqlVehicle : public QSqlTableModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SqlVehicle(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
SqlVehicle(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
|
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
|
||||||
Q_INVOKABLE void addNewVehicle(const QString name, const QString maker, const QString model, const int year, const QString image, const QString vin);
|
Q_INVOKABLE void addNewVehicle(const QString name, const QString maker, const QString model, const int year, const QString image, const QString vin);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include "db/sqlvehicle.h"
|
#include "db/sqlvehicle.h"
|
||||||
#include "db/sqlservicerecord.h"
|
#include "db/sqlservicerecord.h"
|
||||||
|
#include "jsonio.h"
|
||||||
|
|
||||||
Q_DECL_EXPORT int main(int argc, char *argv[])
|
Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -75,11 +76,13 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
|||||||
//Fill model with inital data.
|
//Fill model with inital data.
|
||||||
vehicles.select();
|
vehicles.select();
|
||||||
records.select();
|
records.select();
|
||||||
|
JsonIO converter(&vehicles, &records);
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("appAboutData"), QVariant::fromValue(aboutData));
|
engine.rootContext()->setContextProperty(QStringLiteral("appAboutData"), QVariant::fromValue(aboutData));
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("vehicleModel"), &vehicles);
|
engine.rootContext()->setContextProperty(QStringLiteral("vehicleModel"), &vehicles);
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("recordModel"), &records);
|
engine.rootContext()->setContextProperty(QStringLiteral("recordModel"), &records);
|
||||||
|
engine.rootContext()->setContextProperty(QStringLiteral("jsonConverter"), &converter);
|
||||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||||
|
|
||||||
if (engine.rootObjects().isEmpty()) {
|
if (engine.rootObjects().isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user