users plugin implementation

print
Zdenek Jonak 9 years ago
parent 30a6f57b19
commit a6d795ec87

@ -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 QMap<QStri
{
solveDep(*it, db, schemaMap);
}
}
if (m_solved.contains(plugin->pluginId()))
{
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<Q
bool error = false;
foreach (QString s, sqlList) {
if (!q.exec(s))
if (!s.isEmpty() && !q.exec(s))
{
qDebug() << q.lastError().text();
error = true;

@ -23,7 +23,11 @@ SOURCES += \
igridform.cpp \
defaultformhandler.cpp \
formdialog.cpp \
iform.cpp
iform.cpp \
users/users.cpp \
users/usersui.cpp \
users/tablemodel.cpp \
users/userform.cpp
HEADERS += core.h\
core_global.h \
@ -46,7 +50,11 @@ HEADERS += core.h\
igridform.h \
defaultformhandler.h \
formdialog.h \
iform.h
iform.h \
users/users.h \
users/usersui.h \
users/tablemodel.h \
users/userform.h
unix {
target.path = /usr/lib
@ -68,4 +76,8 @@ DISTFILES += \
FORMS += \
gridform.ui \
formdialog.ui
formdialog.ui \
users/userform.ui
OTHER_FILES += \
users/metaData.json

@ -17,10 +17,10 @@ class User : public QObject
Q_PROPERTY(QString login READ login WRITE setLogin)
Q_PROPERTY(QString password READ password WRITE setPassword)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QDateTime lastModDate READ lastModDate WRITE setLastModDate)
Q_PROPERTY(QDateTime createDate READ createDate WRITE setCreateDate)
Q_PROPERTY(bool active READ active WRITE setActive)
Q_PROPERTY(bool isAdmin READ isAdmin WRITE setIsAdmin)
Q_PROPERTY(QDateTime lastModDate READ lastModDate WRITE setLastModDate)
Q_PROPERTY(QDateTime createDate READ createDate WRITE setCreateDate)
public:
User();

@ -8,6 +8,7 @@
#include <QStringList>
#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<IGridForm*>(m_ui);
if (form != NULL)
{
form->fillData();
}
return m_ui;
}

@ -5,7 +5,7 @@
"default" : "Core plugin",
"CZ" : "Jádro"
},
"descriptoin" : {
"description" : {
"default" : "",
"CZ" : ""
},

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>metaData.json</file>
<file>users/metaData.json</file>
</qresource>
</RCC>

@ -0,0 +1,16 @@
{
"MetaData" : {
"id" : "CORE_USERS",
"name" : {
"default" : "Core Users plugin",
"CZ" : "Uživatelé"
},
"description" : {
"default" : "",
"CZ" : ""
},
"schemaVersion" : 1,
"sql" : [],
"dependencies" : []
}
}

@ -0,0 +1,6 @@
#include "tablemodel.h"
TableModel::TableModel(QObject *parent) :AutoTableModel<User>(parent)
{
}

@ -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<User>
{
Q_OBJECT
public:
explicit TableModel(QObject *parent = NULL);
};
#endif // TABLEMODEL_H

@ -0,0 +1,19 @@
#include "userform.h"
#include "ui_userform.h"
UserForm::UserForm(QWidget *parent) :
AutoForm<User>(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;
}

@ -0,0 +1,25 @@
#ifndef USERFORM_H
#define USERFORM_H
#include <QWidget>
#include "autoform.h"
#include "../data/core-data.h"
#include "core-odb.hxx"
namespace Ui {
class UserForm;
}
class UserForm : public AutoForm<User>
{
Q_OBJECT
public:
explicit UserForm(QWidget *parent = 0);
~UserForm();
private:
Ui::UserForm *ui;
};
#endif // USERFORM_H

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UserForm</class>
<widget class="QWidget" name="UserForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="login"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="name"/>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="isAdmin">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Is Admin</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="active">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Active</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,21 @@
#include "users.h"
#include <QFile>
#include <QJsonDocument>
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<User>;
m_ui = new UsersUi;
((UsersUi *) m_ui)->setForm(new UserForm);
}

@ -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

@ -0,0 +1,12 @@
#include "usersui.h"
#include "tablemodel.h"
UsersUi::UsersUi(QWidget *parent) :GridForm<User>(parent)
{
setTableModel(new TableModel);
}
UsersUi::~UsersUi()
{
}

@ -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<User>
{
Q_OBJECT
public:
explicit UsersUi(QWidget *parent = NULL);
~UsersUi();
};
#endif // USERSUI_H
Loading…
Cancel
Save