From: John Janus Date: Fri, 3 Mar 2017 13:18:07 +0000 (+0100) Subject: fix style, add astylerc X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=50bc707c05ecd90f9b3b9ffb7e2eb0a108d9ca77;p=UserSheets.git fix style, add astylerc --- diff --git a/UserSheets.pro b/UserSheets.pro index 8e50682..e3dd443 100644 --- a/UserSheets.pro +++ b/UserSheets.pro @@ -33,3 +33,5 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin HEADERS += \ database.h \ controller.h + +DISTFILES += style.astylrc diff --git a/controller.cpp b/controller.cpp index 446b74d..7fb9dc1 100644 --- a/controller.cpp +++ b/controller.cpp @@ -2,53 +2,54 @@ #include #include -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 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"; } } diff --git a/controller.h b/controller.h index 029b5a0..7ccf519 100644 --- a/controller.h +++ b/controller.h @@ -11,7 +11,7 @@ class Controller : public QObject { Q_OBJECT public: - explicit Controller(DataBase* db, QObject *parent = 0); + explicit Controller (DataBase* db, QObject* parent = 0); virtual ~Controller(); signals: diff --git a/database.cpp b/database.cpp index 6047d83..51162c5 100644 --- a/database.cpp +++ b/database.cpp @@ -3,14 +3,14 @@ #include #include -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(); } @@ -19,40 +19,40 @@ DataBase::~DataBase() } -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: "<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: "<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(); } @@ -60,15 +60,15 @@ 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"; + 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 index 6f7d604..dc272d0 100644 --- a/database.h +++ b/database.h @@ -11,27 +11,27 @@ class DataBase : public QObject { 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," @@ -39,7 +39,7 @@ private: "birthday date" ")"); - const QLatin1String sqlCreateServiceTable = QLatin1String( + const QLatin1String sqlCreateServiceTable = QLatin1String ( "create table service(" "id integer primary key autoincrement," "name varchar not null," @@ -47,7 +47,7 @@ private: "description varchar" ")"); - const QLatin1String sqlCreateUserTable = QLatin1String( + const QLatin1String sqlCreateUserTable = QLatin1String ( "create table user(" "id integer primary key autoincrement," "humanid integer not null," @@ -58,29 +58,29 @@ private: "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 diff --git a/main.cpp b/main.cpp index 536243b..ef1cb52 100644 --- a/main.cpp +++ b/main.cpp @@ -5,13 +5,13 @@ #include #include -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(); } 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