- Core library header files added to core.h file.

- Fixed windows build.
- Added AccommodationService class.
print
Josef Rokos 9 years ago
parent 53d56f2e13
commit 096605a39e

@ -5,6 +5,7 @@
#include "accommodationform.h"
#include "data/person.h"
#include "accommodationservice.h"
Accommodation::Accommodation()
{
@ -15,11 +16,12 @@ QString Accommodation::pluginName()
return "Ubytovani";
}
void Accommodation::init()
void Accommodation::init(const QJsonObject &metaData)
{
qDebug() << "init accomodation";
qDebug() << "init accomodation" << metaData;
m_ui = new AccommodationForm();
m_service = new Service<Person>();
AccommodationService *service = new AccommodationService();
m_service = service;
}
QString Accommodation::pluginId()

@ -2,14 +2,14 @@
#define ACCOMMODATION_H
#include "accommodation_global.h"
#include <context.h>
#include <iplugin.h>
#include <core.h>
#include <QObject>
#include <QtPlugin>
class ACCOMMODATIONSHARED_EXPORT Accommodation : public QObject, IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "accommodation.json")
Q_INTERFACES(IPlugin)
@ -17,7 +17,7 @@ public:
Accommodation();
QString pluginName() Q_DECL_OVERRIDE;
void init() Q_DECL_OVERRIDE;
void init(const QJsonObject &metaData) Q_DECL_OVERRIDE;
QString pluginId() Q_DECL_OVERRIDE;
};

@ -0,0 +1,12 @@
{
"id" : "ACCOMMODATION",
"name" : {
"default" : "Accommodation",
"CZ" : "Ubytování"
},
"descriptoin" : {
"default" : "",
"CZ" : ""
},
"dependencies" : []
}

@ -14,13 +14,15 @@ DEFINES += ACCOMMODATION_LIBRARY
SOURCES += accommodation.cpp \
accommodationform.cpp \
data/person.cpp \
dialog.cpp
dialog.cpp \
accommodationservice.cpp
HEADERS += accommodation.h\
accommodation_global.h \
accommodationform.h \
data/person.h \
dialog.h
dialog.h \
accommodationservice.h
unix {
target.path = /usr/lib
@ -46,3 +48,4 @@ FORMS += \
ODB_FILES = accommodation/data/person.h
H_DIR = $$PWD/data/*.h
include(../odb.pri)

@ -17,6 +17,6 @@ AccommodationForm::~AccommodationForm()
void AccommodationForm::on_pushButton_clicked()
{
Dialog d;
d.open();
Dialog *d = new Dialog();
d->open();
}

@ -0,0 +1,17 @@
#include "accommodationservice.h"
AccommodationService::AccommodationService()
{
}
AccommodationService::~AccommodationService()
{
}
void AccommodationService::pokus()
{
}

@ -0,0 +1,18 @@
#ifndef ACCOMMODATIONSERVICE_H
#define ACCOMMODATIONSERVICE_H
#include "data/person.h"
#include <core.h>
#include "accommodation_global.h"
class AccommodationService : public Service<Person>
{
public:
AccommodationService();
~AccommodationService();
void pokus();
};
#endif // ACCOMMODATIONSERVICE_H

@ -1,9 +1,10 @@
#include "dialog.h"
#include "ui_dialog.h"
#include <context.h>
#include <iplugin.h>
#include <core.h>
#include "data/person.h"
#include "accommodationservice.h"
#include "accommodation-odb.hxx"
@ -27,5 +28,6 @@ void Dialog::on_buttonBox_accepted()
p->setFirstName(ui->lineEdit->text());
p->setLastName(ui->lineEdit_2->text());
plugin->service<Person>()->save(p);
AccommodationService *service = (AccommodationService*)plugin->service<Person>();
service->save(p);
}

@ -11,6 +11,12 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = prodejna
TEMPLATE = app
win32 {
INCLUDEPATH += d:/prac/odb/libodb-2.4.0
INCLUDEPATH += d:/prac/odb/libodb-qt-2.4.0
INCLUDEPATH += d:/prac/odb/libodb-sqlite-2.4.0
INCLUDEPATH += d:/prac/odb/sqlite
}
SOURCES += main.cpp\
mainwindow.cpp \

@ -1,6 +1,8 @@
#include "mainwindow.h"
#include <QApplication>
#include <QStringList>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);

@ -1,8 +1,7 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <context.h>
#include <iplugin.h>
#include <core.h>
#include <QPushButton>
#include <QVBoxLayout>
@ -57,5 +56,5 @@ void MainWindow::openPlugin()
void MainWindow::on_actionOpen_database_triggered()
{
Context::instance().openDb("/home/jony/db.db");
Context::instance().openDb("D:/prac/prodejna.db");
}

@ -2,11 +2,10 @@
#include <QApplication>
#include <QPluginLoader>
#include "context.h"
#include "iplugin.h"
#include <odb/sqlite/database.hxx>
#include "core.h"
Context &Context::instance()
{
static Context ctx;
@ -22,14 +21,14 @@ void Context::loadPlugins()
{
QDir pluginsDir(qApp->applicationDirPath() + "/../plugins");
foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so")) {
foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) {
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
QObject *p = pluginLoader.instance();
if (p != NULL) {
IPlugin *plugin = qobject_cast<IPlugin*>(p);
if (plugin != NULL) {
plugin->init();
plugin->init(pluginLoader.metaData());
m_plugins.append(plugin);
}
}

@ -2,18 +2,20 @@
#define CONTEXT_H
#include <QList>
#include "core_global.h"
#include <odb/database.hxx>
class IPlugin;
class Context
class CORESHARED_EXPORT Context
{
public:
static Context &instance();
QList<IPlugin*> plugins();
void loadPlugins();
void openDb(const QString &path);
odb::database *db();
odb::database *db() { return m_db; }
private:
Context();

@ -1,6 +0,0 @@
#include "core.h"
Core::Core()
{
}

@ -1,13 +1,7 @@
#ifndef CORE_H
#define CORE_H
#include "core_global.h"
class CORESHARED_EXPORT Core
{
public:
Core();
};
#include "context.h"
#include "iplugin.h"
#endif // CORE_H

@ -11,7 +11,7 @@ TEMPLATE = lib
DEFINES += CORE_LIBRARY
SOURCES += core.cpp \
SOURCES += \
data/user.cpp \
context.cpp

@ -4,6 +4,7 @@
#include <QString>
#include <QWidget>
#include <QtPlugin>
#include <QJsonObject>
#include "service.h"
@ -18,13 +19,13 @@ public:
virtual ~IPlugin() { }
virtual QString pluginName() = 0;
virtual QString pluginId() = 0;
virtual void init() = 0;
virtual void init(const QJsonObject &metaData) = 0;
virtual QWidget *ui() {
return m_ui;
}
template<class T>
Service<T> *service() {
(Service<T>*)m_service;
return (Service<T>*)m_service;
}
protected:

@ -9,6 +9,8 @@
#include <odb/database.hxx>
#include <odb/result.hxx>
#include "core_global.h"
template<class T>
class Service
{
@ -22,7 +24,7 @@ public:
QList<QSharedPointer<T> > ret;
for (typename odb::result<T>::iterator it = res.begin(); it != res.end(); it++) {
QSharedPointer<T> entity = db->template load<T>(((T*)*it)->id());
QSharedPointer<T> entity = db->template load<T>(((T)*it).getId());
ret.append(entity);
}

Loading…
Cancel
Save