From a6d795ec87b576fc948bc109ebb8795664107b4e Mon Sep 17 00:00:00 2001 From: Zdenek Jonak Date: Thu, 19 Nov 2015 22:12:36 +0100 Subject: [PATCH] users plugin implementation --- core/context.cpp | 14 ++++---- core/core.pro | 18 ++++++++-- core/data/user.h | 4 +-- core/iplugin.h | 8 +++++ core/metaData.json | 2 +- core/rc.qrc | 1 + core/users/metaData.json | 16 +++++++++ core/users/tablemodel.cpp | 6 ++++ core/users/tablemodel.h | 15 +++++++++ core/users/userform.cpp | 19 +++++++++++ core/users/userform.h | 25 ++++++++++++++ core/users/userform.ui | 71 +++++++++++++++++++++++++++++++++++++++ core/users/users.cpp | 21 ++++++++++++ core/users/users.h | 17 ++++++++++ core/users/usersui.cpp | 12 +++++++ core/users/usersui.h | 17 ++++++++++ 16 files changed, 254 insertions(+), 12 deletions(-) create mode 100644 core/users/metaData.json create mode 100644 core/users/tablemodel.cpp create mode 100644 core/users/tablemodel.h create mode 100644 core/users/userform.cpp create mode 100644 core/users/userform.h create mode 100644 core/users/userform.ui create mode 100644 core/users/users.cpp create mode 100644 core/users/users.h create mode 100644 core/users/usersui.cpp create mode 100644 core/users/usersui.h diff --git a/core/context.cpp b/core/context.cpp index 3257700..b03cdd0 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -11,6 +11,7 @@ #include "core.h" #include "coreplugin.h" +#include "users/users.h" Context &Context::instance() { @@ -38,6 +39,7 @@ void Context::loadPlugins() { IPlugin *corePlugin = new CorePlugin(); m_plugins.append(corePlugin); + m_plugins.append(new Users); QDir pluginsDir(qApp->applicationDirPath() + "/../plugins"); @@ -113,12 +115,12 @@ void Context::solveDep(IPlugin *plugin, const QSqlDatabase &db, const QMappluginId())) - { - createSchema(plugin, db, schemaMap); - m_solved.append(plugin->pluginId()); - } + if (!m_solved.contains(plugin->pluginId())) + { + createSchema(plugin, db, schemaMap); + m_solved.append(plugin->pluginId()); } } @@ -139,7 +141,7 @@ void Context::createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap #include "service.h" +#include "igridform.h" class IPlugin { @@ -29,6 +30,13 @@ public: virtual void init(const QJsonObject &metaData) = 0; virtual QWidget *ui() { + IGridForm *form = qobject_cast(m_ui); + + if (form != NULL) + { + form->fillData(); + } + return m_ui; } diff --git a/core/metaData.json b/core/metaData.json index 7a513dc..57d6737 100644 --- a/core/metaData.json +++ b/core/metaData.json @@ -5,7 +5,7 @@ "default" : "Core plugin", "CZ" : "Jádro" }, - "descriptoin" : { + "description" : { "default" : "", "CZ" : "" }, diff --git a/core/rc.qrc b/core/rc.qrc index 681c9be..68aa197 100644 --- a/core/rc.qrc +++ b/core/rc.qrc @@ -1,5 +1,6 @@ metaData.json + users/metaData.json diff --git a/core/users/metaData.json b/core/users/metaData.json new file mode 100644 index 0000000..4041d59 --- /dev/null +++ b/core/users/metaData.json @@ -0,0 +1,16 @@ +{ + "MetaData" : { + "id" : "CORE_USERS", + "name" : { + "default" : "Core Users plugin", + "CZ" : "Uživatelé" + }, + "description" : { + "default" : "", + "CZ" : "" + }, + "schemaVersion" : 1, + "sql" : [], + "dependencies" : [] + } +} diff --git a/core/users/tablemodel.cpp b/core/users/tablemodel.cpp new file mode 100644 index 0000000..233e886 --- /dev/null +++ b/core/users/tablemodel.cpp @@ -0,0 +1,6 @@ +#include "tablemodel.h" + +TableModel::TableModel(QObject *parent) :AutoTableModel(parent) +{ + +} diff --git a/core/users/tablemodel.h b/core/users/tablemodel.h new file mode 100644 index 0000000..5cf74f2 --- /dev/null +++ b/core/users/tablemodel.h @@ -0,0 +1,15 @@ +#ifndef TABLEMODEL_H +#define TABLEMODEL_H + +#include "autotablemodel.h" +#include "../data/core-data.h" +#include "core-odb.hxx" + +class TableModel : public AutoTableModel +{ + Q_OBJECT +public: + explicit TableModel(QObject *parent = NULL); +}; + +#endif // TABLEMODEL_H diff --git a/core/users/userform.cpp b/core/users/userform.cpp new file mode 100644 index 0000000..b7d2b36 --- /dev/null +++ b/core/users/userform.cpp @@ -0,0 +1,19 @@ +#include "userform.h" +#include "ui_userform.h" + +UserForm::UserForm(QWidget *parent) : + AutoForm(parent), + ui(new Ui::UserForm) +{ + ui->setupUi(this); + registerBinding(ui->login); + registerBinding(ui->password); + registerBinding(ui->name); + registerBinding(ui->isAdmin); + registerBinding(ui->active); +} + +UserForm::~UserForm() +{ + delete ui; +} diff --git a/core/users/userform.h b/core/users/userform.h new file mode 100644 index 0000000..b549723 --- /dev/null +++ b/core/users/userform.h @@ -0,0 +1,25 @@ +#ifndef USERFORM_H +#define USERFORM_H + +#include +#include "autoform.h" +#include "../data/core-data.h" +#include "core-odb.hxx" + +namespace Ui { +class UserForm; +} + +class UserForm : public AutoForm +{ + Q_OBJECT + +public: + explicit UserForm(QWidget *parent = 0); + ~UserForm(); + +private: + Ui::UserForm *ui; +}; + +#endif // USERFORM_H diff --git a/core/users/userform.ui b/core/users/userform.ui new file mode 100644 index 0000000..ea073bf --- /dev/null +++ b/core/users/userform.ui @@ -0,0 +1,71 @@ + + + UserForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Login + + + + + + + + + + Password + + + + + + + + + + Name + + + + + + + + + + Qt::RightToLeft + + + Is Admin + + + + + + + Qt::RightToLeft + + + Active + + + + + + + + diff --git a/core/users/users.cpp b/core/users/users.cpp new file mode 100644 index 0000000..0ccf2a4 --- /dev/null +++ b/core/users/users.cpp @@ -0,0 +1,21 @@ +#include "users.h" +#include +#include + +Users::Users() +{ + Q_INIT_RESOURCE(rc); + + QFile f (":/users/metaData.json"); + f.open(QIODevice::ReadOnly | QIODevice::Text); + QJsonDocument d = QJsonDocument::fromJson(f.readAll()); + init(d.object()); + f.close(); +} + +void Users::initServiceUi() +{ + m_service = new Service; + m_ui = new UsersUi; + ((UsersUi *) m_ui)->setForm(new UserForm); +} diff --git a/core/users/users.h b/core/users/users.h new file mode 100644 index 0000000..0d2a362 --- /dev/null +++ b/core/users/users.h @@ -0,0 +1,17 @@ +#ifndef USERS_H +#define USERS_H +#include "imetadataplugin.h" +#include "userform.h" +#include "usersui.h" + +class Users : public IMetaDataPlugin +{ +public: + Users(); + + // IMetaDataPlugin interface +protected: + void initServiceUi(); +}; + +#endif // USERS_H diff --git a/core/users/usersui.cpp b/core/users/usersui.cpp new file mode 100644 index 0000000..55be3c0 --- /dev/null +++ b/core/users/usersui.cpp @@ -0,0 +1,12 @@ +#include "usersui.h" +#include "tablemodel.h" + +UsersUi::UsersUi(QWidget *parent) :GridForm(parent) +{ + setTableModel(new TableModel); +} + +UsersUi::~UsersUi() +{ + +} diff --git a/core/users/usersui.h b/core/users/usersui.h new file mode 100644 index 0000000..ff09cb3 --- /dev/null +++ b/core/users/usersui.h @@ -0,0 +1,17 @@ +#ifndef USERSUI_H +#define USERSUI_H + +#include "gridform.h" +#include "../data/core-data.h" +#include "core-odb.hxx" + +class UsersUi : public GridForm +{ + Q_OBJECT + +public: + explicit UsersUi(QWidget *parent = NULL); + ~UsersUi(); +}; + +#endif // USERSUI_H