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

@ -2,14 +2,14 @@
#define ACCOMMODATION_H #define ACCOMMODATION_H
#include "accommodation_global.h" #include "accommodation_global.h"
#include <context.h> #include <core.h>
#include <iplugin.h>
#include <QObject> #include <QObject>
#include <QtPlugin> #include <QtPlugin>
class ACCOMMODATIONSHARED_EXPORT Accommodation : public QObject, IPlugin class ACCOMMODATIONSHARED_EXPORT Accommodation : public QObject, IPlugin
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "accommodation.json") Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "accommodation.json")
Q_INTERFACES(IPlugin) Q_INTERFACES(IPlugin)
@ -17,7 +17,7 @@ public:
Accommodation(); Accommodation();
QString pluginName() Q_DECL_OVERRIDE; QString pluginName() Q_DECL_OVERRIDE;
void init() Q_DECL_OVERRIDE; void init(const QJsonObject &metaData) Q_DECL_OVERRIDE;
QString pluginId() 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 \ SOURCES += accommodation.cpp \
accommodationform.cpp \ accommodationform.cpp \
data/person.cpp \ data/person.cpp \
dialog.cpp dialog.cpp \
accommodationservice.cpp
HEADERS += accommodation.h\ HEADERS += accommodation.h\
accommodation_global.h \ accommodation_global.h \
accommodationform.h \ accommodationform.h \
data/person.h \ data/person.h \
dialog.h dialog.h \
accommodationservice.h
unix { unix {
target.path = /usr/lib target.path = /usr/lib
@ -46,3 +48,4 @@ FORMS += \
ODB_FILES = accommodation/data/person.h ODB_FILES = accommodation/data/person.h
H_DIR = $$PWD/data/*.h H_DIR = $$PWD/data/*.h
include(../odb.pri) include(../odb.pri)

@ -17,6 +17,6 @@ AccommodationForm::~AccommodationForm()
void AccommodationForm::on_pushButton_clicked() void AccommodationForm::on_pushButton_clicked()
{ {
Dialog d; Dialog *d = new Dialog();
d.open(); 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 "dialog.h"
#include "ui_dialog.h" #include "ui_dialog.h"
#include <context.h> #include <core.h>
#include <iplugin.h>
#include "data/person.h" #include "data/person.h"
#include "accommodationservice.h"
#include "accommodation-odb.hxx" #include "accommodation-odb.hxx"
@ -27,5 +28,6 @@ void Dialog::on_buttonBox_accepted()
p->setFirstName(ui->lineEdit->text()); p->setFirstName(ui->lineEdit->text());
p->setLastName(ui->lineEdit_2->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 TARGET = prodejna
TEMPLATE = app 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\ SOURCES += main.cpp\
mainwindow.cpp \ mainwindow.cpp \

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

@ -1,8 +1,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <context.h> #include <core.h>
#include <iplugin.h>
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -57,5 +56,5 @@ void MainWindow::openPlugin()
void MainWindow::on_actionOpen_database_triggered() 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 <QApplication>
#include <QPluginLoader> #include <QPluginLoader>
#include "context.h"
#include "iplugin.h"
#include <odb/sqlite/database.hxx> #include <odb/sqlite/database.hxx>
#include "core.h"
Context &Context::instance() Context &Context::instance()
{ {
static Context ctx; static Context ctx;
@ -22,14 +21,14 @@ void Context::loadPlugins()
{ {
QDir pluginsDir(qApp->applicationDirPath() + "/../plugins"); 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)); QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
QObject *p = pluginLoader.instance(); QObject *p = pluginLoader.instance();
if (p != NULL) { if (p != NULL) {
IPlugin *plugin = qobject_cast<IPlugin*>(p); IPlugin *plugin = qobject_cast<IPlugin*>(p);
if (plugin != NULL) { if (plugin != NULL) {
plugin->init(); plugin->init(pluginLoader.metaData());
m_plugins.append(plugin); m_plugins.append(plugin);
} }
} }

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

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

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

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

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

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

Loading…
Cancel
Save