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
|
||||
db/sqlvehicle.cpp
|
||||
db/sqlservicerecord.cpp
|
||||
jsonio.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick 2.14
|
||||
import org.kde.kirigami 2.12 as Kirigami
|
||||
import QtQuick.Controls 2.9 as Controls
|
||||
import QtQuick.Layouts 1.12 as Layouts
|
||||
import QtQuick.Controls 2.14 as Controls
|
||||
import QtQuick.Layouts 1.14 as Layouts
|
||||
import QtQuick.Controls 1.4 as Old
|
||||
import QtQuick.Dialogs 1.3 as Dialogs
|
||||
|
||||
Kirigami.ApplicationWindow {
|
||||
id: root
|
||||
@@ -38,6 +39,13 @@ Kirigami.ApplicationWindow {
|
||||
}
|
||||
}
|
||||
contextualActions: [
|
||||
Kirigami.Action {
|
||||
iconName: "application-javascript"
|
||||
text: qsTr("Import From Carfax")
|
||||
onTriggered: {
|
||||
importDialog.visible = true;
|
||||
}
|
||||
},
|
||||
Kirigami.Action {
|
||||
iconName: "help-about"
|
||||
text: qsTr("About")
|
||||
@@ -47,6 +55,14 @@ Kirigami.ApplicationWindow {
|
||||
}
|
||||
]
|
||||
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 {
|
||||
anchors.fill: parent
|
||||
id: vehicleView
|
||||
@@ -56,21 +72,34 @@ Kirigami.ApplicationWindow {
|
||||
banner {
|
||||
title: name
|
||||
}
|
||||
header: Row {
|
||||
layoutDirection: Qt.RightToLeft
|
||||
header: Row{
|
||||
topPadding: 10.0
|
||||
rightPadding: 10.0
|
||||
leftPadding: 10.0
|
||||
layoutDirection: Qt.RightToLeft
|
||||
spacing: 5
|
||||
Controls.Label {
|
||||
text: vin
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Image {
|
||||
source: "qrc:/license.svg"
|
||||
sourceSize.width: 32
|
||||
sourceSize.height: 32
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Controls.Label {
|
||||
text: vin
|
||||
visible: root.wideScreen && mainPage.width > 550
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
Image {
|
||||
id: vinIcon
|
||||
source: "qrc:/license.svg"
|
||||
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{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
newItem.setValue("vehicle", this->currentVehicleID);
|
||||
newItem.setValue("vehicle", vehicleId);
|
||||
newItem.setValue("serviceprovider", serviceProvider);
|
||||
newItem.setValue("servicetype", serviceType);
|
||||
newItem.setValue("servicetypename", serviceTypeName);
|
||||
@@ -63,12 +68,12 @@ void SqlServiceRecord::addNewRecord(QString serviceProvider, int serviceType, QS
|
||||
newItem.setValue("notes", notes);
|
||||
this->insertRecord(-1, newItem);
|
||||
if(this->submitAll()) {
|
||||
printf("inserted new service record");
|
||||
printf("inserted new service record\n");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
this->database().rollback();
|
||||
printf("database error");
|
||||
printf("database error\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,12 +81,12 @@ void SqlServiceRecord::removeRecord(int index)
|
||||
{
|
||||
this->removeRow(index);
|
||||
if(this->submitAll()) {
|
||||
printf("removed service record");
|
||||
printf("removed service record\n");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
this->database().rollback();
|
||||
printf("database error");
|
||||
printf("database error\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,10 @@ class SqlServiceRecord : public QSqlTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SqlServiceRecord(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
||||
SqlServiceRecord(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
||||
QHash<int, QByteArray> roleNames() 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 removeRecord(int index);
|
||||
Q_INVOKABLE void changeVehicleFilter(int id);
|
||||
|
||||
@@ -64,12 +64,12 @@ void SqlVehicle::addNewVehicle ( const QString name, const QString maker, const
|
||||
newItem.setValue("vin", vin);
|
||||
this->insertRecord(-1, newItem);
|
||||
if(this->submitAll()) {
|
||||
printf("inserted new vehicle record");
|
||||
printf("inserted new vehicle record\n");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
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->removeRow(index);
|
||||
if(this->submitAll()) {
|
||||
printf("removed vehicle record");
|
||||
printf("removed vehicle record\n");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
this->database().rollback();
|
||||
printf("database error");
|
||||
printf("database error\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class SqlVehicle : public QSqlTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SqlVehicle(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
||||
SqlVehicle(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase());
|
||||
QHash<int, QByteArray> roleNames() 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);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QQmlContext>
|
||||
#include "db/sqlvehicle.h"
|
||||
#include "db/sqlservicerecord.h"
|
||||
#include "jsonio.h"
|
||||
|
||||
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.
|
||||
vehicles.select();
|
||||
records.select();
|
||||
JsonIO converter(&vehicles, &records);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("appAboutData"), QVariant::fromValue(aboutData));
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("vehicleModel"), &vehicles);
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("recordModel"), &records);
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("jsonConverter"), &converter);
|
||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||
|
||||
if (engine.rootObjects().isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user