Merge branch 'qt_module' of https://github.com/HamedMasafi/Nut into qt_module
This commit is contained in:
commit
3caf9fa284
|
|
@ -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
|
||||
|
|
@ -18,37 +18,36 @@
|
|||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QUERYBASE_H
|
||||
#define QUERYBASE_H
|
||||
#ifndef NUT_ABSTRACTQUERY_H
|
||||
#define NUT_ABSTRACTQUERY_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/QExplicitlySharedDataPointer>
|
||||
|
||||
#include "defines.h"
|
||||
#include "query_p.h"
|
||||
#include "abstractquery_p.h"
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
//TODO: remove this class
|
||||
class Table;
|
||||
class AbstractTableSet;
|
||||
class NUT_EXPORT QueryBase : public QObject
|
||||
class AbstractQueryPrivate;
|
||||
class NUT_EXPORT AbstractQuery : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
QExplicitlySharedDataPointer<QueryPrivate> d;
|
||||
AbstractQueryPrivate *d_ptr;
|
||||
Q_DECLARE_PRIVATE(AbstractQuery)
|
||||
|
||||
public:
|
||||
explicit QueryBase(QObject *parent = nullptr);
|
||||
explicit AbstractQuery(QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
// void addTableToSet(AbstractTableSet *set, Table *table);
|
||||
// void addTableToSet(TableSetBase *set, Table *table);
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // QUERYBASE_H
|
||||
#endif // NUT_ABSTRACTQUERY_H
|
||||
|
|
@ -18,8 +18,19 @@
|
|||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QUERY_P_H
|
||||
#define QUERY_P_H
|
||||
#ifndef NUT_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"
|
||||
|
||||
|
|
@ -31,15 +42,15 @@ NUT_BEGIN_NAMESPACE
|
|||
|
||||
class Database;
|
||||
class AbstractTableSet;
|
||||
class QueryBase;
|
||||
class AbstractQuery;
|
||||
struct RelationModel;
|
||||
class NUT_EXPORT QueryPrivate : public QSharedData {
|
||||
QueryBase *q_ptr;
|
||||
Q_DECLARE_PUBLIC(QueryBase)
|
||||
class NUT_EXPORT AbstractQueryPrivate {
|
||||
AbstractQuery *q_ptr;
|
||||
Q_DECLARE_PUBLIC(AbstractQuery)
|
||||
|
||||
public:
|
||||
explicit QueryPrivate(QueryBase *parent);
|
||||
~QueryPrivate();
|
||||
explicit AbstractQueryPrivate(AbstractQuery *parent);
|
||||
~AbstractQueryPrivate();
|
||||
|
||||
QString sql;
|
||||
QString className;
|
||||
|
|
@ -57,4 +68,4 @@ public:
|
|||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // QUERY_P_H
|
||||
#endif // NUT_QUERY_P_H
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
#include <QtCore/QSet>
|
||||
#include <QtCore/QExplicitlySharedDataPointer>
|
||||
|
||||
#include "defines.h"
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
#define NUT_ABSTRACTTABLESETDATA_H
|
||||
|
||||
#include <QtCore/QSharedData>
|
||||
#include "defines.h"
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
|
||||
#include <initializer_list>
|
||||
#include <QtCore/QDebug>
|
||||
#include "defines.h"
|
||||
#include "phraselist.h"
|
||||
#include "fieldphrase.h"
|
||||
#include <QtNut/phraselist.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#define CHANGELOGTABLE_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "table.h"
|
||||
#include <QtNut/table.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@
|
|||
#include <QtCore/QSharedDataPointer>
|
||||
#include <QtSql/QSqlDatabase>
|
||||
|
||||
#include "defines.h"
|
||||
#include "tableset.h"
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/tableset.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@
|
|||
#ifndef DATABASE_P_H
|
||||
#define DATABASE_P_H
|
||||
|
||||
#include "database.h"
|
||||
#include "databasemodel.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QSharedData>
|
||||
|
||||
#include <QtNut/database.h>
|
||||
#include <QtNut/databasemodel.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class ChangeLogTable;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include "defines.h"
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#define NUT_NAMESPACE Nut
|
||||
|
||||
#include "defines_consts.h"
|
||||
#include <QtNut/defines_consts.h>
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
#include "phrase.h"
|
||||
|
||||
#include <QtNut/phrase.h>
|
||||
|
||||
class SqlSerializer;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
#define MYSQLGENERATOR_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "abstractsqlgenerator.h"
|
||||
|
||||
#include <QtNut/abstractsqlgenerator.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
#define POSTGRESQLGENERATOR_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "abstractsqlgenerator.h"
|
||||
|
||||
#include <QtNut/abstractsqlgenerator.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
#define SQLITEGENERATOR_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "abstractsqlgenerator.h"
|
||||
|
||||
#include <QtNut/abstractsqlgenerator.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
#define SQLSERVERGENERATOR_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "abstractsqlgenerator.h"
|
||||
|
||||
#include <QtNut/abstractsqlgenerator.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,7 @@ HEADERS += \
|
|||
$$PWD/changelogtable.h \
|
||||
$$PWD/abstracttableset.h \
|
||||
$$PWD/abstracttablesetdata.h \
|
||||
$$PWD/querybase_p.h \
|
||||
$$PWD/tablemodel.h \
|
||||
$$PWD/query_p.h \
|
||||
$$PWD/table.h \
|
||||
$$PWD/database.h \
|
||||
$$PWD/database_p.h \
|
||||
|
|
@ -49,7 +47,9 @@ HEADERS += \
|
|||
$$PWD/phrases/phrasedatalist.h \
|
||||
$$PWD/phrases/phraselist.h \
|
||||
$$PWD/phrases/datephrase.h \
|
||||
$$PWD/table_p.h
|
||||
$$PWD/table_p.h \
|
||||
$$PWD/abstractquery.h \
|
||||
$$PWD/abstractquery_p.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/generators/abstractsqlgenerator.cpp \
|
||||
|
|
@ -64,7 +64,6 @@ SOURCES += \
|
|||
$$PWD/databasemodel.cpp \
|
||||
$$PWD/abstracttableset.cpp \
|
||||
$$PWD/changelogtable.cpp \
|
||||
$$PWD/querybase.cpp \
|
||||
$$PWD/tablemodel.cpp \
|
||||
$$PWD/table.cpp \
|
||||
$$PWD/database.cpp \
|
||||
|
|
@ -79,7 +78,8 @@ SOURCES += \
|
|||
$$PWD/phrases/phrasedata.cpp \
|
||||
$$PWD/phrases/phrasedatalist.cpp \
|
||||
$$PWD/phrases/phraselist.cpp \
|
||||
$$PWD/phrases/datephrase.cpp
|
||||
$$PWD/phrases/datephrase.cpp \
|
||||
$$PWD/abstractquery.cpp
|
||||
|
||||
load(qt_module)
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,16 @@
|
|||
#ifndef PHRASE_H
|
||||
#define PHRASE_H
|
||||
|
||||
#include "conditionalphrase.h"
|
||||
#include "abstractfieldphrase.h"
|
||||
#include "fieldphrase.h"
|
||||
#include "phraselist.h"
|
||||
#include "assignmentphraselist.h"
|
||||
#include "phrasedatalist.h"
|
||||
#include "phrasedata.h"
|
||||
#include "assignmentphrase.h"
|
||||
#include "numericphrase.h"
|
||||
#include "datephrase.h"
|
||||
#include <QtNut/conditionalphrase.h>
|
||||
#include <QtNut/abstractfieldphrase.h>
|
||||
#include <QtNut/fieldphrase.h>
|
||||
#include <QtNut/phraselist.h>
|
||||
#include <QtNut/assignmentphraselist.h>
|
||||
#include <QtNut/phrasedatalist.h>
|
||||
#include <QtNut/phrasedata.h>
|
||||
#include <QtNut/assignmentphrase.h>
|
||||
#include <QtNut/numericphrase.h>
|
||||
#include <QtNut/datephrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,11 +21,10 @@
|
|||
#ifndef ABSTRACTFIELDPHRASE_H
|
||||
#define ABSTRACTFIELDPHRASE_H
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "assignmentphrase.h"
|
||||
#include "conditionalphrase.h"
|
||||
#include "phraselist.h"
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/assignmentphrase.h>
|
||||
#include <QtNut/conditionalphrase.h>
|
||||
#include <QtNut/phraselist.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@
|
|||
#ifndef ASSIGNMENTPHRASE_H
|
||||
#define ASSIGNMENTPHRASE_H
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "assignmentphraselist.h"
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/assignmentphraselist.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef ASSIGNMENTPHRASELIST_H
|
||||
#define ASSIGNMENTPHRASELIST_H
|
||||
|
||||
#include "defines.h"
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef CONDITIONALPHRASE_H
|
||||
#define CONDITIONALPHRASE_H
|
||||
|
||||
#include "phrasedata.h"
|
||||
#include <QtNut/phrasedata.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,11 @@
|
|||
#ifndef DATEPHRASE_H
|
||||
#define DATEPHRASE_H
|
||||
|
||||
#include "fieldphrase.h"
|
||||
#include <QtCore/QDateTime>
|
||||
#include <type_traits>
|
||||
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
#define COMMON_OPERATORS_DECL(T) \
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@
|
|||
#ifndef FIELDPHRASE_H
|
||||
#define FIELDPHRASE_H
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "abstractfieldphrase.h"
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/abstractfieldphrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#ifndef NUMERICPHRASE_H
|
||||
#define NUMERICPHRASE_H
|
||||
|
||||
#include "fieldphrase.h"
|
||||
#include <type_traits>
|
||||
|
||||
#include <QtNut/fieldphrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
#define SPECIALIZATION_NUMERIC_MEMBER(type, op, cond) \
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef PHRASEDATA_H
|
||||
#define PHRASEDATA_H
|
||||
|
||||
#include "defines.h"
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#ifndef PHRASEDATALIST_H
|
||||
#define PHRASEDATALIST_H
|
||||
|
||||
#include "phrasedata.h"
|
||||
#include <QtNut/phrasedata.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@
|
|||
#ifndef PHRASELIST_H
|
||||
#define PHRASELIST_H
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "phrasedatalist.h"
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/phrasedatalist.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -22,17 +22,6 @@
|
|||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
QueryPrivate::QueryPrivate(QueryBase *parent) : q_ptr(parent),
|
||||
database(nullptr), tableSet(nullptr), skip(-1), take(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QueryPrivate::~QueryPrivate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class Query
|
||||
* \brief This class hold a query. A query can be used for getting database rows, editing or deleting without row fetching.
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef QUERY_H
|
||||
#define QUERY_H
|
||||
#ifndef NUT_QUERY_H
|
||||
#define NUT_QUERY_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QDebug>
|
||||
|
|
@ -36,24 +36,21 @@
|
|||
#endif
|
||||
|
||||
#include <QtNut/table.h>
|
||||
#include <QtNut/private/query_p.h>
|
||||
#include <QtNut/private/querybase_p.h>
|
||||
#include "database.h"
|
||||
#include "databasemodel.h"
|
||||
#include "abstracttableset.h"
|
||||
#include "abstractsqlgenerator.h"
|
||||
#include "phrase.h"
|
||||
#include "tablemodel.h"
|
||||
#include "sqlmodel.h"
|
||||
#include <QtNut/abstractquery.h>
|
||||
|
||||
#include <QtNut/database.h>
|
||||
#include <QtNut/databasemodel.h>
|
||||
#include <QtNut/abstracttableset.h>
|
||||
#include <QtNut/abstractsqlgenerator.h>
|
||||
#include <QtNut/phrase.h>
|
||||
#include <QtNut/tablemodel.h>
|
||||
#include <QtNut/sqlmodel.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
template <class T>
|
||||
class Query : public QueryBase
|
||||
class Query : public AbstractQuery
|
||||
{
|
||||
QueryPrivate *d_ptr;
|
||||
Q_DECLARE_PRIVATE(Query)
|
||||
|
||||
bool m_autoDelete;
|
||||
|
||||
public:
|
||||
|
|
@ -113,7 +110,7 @@ template<typename T>
|
|||
template<typename O>
|
||||
Q_OUTOFLINE_TEMPLATE QList<O> Query<T>::select(const std::function<O (const QSqlQuery &)> allocator)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
QList<O> ret;
|
||||
|
||||
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>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *tableSet,
|
||||
bool autoDelete)
|
||||
: QueryBase(database), d_ptr(new QueryPrivate(this)),
|
||||
m_autoDelete(autoDelete)
|
||||
: AbstractQuery(database), m_autoDelete(autoDelete)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->database = database;
|
||||
d->tableSet = tableSet;
|
||||
|
|
@ -163,14 +159,14 @@ Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *table
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T>::~Query()
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
delete d;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
RowList<T> returnList;
|
||||
d->select = QStringLiteral("*");
|
||||
|
||||
|
|
@ -347,7 +343,7 @@ template <typename T>
|
|||
template <typename F>
|
||||
Q_OUTOFLINE_TEMPLATE QList<F> Query<T>::select(const FieldPhrase<F> f)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
QList<F> ret;
|
||||
|
||||
d->joins.prepend(d->tableName);
|
||||
|
|
@ -385,7 +381,7 @@ Q_OUTOFLINE_TEMPLATE Row<T> Query<T>::first()
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE int Query<T>::count()
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->joins.prepend(d->tableName);
|
||||
d->select = QStringLiteral("COUNT(*)");
|
||||
|
|
@ -405,7 +401,7 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::count()
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::max(const FieldPhrase<int> &f)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->joins.prepend(d->tableName);
|
||||
d->sql = d->database->sqlGenerator()->selectCommand(
|
||||
|
|
@ -423,7 +419,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::max(const FieldPhrase<int> &f)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::min(const FieldPhrase<int> &f)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->joins.prepend(d->tableName);
|
||||
d->sql = d->database->sqlGenerator()->selectCommand(
|
||||
|
|
@ -441,7 +437,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::min(const FieldPhrase<int> &f)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::sum(const FieldPhrase<int> &f)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->joins.prepend(d->tableName);
|
||||
d->sql = d->database->sqlGenerator()->selectCommand(
|
||||
|
|
@ -459,7 +455,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::sum(const FieldPhrase<int> &f)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::average(const FieldPhrase<int> &f)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->joins.prepend(d->tableName);
|
||||
d->sql = d->database->sqlGenerator()->selectCommand(
|
||||
|
|
@ -477,7 +473,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::average(const FieldPhrase<int> &f)
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE QVariant Query<T>::insert(const AssignmentPhraseList &p)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
d->sql = d->database->sqlGenerator()
|
||||
->insertCommand(d->tableName, p);
|
||||
QSqlQuery q = d->database->exec(d->sql);
|
||||
|
|
@ -488,7 +484,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query<T>::insert(const AssignmentPhraseList &p)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::join(const QString &className)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
RelationModel *rel = d->database->model()
|
||||
.relationByClassNames(d->className, className);
|
||||
|
|
@ -517,7 +513,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::join(Table *c)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
if (d->wherePhrase.data)
|
||||
d->wherePhrase = d->wherePhrase && ph;
|
||||
else
|
||||
|
|
@ -528,7 +524,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::where(const ConditionalPhrase &ph)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::setWhere(const ConditionalPhrase &ph)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
d->wherePhrase = ph;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -536,7 +532,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::setWhere(const ConditionalPhrase &ph)
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::skip(int n)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
d->skip = n;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -544,7 +540,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::skip(int n)
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::take(int n)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
d->take = n;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -552,7 +548,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::take(int n)
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::fields(const PhraseList &ph)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
d->fieldPhrase = ph;
|
||||
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,
|
||||
// QString type)
|
||||
//{
|
||||
// Q_D(Query);
|
||||
// Q_D(AbstractQuery);
|
||||
// d->orderPhrases.append(fieldName, type);
|
||||
// return this;
|
||||
//}
|
||||
|
|
@ -569,7 +565,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::fields(const PhraseList &ph)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(const PhraseList &ph)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
d->orderPhrase = ph;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -577,7 +573,7 @@ Q_OUTOFLINE_TEMPLATE Query<T> *Query<T>::orderBy(const PhraseList &ph)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE int Query<T>::update(const AssignmentPhraseList &ph)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->sql = d->database->sqlGenerator()->updateCommand(
|
||||
d->tableName,
|
||||
|
|
@ -594,7 +590,7 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::update(const AssignmentPhraseList &ph)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE int Query<T>::remove()
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->sql = d->database->sqlGenerator()->deleteCommand(
|
||||
d->tableName, d->wherePhrase);
|
||||
|
|
@ -616,7 +612,7 @@ Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query<T>::toModel()
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(QSqlQueryModel *model)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->sql = d->database->sqlGenerator()->selectCommand(
|
||||
d->tableName,
|
||||
|
|
@ -653,7 +649,7 @@ Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(QSqlQueryModel *model)
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(SqlModel *model)
|
||||
{
|
||||
Q_D(Query);
|
||||
Q_D(AbstractQuery);
|
||||
|
||||
d->sql = d->database->sqlGenerator()->selectCommand(
|
||||
d->tableName,
|
||||
|
|
@ -690,7 +686,7 @@ Q_OUTOFLINE_TEMPLATE void Query<T>::toModel(SqlModel *model)
|
|||
template <class T>
|
||||
Q_OUTOFLINE_TEMPLATE QString Query<T>::sqlCommand() const
|
||||
{
|
||||
Q_D(const Query);
|
||||
Q_D(const AbstractQuery);
|
||||
return d->sql;
|
||||
}
|
||||
|
||||
|
|
@ -705,4 +701,4 @@ Q_OUTOFLINE_TEMPLATE QString Query<T>::sqlCommand() const
|
|||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#endif // QUERY_H
|
||||
#endif // NUT_QUERY_H
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -29,43 +29,46 @@
|
|||
|
||||
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)
|
||||
{
|
||||
_renderer = renderer;
|
||||
Q_D(SqlModel);
|
||||
d->renderer = renderer;
|
||||
}
|
||||
|
||||
SqlModel::SqlModel(Database *database, AbstractTableSet *tableSet, QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
, _renderer(nullptr)
|
||||
, d(new SqlModelPrivate(this))
|
||||
, d_ptr(new SqlModelPrivate(this))
|
||||
{
|
||||
Q_D(SqlModel);
|
||||
d->model = database->model()
|
||||
.tableByClassName(tableSet->childClassName());
|
||||
d->tableName = d->model->name();
|
||||
|
||||
|
||||
// setQuery("SELECT * FROM " + d->tableName, database->databaseName());
|
||||
}
|
||||
|
||||
int SqlModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_D(const SqlModel);
|
||||
Q_UNUSED(parent)
|
||||
return d->rows.count();
|
||||
}
|
||||
|
||||
int SqlModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_D(const SqlModel);
|
||||
Q_UNUSED(parent)
|
||||
return d->model->fields().count();
|
||||
}
|
||||
|
||||
QVariant SqlModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
Q_D(const SqlModel);
|
||||
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
|
|
@ -76,8 +79,8 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
|
|||
Row<Table> t = d->rows.at(index.row());
|
||||
QVariant v = t->property(d->model->field(index.column())->name.toLocal8Bit().data());
|
||||
|
||||
if (_renderer != nullptr)
|
||||
v = _renderer(index.column(), v);
|
||||
if (d->renderer != nullptr)
|
||||
v = d->renderer(index.column(), v);
|
||||
return v;
|
||||
}
|
||||
return QVariant();
|
||||
|
|
@ -85,7 +88,8 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
void SqlModel::setRows(RowList<Table> rows)
|
||||
{
|
||||
d.detach();
|
||||
Q_D(SqlModel);
|
||||
|
||||
if (d->rows.count()) {
|
||||
beginRemoveRows(QModelIndex(), 0, d->rows.count());
|
||||
d->rows.clear();
|
||||
|
|
@ -98,19 +102,15 @@ void SqlModel::setRows(RowList<Table> rows)
|
|||
|
||||
void SqlModel::append(Row<Table> table)
|
||||
{
|
||||
d.detach();
|
||||
Q_D(SqlModel);
|
||||
beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count());
|
||||
d->rows.append(table);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
//void SqlModel::append(Table *table)
|
||||
//{
|
||||
// append(TableType<Table>::Row(table));
|
||||
//}
|
||||
|
||||
QVariant SqlModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
Q_D(const SqlModel);
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
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
|
||||
{
|
||||
Q_D(const SqlModel);
|
||||
return d->rows.at(i);
|
||||
}
|
||||
|
||||
SqlModelPrivate::SqlModelPrivate(SqlModel *parent)
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
}
|
||||
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -24,9 +24,8 @@
|
|||
#include <QtCore/QAbstractTableModel>
|
||||
#include <QtCore/QExplicitlySharedDataPointer>
|
||||
#include <QtCore/QList>
|
||||
#include "defines.h"
|
||||
#include "sqlmodel_p.h"
|
||||
#include <functional>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -34,12 +33,12 @@ class Database;
|
|||
class AbstractTableSet;
|
||||
class Table;
|
||||
class TableModel;
|
||||
|
||||
class SqlModelPrivate;
|
||||
class NUT_EXPORT SqlModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
std::function <QVariant(int, QVariant)> _renderer;
|
||||
SqlModelPrivate *d_ptr;
|
||||
Q_DECLARE_PRIVATE(SqlModel)
|
||||
|
||||
public:
|
||||
// explicit SqlModel(Query *q);
|
||||
|
|
@ -60,9 +59,6 @@ public:
|
|||
|
||||
void setRenderer(const std::function<QVariant (int, QVariant)> &renderer);
|
||||
|
||||
private:
|
||||
QExplicitlySharedDataPointer<SqlModelPrivate> d;
|
||||
|
||||
signals:
|
||||
void beforeShowText(int col, QVariant &value);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,21 +3,28 @@
|
|||
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QString>
|
||||
#include "defines.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class SqlModel;
|
||||
class Table;
|
||||
class TableModel;
|
||||
class NUT_EXPORT SqlModelPrivate : public QSharedData {
|
||||
class NUT_EXPORT SqlModelPrivate {
|
||||
public:
|
||||
SqlModel *q_ptr;
|
||||
Q_DECLARE_PUBLIC(SqlModel);
|
||||
|
||||
explicit SqlModelPrivate(SqlModel *parent);
|
||||
|
||||
QString tableName;
|
||||
|
||||
RowList<Table> rows;
|
||||
TableModel *model;
|
||||
std::function <QVariant(int, QVariant)> renderer;
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/QSet>
|
||||
|
||||
#include "tablemodel.h"
|
||||
#include "defines.h"
|
||||
#include "phrase.h"
|
||||
#include <QtNut/defines.h>
|
||||
#include <QtNut/tablemodel.h>
|
||||
#include <QtNut/phrase.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef TABLEPRIVATE_H
|
||||
#define TABLEPRIVATE_H
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QSharedData>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class TableModel;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QDebug>
|
||||
#include "defines.h"
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@
|
|||
|
||||
#include <QtSql/QSqlQuery>
|
||||
|
||||
#include "abstracttableset.h"
|
||||
#include "table.h"
|
||||
#include "bulkinserter.h"
|
||||
#include "databasemodel.h"
|
||||
#include "abstracttablesetdata.h"
|
||||
#include <QtNut/abstracttableset.h>
|
||||
#include <QtNut/table.h>
|
||||
#include <QtNut/bulkinserter.h>
|
||||
#include <QtNut/databasemodel.h>
|
||||
#include <QtNut/abstracttablesetdata.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -21,11 +21,12 @@
|
|||
#ifndef DBGEOGRAPHY_H
|
||||
#define DBGEOGRAPHY_H
|
||||
|
||||
#include "defines.h"
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
#include <QtNut/defines.h>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
class NUT_EXPORT DbGeography
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QtCore/qglobal.h>
|
||||
|
||||
#include "weblogdatabase.h"
|
||||
|
||||
class Post;
|
||||
class User;
|
||||
class BasicTest : public QObject
|
||||
|
|
|
|||
Loading…
Reference in New Issue