diff --git a/accommodation/accommodation.cpp b/accommodation/accommodation.cpp index 29c02f4..34f993a 100644 --- a/accommodation/accommodation.cpp +++ b/accommodation/accommodation.cpp @@ -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(); + AccommodationService *service = new AccommodationService(); + m_service = service; } QString Accommodation::pluginId() diff --git a/accommodation/accommodation.h b/accommodation/accommodation.h index 1b7a8d3..68c46a8 100644 --- a/accommodation/accommodation.h +++ b/accommodation/accommodation.h @@ -2,14 +2,14 @@ #define ACCOMMODATION_H #include "accommodation_global.h" -#include -#include +#include #include #include 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; }; diff --git a/accommodation/accommodation.json b/accommodation/accommodation.json index e69de29..7d4873e 100644 --- a/accommodation/accommodation.json +++ b/accommodation/accommodation.json @@ -0,0 +1,12 @@ +{ + "id" : "ACCOMMODATION", + "name" : { + "default" : "Accommodation", + "CZ" : "Ubytování" + }, + "descriptoin" : { + "default" : "", + "CZ" : "" + }, + "dependencies" : [] +} diff --git a/accommodation/accommodation.pro b/accommodation/accommodation.pro index 233dd9a..27c0f12 100644 --- a/accommodation/accommodation.pro +++ b/accommodation/accommodation.pro @@ -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) + diff --git a/accommodation/accommodationform.cpp b/accommodation/accommodationform.cpp index 0c57a40..8df9782 100644 --- a/accommodation/accommodationform.cpp +++ b/accommodation/accommodationform.cpp @@ -17,6 +17,6 @@ AccommodationForm::~AccommodationForm() void AccommodationForm::on_pushButton_clicked() { - Dialog d; - d.open(); + Dialog *d = new Dialog(); + d->open(); } diff --git a/accommodation/accommodationservice.cpp b/accommodation/accommodationservice.cpp new file mode 100644 index 0000000..e0a7038 --- /dev/null +++ b/accommodation/accommodationservice.cpp @@ -0,0 +1,17 @@ +#include "accommodationservice.h" + +AccommodationService::AccommodationService() +{ + +} + +AccommodationService::~AccommodationService() +{ + +} + +void AccommodationService::pokus() +{ + +} + diff --git a/accommodation/accommodationservice.h b/accommodation/accommodationservice.h new file mode 100644 index 0000000..df75c2b --- /dev/null +++ b/accommodation/accommodationservice.h @@ -0,0 +1,18 @@ +#ifndef ACCOMMODATIONSERVICE_H +#define ACCOMMODATIONSERVICE_H + +#include "data/person.h" +#include + +#include "accommodation_global.h" + +class AccommodationService : public Service +{ +public: + AccommodationService(); + ~AccommodationService(); + + void pokus(); +}; + +#endif // ACCOMMODATIONSERVICE_H diff --git a/accommodation/dialog.cpp b/accommodation/dialog.cpp index 2319acc..3860037 100644 --- a/accommodation/dialog.cpp +++ b/accommodation/dialog.cpp @@ -1,9 +1,10 @@ #include "dialog.h" #include "ui_dialog.h" -#include -#include +#include + #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()->save(p); + AccommodationService *service = (AccommodationService*)plugin->service(); + service->save(p); } diff --git a/application/application.pro b/application/application.pro index 488b680..5ec912f 100644 --- a/application/application.pro +++ b/application/application.pro @@ -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 \ diff --git a/application/main.cpp b/application/main.cpp index b48f94e..f332ade 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,6 +1,8 @@ #include "mainwindow.h" #include +#include + int main(int argc, char *argv[]) { QApplication a(argc, argv); diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index 309b4ba..fffed1e 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -1,8 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include -#include +#include #include #include @@ -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"); } diff --git a/core/context.cpp b/core/context.cpp index 216dc74..d9cee66 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -2,11 +2,10 @@ #include #include -#include "context.h" -#include "iplugin.h" - #include +#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(p); if (plugin != NULL) { - plugin->init(); + plugin->init(pluginLoader.metaData()); m_plugins.append(plugin); } } diff --git a/core/context.h b/core/context.h index 6491f3e..ca06f3d 100644 --- a/core/context.h +++ b/core/context.h @@ -2,18 +2,20 @@ #define CONTEXT_H #include +#include "core_global.h" + #include class IPlugin; -class Context +class CORESHARED_EXPORT Context { public: static Context &instance(); QList plugins(); void loadPlugins(); void openDb(const QString &path); - odb::database *db(); + odb::database *db() { return m_db; } private: Context(); diff --git a/core/core.cpp b/core/core.cpp deleted file mode 100644 index a517063..0000000 --- a/core/core.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "core.h" - - -Core::Core() -{ -} diff --git a/core/core.h b/core/core.h index dab36ee..676943c 100644 --- a/core/core.h +++ b/core/core.h @@ -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 diff --git a/core/core.pro b/core/core.pro index 0b2c799..7ba4db5 100644 --- a/core/core.pro +++ b/core/core.pro @@ -11,7 +11,7 @@ TEMPLATE = lib DEFINES += CORE_LIBRARY -SOURCES += core.cpp \ +SOURCES += \ data/user.cpp \ context.cpp diff --git a/core/iplugin.h b/core/iplugin.h index 8891604..c0ceae5 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -4,6 +4,7 @@ #include #include #include +#include #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 Service *service() { - (Service*)m_service; + return (Service*)m_service; } protected: diff --git a/core/service.h b/core/service.h index 00617e1..1cbcf29 100644 --- a/core/service.h +++ b/core/service.h @@ -9,6 +9,8 @@ #include #include +#include "core_global.h" + template class Service { @@ -22,7 +24,7 @@ public: QList > ret; for (typename odb::result::iterator it = res.begin(); it != res.end(); it++) { - QSharedPointer entity = db->template load(((T*)*it)->id()); + QSharedPointer entity = db->template load(((T)*it).getId()); ret.append(entity); }