diff --git a/camp/camp.cpp b/camp/camp.cpp new file mode 100644 index 0000000..1937270 --- /dev/null +++ b/camp/camp.cpp @@ -0,0 +1,19 @@ +#include "camp.h" + +#include "campgrid.h" +#include "campform.h" + +Camp::Camp() +{ +} + +void Camp::initServiceUi() +{ + m_ui = new CampGrid(); + ((CampGrid*)m_ui)->setForm(new CampForm()); +} + +QIcon Camp::pluginIcon() +{ + return QIcon(":/icons/campPlugin.svg"); +} diff --git a/camp/camp.h b/camp/camp.h new file mode 100644 index 0000000..9c79aa9 --- /dev/null +++ b/camp/camp.h @@ -0,0 +1,27 @@ +#ifndef CAMP_H +#define CAMP_H + +#include "camp_global.h" +#include +#include +#include + +class CAMPSHARED_EXPORT Camp : public QObject, IMetaDataPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "camp.json") + Q_INTERFACES(IPlugin) + +public: + Camp(); + +protected: + void initServiceUi() Q_DECL_OVERRIDE; + + // IPlugin interface +public: + virtual QIcon pluginIcon(); +}; + +#endif // CAMP_H diff --git a/camp/camp.json b/camp/camp.json new file mode 100644 index 0000000..cd72275 --- /dev/null +++ b/camp/camp.json @@ -0,0 +1,65 @@ +{ + "id" : "CAMP", + "name" : { + "default" : "Camp", + "CZ" : "Kemp" + }, + "descriptoin" : { + "default" : "", + "CZ" : "" + }, + "schemaVersion" : 1, + "sql" : [ +"CREATE TABLE \"CampData\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"start\" TEXT NULL, + \"end\" TEXT NULL, + \"ownerFirstame\" TEXT NULL, + \"ownerLastname\" TEXT NULL, + \"ownerAddress\" TEXT NULL, + \"totalPrice\" INTEGER NOT NULL, + \"season\" INTEGER NULL, + CONSTRAINT \"season_fk\" + FOREIGN KEY (\"season\") + REFERENCES \"Season\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); + +CREATE TABLE \"AddressItem\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"firstName\" TEXT NULL, + \"lastName\" TEXT NULL, + \"address\" TEXT NULL, + \"price\" INTEGER NOT NULL, + \"campData\" INTEGER NOT NULL, + CONSTRAINT \"campData_fk\" + FOREIGN KEY (\"campData\") + REFERENCES \"CampData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); + +CREATE TABLE \"ServiceItem\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"code\" TEXT NULL, + \"price\" INTEGER NOT NULL, + \"salePossible\" INTEGER NOT NULL, + \"type\" INTEGER NOT NULL, + \"campData\" INTEGER NOT NULL, + CONSTRAINT \"campData_fk\" + FOREIGN KEY (\"campData\") + REFERENCES \"CampData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED); +" + ], + "dependencies" : [ "ADDRESSBOOK", "SHOP", "SERVICES" ], + "translations" : { + "CZ" : { + "name" : "Název", + "shortName" : "Zobrazit na účtence", + "code" : "Kód", + "type" : "Druh", + "price" : "Cena", + "vat" : "DPH", + "count" : "Počet" + } + } +} diff --git a/camp/camp.pro b/camp/camp.pro new file mode 100644 index 0000000..37e7891 --- /dev/null +++ b/camp/camp.pro @@ -0,0 +1,82 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-04-19T09:20:32 +# +#------------------------------------------------- + +QT += widgets sql + +TARGET = camp +TEMPLATE = lib + +DEFINES += CAMP_LIBRARY + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += camp.cpp \ + data/campdata.cpp \ + data/addressitem.cpp \ + data/serviceitem.cpp \ + campgrid.cpp \ + campform.cpp + +HEADERS += camp.h\ + camp_global.h \ + data/campdata.h \ + data/addressitem.h \ + data/serviceitem.h \ + data/camp-data.h \ + campgrid.h \ + campform.h + +include(../config_plugin.pri) + +ODB_FILES = camp/data/camp-data.h +H_DIR = $$PWD/data/*.h +ODB_OTHER_INCLUDES = -I $$PWD/../shop -I $$PWD/../addressbook/data -I $$PWD/../services/data +include(../odb.pri) + +unix { + target.path = /usr/lib + INSTALLS += target +} + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop +else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lshop + +INCLUDEPATH += $$PWD/../shop +DEPENDPATH += $$PWD/../shop + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook +else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook + +INCLUDEPATH += $$PWD/../addressbook +DEPENDPATH += $$PWD/../addressbook + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lservices +else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lservices + +INCLUDEPATH += $$PWD/../services +INCLUDEPATH += $$PWD/../services/data +DEPENDPATH += $$PWD/../services + +DISTFILES += \ + camp.json + +RESOURCES += \ + camprc.qrc + +FORMS += \ + campform.ui diff --git a/camp/camp_global.h b/camp/camp_global.h new file mode 100644 index 0000000..758c402 --- /dev/null +++ b/camp/camp_global.h @@ -0,0 +1,12 @@ +#ifndef CAMP_GLOBAL_H +#define CAMP_GLOBAL_H + +#include + +#if defined(CAMP_LIBRARY) +# define CAMPSHARED_EXPORT Q_DECL_EXPORT +#else +# define CAMPSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // CAMP_GLOBAL_H diff --git a/camp/campform.cpp b/camp/campform.cpp new file mode 100644 index 0000000..69e805d --- /dev/null +++ b/camp/campform.cpp @@ -0,0 +1,14 @@ +#include "campform.h" +#include "ui_campform.h" + +CampForm::CampForm(QWidget *parent) : + AutoForm(parent), + ui(new Ui::CampForm) +{ + ui->setupUi(this); +} + +CampForm::~CampForm() +{ + delete ui; +} diff --git a/camp/campform.h b/camp/campform.h new file mode 100644 index 0000000..6c4d302 --- /dev/null +++ b/camp/campform.h @@ -0,0 +1,25 @@ +#ifndef CAMPFORM_H +#define CAMPFORM_H + +#include +#include +#include "data/camp-data.h" +#include "camp-odb.hxx" + +namespace Ui { +class CampForm; +} + +class CampForm : public AutoForm +{ + Q_OBJECT + +public: + explicit CampForm(QWidget *parent = 0); + ~CampForm(); + +private: + Ui::CampForm *ui; +}; + +#endif // CAMPFORM_H diff --git a/camp/campform.ui b/camp/campform.ui new file mode 100644 index 0000000..359af06 --- /dev/null +++ b/camp/campform.ui @@ -0,0 +1,21 @@ + + + + + CampForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/camp/campgrid.cpp b/camp/campgrid.cpp new file mode 100644 index 0000000..4c0c007 --- /dev/null +++ b/camp/campgrid.cpp @@ -0,0 +1,6 @@ +#include "campgrid.h" + +CampGrid::CampGrid(QWidget *parent) : GridForm(parent) +{ + setTableModel(new AutoTableModel); +} diff --git a/camp/campgrid.h b/camp/campgrid.h new file mode 100644 index 0000000..409b2e5 --- /dev/null +++ b/camp/campgrid.h @@ -0,0 +1,14 @@ +#ifndef CAMPGRID_H +#define CAMPGRID_H + +#include +#include "data/camp-data.h" +#include "camp-odb.hxx" + +class CampGrid : public GridForm +{ +public: + CampGrid(QWidget *parent = NULL); +}; + +#endif // CAMPGRID_H diff --git a/camp/camprc.qrc b/camp/camprc.qrc new file mode 100644 index 0000000..2c0cc4a --- /dev/null +++ b/camp/camprc.qrc @@ -0,0 +1,5 @@ + + + icons/campPlugin.svg + + diff --git a/camp/data/addressitem.cpp b/camp/data/addressitem.cpp new file mode 100644 index 0000000..afc1dd2 --- /dev/null +++ b/camp/data/addressitem.cpp @@ -0,0 +1,67 @@ +#include "addressitem.h" +#include + +AddressItem::AddressItem(QObject *parent) : QObject(parent) +{ + +} + +int AddressItem::id() const +{ + return m_id; +} + +void AddressItem::setId(int id) +{ + m_id = id; +} + +QString AddressItem::firstName() const +{ + return m_firstName; +} + +void AddressItem::setFirstName(const QString &firstName) +{ + m_firstName = firstName; +} + +QString AddressItem::lastName() const +{ + return m_lastName; +} + +void AddressItem::setLastName(const QString &lastName) +{ + m_lastName = lastName; +} + +QString AddressItem::address() const +{ + return m_address; +} + +void AddressItem::setAddress(const QString &address) +{ + m_address = address; +} + +QDecDouble AddressItem::price() const +{ + return TO_DEC(m_price); +} + +void AddressItem::setPrice(QDecDouble price) +{ + m_price = FROM_DEC(price); +} + +QWeakPointer AddressItem::campData() const +{ + return m_campData; +} + +void AddressItem::setCampData(const QWeakPointer &campData) +{ + m_campData = campData; +} diff --git a/camp/data/addressitem.h b/camp/data/addressitem.h new file mode 100644 index 0000000..ad64bf8 --- /dev/null +++ b/camp/data/addressitem.h @@ -0,0 +1,55 @@ +#ifndef ADDRESSITEM_H +#define ADDRESSITEM_H + +#include "camp-data.h" +#include +#include +#include +#include +#include + +class CampData; + +#pragma db object +class AddressItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString firstName READ firstName WRITE setFirstName) + Q_PROPERTY(QString lastName READ lastName WRITE setLastName) + Q_PROPERTY(QString address READ address WRITE setAddress) + Q_PROPERTY(QDecDouble price READ price WRITE setPrice) + +public: + explicit AddressItem(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString firstName() const; + void setFirstName(const QString &firstName); + + QString lastName() const; + void setLastName(const QString &lastName); + + QString address() const; + void setAddress(const QString &address); + + QDecDouble price() const; + void setPrice(QDecDouble price); + + QWeakPointer campData() const; + void setCampData(const QWeakPointer &campData); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_firstName; + QString m_lastName; + QString m_address; + int m_price; + #pragma db not_null + QWeakPointer m_campData; +}; + +#endif // ADDRESSITEM_H diff --git a/camp/data/camp-data.h b/camp/data/camp-data.h new file mode 100644 index 0000000..ea8dc1a --- /dev/null +++ b/camp/data/camp-data.h @@ -0,0 +1,18 @@ +#ifndef CAMP_DATA_H +#define CAMP_DATA_H + +#include + +class CampData; +class AddressItem; +class ServiceItem; + +typedef QSharedPointer CampDataPtr; +typedef QSharedPointer ServiceItemPtr; +typedef QSharedPointer AddressItemPtr; + +#include "campdata.h" +#include "addressitem.h" +#include "serviceitem.h" + +#endif // CAMP_DATA_H diff --git a/camp/data/campdata.cpp b/camp/data/campdata.cpp new file mode 100644 index 0000000..1954e13 --- /dev/null +++ b/camp/data/campdata.cpp @@ -0,0 +1,117 @@ +#include "campdata.h" +#include + +CampData::CampData(QObject *parent) : QObject(parent) +{ + +} + +int CampData::id() const +{ + return m_id; +} + +void CampData::setId(int id) +{ + m_id = id; +} + +QDate CampData::start() const +{ + return m_start; +} + +void CampData::setStart(const QDate &start) +{ + m_start = start; +} + +QDate CampData::end() const +{ + return m_end; +} + +void CampData::setEnd(const QDate &end) +{ + m_end = end; +} + +QString CampData::ownerFirstame() const +{ + return m_ownerFirstame; +} + +void CampData::setOwnerFirstame(const QString &ownerFirstame) +{ + m_ownerFirstame = ownerFirstame; +} + +QString CampData::ownerLastname() const +{ + return m_ownerLastname; +} + +void CampData::setOwnerLastname(const QString &ownerLastname) +{ + m_ownerLastname = ownerLastname; +} + +QString CampData::ownerAddress() const +{ + return m_ownerAddress; +} + +void CampData::setOwnerAddress(const QString &ownerAddress) +{ + m_ownerAddress = ownerAddress; +} + +QOdbList CampData::services() const +{ + return m_services; +} + +void CampData::setServices(const QOdbList > &services) +{ + m_services = services; +} + +void CampData::addServiceItem(ServiceItemPtr serviceItem) +{ + m_services.append(serviceItem); +} + +QOdbList CampData::people() const +{ + return m_people; +} + +void CampData::setPeople(const QOdbList &people) +{ + m_people = people; +} + +void CampData::addPerson(AddressItemPtr person) +{ + m_people.append(person); +} + +QDecDouble CampData::totalPrice() const +{ + return TO_DEC(m_totalPrice); +} + +void CampData::setTotalPrice(QDecDouble totalPrice) +{ + m_totalPrice = FROM_DEC(totalPrice); +} + +SeasonPtr CampData::season() const +{ + return m_season; +} + +void CampData::setSeason(const SeasonPtr &season) +{ + m_season = season; +} diff --git a/camp/data/campdata.h b/camp/data/campdata.h new file mode 100644 index 0000000..1467864 --- /dev/null +++ b/camp/data/campdata.h @@ -0,0 +1,76 @@ +#ifndef CAMPDATA_H +#define CAMPDATA_H + +#include "camp-data.h" +#include +#include +#include +#include +#include + +#include + +#pragma db object +class CampData : public QObject +{ + Q_OBJECT + Q_PROPERTY(QDate start READ start WRITE setStart) + Q_PROPERTY(QDate end READ end WRITE setEnd) + Q_PROPERTY(QString ownerFirstame READ ownerFirstame WRITE setOwnerFirstame) + Q_PROPERTY(QString ownerLastname READ ownerLastname WRITE setOwnerLastname) + Q_PROPERTY(QString ownerAddress READ ownerAddress WRITE setOwnerAddress) + Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice) + +public: + explicit CampData(QObject *parent = 0); + + int id() const; + void setId(int id); + + QDate start() const; + void setStart(const QDate &start); + + QDate end() const; + void setEnd(const QDate &end); + + QString ownerFirstame() const; + void setOwnerFirstame(const QString &ownerFirstame); + + QString ownerLastname() const; + void setOwnerLastname(const QString &ownerLastname); + + QString ownerAddress() const; + void setOwnerAddress(const QString &ownerAddress); + + QOdbList > services() const; + void setServices(const QOdbList > &services); + void addServiceItem(ServiceItemPtr serviceItem); + + QOdbList people() const; + void setPeople(const QOdbList &people); + void addPerson(AddressItemPtr person); + + QDecDouble totalPrice() const; + void setTotalPrice(QDecDouble totalPrice); + + SeasonPtr season() const; + void setSeason(const SeasonPtr &season); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QDate m_start; + QDate m_end; + QString m_ownerFirstame; + QString m_ownerLastname; + QString m_ownerAddress; + #pragma db value_not_null inverse(m_campData) + QOdbList m_services; + #pragma db value_not_null inverse(m_campData) + QOdbList m_people; + int m_totalPrice; + SeasonPtr m_season; +}; + +#endif // CAMPDATA_H diff --git a/camp/data/serviceitem.cpp b/camp/data/serviceitem.cpp new file mode 100644 index 0000000..d721283 --- /dev/null +++ b/camp/data/serviceitem.cpp @@ -0,0 +1,77 @@ +#include "serviceitem.h" +#include + +ServiceItem::ServiceItem(QObject *parent) : QObject(parent) +{ + +} + +int ServiceItem::id() const +{ + return m_id; +} + +void ServiceItem::setId(int id) +{ + m_id = id; +} + +QString ServiceItem::name() const +{ + return m_name; +} + +void ServiceItem::setName(const QString &name) +{ + m_name = name; +} + +QString ServiceItem::code() const +{ + return m_code; +} + +void ServiceItem::setCode(const QString &code) +{ + m_code = code; +} + +QDecDouble ServiceItem::price() const +{ + return TO_DEC(m_price); +} + +void ServiceItem::setPrice(QDecDouble price) +{ + m_price = FROM_DEC(price); +} + +bool ServiceItem::salePossible() const +{ + return m_salePossible; +} + +void ServiceItem::setSalePossible(bool salePossible) +{ + m_salePossible = salePossible; +} + +AccService::ServiceType ServiceItem::type() const +{ + return m_type; +} + +void ServiceItem::setType(const AccService::ServiceType &type) +{ + m_type = type; +} + +QWeakPointer ServiceItem::campData() const +{ + return m_campData; +} + +void ServiceItem::setCampData(const QWeakPointer &campData) +{ + m_campData = campData; +} diff --git a/camp/data/serviceitem.h b/camp/data/serviceitem.h new file mode 100644 index 0000000..b31aaf1 --- /dev/null +++ b/camp/data/serviceitem.h @@ -0,0 +1,63 @@ +#ifndef SREVICEITEM_H +#define SREVICEITEM_H + +#include "camp-data.h" +#include +#include +#include +#include + +#include +#include + +class CampData; + +#pragma db object +class ServiceItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString code READ code WRITE setCode) + Q_PROPERTY(QDecDouble price READ price WRITE setPrice) + Q_PROPERTY(bool salePossible READ salePossible WRITE setSalePossible) + Q_PROPERTY(AccService::ServiceType type READ type WRITE setType) + Q_ENUMS(AccService::ServiceType) + +public: + explicit ServiceItem(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString name() const; + void setName(const QString &name); + + QString code() const; + void setCode(const QString &code); + + QDecDouble price() const; + void setPrice(QDecDouble price); + + bool salePossible() const; + void setSalePossible(bool salePossible); + + AccService::ServiceType type() const; + void setType(const AccService::ServiceType &type); + + QWeakPointer campData() const; + void setCampData(const QWeakPointer &campData); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_name; + QString m_code; + int m_price; + bool m_salePossible; + AccService::ServiceType m_type; + #pragma db not_null + QWeakPointer m_campData; +}; + +#endif // SREVICEITEM_H diff --git a/camp/icons/campPlugin.svg b/camp/icons/campPlugin.svg new file mode 100644 index 0000000..88f894a --- /dev/null +++ b/camp/icons/campPlugin.svg @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/core/core.pro b/core/core.pro index fe4434a..c0a6c46 100644 --- a/core/core.pro +++ b/core/core.pro @@ -62,7 +62,8 @@ SOURCES += \ settings/seasonnamedialog.cpp \ reporting/report.cpp \ reporting/reportviewer.cpp \ - reporting/reportdialog.cpp + reporting/reportdialog.cpp \ + csvimporter.cpp HEADERS += core.h\ core_global.h \ @@ -122,7 +123,9 @@ HEADERS += core.h\ settings/seasonnamedialog.h \ reporting/report.h \ reporting/reportviewer.h \ - reporting/reportdialog.h + reporting/reportdialog.h \ + iimporter.h \ + csvimporter.h unix { target.path = /usr/lib diff --git a/core/csvimporter.cpp b/core/csvimporter.cpp new file mode 100644 index 0000000..7c8f136 --- /dev/null +++ b/core/csvimporter.cpp @@ -0,0 +1,93 @@ +#include "csvimporter.h" +#include +#include + +CsvImporter::CsvImporter(const QMetaObject *metaObject, QObject *parent) + :QObject(parent), + IImporter(metaObject) +{ + m_parsed = false; + m_currentRec = 1; + m_error = false; +} + +void CsvImporter::setImportFile(const QString &fileName) +{ + m_fileName = fileName; +} + +int CsvImporter::recordCount() +{ + if (!m_parsed) + { + parseFile(); + } + + return m_lines.count() - 1; +} + +QSharedPointer CsvImporter::nextRecord() +{ + if (!m_parsed) + { + parseFile(); + } + + QObject *entity = m_metaObject->newInstance(); + + if (entity == NULL || m_currentRec > recordCount()) + { + ++m_currentRec; + return QSharedPointer(); + } + + QStringList props = m_header.split(m_separator); + QString line = m_lines[m_currentRec]; + QStringList values = line.split(m_separator); + + for (int i = 0; i < props.size(); i++) { + QString property = props[i]; + QString value = values[i]; + if (!entity->setProperty(property.toStdString().c_str(), QVariant(value))) + { + m_error = true; + emit noSuchProperty(property); + + ++m_currentRec; + return QSharedPointer(); + } + } + + ++m_currentRec; + + return QSharedPointer(entity); +} + +bool CsvImporter::isError() +{ + return m_error; +} + +void CsvImporter::parseFile() +{ + QFile file(m_fileName); + + if (!file.open(QFile::ReadOnly | QFile::Text)) + { + m_error = true; + emit parseError(); + return; + } + + QByteArray data = file.readAll(); + QString strData(data); + + m_lines = strData.split("\n"); + m_header = m_lines[0]; + m_parsed = true; +} + +void CsvImporter::setSeparator(const QString &separator) +{ + m_separator = separator; +} diff --git a/core/csvimporter.h b/core/csvimporter.h new file mode 100644 index 0000000..b395fd9 --- /dev/null +++ b/core/csvimporter.h @@ -0,0 +1,40 @@ +#ifndef CSVIMPORTER_H +#define CSVIMPORTER_H + +#include "iimporter.h" +#include +#include + +class CsvImporter : public QObject, public IImporter +{ + Q_OBJECT + +public: + explicit CsvImporter(const QMetaObject *metaObject, QObject *parent = NULL); + + // IImporter interface +public: + void setImportFile(const QString &fileName); + int recordCount(); + QSharedPointer nextRecord(); + bool isError(); + + void setSeparator(const QString &separator); + +signals: + void parseError(); + void noSuchProperty(QString propName); + +private: + void parseFile(); + + QString m_header; + QString m_separator; + QString m_fileName; + QStringList m_lines; + bool m_parsed; + bool m_error; + int m_currentRec; +}; + +#endif // CSVIMPORTER_H diff --git a/core/igridform.cpp b/core/igridform.cpp index f98d651..05d2c86 100644 --- a/core/igridform.cpp +++ b/core/igridform.cpp @@ -54,6 +54,11 @@ QTableView *IGridForm::tableView() return ui->tableView; } +QWidget *IGridForm::toolbar() +{ + return ui->widget; +} + void IGridForm::hideColumns(const QList &cols) { foreach (int col, cols) { diff --git a/core/igridform.h b/core/igridform.h index 7017afa..e419706 100644 --- a/core/igridform.h +++ b/core/igridform.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "columndialog.h" #include "filterui.h" @@ -27,6 +28,7 @@ public: void setPluginId(const QString &pluginId); QString pluginId(); QTableView *tableView(); + QWidget *toolbar(); virtual void setTranslations(const QMap &translations) = 0; signals: diff --git a/core/iimporter.h b/core/iimporter.h new file mode 100644 index 0000000..19d62a7 --- /dev/null +++ b/core/iimporter.h @@ -0,0 +1,22 @@ +#ifndef IIMPORTER_H +#define IIMPORTER_H + +#include +#include +#include + +class IImporter +{ +public: + explicit IImporter(const QMetaObject *metaObject) { m_metaObject = metaObject; } + + virtual void setImportFile(const QString &fileName) = 0; + virtual int recordCount() = 0; + virtual QSharedPointer nextRecord() = 0; + virtual bool isError() = 0; + +protected: + const QMetaObject *m_metaObject; +}; + +#endif // IIMPORTER_H diff --git a/core/iplugin.h b/core/iplugin.h index e669d13..0d47eba 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -75,6 +75,7 @@ public: return (Service*)m_service; } + virtual bool showIcon() { return true; } virtual QTranslator* translator() { return NULL; } virtual QIcon pluginIcon() { return QIcon(); } QMap translations() { return m_translations; } diff --git a/core/service.h b/core/service.h index e3267db..60b9fa0 100644 --- a/core/service.h +++ b/core/service.h @@ -14,6 +14,7 @@ #include "context.h" #include "iservice.h" #include "permissionevaluator.h" +#include "iimporter.h" #include "transaction.h" @@ -178,6 +179,33 @@ public: } } + bool importData(IImporter *importer) { + int count = importer->recordCount(); + + if (importer->isError()) { + return false; + } + + for (int i = 0; i < count - 1; i++) { + QSharedPointer qentity = importer->nextRecord(); + + if (importer->isError() || qentity.isNull()) { + return false; + } + + QSharedPointer entity = qentity.dynamicCast(); + if (!entity.isNull()) { + this->save(entity); + } + else + { + return false; + } + } + + return true; + } + protected: bool checkPermission(const QString &permission) { if (!m_pluginId.isEmpty()) { diff --git a/prodejna.pro b/prodejna.pro index f5e7574..95848ec 100644 --- a/prodejna.pro +++ b/prodejna.pro @@ -5,9 +5,9 @@ SUBDIRS += \ qdecimal \ core \ application \ - accommodation \ services \ addressbook \ shop \ - commodity + commodity \ + camp