Revision c5d0ed54
Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt
samples/samples.pri | ||
---|---|---|
|
||
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/src/ $$EM_LIB
|
||
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/src/ $$EM_LIB
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/release/src/ $$EM_LIB
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/debug/src/ $$EM_LIB
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/src/ $$EM_LIB
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/src/ $$EM_LIB
|
||
|
||
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
||
|
samples/simple/article.cpp | ||
---|---|---|
/*
|
||
Small test class
|
||
Copyright (C) 2013 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
|
||
This file is part of OpenTeacherTool.
|
||
|
||
OpenTeacherTool is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
OpenTeacherTool is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with OpenTeacherTool. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#include "article.h"
|
||
|
||
QString Article::getName() const {
|
||
return name;
|
||
}
|
||
|
||
void Article::setName(const QString &value) {
|
||
name = value;
|
||
}
|
||
|
||
Article::~Article() {
|
||
|
||
}
|
||
|
||
Article::Article() : Entity() {
|
||
this->price = 0.0;
|
||
this->name = "";
|
||
}
|
||
|
||
Article::Article(double preis, QString name) : Entity() {
|
||
this->price = preis;
|
||
this->name = name;
|
||
}
|
||
|
||
double Article::getPrice() const
|
||
{
|
||
return price;
|
||
}
|
||
|
||
void Article::setPrice(double value)
|
||
{
|
||
price = value;
|
||
}
|
samples/simple/article.h | ||
---|---|---|
/*
|
||
Small test class
|
||
Copyright (C) 2013 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
|
||
This file is part of OpenTeacherTool.
|
||
|
||
OpenTeacherTool is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
OpenTeacherTool is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with OpenTeacherTool. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#ifndef ARTICLE_H
|
||
#define ARTICLE_H
|
||
#include "entity.h"
|
||
|
||
class Article : public CuteEntityManager::Entity {
|
||
Q_OBJECT
|
||
Q_PROPERTY(double price READ getPrice WRITE setPrice)
|
||
Q_PROPERTY(QString name READ getName WRITE setName)
|
||
private:
|
||
double price;
|
||
QString name;
|
||
|
||
public:
|
||
virtual ~Article();
|
||
Q_INVOKABLE Article();
|
||
Article(double price, QString name);
|
||
QString getName() const;
|
||
void setName(const QString &value);
|
||
double getPrice() const;
|
||
void setPrice(double value);
|
||
};
|
||
#endif // ARTIKEL_H
|
samples/simple/artikel.cpp | ||
---|---|---|
/*
|
||
Small test class
|
||
Copyright (C) 2013 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
|
||
This file is part of OpenTeacherTool.
|
||
|
||
OpenTeacherTool is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
OpenTeacherTool is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with OpenTeacherTool. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
#include "artikel.h"
|
||
|
||
double Artikel::getPreis() const {
|
||
return preis;
|
||
}
|
||
|
||
void Artikel::setPreis(double value) {
|
||
preis = value;
|
||
}
|
||
|
||
QString Artikel::getName() const {
|
||
return name;
|
||
}
|
||
|
||
void Artikel::setName(const QString &value) {
|
||
name = value;
|
||
}
|
||
|
||
Artikel::~Artikel() {
|
||
|
||
}
|
||
|
||
Artikel::Artikel() : Entity() {
|
||
this->preis = 0.0;
|
||
this->name = "";
|
||
}
|
||
|
||
Artikel::Artikel(double preis, QString name) : Entity() {
|
||
this->preis = preis;
|
||
this->name = name;
|
||
}
|
samples/simple/artikel.h | ||
---|---|---|
/*
|
||
Small test class
|
||
Copyright (C) 2013 Christian Ehringfeld <c.ehringfeld@t-online.de>
|
||
|
||
This file is part of OpenTeacherTool.
|
||
|
||
OpenTeacherTool is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
OpenTeacherTool is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with OpenTeacherTool. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#ifndef ARTIKEL_H
|
||
#define ARTIKEL_H
|
||
#include "../../src/entity.h"
|
||
#include <QHash>
|
||
#include <QVariant>
|
||
|
||
class Artikel : public CuteEntityManager::Entity {
|
||
Q_OBJECT
|
||
Q_PROPERTY(double preis READ getPreis WRITE setPreis)
|
||
Q_PROPERTY(QString name READ getName WRITE setName)
|
||
private:
|
||
double preis;
|
||
QString name;
|
||
|
||
public:
|
||
virtual ~Artikel();
|
||
Q_INVOKABLE Artikel();
|
||
Artikel(double preis, QString name);
|
||
double getPreis() const;
|
||
void setPreis(double value);
|
||
QString getName() const;
|
||
void setName(const QString &value);
|
||
};
|
||
#endif // ARTIKEL_H
|
samples/simple/main.cpp | ||
---|---|---|
#include <QCoreApplication>
|
||
#include <QDir>
|
||
#include <QDebug>
|
||
#include "artikel.h"
|
||
#include "article.h"
|
||
#include "entitymanager.h"
|
||
#include "entityinstancefactory.h"
|
||
|
||
... | ... | |
using namespace CuteEntityManager;
|
||
int main(int argc, char *argv[]) {
|
||
Q_UNUSED(argc) Q_UNUSED(argv)
|
||
EntityInstanceFactory::registerClass<Artikel>();
|
||
QSharedPointer<CuteEntityManager::EntityManager> e = QSharedPointer<CuteEntityManager::EntityManager>(new
|
||
CuteEntityManager::EntityManager("QSQLITE", QDir::currentPath() + "/db.sqlite"));
|
||
QStringList inits = QStringList() << "Artikel";
|
||
EntityInstanceFactory::registerClass<Article>();
|
||
QSharedPointer<CuteEntityManager::EntityManager> e =
|
||
QSharedPointer<CuteEntityManager::EntityManager>(new
|
||
CuteEntityManager::EntityManager("QSQLITE",
|
||
QDir::currentPath() + "/db.sqlite"));
|
||
QStringList inits = QStringList() << "Article";
|
||
e->startup("0.1", inits);
|
||
QSharedPointer<Artikel> a = QSharedPointer<Artikel>(new Artikel(20.0,
|
||
"Müsli"));
|
||
QSharedPointer<Article> a = QSharedPointer<Article>(new Article(5.0,
|
||
"muesli"));
|
||
auto ep = a.objectCast<CuteEntityManager::Entity>();
|
||
qDebug() << e->create(ep, true, true);
|
||
qDebug() << e->create(ep, true, true); //INSERT on database
|
||
a->setPrice(6.0); //inflation
|
||
a->setName("muesli improved"); //1337 muesli upgrade
|
||
qDebug() << e->save(ep); //UPDATE on database
|
||
qDebug() << e->remove(ep); //REMOVE on database
|
||
return 0;
|
||
}
|
samples/simple/simple.pro | ||
---|---|---|
TEMPLATE = app
|
||
|
||
HEADERS += \
|
||
artikel.h
|
||
article.h
|
||
|
||
SOURCES += \
|
||
main.cpp \
|
||
artikel.cpp
|
||
article.cpp
|
tests/models.h | ||
---|---|---|
|
||
public:
|
||
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
|
||
Q_ENUM(Gender)
|
||
Q_ENUM(Gender);
|
||
enum class NameOrder {FIRST_FAMILY_NAME_ORDER, FAMILY_FIRST_NAME_ORDER};
|
||
Q_ENUM(NameOrder)
|
||
Q_ENUM(NameOrder);
|
||
Q_INVOKABLE explicit Person(QObject *parent = 0);
|
||
Person(QString firstName, QString familyName,
|
||
Gender gender = Gender::UNKNOWNGENDER,
|
tests/tests.pri | ||
---|---|---|
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/src/ $$EM_LIB
|
||
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/src/ $$EM_LIB
|
||
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/release/src/ $$EM_LIB
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/debug/src/ $$EM_LIB
|
||
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/src/ $$EM_LIB
|
||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/src/ $$EM_LIB
|
||
|
Auch abrufbar als: Unified diff
samples and includes