From 4ba81e885e0268c75c01f0b922f4a3da3f6bcf05 Mon Sep 17 00:00:00 2001 From: John Janus Date: Wed, 7 Jun 2017 01:19:32 +0200 Subject: [PATCH] initial commit, nothing works --- .gitignore | 73 ++++++++++++++++++++++++++++++++++++++++++++ CleaningService.pro | 41 +++++++++++++++++++++++++ MainForm.ui.qml | 29 ++++++++++++++++++ Tests/tests.cpp | 6 ++++ Tests/tests.h | 17 +++++++++++ dbconn.cpp | 55 +++++++++++++++++++++++++++++++++ dbconn.h | 74 +++++++++++++++++++++++++++++++++++++++++++++ logging.cpp | 4 +++ logging.h | 11 +++++++ main.cpp | 14 +++++++++ main.qml | 16 ++++++++++ qml.qrc | 6 ++++ style.astylerc | 12 ++++++++ 13 files changed, 358 insertions(+) create mode 100644 .gitignore create mode 100644 CleaningService.pro create mode 100644 MainForm.ui.qml create mode 100644 Tests/tests.cpp create mode 100644 Tests/tests.h create mode 100644 dbconn.cpp create mode 100644 dbconn.h create mode 100644 logging.cpp create mode 100644 logging.h create mode 100644 main.cpp create mode 100644 main.qml create mode 100644 qml.qrc create mode 100644 style.astylerc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/CleaningService.pro b/CleaningService.pro new file mode 100644 index 0000000..b35ca2b --- /dev/null +++ b/CleaningService.pro @@ -0,0 +1,41 @@ +TEMPLATE = app + +QT += qml quick sql testlib +CONFIG += c++11 testcase + +SOURCES += main.cpp \ + dbconn.cpp \ + logging.cpp \ + Tests/tests.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +HEADERS += \ + dbconn.h \ + logging.h \ + Tests/tests.h + +DISTFILES += \ + style.astylerc diff --git a/MainForm.ui.qml b/MainForm.ui.qml new file mode 100644 index 0000000..f2cd99e --- /dev/null +++ b/MainForm.ui.qml @@ -0,0 +1,29 @@ +import QtQuick 2.7 + +Rectangle { + property alias mouseArea: mouseArea + property alias textEdit: textEdit + + width: 360 + height: 360 + + MouseArea { + id: mouseArea + anchors.fill: parent + } + + TextEdit { + id: textEdit + text: qsTr("Enter some text...") + verticalAlignment: Text.AlignVCenter + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 20 + Rectangle { + anchors.fill: parent + anchors.margins: -10 + color: "transparent" + border.width: 1 + } + } +} diff --git a/Tests/tests.cpp b/Tests/tests.cpp new file mode 100644 index 0000000..c493976 --- /dev/null +++ b/Tests/tests.cpp @@ -0,0 +1,6 @@ +#include "tests.h" + +Tests::Tests(QObject *parent) : QObject(parent) +{ + +} diff --git a/Tests/tests.h b/Tests/tests.h new file mode 100644 index 0000000..53fe24d --- /dev/null +++ b/Tests/tests.h @@ -0,0 +1,17 @@ +#ifndef TESTS_H +#define TESTS_H + +#include + +class Tests : public QObject +{ + Q_OBJECT +public: + explicit Tests(QObject *parent = nullptr); + +signals: + +public slots: +}; + +#endif // TESTS_H \ No newline at end of file diff --git a/dbconn.cpp b/dbconn.cpp new file mode 100644 index 0000000..da9e690 --- /dev/null +++ b/dbconn.cpp @@ -0,0 +1,55 @@ +#include "dbconn.h" +#include "logging.h" +#include +#include + +DbConn::DbConn (QObject* parent) : QObject (parent) +{ + db = QSqlDatabase::addDatabase ("QSQLITE"); + db.setDatabaseName ("cleaners.db"); + if (!db.open() ) { + qCCritical (dbase) << "Openeing database failed"; + } + qCDebug (dbase) << initDB(); +} + +QSqlError DbConn::initDB() const +{ + QStringList tables = db.tables(); + QSqlQuery q; + if (!tables.contains (this->tabNameCustomers, Qt::CaseSensitivity::CaseInsensitive) ) { + if (!q.exec (this->sqlCreateCustomerTable) ) return q.lastError(); + } + if (!tables.contains (this->tabNameServices, Qt::CaseSensitivity::CaseInsensitive) ) { + if (!q.exec (this->sqlCreateServicesTable) ) return q.lastError(); + } + if (!tables.contains (this->tabNameOrders, Qt::CaseSensitivity::CaseInsensitive) ) { + if (!q.exec (this->sqlCreateOrdersTable) ) return q.lastError(); + } + if (!tables.contains (this->tabNameOrderitems, Qt::CaseSensitivity::CaseInsensitive) ) { + if (!q.exec (this->sqlCreateOrderItemsTable) ) return q.lastError(); + } + if (!tables.contains (this->tabNameInvoices, Qt::CaseSensitivity::CaseInsensitive) ) { + if (!q.exec (this->sqlCreateInvoiceTable) ) return q.lastError(); + } + + return QSqlError(); +} + +void DbConn::addService (const QVariant& name, const QVariant& cost) const +{ + +} +void DbConn::addCustomer (const QVariant& name, const QVariant& street, const QVariant& number, + const QVariant& city, const QVariant& zip) const +{ + +} +void DbConn::addOrder (const QVariant& customerID, QVariant& date, QVariant& items) const +{ + +} +void DbConn::addInvoice (const QVariant& date, QVariant& OrderID) const +{ + +} diff --git a/dbconn.h b/dbconn.h new file mode 100644 index 0000000..241f315 --- /dev/null +++ b/dbconn.h @@ -0,0 +1,74 @@ +#ifndef DBCONN_H +#define DBCONN_H + +#include +#include +#include +#include + +class DbConn : public QObject +{ + Q_OBJECT + QSqlDatabase db; + QSqlError initDB() const; + const QLatin1String tabNameCustomers {"customers"}; + const QLatin1String tabNameOrders {"orders"}; + const QLatin1String tabNameOrderitems {"orderitems"}; + const QLatin1String tabNameInvoices{"invoices"}; + const QLatin1String tabNameServices{"services"}; + const QLatin1String sqlCreateCustomerTable { + "create table customers(" + "id integer primary key autoincrement," + "name text not null," + "street text," + "number text" + "city text," + "zip integer" + ")" + }; + const QLatin1String sqlCreateServicesTable { + "create table services(" + "id integer primary key autoincrement," + "name text," + "costs integer" + ")" + }; + const QLatin1String sqlCreateOrdersTable { + "create table orders(" + "id integer primary key autoincrement," + "customerid integer not null," + "date text" + "foreign key(customerid) references customers(id)" + ")" + }; + const QLatin1String sqlCreateOrderItemsTable { + "create table orderitems(" + "id integer primary key autoincrement," + "orderid integer," + "serviceid integer," + "foreign key(orderid) references orders(id)," + "foreign key(serviceid) references services(id)" + ")" + }; + const QLatin1String sqlCreateInvoiceTable { + "create table invoices(" + "id integer primary key autoincrement," + "orderid integer," + "date text," + "foreign key(orderid) references orders(id)" + ")" + }; +public: + explicit DbConn (QObject* parent = nullptr); + +signals: + +public slots: + void addService (const QVariant& name, const QVariant& cost) const; + void addCustomer (const QVariant& name, const QVariant& street, const QVariant& number, + const QVariant& city, const QVariant& zip) const; + void addOrder (const QVariant& customerID, QVariant& date, QVariant& items) const; + void addInvoice (const QVariant& date, QVariant& OrderID) const; +}; + +#endif // DBCONN_H diff --git a/logging.cpp b/logging.cpp new file mode 100644 index 0000000..408b1ec --- /dev/null +++ b/logging.cpp @@ -0,0 +1,4 @@ +#include "logging.h" + + +Q_LOGGING_CATEGORY (dbase, "database") diff --git a/logging.h b/logging.h new file mode 100644 index 0000000..a022884 --- /dev/null +++ b/logging.h @@ -0,0 +1,11 @@ +#ifndef LOGGING_H +#define LOGGING_H +#include +#include + +const QtMsgType loglevel = QtMsgType::QtWarningMsg; +Q_DECLARE_LOGGING_CATEGORY (dbase) + + + +#endif // LOGGING_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..82fa785 --- /dev/null +++ b/main.cpp @@ -0,0 +1,14 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/main.qml b/main.qml new file mode 100644 index 0000000..518666f --- /dev/null +++ b/main.qml @@ -0,0 +1,16 @@ +import QtQuick 2.7 +import QtQuick.Window 2.2 + +Window { + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + + MainForm { + anchors.fill: parent + mouseArea.onClicked: { + console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"')) + } + } +} diff --git a/qml.qrc b/qml.qrc new file mode 100644 index 0000000..7684346 --- /dev/null +++ b/qml.qrc @@ -0,0 +1,6 @@ + + + main.qml + MainForm.ui.qml + + diff --git a/style.astylerc b/style.astylerc new file mode 100644 index 0000000..5706c31 --- /dev/null +++ b/style.astylerc @@ -0,0 +1,12 @@ +--style=kr #mozilla +#-s2 -p -d -H -k1 -c -xy -xC120 -xL +indent=spaces=2 +pad-oper +pad-paren-out +pad-header +align-pointer=type +convert-tabs +#close-templates +max-code-length=120 +#indent-continuation=2 +#pad-comma -- 2.47.1