Merge branch 'qt_module' of https://github.com/HamedMasafi/Nut into qt_module

This commit is contained in:
Hamed Masafi 2020-08-09 15:03:06 +04:30
commit 3caf9fa284
40 changed files with 218 additions and 193 deletions

43
src/nut/abstractquery.cpp Normal file
View File

@ -0,0 +1,43 @@
/**************************************************************************
**
** 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/>.
**
**************************************************************************/
#include "abstractquery.h"
#include "abstractquery_p.h"
NUT_BEGIN_NAMESPACE
AbstractQuery::AbstractQuery(QObject *parent) : QObject(parent)
, d_ptr(new AbstractQueryPrivate(this))
{
}
Nut::AbstractQueryPrivate::AbstractQueryPrivate(Nut::AbstractQuery *parent) :
q_ptr(parent)
{
}
Nut::AbstractQueryPrivate::~AbstractQueryPrivate()
{
}
NUT_END_NAMESPACE

View File

@ -18,37 +18,36 @@
** **
**************************************************************************/ **************************************************************************/
#ifndef QUERYBASE_H #ifndef NUT_ABSTRACTQUERY_H
#define QUERYBASE_H #define NUT_ABSTRACTQUERY_H
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include <QtCore/QExplicitlySharedDataPointer> #include <QtCore/QExplicitlySharedDataPointer>
#include "defines.h" #include "defines.h"
#include "query_p.h" #include "abstractquery_p.h"
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
//TODO: remove this class class AbstractQueryPrivate;
class Table; class NUT_EXPORT AbstractQuery : public QObject
class AbstractTableSet;
class NUT_EXPORT QueryBase : public QObject
{ {
Q_OBJECT Q_OBJECT
protected: protected:
QExplicitlySharedDataPointer<QueryPrivate> d; AbstractQueryPrivate *d_ptr;
Q_DECLARE_PRIVATE(AbstractQuery)
public: public:
explicit QueryBase(QObject *parent = nullptr); explicit AbstractQuery(QObject *parent = nullptr);
protected: protected:
// void addTableToSet(AbstractTableSet *set, Table *table); // void addTableToSet(TableSetBase *set, Table *table);
public slots: public slots:
}; };
NUT_END_NAMESPACE NUT_END_NAMESPACE
#endif // QUERYBASE_H #endif // NUT_ABSTRACTQUERY_H

View File

