Implement canceling of adding pages. Implement code for record display and adding.
This commit is contained in:
@@ -71,7 +71,7 @@ Kirigami.ApplicationWindow {
|
||||
text: qsTr("Examine Logs")
|
||||
iconName: "edit-find"
|
||||
onTriggered: {
|
||||
//
|
||||
router.navigateToRoute(["main", {"route": "servicerecords", "data": {"id": id, "name": name}}]);
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -129,7 +129,7 @@ Kirigami.ApplicationWindow {
|
||||
Controls.TextField {
|
||||
id: nameField
|
||||
selectByMouse: true
|
||||
Kirigami.FormData.label: qsTr("Name")+":"
|
||||
Kirigami.FormData.label: qsTr("Vehicle Name")+":"
|
||||
}
|
||||
|
||||
Controls.TextField {
|
||||
@@ -161,12 +161,143 @@ Kirigami.ApplicationWindow {
|
||||
Kirigami.FormData.label: qsTr("VIN")+":"
|
||||
}
|
||||
|
||||
Controls.Button {
|
||||
text: qsTr("Add")
|
||||
highlighted: true
|
||||
onClicked: {
|
||||
vehicleModel.addNewVehicle(nameField.text, makeField.text, modelField.text, parseInt(yearField.text), "", vinField.text);
|
||||
router.popRoute();
|
||||
Layouts.RowLayout {
|
||||
|
||||
Controls.Button {
|
||||
text: qsTr("Add")
|
||||
highlighted: true
|
||||
onClicked: {
|
||||
vehicleModel.addNewVehicle(nameField.text, makeField.text, modelField.text, parseInt(yearField.text), "", vinField.text);
|
||||
router.popRoute();
|
||||
}
|
||||
}
|
||||
|
||||
Controls.Button {
|
||||
text: qsTr("Cancel")
|
||||
onClicked: {
|
||||
router.popRoute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.PageRoute {
|
||||
name: "servicerecords"
|
||||
Component {
|
||||
Kirigami.ScrollablePage {
|
||||
property var serviceId: Kirigami.PageRouter.data.id
|
||||
Component.onCompleted: {
|
||||
recordModel.changeVehicleFilter(serviceId);
|
||||
}
|
||||
id: serviceRecordPage
|
||||
title: qsTr("Service Records for ") + Kirigami.PageRouter.data.name
|
||||
mainAction: Kirigami.Action {
|
||||
text: qsTr("Add Service Record")
|
||||
iconName: "list-add"
|
||||
onTriggered: {
|
||||
router.pushRoute({"route": "addrecord", "data": serviceId});
|
||||
}
|
||||
}
|
||||
ListView {
|
||||
id: serviceView
|
||||
model: recordModel
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
contentItem: Layouts.ColumnLayout {
|
||||
Controls.Label {
|
||||
text: serviceprovider
|
||||
}
|
||||
Controls.Label {
|
||||
text: servicetype
|
||||
}
|
||||
Controls.Label {
|
||||
text: servicedate
|
||||
}
|
||||
Controls.Label {
|
||||
text: miles
|
||||
}
|
||||
Controls.Label {
|
||||
text: notes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.PageRoute {
|
||||
name: "addrecord"
|
||||
Component {
|
||||
Kirigami.Page {
|
||||
id: recordAddPage
|
||||
title: qsTr("Add Service Record")
|
||||
Layouts.ColumnLayout {
|
||||
anchors.fill: parent
|
||||
Kirigami.FormLayout {
|
||||
Layouts.Layout.alignment: Qt.AlignHCenter
|
||||
Layouts.Layout.fillWidth: true
|
||||
width: recordAddPage.width
|
||||
|
||||
Item {
|
||||
Kirigami.FormData.isSection: true
|
||||
Kirigami.FormData.label: "Service Information"
|
||||
}
|
||||
|
||||
Controls.TextField {
|
||||
id: providerField
|
||||
selectByMouse: true
|
||||
Kirigami.FormData.label: qsTr("Service Provider")+":"
|
||||
}
|
||||
|
||||
Controls.TextField {
|
||||
id: typeField
|
||||
selectByMouse: true
|
||||
Kirigami.FormData.label: qsTr("Service Type")+":"
|
||||
}
|
||||
|
||||
Controls.TextField {
|
||||
id: dateField
|
||||
selectByMouse: true
|
||||
Kirigami.FormData.label: qsTr("Date")+":"
|
||||
inputMethodHints: Qt.ImhDate //TODO: implement better input
|
||||
}
|
||||
|
||||
Controls.TextField {
|
||||
id: milesField
|
||||
selectByMouse: true
|
||||
Kirigami.FormData.label: qsTr("Miles")+":"
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
validator: IntValidator {
|
||||
bottom: 0
|
||||
top: 400000
|
||||
}
|
||||
}
|
||||
|
||||
Controls.TextField {
|
||||
id: notesField
|
||||
selectByMouse: true
|
||||
Kirigami.FormData.label: qsTr("Notes")+":"
|
||||
}
|
||||
|
||||
Layouts.RowLayout {
|
||||
|
||||
Controls.Button {
|
||||
text: qsTr("Add")
|
||||
highlighted: true
|
||||
onClicked: {
|
||||
recordModel.addNewRecord(providerField.text, typeField.text, -1, parseInt(milesField.text), notesField.text); //TODO: add proper date
|
||||
router.popRoute();
|
||||
}
|
||||
}
|
||||
Controls.Button {
|
||||
text: qsTr("Cancel")
|
||||
onClicked: {
|
||||
router.popRoute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,47 @@ QVariant SqlServiceRecord::data ( const QModelIndex& index, int role ) const
|
||||
return value;
|
||||
}
|
||||
|
||||
void SqlServiceRecord::addNewRecord(QString serviceProvider, QString serviceType, qlonglong dateEpoch, int miles, QString notes)
|
||||
{
|
||||
QSqlRecord newItem = this->record();
|
||||
newItem.setValue("vehicle", this->currentVehicleID);
|
||||
newItem.setValue("serviceprovider", serviceProvider);
|
||||
newItem.setValue("servicetype", serviceType);
|
||||
newItem.setValue("servicedate", dateEpoch);
|
||||
newItem.setValue("miles", miles);
|
||||
newItem.setValue("notes", notes);
|
||||
this->insertRecord(-1, newItem);
|
||||
if(this->submitAll()) {
|
||||
printf("inserted new service record");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
this->database().rollback();
|
||||
printf("database error");
|
||||
}
|
||||
}
|
||||
|
||||
void SqlServiceRecord::removeRecord(int index)
|
||||
{
|
||||
this->removeRow(index);
|
||||
if(this->submitAll()) {
|
||||
printf("removed service record");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
this->database().rollback();
|
||||
printf("database error");
|
||||
}
|
||||
}
|
||||
|
||||
void SqlServiceRecord::changeVehicleFilter(int id)
|
||||
{
|
||||
this->setFilter("vehicle='"+QString::number(id)+"'");
|
||||
this->select();
|
||||
this->currentVehicleID = id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,12 @@ public:
|
||||
explicit 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(QString serviceProvider, QString serviceType, qlonglong dateEpoch, int miles, QString notes);
|
||||
Q_INVOKABLE void removeRecord(int index);
|
||||
Q_INVOKABLE void changeVehicleFilter(int id);
|
||||
|
||||
private:
|
||||
int currentVehicleID = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -70,14 +70,14 @@ void SqlVehicle::addNewVehicle ( const QString name, const QString maker, const
|
||||
this->database().rollback();
|
||||
printf("database error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SqlVehicle::removeVehicle(int index)
|
||||
{
|
||||
//TODO: remove any service records related
|
||||
this->removeRow(index);
|
||||
if(this->submitAll()) {
|
||||
printf("inserted new vehicle record");
|
||||
printf("removed vehicle record");
|
||||
this->database().commit();
|
||||
this->select();
|
||||
} else {
|
||||
|
||||
@@ -59,7 +59,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
//Create table structure
|
||||
db.open();
|
||||
db.exec("CREATE TABLE vehicles (id INTEGER PRIMARY KEY, name TEXT, maker TEXT, vmodel TEXT, year INTEGER, image TEXT, vin TEXT);");
|
||||
db.exec("CREATE TABLE records (id INTEGER PRIMARY KEY, servicetype TEXT, date INTEGER, miles INTEGER, notes TEXT);");
|
||||
db.exec("CREATE TABLE records (id INTEGER PRIMARY KEY, vehicle INTEGER, serviceprovider TEXT, servicetype TEXT, servicedate INTEGER, miles INTEGER, notes TEXT);");
|
||||
db.commit();
|
||||
db.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user