From 373d7609d1c2c3e2cf81d5c4608b8bd52c52a1f8 Mon Sep 17 00:00:00 2001 From: John Janus Date: Mon, 27 Feb 2017 16:38:28 +0100 Subject: [PATCH 1/1] Initial commit --- .gitignore | 73 +++++++++++++++++++++++++++++++++++++++++++ AddHuman.qml | 23 ++++++++++++++ UserSheets.pro | 33 +++++++++++++++++++ database.cpp | 49 +++++++++++++++++++++++++++++ database.h | 37 ++++++++++++++++++++++ main.cpp | 16 ++++++++++ main.qml | 23 ++++++++++++++ qml.qrc | 7 +++++ qtquickcontrols2.conf | 15 +++++++++ 9 files changed, 276 insertions(+) create mode 100644 .gitignore create mode 100644 AddHuman.qml create mode 100644 UserSheets.pro create mode 100644 database.cpp create mode 100644 database.h create mode 100644 main.cpp create mode 100644 main.qml create mode 100644 qml.qrc create mode 100644 qtquickcontrols2.conf 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/AddHuman.qml b/AddHuman.qml new file mode 100644 index 0000000..0eae420 --- /dev/null +++ b/AddHuman.qml @@ -0,0 +1,23 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Layouts 1.0 + +ApplicationWindow { + id: root + //width: 200 + //height: 200 + Text{ + id: lblname + anchors.left: parent.left + anchors.verticalCenter: name.verticalCenter + text:qsTr("Name: ") + } + + TextField { + id: name + anchors.left: lblname.right + anchors.top: parent.top + placeholderText: qsTr("Karl-Heinz") + } + +} diff --git a/UserSheets.pro b/UserSheets.pro new file mode 100644 index 0000000..9e2b8c6 --- /dev/null +++ b/UserSheets.pro @@ -0,0 +1,33 @@ +QT += qml quick sql + +CONFIG += c++11 + +SOURCES += main.cpp \ + database.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 += \ + database.h diff --git a/database.cpp b/database.cpp new file mode 100644 index 0000000..1deeb70 --- /dev/null +++ b/database.cpp @@ -0,0 +1,49 @@ +#include "database.h" +#include +#include + +DataBase::DataBase(QObject *parent) : QObject(parent) +{ + db = QSqlDatabase::addDatabase("QSQLITE"); + db.setDatabaseName("usersheets.db"); + if (!db.open()) { + //do stuff + } + qDebug() << initDB(); + +} + +DataBase::~DataBase() +{ + +} + +QVariant DataBase::addHuman(const QString& name, const QString& firstname, const QDate& birthday) +{ + QSqlQuery q; + +} + +QVariant DataBase::addService(const QString& name, const QUrl& url, const QString& description) +{ + +} + +QVariant DataBase::addUser(const QVariant& humanID, const QVariant& serviceID, const QString& username, const QString& password) +{ + +} + +QSqlError DataBase::initDB() +{ + QStringList tables = db.tables(); + QSqlQuery q; + if (!tables.contains("human", Qt::CaseSensitivity::CaseInsensitive)){ if (!q.exec(this->sqlCreateHumanTable)) return q.lastError();} + else qDebug() << "table human already created"; + if (!tables.contains("service", Qt::CaseSensitivity::CaseInsensitive)){ if (!q.exec(this->sqlCreateServiceTable)) return q.lastError();} + else qDebug() << "table service already created"; + if (!tables.contains("user", Qt::CaseSensitivity::CaseInsensitive)){ if (!q.exec(this->sqlCreateUserTable)) return q.lastError();} + else qDebug() << "table user already created"; + + return QSqlError(); +} diff --git a/database.h b/database.h new file mode 100644 index 0000000..ab1a156 --- /dev/null +++ b/database.h @@ -0,0 +1,37 @@ +#ifndef DATABASE_H +#define DATABASE_H +#include +#include +#include +#include +#include +#include + +class DataBase : public QObject +{ + Q_OBJECT +public: + explicit DataBase(QObject *parent = 0); + virtual ~DataBase(); + +signals: + +public slots: + QVariant addHuman(const QString& name, const QString& firstname, const QDate& birthday); + QVariant addService(const QString& name, const QUrl& url, const QString& description); + QVariant addUser(const QVariant& humanID, const QVariant& serviceID, const QString& username, const QString& password); + + +private: + QSqlError initDB(); + + QSqlDatabase db; + QLatin1String sqlCreateHumanTable = QLatin1String("create table human(id integer primary key, name varchar, firstname varchar, birthday date)"); + QLatin1String sqlCreateServiceTable = QLatin1String("create table service(id integer primary key, name varchar, url varchar, desription varchar)"); + QLatin1String sqlCreateUserTable = QLatin1String( + "create table user(id integer primary key, humanid integer not null, serviceid integer not null, username varchar, password varchar," + "foreign key(humanid) references human(id)," + "foreign key(serviceid) references service(id))"); +}; + +#endif // DATABASE_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..cb3e89d --- /dev/null +++ b/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include "database.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QLatin1String("qrc:/main.qml"))); + DataBase db; + + + return app.exec(); +} diff --git a/main.qml b/main.qml new file mode 100644 index 0000000..8968866 --- /dev/null +++ b/main.qml @@ -0,0 +1,23 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Layouts 1.0 + +ApplicationWindow { + id: root + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + + Button { + id: btnaddhuman + anchors.centerIn: parent + visible: true + text: "Add Human" + onClicked: { + var addHumanDialog = Qt.createComponent("AddHuman.qml") + var window = addHumanDialog.createObject(root) + window.show(); + } + } +} diff --git a/qml.qrc b/qml.qrc new file mode 100644 index 0000000..3c1c2b5 --- /dev/null +++ b/qml.qrc @@ -0,0 +1,7 @@ + + + main.qml + qtquickcontrols2.conf + AddHuman.qml + + diff --git a/qtquickcontrols2.conf b/qtquickcontrols2.conf new file mode 100644 index 0000000..1764b16 --- /dev/null +++ b/qtquickcontrols2.conf @@ -0,0 +1,15 @@ +; This file can be edited to change the style of the application +; See Styling Qt Quick Controls 2 in the documentation for details: +; http://doc.qt.io/qt-5/qtquickcontrols2-styles.html + +[Controls] +Style=Default + +[Universal] +Theme=Light +;Accent=Steel + +[Material] +Theme=Light +;Accent=BlueGrey +;Primary=BlueGray -- 2.47.0