@ -18,8 +18,19 @@
** **
**************************************************************************/ **************************************************************************/
#ifndef QUERY_P_H #ifndef NUT_QUERY_P_H
#define QUERY_P_H #define NUT_QUERY_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
//
#include "phrase.h" #include "phrase.h"
@ -31,15 +42,15 @@ NUT_BEGIN_NAMESPACE
class Database; class Database;
class AbstractTableSet; class AbstractTableSet;
class QueryBase; class AbstractQuery;
struct RelationModel; struct RelationModel;
class NUT_EXPORT QueryPrivate : public QSharedData { class NUT_EXPORT AbstractQueryPrivate {
QueryBase *q_ptr; AbstractQuery *q_ptr;
Q_DECLARE_PUBLIC(QueryBase) Q_DECLARE_PUBLIC(AbstractQuery)
public: public:
explicit QueryPrivate(QueryBase *parent); explicit AbstractQueryPrivate(AbstractQuery *parent);
~QueryPrivate(); ~AbstractQueryPrivate();
QString sql; QString sql;
QString className; QString className;
@ -57,4 +68,4 @@ public:
NUT_END_NAMESPACE NUT_END_NAMESPACE
#endif // QUERY_P_H #endif // NUT_QUERY_P_H

View File

@ -26,7 +26,7 @@
#include <QtCore/QSet> #include <QtCore/QSet>
#include <QtCore/QExplicitlySharedDataPointer> #include <QtCore/QExplicitlySharedDataPointer>
#include "defines.h" #include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -22,7 +22,8 @@
#define NUT_ABSTRACTTABLESETDATA_H #define NUT_ABSTRACTTABLESETDATA_H
#include <QtCore/QSharedData> #include <QtCore/QSharedData>
#include "defines.h"
#include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -3,9 +3,10 @@
#include <initializer_list> #include <initializer_list>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include "defines.h" #include <QtNut/phraselist.h>
#include "phraselist.h" #include <QtNut/fieldphrase.h>
#include "fieldphrase.h"
#include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -22,7 +22,7 @@
#define CHANGELOGTABLE_H #define CHANGELOGTABLE_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "table.h" #include <QtNut/table.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -26,8 +26,8 @@
#include <QtCore/QSharedDataPointer> #include <QtCore/QSharedDataPointer>
#include <QtSql/QSqlDatabase> #include <QtSql/QSqlDatabase>
#include "defines.h" #include <QtNut/defines.h>
#include "tableset.h" #include <QtNut/tableset.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,12 +21,12 @@
#ifndef DATABASE_P_H #ifndef DATABASE_P_H
#define DATABASE_P_H #define DATABASE_P_H
#include "database.h"
#include "databasemodel.h"
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QSharedData> #include <QtCore/QSharedData>
#include <QtNut/database.h>
#include <QtNut/databasemodel.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
class ChangeLogTable; class ChangeLogTable;

View File

@ -25,7 +25,7 @@
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QString> #include <QtCore/QString>
#include "defines.h" #include <QtNut/defines.h>
class QJsonObject; class QJsonObject;

View File

@ -23,7 +23,7 @@
#define NUT_NAMESPACE Nut #define NUT_NAMESPACE Nut
#include "defines_consts.h" #include <QtNut/defines_consts.h>
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
#include <QtCore/QString> #include <QtCore/QString>

View File

@ -24,7 +24,8 @@
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include "phrase.h"
#include <QtNut/phrase.h>
class SqlSerializer; class SqlSerializer;

View File

@ -22,7 +22,8 @@
#define MYSQLGENERATOR_H #define MYSQLGENERATOR_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "abstractsqlgenerator.h"
#include <QtNut/abstractsqlgenerator.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -22,7 +22,8 @@
#define POSTGRESQLGENERATOR_H #define POSTGRESQLGENERATOR_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "abstractsqlgenerator.h"
#include <QtNut/abstractsqlgenerator.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -22,7 +22,8 @@
#define SQLITEGENERATOR_H #define SQLITEGENERATOR_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "abstractsqlgenerator.h"
#include <QtNut/abstractsqlgenerator.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -22,7 +22,8 @@
#define SQLSERVERGENERATOR_H #define SQLSERVERGENERATOR_H
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "abstractsqlgenerator.h"
#include <QtNut/abstractsqlgenerator.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -30,9 +30,7 @@ HEADERS += \
$$PWD/changelogtable.h \ $$PWD/changelogtable.h \
$$PWD/abstracttableset.h \ $$PWD/abstracttableset.h \
$$PWD/abstracttablesetdata.h \ $$PWD/abstracttablesetdata.h \
$$PWD/querybase_p.h \
$$PWD/tablemodel.h \ $$PWD/tablemodel.h \
$$PWD/query_p.h \
$$PWD/table.h \ $$PWD/table.h \
$$PWD/database.h \ $$PWD/database.h \
$$PWD/database_p.h \ $$PWD/database_p.h \
@ -49,7 +47,9 @@ HEADERS += \
$$PWD/phrases/phrasedatalist.h \ $$PWD/phrases/phrasedatalist.h \
$$PWD/phrases/phraselist.h \ $$PWD/phrases/phraselist.h \
$$PWD/phrases/datephrase.h \ $$PWD/phrases/datephrase.h \
$$PWD/table_p.h $$PWD/table_p.h \
$$PWD/abstractquery.h \
$$PWD/abstractquery_p.h
SOURCES += \ SOURCES += \
$$PWD/generators/abstractsqlgenerator.cpp \ $$PWD/generators/abstractsqlgenerator.cpp \
@ -64,7 +64,6 @@ SOURCES += \
$$PWD/databasemodel.cpp \ $$PWD/databasemodel.cpp \
$$PWD/abstracttableset.cpp \ $$PWD/abstracttableset.cpp \
$$PWD/changelogtable.cpp \ $$PWD/changelogtable.cpp \
$$PWD/querybase.cpp \
$$PWD/tablemodel.cpp \ $$PWD/tablemodel.cpp \
$$PWD/table.cpp \ $$PWD/table.cpp \
$$PWD/database.cpp \ $$PWD/database.cpp \
@ -79,7 +78,8 @@ SOURCES += \
$$PWD/phrases/phrasedata.cpp \ $$PWD/phrases/phrasedata.cpp \
$$PWD/phrases/phrasedatalist.cpp \ $$PWD/phrases/phrasedatalist.cpp \
$$PWD/phrases/phraselist.cpp \ $$PWD/phrases/phraselist.cpp \
$$PWD/phrases/datephrase.cpp $$PWD/phrases/datephrase.cpp \
$$PWD/abstractquery.cpp
load(qt_module) load(qt_module)

View File

@ -21,16 +21,16 @@
#ifndef PHRASE_H #ifndef PHRASE_H
#define PHRASE_H #define PHRASE_H
#include "conditionalphrase.h" #include <QtNut/conditionalphrase.h>
#include "abstractfieldphrase.h" #include <QtNut/abstractfieldphrase.h>
#include "fieldphrase.h" #include <QtNut/fieldphrase.h>
#include "phraselist.h" #include <QtNut/phraselist.h>
#include "assignmentphraselist.h" #include <QtNut/assignmentphraselist.h>
#include "phrasedatalist.h" #include <QtNut/phrasedatalist.h>
#include "phrasedata.h" #include <QtNut/phrasedata.h>
#include "assignmentphrase.h" #include <QtNut/assignmentphrase.h>
#include "numericphrase.h" #include <QtNut/numericphrase.h>
#include "datephrase.h" #include <QtNut/datephrase.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,11 +21,10 @@
#ifndef ABSTRACTFIELDPHRASE_H #ifndef ABSTRACTFIELDPHRASE_H
#define ABSTRACTFIELDPHRASE_H #define ABSTRACTFIELDPHRASE_H
#include "defines.h" #include <QtNut/defines.h>
#include <QtNut/assignmentphrase.h>
#include "assignmentphrase.h" #include <QtNut/conditionalphrase.h>
#include "conditionalphrase.h" #include <QtNut/phraselist.h>
#include "phraselist.h"
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,9 +21,8 @@
#ifndef ASSIGNMENTPHRASE_H #ifndef ASSIGNMENTPHRASE_H
#define ASSIGNMENTPHRASE_H #define ASSIGNMENTPHRASE_H
#include "defines.h" #include <QtNut/defines.h>
#include <QtNut/assignmentphraselist.h>
#include "assignmentphraselist.h"
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,7 +21,7 @@
#ifndef ASSIGNMENTPHRASELIST_H #ifndef ASSIGNMENTPHRASELIST_H
#define ASSIGNMENTPHRASELIST_H #define ASSIGNMENTPHRASELIST_H
#include "defines.h" #include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,7 +21,7 @@
#ifndef CONDITIONALPHRASE_H #ifndef CONDITIONALPHRASE_H
#define CONDITIONALPHRASE_H #define CONDITIONALPHRASE_H
#include "phrasedata.h" #include <QtNut/phrasedata.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,10 +21,11 @@
#ifndef DATEPHRASE_H #ifndef DATEPHRASE_H
#define DATEPHRASE_H #define DATEPHRASE_H
#include "fieldphrase.h"
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <type_traits> #include <type_traits>
#include <QtNut/fieldphrase.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
#define COMMON_OPERATORS_DECL(T) \ #define COMMON_OPERATORS_DECL(T) \

View File

@ -21,9 +21,8 @@
#ifndef FIELDPHRASE_H #ifndef FIELDPHRASE_H
#define FIELDPHRASE_H #define FIELDPHRASE_H
#include "defines.h" #include <QtNut/defines.h>
#include <QtNut/abstractfieldphrase.h>
#include "abstractfieldphrase.h"
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -1,9 +1,10 @@
#ifndef NUMERICPHRASE_H #ifndef NUMERICPHRASE_H
#define NUMERICPHRASE_H #define NUMERICPHRASE_H
#include "fieldphrase.h"
#include <type_traits> #include <type_traits>
#include <QtNut/fieldphrase.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
#define SPECIALIZATION_NUMERIC_MEMBER(type, op, cond) \ #define SPECIALIZATION_NUMERIC_MEMBER(type, op, cond) \

View File

@ -21,7 +21,7 @@
#ifndef PHRASEDATA_H #ifndef PHRASEDATA_H
#define PHRASEDATA_H #define PHRASEDATA_H
#include "defines.h" #include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,7 +21,7 @@
#ifndef PHRASEDATALIST_H #ifndef PHRASEDATALIST_H
#define PHRASEDATALIST_H #define PHRASEDATALIST_H
#include "phrasedata.h" #include <QtNut/phrasedata.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,9 +21,8 @@
#ifndef PHRASELIST_H #ifndef PHRASELIST_H
#define PHRASELIST_H #define PHRASELIST_H
#include "defines.h" #include <QtNut/defines.h>
#include <QtNut/phrasedatalist.h>
#include "phrasedatalist.h"
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -22,17 +22,6 @@
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
QueryPrivate::QueryPrivate(QueryBase *parent) : q_ptr(parent),
database(nullptr), tableSet(nullptr), skip(-1), take(-1)
{
}
QueryPrivate::~QueryPrivate()
{
}
/*! /*!
* \class Query * \class Query
* \brief This class hold a query. A query can be used for getting database rows, editing or deleting without row fetching. * \brief This class hold a query. A query can be used for getting database rows, editing or deleting without row fetching.

View File

@ -18,8 +18,8 @@
** **
**************************************************************************/ **************************************************************************/
#ifndef QUERY_H #ifndef NUT_QUERY_H
#define QUERY_H #define NUT_QUERY_H
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtCore/QDebug> #include <QtCore/QDebug>
@ -36,24 +36,21 @@
#endif #endif
#include <QtNut/table.h> #include <QtNut/table.h>
#include <QtNut/private/query_p.h> #include <QtNut/abstractquery.h>
#include <QtNut/private/querybase_p.h>
#include "database.h" #include <QtNut/database.h>
#include "databasemodel.h" #include <QtNut/databasemodel.h>
#include "abstracttableset.h" #include <QtNut/abstracttableset.h>
#include "abstractsqlgenerator.h" #include <QtNut/abstractsqlgenerator.h>
#include "phrase.h" #include <QtNut/phrase.h>
#include "tablemodel.h" #include <QtNut/tablemodel.h>
#include "sqlmodel.h" #include <QtNut/sqlmodel.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
template <class T> template <class T>
class Query : public QueryBase class Query : public AbstractQuery
{ {
QueryPrivate *d_ptr;
Q_DECLARE_PRIVATE(Query)
bool m_autoDelete; bool m_autoDelete;
public: public:
@ -113,7 +110,7 @@ template<typename T>
template<typename O> template<typename O>
Q_OUTOFLINE_TEMPLATE QList<O> Query<T>::select(const std::function<O (const QSqlQuery &)> allocator) Q_OUTOFLINE_TEMPLATE QList<O> Query<T>::select(const std::function<O (const QSqlQuery &)> allocator)
{ {
Q_D(Query); Q_D(AbstractQuery);
QList<O> ret; QList<O> ret;
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
@ -146,10 +143,9 @@ Q_OUTOFLINE_TEMPLATE QList<O> Query<T>::select(const std::function<O (const QSql
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *tableSet, Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *tableSet,
bool autoDelete) bool autoDelete)
: QueryBase(database), d_ptr(new QueryPrivate(this)), : AbstractQuery(database), m_autoDelete(autoDelete)
m_autoDelete(autoDelete)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->database = database; d->database = database;
d->tableSet = tableSet; d->tableSet = tableSet;
@ -163,14 +159,14 @@ Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *table
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE Query<T>::~Query() Q_OUTOFLINE_TEMPLATE Query<T>::~Query()
{ {
Q_D(Query); Q_D(AbstractQuery);
delete d; delete d;
} }
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count) Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
{ {
Q_D(Query); Q_D(AbstractQuery);
RowList<T> returnList; RowList<T> returnList;
d->select = QStringLiteral("*"); d->select = QStringLiteral("*");
@ -347,7 +343,7 @@ template <typename T>
template <typename F> template <typename F>
Q_OUTOFLINE_TEMPLATE QList<F> Query<T>::select(const FieldPhrase<F> f) Q_OUTOFLINE_TEMPLATE QList<F> Query<T>::select(const FieldPhrase<F> f)
{ {
Q_D(Query); Q_D(AbstractQuery);
QList<F> ret; QList<F> ret;
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
@ -385,7 +381,7 @@ Q_OUTOFLINE_TEMPLATE Row<T> Query<T>::first()
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE int Query<T>::count() Q_OUTOFLINE_TEMPLATE int Query<T>::count()
{ {
Q_D(Query); Q_D(AbstractQuery);
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
d->select = QStringLiteral("COUNT(*)"); d->select = QStringLiteral("COUNT(*)");
@ -405,7 +401,7 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::count()
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::max(const FieldPhrase<int> &f) Q_OUTOFLINE_TEMPLATE QVariant Query<T>::max(const FieldPhrase<int> &f)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
d->sql = d->database->sqlGenerator()->selectCommand( d->sql = d->database->sqlGenerator()->selectCommand(
@ -423,7 +419,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::max(const FieldPhrase<int> &f)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::min(const FieldPhrase<int> &f) Q_OUTOFLINE_TEMPLATE QVariant Query<T>::min(const FieldPhrase<int> &f)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
d->sql = d->database->sqlGenerator()->selectCommand( d->sql = d->database->sqlGenerator()->selectCommand(
@ -441,7 +437,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::min(const FieldPhrase<int> &f)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::sum(const FieldPhrase<int> &f) Q_OUTOFLINE_TEMPLATE QVariant Query<T>::sum(const FieldPhrase<int> &f)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
d->sql = d->database->sqlGenerator()->selectCommand( d->sql = d->database->sqlGenerator()->selectCommand(
@ -459,7 +455,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::sum(const FieldPhrase<int> &f)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::average(const FieldPhrase<int> &f) Q_OUTOFLINE_TEMPLATE QVariant Query<T>::average(const FieldPhrase<int> &f)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->joins.prepend(d->tableName); d->joins.prepend(d->tableName);
d->sql = d->database->sqlGenerator()->selectCommand( d->sql = d->database->sqlGenerator()->selectCommand(
@ -477,7 +473,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::average(const FieldPhrase<int> &f)
template<class T> template<class T>
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::insert(const AssignmentPhraseList &p) Q_OUTOFLINE_TEMPLATE QVariant Query<T>::insert(const AssignmentPhraseList &p)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->sql = d->database->sqlGenerator() d->sql = d->database->sqlGenerator()
->insertCommand(d->tableName, p); ->insertCommand(d->tableName, p);
QSqlQuery q = d->database->exec(d->sql); QSqlQuery q = d->database->exec(d->sql);
@ -488,7 +484,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::insert(const AssignmentPhraseList &p)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::join(const QString &className) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::join(const QString &className)
{ {
Q_D(Query); Q_D(AbstractQuery);
RelationModel *rel = d->database->model() RelationModel *rel = d->database->model()
.relationByClassNames(d->className, className); .relationByClassNames(d->className, className);
@ -517,7 +513,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::join(Table *c)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
{ {
Q_D(Query); Q_D(AbstractQuery);
if (d->wherePhrase.data) if (d->wherePhrase.data)
d->wherePhrase = d->wherePhrase && ph; d->wherePhrase = d->wherePhrase && ph;
else else
@ -528,7 +524,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::setWhere(const ConditionalPhrase &ph) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::setWhere(const ConditionalPhrase &ph)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->wherePhrase = ph; d->wherePhrase = ph;
return this; return this;
} }
@ -536,7 +532,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::setWhere(const ConditionalPhrase &ph)
template<class T> template<class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::skip(int n) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::skip(int n)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->skip = n; d->skip = n;
return this; return this;
} }
@ -544,7 +540,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::skip(int n)
template<class T> template<class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::take(int n) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::take(int n)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->take = n; d->take = n;
return this; return this;
} }
@ -552,7 +548,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::take(int n)
template<class T> template<class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::fields(const PhraseList &ph) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::fields(const PhraseList &ph)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->fieldPhrase = ph; d->fieldPhrase = ph;
return this; return this;
} }
@ -561,7 +557,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::fields(const PhraseList &ph)
//Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(QString fieldName, //Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(QString fieldName,
// QString type) // QString type)
//{ //{
// Q_D(Query); // Q_D(AbstractQuery);
// d->orderPhrases.append(fieldName, type); // d->orderPhrases.append(fieldName, type);
// return this; // return this;
//} //}
@ -569,7 +565,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::fields(const PhraseList &ph)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(const PhraseList &ph) Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(const PhraseList &ph)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->orderPhrase = ph; d->orderPhrase = ph;
return this; return this;
} }
@ -577,7 +573,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(const PhraseList &ph)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE int Query<T>::update(const AssignmentPhraseList &ph) Q_OUTOFLINE_TEMPLATE int Query<T>::update(const AssignmentPhraseList &ph)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->sql = d->database->sqlGenerator()->updateCommand( d->sql = d->database->sqlGenerator()->updateCommand(
d->tableName, d->tableName,
@ -594,7 +590,7 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::update(const AssignmentPhraseList &ph)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE int Query<T>::remove() Q_OUTOFLINE_TEMPLATE int Query<T>::remove()
{ {
Q_D(Query); Q_D(AbstractQuery);
d->sql = d->database->sqlGenerator()->deleteCommand( d->sql = d->database->sqlGenerator()->deleteCommand(
d->tableName, d->wherePhrase); d->tableName, d->wherePhrase);
@ -616,7 +612,7 @@ Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query<T>::toModel()
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(QSqlQueryModel *model) Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(QSqlQueryModel *model)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->sql = d->database->sqlGenerator()->selectCommand( d->sql = d->database->sqlGenerator()->selectCommand(
d->tableName, d->tableName,
@ -653,7 +649,7 @@ Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(QSqlQueryModel *model)
template<class T> template<class T>
Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(SqlModel *model) Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(SqlModel *model)
{ {
Q_D(Query); Q_D(AbstractQuery);
d->sql = d->database->sqlGenerator()->selectCommand( d->sql = d->database->sqlGenerator()->selectCommand(
d->tableName, d->tableName,
@ -690,7 +686,7 @@ Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(SqlModel *model)
template <class T> template <class T>
Q_OUTOFLINE_TEMPLATE QString Query<T>::sqlCommand() const Q_OUTOFLINE_TEMPLATE QString Query<T>::sqlCommand() const
{ {
Q_D(const Query); Q_D(const AbstractQuery);
return d->sql; return d->sql;
} }
@ -705,4 +701,4 @@ Q_OUTOFLINE_TEMPLATE QString Query<T>::sqlCommand() const
NUT_END_NAMESPACE NUT_END_NAMESPACE
#endif // QUERY_H #endif // NUT_QUERY_H

View File

@ -1,19 +0,0 @@
#include "querybase_p.h"
#include "table.h"
#include "abstracttableset.h"
NUT_BEGIN_NAMESPACE
QueryBase::QueryBase(QObject *parent) : QObject(parent)
{
}
//void QueryBase::addTableToSet(AbstractTableSet *set, Table *table)
//{
// set->add(table);
//}
NUT_END_NAMESPACE

View File

@ -29,43 +29,46 @@
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
//SqlModel::SqlModel(Query *q) : QAbstractItemModel(q.) SqlModelPrivate::SqlModelPrivate(SqlModel *parent) : q_ptr(parent)
//{ , renderer(nullptr)
{
//} Q_UNUSED(parent)
}
void SqlModel::setRenderer(const std::function<QVariant (int, QVariant)> &renderer) void SqlModel::setRenderer(const std::function<QVariant (int, QVariant)> &renderer)
{ {
_renderer = renderer; Q_D(SqlModel);
d->renderer = renderer;
} }
SqlModel::SqlModel(Database *database, AbstractTableSet *tableSet, QObject *parent) SqlModel::SqlModel(Database *database, AbstractTableSet *tableSet, QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
, _renderer(nullptr) , d_ptr(new SqlModelPrivate(this))
, d(new SqlModelPrivate(this))
{ {
Q_D(SqlModel);
d->model = database->model() d->model = database->model()
.tableByClassName(tableSet->childClassName()); .tableByClassName(tableSet->childClassName());
d->tableName = d->model->name(); d->tableName = d->model->name();
// setQuery("SELECT * FROM " + d->tableName, database->databaseName());
} }
int SqlModel::rowCount(const QModelIndex &parent) const int SqlModel::rowCount(const QModelIndex &parent) const
{ {
Q_D(const SqlModel);
Q_UNUSED(parent) Q_UNUSED(parent)
return d->rows.count(); return d->rows.count();
} }
int SqlModel::columnCount(const QModelIndex &parent) const int SqlModel::columnCount(const QModelIndex &parent) const
{ {
Q_D(const SqlModel);
Q_UNUSED(parent) Q_UNUSED(parent)
return d->model->fields().count(); return d->model->fields().count();
} }
QVariant SqlModel::data(const QModelIndex &index, int role) const QVariant SqlModel::data(const QModelIndex &index, int role) const
{ {
Q_D(const SqlModel);
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
@ -76,8 +79,8 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
Row<Table> t = d->rows.at(index.row()); Row<Table> t = d->rows.at(index.row());
QVariant v = t->property(d->model->field(index.column())->name.toLocal8Bit().data()); QVariant v = t->property(d->model->field(index.column())->name.toLocal8Bit().data());
if (_renderer != nullptr) if (d->renderer != nullptr)
v = _renderer(index.column(), v); v = d->renderer(index.column(), v);
return v; return v;
} }
return QVariant(); return QVariant();
@ -85,7 +88,8 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
void SqlModel::setRows(RowList<Table> rows) void SqlModel::setRows(RowList<Table> rows)
{ {
d.detach(); Q_D(SqlModel);
if (d->rows.count()) { if (d->rows.count()) {
beginRemoveRows(QModelIndex(), 0, d->rows.count()); beginRemoveRows(QModelIndex(), 0, d->rows.count());
d->rows.clear(); d->rows.clear();
@ -98,19 +102,15 @@ void SqlModel::setRows(RowList<Table> rows)
void SqlModel::append(Row<Table> table) void SqlModel::append(Row<Table> table)
{ {
d.detach(); Q_D(SqlModel);
beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count()); beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count());
d->rows.append(table); d->rows.append(table);
endInsertRows(); endInsertRows();
} }
//void SqlModel::append(Table *table)
//{
// append(TableType<Table>::Row(table));
//}
QVariant SqlModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant SqlModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
Q_D(const SqlModel);
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
return d->model->field(section)->displayName; return d->model->field(section)->displayName;
} }
@ -119,13 +119,8 @@ QVariant SqlModel::headerData(int section, Qt::Orientation orientation, int role
Row<Table> SqlModel::at(const int &i) const Row<Table> SqlModel::at(const int &i) const
{ {
Q_D(const SqlModel);
return d->rows.at(i); return d->rows.at(i);
} }
SqlModelPrivate::SqlModelPrivate(SqlModel *parent)
{
Q_UNUSED(parent)
}
NUT_END_NAMESPACE NUT_END_NAMESPACE

View File

@ -24,9 +24,8 @@
#include <QtCore/QAbstractTableModel> #include <QtCore/QAbstractTableModel>
#include <QtCore/QExplicitlySharedDataPointer> #include <QtCore/QExplicitlySharedDataPointer>
#include <QtCore/QList> #include <QtCore/QList>
#include "defines.h"
#include "sqlmodel_p.h" #include <QtNut/defines.h>
#include <functional>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
@ -34,12 +33,12 @@ class Database;
class AbstractTableSet; class AbstractTableSet;
class Table; class Table;
class TableModel; class TableModel;
class SqlModelPrivate;
class NUT_EXPORT SqlModel : public QAbstractTableModel class NUT_EXPORT SqlModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT
SqlModelPrivate *d_ptr;
std::function <QVariant(int, QVariant)> _renderer; Q_DECLARE_PRIVATE(SqlModel)
public: public:
// explicit SqlModel(Query *q); // explicit SqlModel(Query *q);
@ -60,9 +59,6 @@ public:
void setRenderer(const std::function<QVariant (int, QVariant)> &renderer); void setRenderer(const std::function<QVariant (int, QVariant)> &renderer);
private:
QExplicitlySharedDataPointer<SqlModelPrivate> d;
signals: signals:
void beforeShowText(int col, QVariant &value); void beforeShowText(int col, QVariant &value);
}; };

View File

@ -3,21 +3,28 @@
#include <QtCore/QSharedPointer> #include <QtCore/QSharedPointer>
#include <QtCore/QString> #include <QtCore/QString>
#include "defines.h"
#include <functional>
#include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
class SqlModel; class SqlModel;
class Table; class Table;
class TableModel; class TableModel;
class NUT_EXPORT SqlModelPrivate : public QSharedData { class NUT_EXPORT SqlModelPrivate {
public: public:
SqlModel *q_ptr;
Q_DECLARE_PUBLIC(SqlModel);
explicit SqlModelPrivate(SqlModel *parent); explicit SqlModelPrivate(SqlModel *parent);
QString tableName; QString tableName;
RowList<Table> rows; RowList<Table> rows;
TableModel *model; TableModel *model;
std::function <QVariant(int, QVariant)> renderer;
}; };
NUT_END_NAMESPACE NUT_END_NAMESPACE

View File

@ -25,9 +25,9 @@
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include <QtCore/QSet> #include <QtCore/QSet>
#include "tablemodel.h" #include <QtNut/defines.h>
#include "defines.h" #include <QtNut/tablemodel.h>
#include "phrase.h" #include <QtNut/phrase.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -1,11 +1,11 @@
#ifndef TABLEPRIVATE_H #ifndef TABLEPRIVATE_H
#define TABLEPRIVATE_H #define TABLEPRIVATE_H
#include "defines.h"
#include <QtCore/QSet> #include <QtCore/QSet>
#include <QtCore/QSharedData> #include <QtCore/QSharedData>
#include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
class TableModel; class TableModel;

View File

@ -23,7 +23,8 @@
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include "defines.h"
#include <QtNut/defines.h>
class QJsonObject; class QJsonObject;

View File

@ -29,11 +29,11 @@
#include <QtSql/QSqlQuery> #include <QtSql/QSqlQuery>
#include "abstracttableset.h" #include <QtNut/abstracttableset.h>
#include "table.h" #include <QtNut/table.h>
#include "bulkinserter.h" #include <QtNut/bulkinserter.h>
#include "databasemodel.h" #include <QtNut/databasemodel.h>
#include "abstracttablesetdata.h" #include <QtNut/abstracttablesetdata.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE

View File

@ -21,11 +21,12 @@
#ifndef DBGEOGRAPHY_H #ifndef DBGEOGRAPHY_H
#define DBGEOGRAPHY_H #define DBGEOGRAPHY_H
#include "defines.h"
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtNut/defines.h>
NUT_BEGIN_NAMESPACE NUT_BEGIN_NAMESPACE
class NUT_EXPORT DbGeography class NUT_EXPORT DbGeography

View File

@ -5,6 +5,7 @@
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include "weblogdatabase.h" #include "weblogdatabase.h"
class Post; class Post;
class User; class User;
class BasicTest : public QObject class BasicTest : public QObject