merge sub projects
This commit is contained in:
commit
abf8d246b8
|
|
@ -4,23 +4,23 @@ In *shared pointer* mode results of queries is QList<QSharedPointer<T>> and in *
|
|||
|
||||
Almost in every case shared pointer mode is better, But nut support regular mode for backward comptability.
|
||||
|
||||
To compiling in *shared pointer* define **NUT_SHARED_POINTER** macro
|
||||
By default _Nut_ compiles in shared pointer mode, to switch to ols raw pointer mode you must define **NUT_RAW_POINTER** macro
|
||||
|
||||
Nut has template alias
|
||||
|
||||
```cpp
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
template <typename T>
|
||||
using RowList = QList<QSharedPointer<T>>;
|
||||
|
||||
template <typename T>
|
||||
using Row = QSharedPointer<T>;
|
||||
#else
|
||||
#ifdef NUT_RAW_POINTER
|
||||
template <typename T>
|
||||
using RowList = QList<T*>;
|
||||
|
||||
template <typename T>
|
||||
using Row = T*;
|
||||
#else
|
||||
template <typename T>
|
||||
using RowList = QList<QSharedPointer<T>>;
|
||||
|
||||
template <typename T>
|
||||
using Row = QSharedPointer<T>;
|
||||
#endif
|
||||
```
|
||||
|
||||
|
|
@ -36,16 +36,16 @@ For the integration of your source, you can use these aliases.
|
|||
Ans also Nut::create<T>() method are defined for two mode
|
||||
|
||||
```cpp
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
template<class T>
|
||||
inline Row<T> create(QObject *parent) {
|
||||
return QSharedPointer<T>(new T(parent));
|
||||
}
|
||||
#else
|
||||
#ifdef NUT_RAW_POINTER
|
||||
template<class T>
|
||||
inline Row<T> create() {
|
||||
return new T;
|
||||
}
|
||||
#else
|
||||
template<class T>
|
||||
inline Row<T> create(QObject *parent) {
|
||||
return QSharedPointer<T>(new T(parent));
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
||||
|
|
@ -54,6 +54,6 @@ So you can use the Nut::create function without considering in what way the libr
|
|||
auto post = Nut::create<Post>();
|
||||
```
|
||||
|
||||
In above example if *NUT_SHARED_POINTER* is defined *post* is *QSharedPointer<Post>* else is *Post\**
|
||||
In above example if *NUT_RAW_POINTER* is defined *post* is *Post\** else is *QSharedPointer<Post>*
|
||||
|
||||
I recommand use *NUT_SHARED_POINTER* always!
|
||||
I recommand use shared pointer mode (default) always!
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/nut_config.h \
|
||||
$$PWD/nut_consts.h \
|
||||
$$PWD/nut_global.h \
|
||||
$$PWD/nut_macros.h \
|
||||
$$PWD/nut_namespace.h
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef NUT_CONFIG_H
|
||||
#define NUT_CONFIG_H
|
||||
|
||||
#if defined(NUT_SHARED) || !defined(NUT_STATIC)
|
||||
# ifdef NUT_STATIC
|
||||
# error "Both NUT_SHARED and NUT_STATIC defined, please make up your mind"
|
||||
# endif
|
||||
# ifndef NUT_SHARED
|
||||
# define NUT_SHARED
|
||||
# endif
|
||||
# if defined(NUT_BUILD_LIB)
|
||||
# define NUT_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NUT_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define NUT_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // NUT_CONFIG_H
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef DEFINES_P_H
|
||||
#define DEFINES_P_H
|
||||
#ifndef NUT_CONSTS_H
|
||||
#define NUT_CONSTS_H
|
||||
|
||||
#define __NAME "name"
|
||||
#define __TYPE "type"
|
||||
|
|
@ -56,4 +56,4 @@
|
|||
# define NUT_WRAP_NAMESPACE(x) x
|
||||
#endif
|
||||
|
||||
#endif // DEFINES_P_H
|
||||
#endif // NUT_CONSTS_H
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef NUT_GLOBAL_H
|
||||
#define NUT_GLOBAL_H
|
||||
|
||||
#define NUT_NAMESPACE Nut
|
||||
|
||||
#include <QtNut/nut_config.h>
|
||||
#include <QtNut/nut_consts.h>
|
||||
#include <QtNut/nut_macros.h>
|
||||
#include <QtNut/nut_macros.h>
|
||||
#include <QtNut/nut_namespace.h>
|
||||
|
||||
#endif // NUT_GLOBAL_H
|
||||
|
|
@ -1,51 +1,6 @@
|
|||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Nut project.
|
||||
** https://github.com/HamedMasafi/Nut
|
||||
**
|
||||
** Nut is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Nut 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 Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public License
|
||||
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
**************************************************************************/
|
||||
#ifndef NUT_MACROS_H
|
||||
#define NUT_MACROS_H
|
||||
|
||||
#ifndef SYNTAX_DEFINES_H
|
||||
#define SYNTAX_DEFINES_H
|
||||
|
||||
#define NUT_NAMESPACE Nut
|
||||
|
||||
#include <QtNut/defines_consts.h>
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QMetaClassInfo>
|
||||
|
||||
#if defined(NUT_SHARED) || !defined(NUT_STATIC)
|
||||
# ifdef NUT_STATIC
|
||||
# error "Both NUT_SHARED and NUT_STATIC defined, please make up your mind"
|
||||
# endif
|
||||
# ifndef NUT_SHARED
|
||||
# define NUT_SHARED
|
||||
# endif
|
||||
# if defined(NUT_BUILD_LIB)
|
||||
# define NUT_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define NUT_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define NUT_EXPORT
|
||||
#endif
|
||||
|
||||
#define NUT_INFO(type, name, value) \
|
||||
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, \
|
||||
|
|
@ -180,132 +135,4 @@ public slots: \
|
|||
#define NUT_NOT_NULL(x) NUT_INFO(__nut_NOT_NULL, x, 1)
|
||||
#define NUT_INDEX(name, field, order)
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
inline bool nutClassInfo(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, QVariant &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = QVariant::fromValue(parts[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool nutClassInfoString(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, QString &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = parts[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool nutClassInfoBool(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, bool &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
|
||||
QString buffer = parts[2].toLower();
|
||||
if (buffer != QStringLiteral("true") && buffer != QStringLiteral("false"))
|
||||
return false;
|
||||
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = (buffer == QStringLiteral("true"));
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool nutClassInfoInt(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, bool &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
bool ok;
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = parts[2].toInt(&ok);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
template <class T>
|
||||
using RowList = QList<QSharedPointer<T>>;
|
||||
|
||||
template <class T>
|
||||
using RowSet = QSet<QSharedPointer<T>>;
|
||||
|
||||
template <typename T>
|
||||
using Row = QSharedPointer<T>;
|
||||
|
||||
template<class T>
|
||||
inline Row<T> create() {
|
||||
return QSharedPointer<T>(new T);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline Row<T> create(QObject *parent) {
|
||||
return QSharedPointer<T>(new T(parent));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline Row<T> createFrom(T *row) {
|
||||
return QSharedPointer<T>(row);
|
||||
}
|
||||
template<class T>
|
||||
inline Row<T> createFrom(const QSharedPointer<T> row) {
|
||||
return row;
|
||||
}
|
||||
|
||||
#else
|
||||
template <typename T>
|
||||
using RowList = QList<T*>;
|
||||
|
||||
template <typename T>
|
||||
using RowSet = QSet<T*>;
|
||||
|
||||
template <typename T>
|
||||
using Row = T*;
|
||||
|
||||
template<class T>
|
||||
inline Row<T> create() {
|
||||
return new T;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(const Row<T> row) {
|
||||
return row;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(const QSharedPointer<T> row) {
|
||||
return row.data();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // SYNTAX_DEFINES_H
|
||||
#endif // NUT_MACROS_H
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
#ifndef NUT_NAMESPACE_H
|
||||
#define NUT_NAMESPACE_H
|
||||
|
||||
#ifndef NUT_GLOBAL_H
|
||||
# error "Do not include nut_namespace.h header directly!"
|
||||
#endif
|
||||
|
||||
//avoid ide warnings
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QMetaClassInfo>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
inline bool nutClassInfo(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, QVariant &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = QVariant::fromValue(parts[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool nutClassInfoString(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, QString &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = parts[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool nutClassInfoBool(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, bool &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
|
||||
QString buffer = parts[2].toLower();
|
||||
if (buffer != QStringLiteral("true") && buffer != QStringLiteral("false"))
|
||||
return false;
|
||||
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = (buffer == QStringLiteral("true"));
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool nutClassInfoInt(const QMetaClassInfo &classInfo,
|
||||
QString &type, QString &name, bool &value)
|
||||
{
|
||||
if (!QString::fromUtf8(classInfo.name()).startsWith(QStringLiteral(__nut_NAME_PERFIX)))
|
||||
return false;
|
||||
|
||||
QStringList parts = QString::fromUtf8(classInfo.value()).split(QStringLiteral("\n"));
|
||||
if (parts.count() != 3)
|
||||
return false;
|
||||
bool ok;
|
||||
type = parts[0];
|
||||
name = parts[1];
|
||||
value = parts[2].toInt(&ok);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifdef NUT_RAW_POINTER
|
||||
template <typename T>
|
||||
using RowList = QList<T*>;
|
||||
|
||||
template <typename T>
|
||||
using RowSet = QSet<T*>;
|
||||
|
||||
template <typename T>
|
||||
using Row = T*;
|
||||
|
||||
template<class T>
|
||||
inline Row<T> create() {
|
||||
return new T;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(const Row<T> row) {
|
||||
return row;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *get(const QSharedPointer<T> row) {
|
||||
return row.data();
|
||||
}
|
||||
#else
|
||||
template <class T>
|
||||
using RowList = QList<QSharedPointer<T>>;
|
||||
|
||||
template <class T>
|
||||
using RowSet = QSet<QSharedPointer<T>>;
|
||||
|
||||
template <typename T>
|
||||
using Row = QSharedPointer<T>;
|
||||
|
||||
template<class T>
|
||||
inline Row<T> create() {
|
||||
return QSharedPointer<T>(new T);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline Row<T> create(QObject *parent) {
|
||||
return QSharedPointer<T>(new T(parent));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline Row<T> createFrom(T *row) {
|
||||
return QSharedPointer<T>(row);
|
||||
}
|
||||
template<class T>
|
||||
inline Row<T> createFrom(const QSharedPointer<T> row) {
|
||||
return row;
|
||||
}
|
||||
#endif
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // NUT_NAMESPACE_H
|
||||
|
|
@ -63,10 +63,10 @@ int AbstractTableSet::save(Database *db, bool cleanUp)
|
|||
|| t->status() == Table::Deleted) {
|
||||
rowsAffected += t->save(db);
|
||||
if (cleanUp)
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
remove(t);
|
||||
#else
|
||||
#ifdef NUT_RAW_POINTER
|
||||
t->deleteLater();
|
||||
#else
|
||||
remove(t);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ int AbstractTableSet::save(Database *db, bool cleanUp)
|
|||
|
||||
void AbstractTableSet::clearChilds()
|
||||
{
|
||||
#ifndef NUT_SHARED_POINTER
|
||||
#ifdef NUT_RAW_POINTER
|
||||
foreach (Table *t, data->childs)
|
||||
t->deleteLater();
|
||||
#endif
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
#include <QtCore/QSet>
|
||||
#include <QtCore/QExplicitlySharedDataPointer>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <QtCore/QSharedData>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -5,7 +5,6 @@
|
|||
#include "database.h"
|
||||
#include "abstractsqlgenerator.h"
|
||||
#include "databasemodel.h"
|
||||
#include "tablemodel.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
#include <QtNut/phraselist.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/abstracttableset.h \
|
||||
$$PWD/abstracttablesetdata.h \
|
||||
$$PWD/bulkinserter.h \
|
||||
$$PWD/bulkinserter_p.h \
|
||||
$$PWD/changelogtable.h \
|
||||
$$PWD/database.h \
|
||||
$$PWD/database_p.h \
|
||||
$$PWD/query.h \
|
||||
$$PWD/table.h \
|
||||
$$PWD/table_p.h \
|
||||
$$PWD/tableset.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/abstracttableset.cpp \
|
||||
$$PWD/bulkinserter.cpp \
|
||||
$$PWD/changelogtable.cpp \
|
||||
$$PWD/database.cpp \
|
||||
$$PWD/query.cpp \
|
||||
$$PWD/table.cpp \
|
||||
$$PWD/tableset.cpp
|
||||
|
||||
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
#include "table.h"
|
||||
#include "tableset.h"
|
||||
#include "database_p.h"
|
||||
#include "defines.h"
|
||||
#include "config/nut_global.h"
|
||||
#include "tablemodel.h"
|
||||
#include "postgresqlgenerator.h"
|
||||
#include "mysqlgenerator.h"
|
||||
|
|
@ -348,7 +348,9 @@ bool DatabasePrivate::putModelToDatabase()
|
|||
void DatabasePrivate::createChangeLogs()
|
||||
{
|
||||
// currentModel.model("change_log")
|
||||
QStringList diff = sqlGenerator->diff(nullptr, currentModel.tableByName(QStringLiteral("__change_log")));
|
||||
QStringList diff = sqlGenerator->diff(nullptr,
|
||||
currentModel.tableByName(
|
||||
QStringLiteral("__change_log")));
|
||||
|
||||
foreach (QString s, diff)
|
||||
db.exec(s);
|
||||
|
|
@ -362,7 +364,6 @@ void DatabasePrivate::createChangeLogs()
|
|||
Database::Database(QObject *parent)
|
||||
: QObject(parent), d_ptr(new DatabasePrivate(this))
|
||||
{
|
||||
// _d = new QSharedDataPointer<DatabasePrivate>(new DatabasePrivate(this));
|
||||
DatabasePrivate::lastId++;
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +371,6 @@ Database::Database(const Database &other)
|
|||
: QObject(other.parent()), d_ptr(new DatabasePrivate(this))
|
||||
{
|
||||
DatabasePrivate::lastId++;
|
||||
// _d = other._d;
|
||||
|
||||
setDriver(other.driver());
|
||||
setHostName(other.hostName());
|
||||
|
|
@ -385,7 +385,7 @@ Database::Database(const QSqlDatabase &other)
|
|||
//TODO: make a polish here
|
||||
DatabasePrivate::lastId++;
|
||||
|
||||
// setDriver(other.driver());
|
||||
setDriver(other.driverName());
|
||||
setHostName(other.hostName());
|
||||
setPort(other.port());
|
||||
setDatabaseName(other.databaseName());
|
||||
|
|
@ -394,6 +394,12 @@ Database::Database(const QSqlDatabase &other)
|
|||
qRegisterMetaType<ChangeLogTable*>();
|
||||
}
|
||||
|
||||
Database::Database(Database &&other)
|
||||
{
|
||||
d_ptr = other.d_ptr;
|
||||
other.d_ptr = nullptr;
|
||||
}
|
||||
|
||||
Database::~Database()
|
||||
{
|
||||
Q_D(Database);
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
#include <QtCore/QSharedDataPointer>
|
||||
#include <QtSql/QSqlDatabase>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/tableset.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
|
@ -48,6 +48,7 @@ public:
|
|||
explicit Database(QObject *parent = nullptr);
|
||||
explicit Database(const Database &other);
|
||||
explicit Database(const QSqlDatabase &other);
|
||||
explicit Database(Database &&other);
|
||||
~Database();
|
||||
|
||||
bool open();
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class ChangeLogTable;
|
||||
class NUT_EXPORT DatabasePrivate //: public QSharedData
|
||||
class NUT_EXPORT DatabasePrivate
|
||||
{
|
||||
Database *q_ptr;
|
||||
Q_DECLARE_PUBLIC(Database)
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
#include <QtSql/QSqlQueryModel>
|
||||
#include <QtSql/QSqlQuery>
|
||||
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
#ifndef NUT_RAW_POINTER
|
||||
#include <QtCore/QSharedPointer>
|
||||
#endif
|
||||
|
||||
|
|
@ -351,10 +351,10 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
|||
Row<Table> row;
|
||||
if (data.table->className() == d->className) {
|
||||
row = Nut::create<T>();
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
returnList.append(row.objectCast<T>());
|
||||
#else
|
||||
#ifdef NUT_RAW_POINTER
|
||||
returnList.append(dynamic_cast<T*>(table));
|
||||
#else
|
||||
returnList.append(row.objectCast<T>());
|
||||
#endif
|
||||
d->tableSet->add(row);
|
||||
|
||||
|
|
@ -43,6 +43,10 @@ NUT_BEGIN_NAMESPACE
|
|||
* This should be fixed to v1.2
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \class Table
|
||||
* \brief Base class for all tables
|
||||
*/
|
||||
Table::Table(QObject *parent) : QObject(parent),
|
||||
d(new TablePrivate)
|
||||
{ }
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/QSet>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/tablemodel.h>
|
||||
#include <QtNut/phrase.h>
|
||||
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
#include <QtCore/QSet>
|
||||
#include <QtCore/QSharedData>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/table.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -100,10 +100,10 @@ Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE Row<T> TableSet<T>::at(int i) const
|
||||
{
|
||||
#ifdef NUT_SHARED_POINTER
|
||||
return data->childs.at(i).template objectCast<T>();
|
||||
#else
|
||||
#ifdef NUT_RAW_POINTER
|
||||
return reinterpret_cast<T*>(data->childs.at(i));
|
||||
#else
|
||||
return data->childs.at(i).template objectCast<T>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -616,10 +616,10 @@ QString AbstractSqlGenerator::selectCommand(const QString &tableName,
|
|||
QString sql = QStringLiteral("SELECT ") + selectText
|
||||
+ QStringLiteral(" FROM ") + fromText;
|
||||
|
||||
if (whereText != QStringLiteral(""))
|
||||
if (!whereText.isEmpty())
|
||||
sql.append(QStringLiteral(" WHERE ") + whereText);
|
||||
|
||||
if (orderText != QStringLiteral(""))
|
||||
if (!orderText.isEmpty())
|
||||
sql.append(QStringLiteral(" ORDER BY ") + orderText);
|
||||
|
||||
// for (int i = 0; i < _database->model().count(); i++)
|
||||
|
|
@ -648,7 +648,7 @@ QString AbstractSqlGenerator::selectCommand(const QString &tableName,
|
|||
QString sql = QStringLiteral("SELECT ") + selectText
|
||||
+ QStringLiteral(" FROM ") + fromText;
|
||||
|
||||
if (whereText != QStringLiteral(""))
|
||||
if (!whereText.isEmpty())
|
||||
sql.append(QStringLiteral(" WHERE ") + whereText);
|
||||
|
||||
for (int i = 0; i < _database->model().count(); i++)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/abstractsqlgenerator.h \
|
||||
$$PWD/postgresqlgenerator.h \
|
||||
$$PWD/mysqlgenerator.h \
|
||||
$$PWD/sqlitegenerator.h \
|
||||
$$PWD/sqlservergenerator.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/abstractsqlgenerator.cpp \
|
||||
$$PWD/postgresqlgenerator.cpp \
|
||||
$$PWD/mysqlgenerator.cpp \
|
||||
$$PWD/sqlitegenerator.cpp \
|
||||
$$PWD/sqlservergenerator.cpp
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/databasemodel.h \
|
||||
$$PWD/sqlmodel.h \
|
||||
$$PWD/sqlmodel_p.h \
|
||||
$$PWD/tablemodel.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/databasemodel.cpp \
|
||||
$$PWD/sqlmodel.cpp \
|
||||
$$PWD/tablemodel.cpp
|
||||
|
||||
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtCore/QExplicitlySharedDataPointer>
|
||||
#include <QtCore/QList>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ public:
|
|||
void append(Row<Table> table);
|
||||
// void append(Table *table);
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
Row<Nut::Table> at(const int &i) const;
|
||||
Row<Table> at(const int &i) const;
|
||||
|
||||
void setRenderer(const std::function<QVariant (int, QVariant)> &renderer);
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtCore/QJsonObject>
|
||||
|
||||
#include "tablemodel.h"
|
||||
#include "defines.h"
|
||||
#include "nut_global.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ HEADERS += \
|
|||
$$PWD/types/dbgeography.h \
|
||||
$$PWD/tableset.h \
|
||||
$$PWD/defines_consts.h \
|
||||
$$PWD/defines.h \
|
||||
$$PWD/nut_global.h \
|
||||
$$PWD/query.h \
|
||||
$$PWD/databasemodel.h \
|
||||
$$PWD/changelogtable.h \
|
||||
|
|
@ -9,75 +9,18 @@ DEFINES += QT_DEPRECATED_WARNINGS NUT_SHARED NUT_BUILD_LIB
|
|||
|
||||
DEFINES += NUT_SHARED_POINTER
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$PWD/generators \
|
||||
$$PWD/phrases \
|
||||
$$PWD/types
|
||||
include(config/config.pri)
|
||||
include(core/core.pri)
|
||||
include(generators/generators.pri)
|
||||
include(types/types.pri)
|
||||
include(phrases/phrases.pri)
|
||||
include(models/models.pri)
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/generators/abstractsqlgenerator.h \
|
||||
$$PWD/generators/postgresqlgenerator.h \
|
||||
$$PWD/generators/mysqlgenerator.h \
|
||||
$$PWD/generators/sqlitegenerator.h \
|
||||
$$PWD/generators/sqlservergenerator.h \
|
||||
$$PWD/types/dbgeography.h \
|
||||
$$PWD/tableset.h \
|
||||
$$PWD/defines_consts.h \
|
||||
$$PWD/defines.h \
|
||||
$$PWD/query.h \
|
||||
$$PWD/bulkinserter.h \
|
||||
$$PWD/databasemodel.h \
|
||||
$$PWD/changelogtable.h \
|
||||
$$PWD/abstracttableset.h \
|
||||
$$PWD/abstracttablesetdata.h \
|
||||
$$PWD/tablemodel.h \
|
||||
$$PWD/table.h \
|
||||
$$PWD/database.h \
|
||||
$$PWD/database_p.h \
|
||||
$$PWD/serializableobject.h \
|
||||
$$PWD/sqlmodel.h \
|
||||
$$PWD/sqlmodel_p.h \
|
||||
$$PWD/phrase.h \
|
||||
$$PWD/phrases/abstractfieldphrase.h \
|
||||
$$PWD/phrases/assignmentphrase.h \
|
||||
$$PWD/phrases/assignmentphraselist.h \
|
||||
$$PWD/phrases/conditionalphrase.h \
|
||||
$$PWD/phrases/fieldphrase.h \
|
||||
$$PWD/phrases/phrasedata.h \
|
||||
$$PWD/phrases/phrasedatalist.h \
|
||||
$$PWD/phrases/phraselist.h \
|
||||
$$PWD/phrases/datephrase.h \
|
||||
$$PWD/table_p.h \
|
||||
bulkinserter_p.h
|
||||
$$PWD/phrase.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/generators/abstractsqlgenerator.cpp \
|
||||
$$PWD/generators/postgresqlgenerator.cpp \
|
||||
$$PWD/generators/mysqlgenerator.cpp \
|
||||
$$PWD/generators/sqlitegenerator.cpp \
|
||||
$$PWD/generators/sqlservergenerator.cpp \
|
||||
$$PWD/types/dbgeography.cpp \
|
||||
$$PWD/tableset.cpp \
|
||||
$$PWD/query.cpp \
|
||||
$$PWD/bulkinserter.cpp \
|
||||
$$PWD/databasemodel.cpp \
|
||||
$$PWD/abstracttableset.cpp \
|
||||
$$PWD/changelogtable.cpp \
|
||||
$$PWD/tablemodel.cpp \
|
||||
$$PWD/table.cpp \
|
||||
$$PWD/database.cpp \
|
||||
$$PWD/serializableobject.cpp \
|
||||
$$PWD/sqlmodel.cpp \
|
||||
$$PWD/phrase.cpp \
|
||||
$$PWD/phrases/abstractfieldphrase.cpp \
|
||||
$$PWD/phrases/assignmentphrase.cpp \
|
||||
$$PWD/phrases/assignmentphraselist.cpp \
|
||||
$$PWD/phrases/conditionalphrase.cpp \
|
||||
$$PWD/phrases/fieldphrase.cpp \
|
||||
$$PWD/phrases/phrasedata.cpp \
|
||||
$$PWD/phrases/phrasedatalist.cpp \
|
||||
$$PWD/phrases/phraselist.cpp \
|
||||
$$PWD/phrases/datephrase.cpp
|
||||
$$PWD/phrase.cpp
|
||||
|
||||
load(qt_module)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,47 +19,3 @@
|
|||
**************************************************************************/
|
||||
|
||||
#include "phrase.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//AssignmentPhrase::AssignmentPhrase(AssignmentPhrase *l, const AssignmentPhrase *r)
|
||||
//{
|
||||
//// data = new PhraseData(l->data, PhraseData::Append, r->data);
|
||||
// qFatal("SS");
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, const AssignmentPhrase &r)
|
||||
//{
|
||||
// return AssignmentPhraseList(l, r);
|
||||
//}
|
||||
|
||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, AssignmentPhrase &&r)
|
||||
//{
|
||||
// r.data = 0;
|
||||
// return AssignmentPhraseList(l, r);
|
||||
//}
|
||||
|
||||
//AssignmentPhraseList operator &(AssignmentPhrase &&l, const AssignmentPhrase &r)
|
||||
//{
|
||||
// l.data = 0;
|
||||
// return AssignmentPhraseList(l, r);
|
||||
//}
|
||||
|
||||
//AssignmentPhraseList operator &(AssignmentPhrase &&l, AssignmentPhrase &&r)
|
||||
//{
|
||||
// r.data = l.data = 0;
|
||||
// return AssignmentPhraseList(l, r);
|
||||
//}
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#ifndef PHRASE_H
|
||||
#define PHRASE_H
|
||||
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/conditionalphrase.h>
|
||||
#include <QtNut/abstractfieldphrase.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
|
@ -30,44 +31,8 @@
|
|||
#include <QtNut/phrasedata.h>
|
||||
#include <QtNut/assignmentphrase.h>
|
||||
#include <QtNut/numericphrase.h>
|
||||
#include <QtNut/datephrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
#define SPECIALIZATION_NUMERIC_MEMBER(type, op, cond) \
|
||||
ConditionalPhrase operator op(const QVariant &other) \
|
||||
{ \
|
||||
return ConditionalPhrase(this, cond, other); \
|
||||
}
|
||||
|
||||
class AbstractFieldPhrase;
|
||||
class AssignmentPhrase;
|
||||
class PhraseList;
|
||||
|
||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, const AssignmentPhrase &r);
|
||||
//AssignmentPhraseList operator &(const AssignmentPhrase &l, AssignmentPhrase &&r);
|
||||
//AssignmentPhraseList operator &(AssignmentPhrase &&l, const AssignmentPhrase &r);
|
||||
//AssignmentPhraseList operator &(AssignmentPhrase &&l, AssignmentPhrase &&r);
|
||||
|
||||
|
||||
//ConditionalPhrase operator <(AbstractFieldPhrase &l, ConditionalPhrase &&other)
|
||||
//{
|
||||
// return ConditionalPhrase(&l, PhraseData::Less, other);
|
||||
//}
|
||||
|
||||
//template<typename T>
|
||||
//class FieldPhrase : public AbstractFieldPhrase
|
||||
//{
|
||||
//public:
|
||||
// FieldPhrase(const char *className, const char *s) :
|
||||
// AbstractFieldPhrase(className, s)
|
||||
// {}
|
||||
|
||||
// AssignmentPhrase operator =(const QVariant &other) {
|
||||
// return AssignmentPhrase(this, other);
|
||||
// }
|
||||
//};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
#include <QtNut/fieldphrase_date.h>
|
||||
#include <QtNut/fieldphrase_qstring.h>
|
||||
#include <QtNut/fieldphrase_bool.h>
|
||||
|
||||
#endif // PHRASE_H
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
**************************************************************************/
|
||||
|
||||
#include "abstractfieldphrase.h"
|
||||
#include <QDebug>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -34,22 +35,26 @@ AbstractFieldPhrase::AbstractFieldPhrase(const char *className,
|
|||
AbstractFieldPhrase::AbstractFieldPhrase(const AbstractFieldPhrase &other)
|
||||
{
|
||||
data = other.data;
|
||||
data->parents++;
|
||||
data->ref.ref();
|
||||
}
|
||||
|
||||
AbstractFieldPhrase::AbstractFieldPhrase(AbstractFieldPhrase &&other)
|
||||
{
|
||||
data = other.data;
|
||||
data->parents++;
|
||||
other.data = nullptr;
|
||||
}
|
||||
|
||||
AbstractFieldPhrase::~AbstractFieldPhrase()
|
||||
{
|
||||
if (data) {
|
||||
--data->parents;
|
||||
if (data->parents <= 0)
|
||||
if (!data->ref.deref()) {
|
||||
qDebug() << "deleted" << data->className
|
||||
<< data->fieldName;
|
||||
delete data;
|
||||
}
|
||||
else
|
||||
qDebug() << "more parents for" << data->className
|
||||
<< data->fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +92,14 @@ AssignmentPhrase AbstractFieldPhrase::operator <<(const QVariant &other)
|
|||
return AssignmentPhrase(this, other);
|
||||
}
|
||||
|
||||
void AbstractFieldPhrase::detach()
|
||||
{
|
||||
auto clone = data->clone();
|
||||
if (!data->ref.deref())
|
||||
delete data;
|
||||
data = clone;
|
||||
}
|
||||
|
||||
#define AbstractFieldPhraseOperatorVariant(class, op, cond) \
|
||||
ConditionalPhrase class::operator op(const QVariant &other) \
|
||||
{ \
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef ABSTRACTFIELDPHRASE_H
|
||||
#define ABSTRACTFIELDPHRASE_H
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/assignmentphrase.h>
|
||||
#include <QtNut/conditionalphrase.h>
|
||||
#include <QtNut/phraselist.h>
|
||||
|
|
@ -80,6 +80,9 @@ public:
|
|||
AssignmentPhrase operator =(const QVariant &other);
|
||||
AssignmentPhrase operator =(const ConditionalPhrase &other);
|
||||
AssignmentPhrase operator <<(const QVariant &other);
|
||||
|
||||
protected:
|
||||
void detach();
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ NUT_BEGIN_NAMESPACE
|
|||
|
||||
AssignmentPhrase::AssignmentPhrase(PhraseData *d) : data(d)
|
||||
{
|
||||
d->parents++;
|
||||
d->ref.ref();
|
||||
}
|
||||
|
||||
AssignmentPhrase::AssignmentPhrase(AbstractFieldPhrase *l, const QVariant r)
|
||||
|
|
@ -56,9 +56,8 @@ AssignmentPhrase::AssignmentPhrase(AssignmentPhrase *ph, const QVariant &v)
|
|||
|
||||
AssignmentPhrase::~AssignmentPhrase()
|
||||
{
|
||||
if (data)
|
||||
if (!--data->parents)
|
||||
delete data;
|
||||
if (data && data->ref.deref())
|
||||
delete data;
|
||||
}
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef ASSIGNMENTPHRASE_H
|
||||
#define ASSIGNMENTPHRASE_H
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/assignmentphraselist.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@ AssignmentPhraseList AssignmentPhraseList::operator &(const AssignmentPhrase
|
|||
|
||||
AssignmentPhraseList::~AssignmentPhraseList()
|
||||
{
|
||||
foreach (PhraseData *d, data)
|
||||
if (!--d->parents)
|
||||
delete d;
|
||||
// foreach (PhraseData *d, data)
|
||||
// if (!d->ref.deref())
|
||||
// delete d;
|
||||
// qDeleteAll(data);
|
||||
// data.clear();
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ AssignmentPhraseList::~AssignmentPhraseList()
|
|||
void AssignmentPhraseList::incAllDataParents()
|
||||
{
|
||||
foreach (PhraseData *d, data)
|
||||
d->parents++;
|
||||
d->ref.ref();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef ASSIGNMENTPHRASELIST_H
|
||||
#define ASSIGNMENTPHRASELIST_H
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "abstractfieldphrase.h"
|
||||
#include "conditionalphrase.h"
|
||||
#include "phrasedata.h"
|
||||
|
|
@ -30,21 +32,21 @@ ConditionalPhrase::ConditionalPhrase() : data(nullptr)
|
|||
ConditionalPhrase::ConditionalPhrase(const ConditionalPhrase &other)
|
||||
{
|
||||
data = other.data;
|
||||
data->parents++;
|
||||
// const_cast<ConditionalPhrase&>(other).data = 0;
|
||||
data->ref.ref();
|
||||
}
|
||||
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
ConditionalPhrase::ConditionalPhrase(ConditionalPhrase &&other)
|
||||
{
|
||||
this->data = qMove(other.data);
|
||||
data = other.data;
|
||||
other.data = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
ConditionalPhrase::ConditionalPhrase(const PhraseData *data)
|
||||
{
|
||||
this->data = const_cast<PhraseData*>(data);
|
||||
this->data->parents++;
|
||||
data = const_cast<PhraseData*>(data);
|
||||
data->ref.ref();
|
||||
}
|
||||
|
||||
ConditionalPhrase::ConditionalPhrase(AbstractFieldPhrase *l,
|
||||
|
|
@ -104,8 +106,10 @@ ConditionalPhrase::~ConditionalPhrase()
|
|||
{
|
||||
if (data) {
|
||||
data->cleanUp();
|
||||
if (!--data->parents)
|
||||
if (!data->ref.deref()) {
|
||||
qDebug() << "deleted for cond";
|
||||
delete data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +117,7 @@ ConditionalPhrase &ConditionalPhrase::operator =(const ConditionalPhrase &other)
|
|||
{
|
||||
data = other.data;
|
||||
if (data)
|
||||
data->parents++;
|
||||
data->ref.ref();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -122,23 +126,6 @@ ConditionalPhrase ConditionalPhrase::operator ==(const QVariant &other)
|
|||
return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||
}
|
||||
|
||||
//ConditionalPhrase ConditionalPhrase::operator ==(const AbstractFieldPhrase &other)
|
||||
//{
|
||||
// return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||
//}
|
||||
|
||||
//ConditionalPhrase ConditionalPhrase::operator &&(const ConditionalPhrase &other)
|
||||
//{
|
||||
// return ConditionalPhrase(this, PhraseData::And,
|
||||
// const_cast<ConditionalPhrase&>(other));
|
||||
//}
|
||||
|
||||
//ConditionalPhrase ConditionalPhrase::operator ||(const ConditionalPhrase &other)
|
||||
//{
|
||||
// return ConditionalPhrase(this, PhraseData::Or,
|
||||
// const_cast<ConditionalPhrase&>(other));
|
||||
//}
|
||||
|
||||
#define DECLARE_CONDITIONALPHRASE_OPERATORS_IMPL(op, cond) \
|
||||
ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
||||
const ConditionalPhrase &r) \
|
||||
|
|
@ -149,8 +136,8 @@ ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
|||
p.data->operatorCond = cond; \
|
||||
p.data->left = l.data; \
|
||||
p.data->right = r.data; \
|
||||
l.data->parents++; \
|
||||
r.data->parents++; \
|
||||
l.data->ref.ref(); \
|
||||
r.data->ref.ref(); \
|
||||
return p; \
|
||||
} \
|
||||
ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
||||
|
|
@ -162,8 +149,8 @@ ConditionalPhrase operator op(const ConditionalPhrase &l, \
|
|||
p.data->operatorCond = cond; \
|
||||
p.data->left = l.data; \
|
||||
p.data->right = r.data; \
|
||||
l.data->parents++; \
|
||||
r.data->parents++; \
|
||||
l.data->ref.ref(); \
|
||||
r.data = nullptr; \
|
||||
return p; \
|
||||
} \
|
||||
ConditionalPhrase operator op(ConditionalPhrase &&l, \
|
||||
|
|
@ -175,8 +162,8 @@ ConditionalPhrase operator op(ConditionalPhrase &&l, \
|
|||
p.data->operatorCond = cond; \
|
||||
p.data->left = l.data; \
|
||||
p.data->right = r.data; \
|
||||
l.data->parents++; \
|
||||
r.data->parents++; \
|
||||
r.data->ref.ref(); \
|
||||
l.data = nullptr; \
|
||||
return p; \
|
||||
} \
|
||||
ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r) \
|
||||
|
|
@ -187,8 +174,8 @@ ConditionalPhrase operator op(ConditionalPhrase &&l, ConditionalPhrase &&r) \
|
|||
p.data->operatorCond = cond; \
|
||||
p.data->left = l.data; \
|
||||
p.data->right = r.data; \
|
||||
l.data->parents++; \
|
||||
r.data->parents++; \
|
||||
l.data = nullptr; \
|
||||
r.data = nullptr; \
|
||||
return p; \
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef FIELDPHRASE_H
|
||||
#define FIELDPHRASE_H
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/abstractfieldphrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
|
@ -50,29 +50,6 @@ Q_OUTOFLINE_TEMPLATE ConditionalPhrase FieldPhrase<T>::operator ==(const QVarian
|
|||
return ConditionalPhrase(this, PhraseData::Equal, other);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
class FieldPhrase<QString> : public AbstractFieldPhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s) :
|
||||
AbstractFieldPhrase(className, s)
|
||||
{}
|
||||
|
||||
ConditionalPhrase like(const QString &term) {
|
||||
return ConditionalPhrase(this, PhraseData::Like, term);
|
||||
}
|
||||
|
||||
ConditionalPhrase contains(const QString &term) {
|
||||
return ConditionalPhrase(this, PhraseData::Like,
|
||||
QVariant(QStringLiteral("%") + term + QStringLiteral("%")));
|
||||
}
|
||||
|
||||
AssignmentPhrase operator =(const QVariant &v) {
|
||||
return AssignmentPhrase(this, v);
|
||||
}
|
||||
};
|
||||
|
||||
//Date and time
|
||||
#define CONDITIONAL_VARIANT_METHOD(name, cond) \
|
||||
ConditionalPhrase name(int val) \
|
||||
|
|
@ -80,31 +57,6 @@ public:
|
|||
return ConditionalPhrase(this, cond, val); \
|
||||
}
|
||||
|
||||
template<>
|
||||
class FieldPhrase<bool> : public AbstractFieldPhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s) :
|
||||
AbstractFieldPhrase(className, s)
|
||||
{}
|
||||
|
||||
AssignmentPhrase operator =(const bool &other) {
|
||||
return AssignmentPhrase(this, other);
|
||||
}
|
||||
|
||||
FieldPhrase<bool> operator !()
|
||||
{
|
||||
FieldPhrase<bool> f(data->className, data->fieldName);
|
||||
// f.data = new PhraseData(data);
|
||||
f.data->isNot = !data->isNot;
|
||||
return f;
|
||||
}
|
||||
|
||||
operator ConditionalPhrase()
|
||||
{
|
||||
return ConditionalPhrase(this, PhraseData::Equal, !data->isNot);
|
||||
}
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
#include "fieldphrase_bool.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef NUT_FIELDPHRASE_BOOL_H
|
||||
#define NUT_FIELDPHRASE_BOOL_H
|
||||
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
template<>
|
||||
class FieldPhrase<bool> : public AbstractFieldPhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s) :
|
||||
AbstractFieldPhrase(className, s)
|
||||
{}
|
||||
|
||||
AssignmentPhrase operator =(const bool &other) {
|
||||
return AssignmentPhrase(this, other);
|
||||
}
|
||||
|
||||
FieldPhrase<bool> operator !()
|
||||
{
|
||||
FieldPhrase<bool> f(data->className, data->fieldName);
|
||||
// f.data = new PhraseData(data);
|
||||
f.data->isNot = !data->isNot;
|
||||
return f;
|
||||
}
|
||||
|
||||
operator ConditionalPhrase()
|
||||
{
|
||||
return ConditionalPhrase(this, PhraseData::Equal, !data->isNot);
|
||||
}
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // NUT_FIELDPHRASE_BOOL_H
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "datephrase.h"
|
||||
#include "fieldphrase_date.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
#include "fieldphrase_qstring.h"
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef NUT_FIELDPHRASE_QSTRING_H
|
||||
#define NUT_FIELDPHRASE_QSTRING_H
|
||||
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/abstractfieldphrase.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
template<>
|
||||
class FieldPhrase<QString> : public AbstractFieldPhrase
|
||||
{
|
||||
public:
|
||||
FieldPhrase(const char *className, const char *s)
|
||||
: AbstractFieldPhrase(className, s)
|
||||
{}
|
||||
|
||||
ConditionalPhrase like(const QString &term)
|
||||
{
|
||||
return ConditionalPhrase(this, PhraseData::Like, term);
|
||||
}
|
||||
|
||||
ConditionalPhrase contains(const QString &term)
|
||||
{
|
||||
return ConditionalPhrase(this,
|
||||
PhraseData::Like,
|
||||
QVariant(QStringLiteral("%") + term
|
||||
+ QStringLiteral("%")));
|
||||
}
|
||||
|
||||
AssignmentPhrase operator=(const QVariant &v)
|
||||
{
|
||||
return AssignmentPhrase(this, v);
|
||||
}
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // NUT_FIELDPHRASE_QSTRING_H
|
||||
|
|
@ -22,52 +22,57 @@
|
|||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
PhraseData::PhraseData() :
|
||||
className(""), fieldName(""),
|
||||
type(Field), operatorCond(NotAssign),
|
||||
left(nullptr), right(nullptr), operand(QVariant::Invalid), isNot(false), parents(1)
|
||||
PhraseData::PhraseData()
|
||||
: className(""), fieldName(""), type(Field), operatorCond(NotAssign),
|
||||
left(nullptr), right(nullptr), operand(QVariant::Invalid), isNot(false),
|
||||
ref(1)
|
||||
{ }
|
||||
|
||||
PhraseData::PhraseData(const char *className, const char *fieldName) :
|
||||
className(className), fieldName(fieldName),
|
||||
type(Field), operatorCond(NotAssign),
|
||||
left(nullptr), right(nullptr), operand(QVariant::Invalid), isNot(false), parents(1)
|
||||
PhraseData::PhraseData(const char *className, const char *fieldName)
|
||||
: className(className), fieldName(fieldName), type(Field),
|
||||
operatorCond(NotAssign), left(nullptr), right(nullptr),
|
||||
operand(QVariant::Invalid), isNot(false), ref(1)
|
||||
{ }
|
||||
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o)
|
||||
: className(nullptr), fieldName(nullptr),
|
||||
type(WithoutOperand), operatorCond(o), left(l), right(nullptr),
|
||||
isNot(false), parents(1)
|
||||
: className(nullptr), fieldName(nullptr), type(WithoutOperand),
|
||||
operatorCond(o), left(l), right(nullptr), isNot(false), ref(1)
|
||||
{
|
||||
l->parents++;
|
||||
l->ref.ref();
|
||||
}
|
||||
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o,
|
||||
PhraseData *r)
|
||||
: className(nullptr), fieldName(nullptr),
|
||||
type(WithOther), operatorCond(o),
|
||||
left(l), right(r),
|
||||
isNot(false), parents(1)
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, PhraseData *r)
|
||||
: className(nullptr), fieldName(nullptr), type(WithOther), operatorCond(o),
|
||||
left(l), right(r), isNot(false), ref(1)
|
||||
{
|
||||
l->parents++;
|
||||
r->parents++;
|
||||
l->ref.ref();
|
||||
r->ref.ref();
|
||||
}
|
||||
|
||||
PhraseData::PhraseData(PhraseData *l, PhraseData::Condition o, QVariant r)
|
||||
: className(nullptr), fieldName(nullptr),
|
||||
type(WithVariant), operatorCond(o), left(l),
|
||||
right(nullptr), operand(r), isNot(false), parents(1)
|
||||
: className(nullptr), fieldName(nullptr), type(WithVariant),
|
||||
operatorCond(o), left(l), right(nullptr), operand(r), isNot(false),
|
||||
ref(1)
|
||||
{ }
|
||||
|
||||
PhraseData::~PhraseData()
|
||||
{
|
||||
// if (left && !left->ref.deref())
|
||||
// delete left;
|
||||
|
||||
// if (right && !right->ref.deref())
|
||||
// delete right;
|
||||
}
|
||||
|
||||
PhraseData *PhraseData::operator =(PhraseData *other)
|
||||
{
|
||||
other->parents++;
|
||||
other->ref.ref();
|
||||
return other;
|
||||
}
|
||||
|
||||
PhraseData &PhraseData::operator =(PhraseData &other)
|
||||
{
|
||||
other.parents++;
|
||||
other.ref.ref();
|
||||
return other;
|
||||
}
|
||||
|
||||
|
|
@ -81,6 +86,26 @@ void PhraseData::cleanUp()
|
|||
{
|
||||
}
|
||||
|
||||
PhraseData *PhraseData::clone() const
|
||||
{
|
||||
auto c = new PhraseData;
|
||||
c->className = className;
|
||||
c->fieldName = fieldName;
|
||||
|
||||
c->type = type;
|
||||
|
||||
c->operatorCond = operatorCond;
|
||||
|
||||
c->left = left;
|
||||
c->right = right;
|
||||
|
||||
c->operand = operand;
|
||||
c->isNot = isNot;
|
||||
// c->parents = parents;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void PhraseData::cleanUp(PhraseData *d)
|
||||
{
|
||||
if (d->left)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef PHRASEDATA_H
|
||||
#define PHRASEDATA_H
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -97,24 +97,25 @@ public:
|
|||
|
||||
QVariant operand;
|
||||
bool isNot;
|
||||
quint16 parents;
|
||||
// quint16 parents;
|
||||
|
||||
mutable QAtomicInt ref;
|
||||
|
||||
PhraseData();
|
||||
PhraseData(const char *className, const char *fieldName);
|
||||
PhraseData(PhraseData *l, Condition o);
|
||||
PhraseData(PhraseData *l, Condition o, PhraseData *r);
|
||||
PhraseData(PhraseData *l, Condition o, QVariant r);
|
||||
// explicit PhraseData(const PhraseData &other);
|
||||
// explicit PhraseData(const PhraseData *other);
|
||||
|
||||
virtual ~PhraseData();
|
||||
|
||||
PhraseData *operator =(PhraseData *other);
|
||||
PhraseData &operator =(PhraseData &other);
|
||||
|
||||
QString toString() const;
|
||||
|
||||
~PhraseData() = default;
|
||||
|
||||
void cleanUp();
|
||||
PhraseData *clone() const;
|
||||
private:
|
||||
void cleanUp(PhraseData *d);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -37,14 +37,14 @@ PhraseDataList::PhraseDataList(const PhraseDataList &other) : QList<PhraseData*>
|
|||
|
||||
void PhraseDataList::append(PhraseData *d)
|
||||
{
|
||||
d->parents++;
|
||||
d->ref.ref();
|
||||
QList<PhraseData*>::append(d);
|
||||
}
|
||||
|
||||
void PhraseDataList::append(QList<PhraseData *> &dl)
|
||||
{
|
||||
foreach (PhraseData *d, dl)
|
||||
d->parents++;
|
||||
d->ref.ref();
|
||||
QList<PhraseData*>::append(dl);
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ PhraseDataList::~PhraseDataList()
|
|||
QList<PhraseData*>::iterator i;
|
||||
for (i = begin(); i != end(); ++i) {
|
||||
(*i)->cleanUp();
|
||||
if (!--(*i)->parents)
|
||||
if (!(*i)->ref.deref())
|
||||
delete *i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef PHRASELIST_H
|
||||
#define PHRASELIST_H
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
#include <QtNut/phrasedatalist.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/abstractfieldphrase.h \
|
||||
$$PWD/assignmentphrase.h \
|
||||
$$PWD/assignmentphraselist.h \
|
||||
$$PWD/conditionalphrase.h \
|
||||
$$PWD/fieldphrase.h \
|
||||
$$PWD/phrasedata.h \
|
||||
$$PWD/phrasedatalist.h \
|
||||
$$PWD/phraselist.h \
|
||||
$$PWD/fieldphrase_date.h \
|
||||
$$PWD/fieldphrase_bool.h \
|
||||
$$PWD/fieldphrase_qstring.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/abstractfieldphrase.cpp \
|
||||
$$PWD/assignmentphrase.cpp \
|
||||
$$PWD/assignmentphraselist.cpp \
|
||||
$$PWD/conditionalphrase.cpp \
|
||||
$$PWD/fieldphrase.cpp \
|
||||
$$PWD/phrasedata.cpp \
|
||||
$$PWD/phrasedatalist.cpp \
|
||||
$$PWD/phraselist.cpp \
|
||||
$$PWD/fieldphrase_date.cpp \
|
||||
$$PWD/fieldphrase_bool.cpp \
|
||||
$$PWD/fieldphrase_qstring.cpp
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#include "serializableobject.h"
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef SERIALIZABLEOBJECT_H
|
||||
#define SERIALIZABLEOBJECT_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
class SerializableObject
|
||||
{
|
||||
public:
|
||||
SerializableObject() = default;
|
||||
|
||||
virtual void load(const QVariant &value) = 0;
|
||||
virtual QVariant save() = 0;
|
||||
};
|
||||
|
||||
#endif // SERIALIZABLEOBJECT_H
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#include "tuple.h"
|
||||
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef TUPLE_H
|
||||
#define TUPLE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
//class AbstractTuple
|
||||
//{
|
||||
// Q_GADGET
|
||||
//};
|
||||
|
||||
//template <typename T>
|
||||
//class Tuple
|
||||
//{
|
||||
//public:
|
||||
// T _1;
|
||||
//};
|
||||
|
||||
#endif // TUPLE_H
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/nut_global.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/dbgeography.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/dbgeography.cpp
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
%modules = (
|
||||
"QtNut" => "$basedir/src/nut",
|
||||
);
|
||||
|
||||
%classnames = (
|
||||
"nut_global.h" => "NutGlobal"
|
||||
);
|
||||
$publicclassregexp = ".+";
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "tst_phrases.h"
|
||||
#include "phrase.h"
|
||||
#include "sqlitegenerator.h"
|
||||
|
||||
using namespace Nut;
|
||||
|
||||
|
|
@ -17,11 +18,15 @@ void PhrasesTest::initTestCase()
|
|||
|
||||
void PhrasesTest::no1()
|
||||
{
|
||||
FieldPhrase<int> id("main", "id");
|
||||
FieldPhrase<QString> name("main", "name");
|
||||
FieldPhrase<QString> last_name("main", "last_name");
|
||||
FieldPhrase<QDate> date("main", "date");
|
||||
auto w = (id == 4 && name == "hi");
|
||||
{
|
||||
FieldPhrase<int> id("main", "id");
|
||||
FieldPhrase<QString> name("main", "name");
|
||||
FieldPhrase<QString> last_name("main", "last_name");
|
||||
FieldPhrase<QDate> date("main", "date");
|
||||
auto w = (id == 4 && name == QStringLiteral("hi"));
|
||||
|
||||
SqliteGenerator g;
|
||||
}
|
||||
}
|
||||
|
||||
void PhrasesTest::numeric()
|
||||
|
|
|
|||
Loading…
Reference in New Issue