HEADERS += \
database.h \
controller.h
+
+DISTFILES += style.astylrc
#include <QDebug>
#include <QQuickWindow>
-Controller::Controller(DataBase* d, QObject *parent) :
- QObject(parent),
+Controller::Controller (DataBase* d, QObject* parent) :
+ QObject (parent),
db{d}
{
engine = new QQmlApplicationEngine();
- this->engine->load(QUrl(QLatin1String("qrc:/main.qml")));
+ this->engine->load (QUrl (QLatin1String ("qrc:/main.qml") ) );
//connect qml Signals to controller
QList<QObject*> roots = engine->rootObjects();
QObject* qmlRoot = roots.first();
- QObject::connect(qmlRoot,SIGNAL(openAddHuman()),
- this, SLOT(openAddHuman()));
+ QObject::connect (qmlRoot, SIGNAL (openAddHuman() ),
+ this, SLOT (openAddHuman() ) );
- QObject::connect(qmlRoot, SIGNAL(openAddService()),
- this, SLOT(openAddService()));
+ QObject::connect (qmlRoot, SIGNAL (openAddService() ),
+ this, SLOT (openAddService() ) );
}
void Controller::openAddHuman()
{
- QQmlComponent component(engine, QUrl(QStringLiteral("qrc:/addhuman.qml")), QQmlComponent::PreferSynchronous);
+ QQmlComponent component (engine, QUrl (QStringLiteral ("qrc:/addhuman.qml") ), QQmlComponent::PreferSynchronous,
+ engine->rootObjects().first() );
- if (component.isReady()) {
+ if (component.isReady() ) {
QObject* dialog = component.create();
- QQmlEngine::setObjectOwnership(dialog, QQmlEngine::CppOwnership);
- dialog->setParent(engine->rootObjects().first());
- QObject::connect(dialog, SIGNAL(addHuman(QVariant, QVariant, QVariant)),
- db, SLOT(addHuman(QVariant, QVariant, QVariant)));
+ QQmlEngine::setObjectOwnership (dialog, QQmlEngine::CppOwnership);
+ QObject::connect (dialog, SIGNAL (addHuman (QVariant, QVariant, QVariant) ),
+ db, SLOT (addHuman (QVariant, QVariant, QVariant) ) );
} else {
qDebug() << "Dialog not loaded";
}
+
}
void Controller::openAddService()
{
- QQmlComponent component(engine, QUrl(QStringLiteral("qrc:/addservice.qml")), QQmlComponent::PreferSynchronous);
+ QQmlComponent component (engine, QUrl (QStringLiteral ("qrc:/addservice.qml") ), QQmlComponent::PreferSynchronous,
+ engine->rootObjects().first() );
- if (component.isReady()) {
+ if (component.isReady() ) {
QObject* dialog = component.create();
- QQmlEngine::setObjectOwnership(dialog, QQmlEngine::CppOwnership);
- dialog->setParent(engine->rootObjects().first());
- QObject::connect(dialog, SIGNAL(addService(QVariant, QVariant, QVariant)),
- db, SLOT(addService(QVariant, QVariant, QVariant)));
+ QQmlEngine::setObjectOwnership (dialog, QQmlEngine::CppOwnership);
+ QObject::connect (dialog, SIGNAL (addService (QVariant, QVariant, QVariant) ),
+ db, SLOT (addService (QVariant, QVariant, QVariant) ) );
} else {
- qDebug()<<"Dialog not loaded";
+ qDebug() << "Dialog not loaded";
}
}
{
Q_OBJECT
public:
- explicit Controller(DataBase* db, QObject *parent = 0);
+ explicit Controller (DataBase* db, QObject* parent = 0);
virtual ~Controller();
signals:
#include <QDebug>
#include <QDate>
-DataBase::DataBase(QObject *parent) : QObject(parent)
+DataBase::DataBase (QObject* parent) : QObject (parent)
{
- db = QSqlDatabase::addDatabase("QSQLITE");
- db.setDatabaseName("usersheets.db");
- if (!db.open()) {
- //do stuff
- }
- qDebug() << initDB();
+ db = QSqlDatabase::addDatabase ("QSQLITE");
+ db.setDatabaseName ("usersheets.db");
+ if (!db.open() ) {
+ //do stuff
+ }
+ qDebug() << initDB();
}
}
-void DataBase::addHuman(const QVariant& name, const QVariant& firstname,
- const QVariant& birthday)
+void DataBase::addHuman (const QVariant& name, const QVariant& firstname,
+ const QVariant& birthday)
{
- qDebug()<<"addHuman slot called with: "<<name<<", "<<firstname<<", "<< birthday;
+ qDebug() << "addHuman slot called with: " << name << ", " << firstname << ", " << birthday;
QSqlQuery q;
- if (!q.prepare(this->sqlAddHuman)) qDebug() << "error while preparing: " << q.lastError();
- q.addBindValue(name.toString());
- q.addBindValue(firstname.toString());
- q.addBindValue(birthday.toDate());
- if (!q.exec())qDebug()<<"error: "<< q.lastError();
+ if (!q.prepare (this->sqlAddHuman) ) qDebug() << "error while preparing: " << q.lastError();
+ q.addBindValue (name.toString() );
+ q.addBindValue (firstname.toString() );
+ q.addBindValue (birthday.toDate() );
+ if (!q.exec() ) qDebug() << "error: " << q.lastError();
}
-void DataBase::addService(const QVariant& name, const QVariant& url,
- const QVariant& description)
+void DataBase::addService (const QVariant& name, const QVariant& url,
+ const QVariant& description)
{
- qDebug()<<"addService slot called with: "<<name<<", "<<url<<", "<< description;
+ qDebug() << "addService slot called with: " << name << ", " << url << ", " << description;
QSqlQuery q;
- if (!q.prepare(this->sqlAddService)) qDebug() << "error while preparing: " << q.lastError();
- q.addBindValue(name.toString());
- q.addBindValue(url.toUrl());
- q.addBindValue(description.toString());
- if (!q.exec())qDebug()<<"error: "<< q.lastError();
+ if (!q.prepare (this->sqlAddService) ) qDebug() << "error while preparing: " << q.lastError();
+ q.addBindValue (name.toString() );
+ q.addBindValue (url.toUrl() );
+ q.addBindValue (description.toString() );
+ if (!q.exec() ) qDebug() << "error: " << q.lastError();
}
-void DataBase::addUser(const QVariant& humanID, const QVariant& serviceID,
- const QString& username, const QString& password)
+void DataBase::addUser (const QVariant& humanID, const QVariant& serviceID,
+ const QString& username, const QString& password)
{
QSqlQuery q;
- q.prepare(this->sqlAddUser);
- q.addBindValue(humanID);
- q.addBindValue(serviceID);
- q.addBindValue(username);
- q.addBindValue(password);
+ q.prepare (this->sqlAddUser);
+ q.addBindValue (humanID);
+ q.addBindValue (serviceID);
+ q.addBindValue (username);
+ q.addBindValue (password);
q.exec();
}
{
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";
+ 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();
}
{
Q_OBJECT
public:
- explicit DataBase(QObject *parent = 0);
+ explicit DataBase (QObject* parent = 0);
virtual ~DataBase();
signals:
public slots:
- void addHuman(const QVariant& name, const QVariant& firstname,
- const QVariant& birthday);
+ void addHuman (const QVariant& name, const QVariant& firstname,
+ const QVariant& birthday);
- void addService(const QVariant& name, const QVariant& url,
- const QVariant& description);
+ void addService (const QVariant& name, const QVariant& url,
+ const QVariant& description);
- void addUser(const QVariant& humanID, const QVariant& serviceID,
- const QString& username, const QString& password);
+ void addUser (const QVariant& humanID, const QVariant& serviceID,
+ const QString& username, const QString& password);
private:
QSqlError initDB();
QSqlDatabase db;
- const QLatin1String sqlCreateHumanTable = QLatin1String(
+ const QLatin1String sqlCreateHumanTable = QLatin1String (
"create table human("
"id integer primary key autoincrement,"
"name varchar not null,"
"birthday date"
")");
- const QLatin1String sqlCreateServiceTable = QLatin1String(
+ const QLatin1String sqlCreateServiceTable = QLatin1String (
"create table service("
"id integer primary key autoincrement,"
"name varchar not null,"
"description varchar"
")");
- const QLatin1String sqlCreateUserTable = QLatin1String(
+ const QLatin1String sqlCreateUserTable = QLatin1String (
"create table user("
"id integer primary key autoincrement,"
"humanid integer not null,"
"foreign key(serviceid) references service(id)"
")");
- const QLatin1String sqlAddHuman = QLatin1String(
- "insert or ignore into "
- "human "
- "(name, firstname, birthday)"
- " values "
- "(?,?,?)"
- );
+ const QLatin1String sqlAddHuman = QLatin1String (
+ "insert or ignore into "
+ "human "
+ "(name, firstname, birthday)"
+ " values "
+ "(?,?,?)"
+ );
- const QLatin1String sqlAddService = QLatin1String(
- "insert or ignore into "
- "service "
- "(name, url, description)"
- " values "
- "(?,?,?)"
- );
+ const QLatin1String sqlAddService = QLatin1String (
+ "insert or ignore into "
+ "service "
+ "(name, url, description)"
+ " values "
+ "(?,?,?)"
+ );
- const QLatin1String sqlAddUser = QLatin1String(
- "insert or ignore into "
- "user "
- "(humanid, serviceid, username, password)"
- " values "
- "(?,?,?,?)"
- );
+ const QLatin1String sqlAddUser = QLatin1String (
+ "insert or ignore into "
+ "user "
+ "(humanid, serviceid, username, password)"
+ " values "
+ "(?,?,?,?)"
+ );
};
#endif // DATABASE_H
#include <QList>
#include <QVariant>
-int main(int argc, char *argv[])
+int main (int argc, char* argv[])
{
// QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QApplication app(argc, argv);
+ QApplication app (argc, argv);
DataBase db;
- Controller c(&db);
+ Controller c (&db);
return app.exec();
}
--- /dev/null
+--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