diff --git a/core/context.cpp b/core/context.cpp index 9d6042a..9f656dd 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -15,6 +15,8 @@ #include "users/users.h" #include "roles/roles.h" #include "permissionservice.h" +#include "seasonservice.h" +#include "numberseriesservice.h" Context::~Context() { @@ -50,7 +52,7 @@ void Context::loadPlugins() m_plugins.append(new Users); m_plugins.append(new Roles); - QDir pluginsDir(qApp->applicationDirPath() + "/../plugins"); + QDir pluginsDir(qApp->applicationDirPath() + "/../../plugins"); foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) { QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); @@ -86,6 +88,8 @@ void Context::openDb(const QString &path) m_dbOpened = true; checkPermissions(); + checkSeason(); + checkNumberSeries(); } void Context::destroy() @@ -253,3 +257,42 @@ void Context::checkPermissions() permService.checkForAdmin(); } + +void Context::checkSeason() +{ + SeasonService srv; + QSharedPointer season = srv.active(); + + if (season.isNull()) + { + season = QSharedPointer(new Season()); + season->setName("<>"); + season->setValidFrom(QDate::currentDate()); + season->setActive(true); + srv.save(season); + } +} + +void Context::checkNumberSeries() +{ + NumberSeriesService srv; + SeasonService sesSrv; + QSharedPointer curSeason = sesSrv.active(); + + foreach (IPlugin *plugin, m_plugins) { + if (plugin->hasNumberSeries()) + { + QSharedPointer numSer = srv.forPlugin(plugin->pluginId()); + + if (numSer.isNull()) + { + numSer = QSharedPointer(new NumberSeries()); + numSer->setPrefix(plugin->numberSeriesPrefix()); + numSer->setPluginId(plugin->pluginId()); + numSer->setSeason(curSeason); + + srv.save(numSer); + } + } + } +} diff --git a/core/context.h b/core/context.h index 7d28143..7eb06a7 100644 --- a/core/context.h +++ b/core/context.h @@ -55,6 +55,8 @@ private: void solveDep(IPlugin *plugin, const QSqlDatabase &db, const QMap &schemaMap); void createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap &schemaMap); void checkPermissions(); + void checkSeason(); + void checkNumberSeries(); }; #endif // CONTEXT_H diff --git a/core/core.pro b/core/core.pro index 5b64143..0a86309 100644 --- a/core/core.pro +++ b/core/core.pro @@ -52,7 +52,11 @@ SOURCES += \ settingsform.cpp \ settings/globalsettingsform.cpp \ permissionevaluator.cpp \ - objectbinder.cpp + objectbinder.cpp \ + data/numberseries.cpp \ + data/season.cpp \ + seasonservice.cpp \ + numberseriesservice.cpp HEADERS += core.h\ core_global.h \ @@ -104,7 +108,11 @@ HEADERS += core.h\ settings/globalsettingsform.h \ formbinder.h \ permissionevaluator.h \ - objectbinder.h + objectbinder.h \ + data/numberseries.h \ + data/season.h \ + seasonservice.h \ + numberseriesservice.h unix { target.path = /usr/lib diff --git a/core/data/core-data.h b/core/data/core-data.h index c1f1e1e..b8c8a88 100644 --- a/core/data/core-data.h +++ b/core/data/core-data.h @@ -4,11 +4,15 @@ class User; class Permission; class Role; +class Season; +class NumberSeries; #include "user.h" #include "role.h" #include "permission.h" #include "system.h" +#include "search.h" +#include "numberseries.h" #endif // COREDATA_H diff --git a/core/data/numberseries.cpp b/core/data/numberseries.cpp new file mode 100644 index 0000000..2813c82 --- /dev/null +++ b/core/data/numberseries.cpp @@ -0,0 +1,75 @@ +#include "numberseries.h" +#include "../context.h" +#include "../iplugin.h" + +NumberSeries::NumberSeries(QObject *parent) : QObject(parent) +{ + m_id = 0; + m_lastNumber = 0; +} + +int NumberSeries::id() const +{ + return m_id; +} + +void NumberSeries::setId(int id) +{ + m_id = id; +} + +QString NumberSeries::prefix() const +{ + return m_prefix; +} + +void NumberSeries::setPrefix(const QString &prefix) +{ + m_prefix = prefix; +} + +int NumberSeries::lastNumber() const +{ + return m_lastNumber; +} + +void NumberSeries::setLastNumber(int lastNumber) +{ + m_lastNumber = lastNumber; +} + +QString NumberSeries::pluginId() const +{ + return m_pluginId; +} + +void NumberSeries::setPluginId(const QString &pluginId) +{ + m_pluginId = pluginId; +} + +QSharedPointer NumberSeries::season() const +{ + return m_season; +} + +void NumberSeries::setSeason(const QSharedPointer &season) +{ + m_season = season; +} + +QString NumberSeries::seasonName() const +{ + if (!m_season.isNull()) + { + return m_season->name(); + } + + return ""; +} + +QString NumberSeries::pluginName() const +{ + IPlugin *plugin = Context::instance().plugin(m_pluginId); + return plugin != NULL ? plugin->pluginName() : ""; +} diff --git a/core/data/numberseries.h b/core/data/numberseries.h new file mode 100644 index 0000000..7c189e0 --- /dev/null +++ b/core/data/numberseries.h @@ -0,0 +1,52 @@ +#ifndef NUMBERSERIES_H +#define NUMBERSERIES_H + +#include +#include + +#include + +#include "season.h" + +#pragma db object +class NumberSeries : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString prefix READ prefix WRITE setPrefix) + Q_PROPERTY(int lastNumber READ lastNumber WRITE setLastNumber) + Q_PROPERTY(QString pluginName READ pluginName) + Q_PROPERTY(QString seasonName READ seasonName) +public: + explicit NumberSeries(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString prefix() const; + void setPrefix(const QString &prefix); + + int lastNumber() const; + void setLastNumber(int lastNumber); + + QString pluginId() const; + void setPluginId(const QString &pluginId); + + QSharedPointer season() const; + void setSeason(const QSharedPointer &season); + + QString seasonName() const; + + QString pluginName() const; + +private: + friend class odb::access; + +#pragma db id auto + int m_id; + QString m_prefix; + int m_lastNumber; + QString m_pluginId; + QSharedPointer m_season; +}; + +#endif // NUMBERSERIES_H diff --git a/core/data/season.cpp b/core/data/season.cpp new file mode 100644 index 0000000..8328f08 --- /dev/null +++ b/core/data/season.cpp @@ -0,0 +1,58 @@ +#include "season.h" + +Season::Season(QObject *parent) + :QObject(parent) +{ + m_id = 0; + m_active = false; +} + +QString Season::name() const +{ + return m_name; +} + +void Season::setName(const QString &name) +{ + m_name = name; +} + +QDate Season::validFrom() const +{ + return m_validFrom; +} + +void Season::setValidFrom(const QDate &validFrom) +{ + m_validFrom = validFrom; +} + +QDate Season::validTo() const +{ + return m_validTo; +} + +void Season::setValidTo(const QDate &validTo) +{ + m_validTo = validTo; +} + +bool Season::active() const +{ + return m_active; +} + +void Season::setActive(bool active) +{ + m_active = active; +} + +int Season::id() const +{ + return m_id; +} + +void Season::setId(int id) +{ + m_id = id; +} diff --git a/core/data/season.h b/core/data/season.h new file mode 100644 index 0000000..cf7158d --- /dev/null +++ b/core/data/season.h @@ -0,0 +1,49 @@ +#ifndef SEASON_H +#define SEASON_H + +#include "core_global.h" + +#include +#include +#include + +#include + +#pragma db object +class CORESHARED_EXPORT Season : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QDate validFrom READ validFrom WRITE setValidFrom) + Q_PROPERTY(QDate validTo READ validTo WRITE setValidTo) + Q_PROPERTY(bool active READ active WRITE setActive) +public: + explicit Season(QObject *parent = 0); + + QString name() const; + void setName(const QString &name); + + QDate validFrom() const; + void setValidFrom(const QDate &validFrom); + + QDate validTo() const; + void setValidTo(const QDate &validTo); + + bool active() const; + void setActive(bool active); + + int id() const; + void setId(int id); + +private: + friend class odb::access; + +#pragma db id auto + int m_id; + QString m_name; + QDate m_validFrom; + QDate m_validTo; + bool m_active; +}; + +#endif // SEASON_H diff --git a/core/iplugin.h b/core/iplugin.h index 018b2dc..afebb9b 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -77,6 +77,9 @@ public: virtual QIcon pluginIcon() { return QIcon(); } QMap translations() { return m_translations; } + virtual bool hasNumberSeries() { return false; } + virtual QString numberSeriesPrefix() { return ""; } + protected: QTranslator* translatorFrom(QString fileName) { QTranslator *trans = new QTranslator(); diff --git a/core/metaData.json b/core/metaData.json index 5821dc8..e3df92f 100644 --- a/core/metaData.json +++ b/core/metaData.json @@ -74,6 +74,23 @@ CREATE TABLE \"Permission\" ( \"createDate\" TEXT NULL, \"active\" INTEGER NOT NULL); +CREATE TABLE \"Season\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"validFrom\" TEXT NULL, + \"validTo\" TEXT NULL, + \"active\" INTEGER NOT NULL); + +CREATE TABLE \"NumberSeries\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"prefix\" TEXT NULL, + \"lastNumber\" INTEGER NOT NULL, + \"pluginId\" TEXT NULL, + \"season\" INTEGER NULL, + CONSTRAINT \"season_fk\" + FOREIGN KEY (\"season\") + REFERENCES \"Season\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); " ], "dependencies" : [] } diff --git a/core/numberseriesservice.cpp b/core/numberseriesservice.cpp new file mode 100644 index 0000000..ecd121c --- /dev/null +++ b/core/numberseriesservice.cpp @@ -0,0 +1,53 @@ +#include "numberseriesservice.h" +#include "seasonservice.h" +#include "core-odb.hxx" + +NumberSeriesService::NumberSeriesService() +{ + +} + +QSharedPointer NumberSeriesService::forPluginAndSeason(QString pluginId, QSharedPointer season) +{ + QList > series = all(QString("pluginId = '%1' AND season = %2").arg(pluginId, QString::number(season->id()))); + + if (!series.isEmpty()) + { + return series[0]; + } + + return QSharedPointer(); +} + +QSharedPointer NumberSeriesService::forPlugin(QString pluginId) +{ + SeasonService sesSrv; + QSharedPointer currentSeason = sesSrv.active(); + + if (!currentSeason.isNull()) + { + return forPluginAndSeason(pluginId, currentSeason); + } + + return QSharedPointer(); +} + +QSharedPointer NumberSeriesService::nextForPlugin(QString pluginId) +{ + QSharedPointer numSer = forPlugin(pluginId); + + if (numSer.isNull()) + { + return QSharedPointer(); + } + + numSer->setLastNumber(numSer->lastNumber() + 1); + update(numSer); + + return numSer; +} + +QList > NumberSeriesService::allForSeason(QSharedPointer season) +{ + return all(QString("season = %1").arg(QString::number(season->id()))); +} diff --git a/core/numberseriesservice.h b/core/numberseriesservice.h new file mode 100644 index 0000000..d2e1ed0 --- /dev/null +++ b/core/numberseriesservice.h @@ -0,0 +1,20 @@ +#ifndef NUMBERSERIESSERVICE_H +#define NUMBERSERIESSERVICE_H + +#include "data/numberseries.h" +#include "data/season.h" +#include "service.h" +#include "core_global.h" + +class CORESHARED_EXPORT NumberSeriesService : public Service +{ +public: + NumberSeriesService(); + + QSharedPointer forPluginAndSeason(QString pluginId, QSharedPointer season); + QSharedPointer forPlugin(QString pluginId); + QSharedPointer nextForPlugin(QString pluginId); + QList > allForSeason(QSharedPointer season); +}; + +#endif // NUMBERSERIESSERVICE_H diff --git a/core/seasonservice.cpp b/core/seasonservice.cpp new file mode 100644 index 0000000..f22256b --- /dev/null +++ b/core/seasonservice.cpp @@ -0,0 +1,34 @@ +#include "seasonservice.h" + +#include "core-odb.hxx" + +SeasonService::SeasonService() +{ + +} + +QSharedPointer SeasonService::active() +{ + QList > seasons = all("active = 1"); + if (seasons.count() > 0) + { + return seasons[0]; + } + + return QSharedPointer(); +} + +void SeasonService::activate(QSharedPointer season) +{ + Transaction tx; + + foreach (QSharedPointer ses, all()) { + ses->setActive(false); + update(ses); + } + + season->setActive(true); + update(season); + + tx.commit(); +} diff --git a/core/seasonservice.h b/core/seasonservice.h new file mode 100644 index 0000000..738c8c4 --- /dev/null +++ b/core/seasonservice.h @@ -0,0 +1,18 @@ +#ifndef SEASONSERVICE_H +#define SEASONSERVICE_H + +#include + +#include "data/season.h" +#include "service.h" +#include "core_global.h" + +class CORESHARED_EXPORT SeasonService : public Service +{ +public: + SeasonService(); + QSharedPointer active(); + void activate(QSharedPointer season); +}; + +#endif // SEASONSERVICE_H diff --git a/qdecimal/common.pri b/qdecimal/common.pri index 7d8b6fa..5414398 100644 --- a/qdecimal/common.pri +++ b/qdecimal/common.pri @@ -6,7 +6,7 @@ #DEFINES += DECEXTFLAG=1 # default is 1 #DEFINES += DECLITEND=0 # default is 1 -CONFIG += debug +#CONFIG += debug if(win32) { @@ -24,7 +24,7 @@ if(win32) { #msvc2010 onwards above flags are deprecated. # Use Run-time checks for stack corruption and uninitialized var use - QMAKE_CXXFLAGS += /RTC1 + #QMAKE_CXXFLAGS += /RTC1 } } # end win32 diff --git a/shop/shop.cpp b/shop/shop.cpp index 448c811..7d7e8cc 100644 --- a/shop/shop.cpp +++ b/shop/shop.cpp @@ -31,3 +31,13 @@ QTranslator *Shop::translator() { return translatorFrom(":/translations/shop_"); } + +bool Shop::hasNumberSeries() +{ + return true; +} + +QString Shop::numberSeriesPrefix() +{ + return "PD"; +} diff --git a/shop/shop.h b/shop/shop.h index 2d36993..a3b061b 100644 --- a/shop/shop.h +++ b/shop/shop.h @@ -24,6 +24,8 @@ public: virtual QIcon pluginIcon(); virtual QWidget *ui() override; QTranslator *translator(); + bool hasNumberSeries(); + QString numberSeriesPrefix(); }; #endif // SHOP_H