commit
cc6ed112b6
|
|
@ -209,6 +209,11 @@ 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 T *get(T *row) {
|
||||
return row;
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ QString PostgreSqlGenerator::fieldType(FieldModel *field)
|
|||
case QMetaType::QJsonValue:
|
||||
case QMetaType::QJsonObject:
|
||||
case QMetaType::QJsonDocument:
|
||||
return "JSON";
|
||||
return "JSONB";
|
||||
|
||||
case QMetaType::QStringList:
|
||||
return "TEXT[]";
|
||||
|
|
|
|||
|
|
@ -159,6 +159,9 @@ protected:
|
|||
QString agregateText(const AgregateType &t, const QString &arg = QString()) const;
|
||||
QString fromTableText(const QString &tableName, QString &joinClassName, QString &orderBy) const;
|
||||
// QString createWhere(QList<WherePhrase> &wheres);
|
||||
|
||||
void replaceTableNames(QString &command);
|
||||
void removeTableNames(QString &command);
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -186,11 +186,4 @@ void SqlServerGenerator::appendSkipTake(QString &sql, int skip, int take)
|
|||
.arg(skip).arg(take));
|
||||
}
|
||||
|
||||
void SqlServerGenerator::replaceTableNames(QString &command)
|
||||
{
|
||||
foreach (TableModel *m, TableModel::allModels())
|
||||
command = command
|
||||
.replace("[" + m->className() + "]", m->name() );
|
||||
}
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
10
src/query.h
10
src/query.h
|
|
@ -57,14 +57,6 @@ template <class T>
|
|||
bool m_autoDelete;
|
||||
|
||||
public:
|
||||
//#ifdef NUT_SHARED_POINTER
|
||||
// typedef QList<QSharedPointer<T>> RowList;
|
||||
// typedef QSharedPointer<T> Row;
|
||||
//#else
|
||||
// typedef QList<T*> RowList;
|
||||
// typedef T* Row;
|
||||
//#endif
|
||||
|
||||
explicit Query(Database *database, TableSetBase *tableSet, bool autoDelete);
|
||||
~Query();
|
||||
|
||||
|
|
@ -185,7 +177,7 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
|||
d->sql = d->database->sqlGenertor()->selectCommand(
|
||||
d->tableName, d->fieldPhrase, d->wherePhrase, d->orderPhrase,
|
||||
d->relations, d->skip, d->take);
|
||||
qDebug()<<d->sql;
|
||||
|
||||
QSqlQuery q = d->database->exec(d->sql);
|
||||
if (q.lastError().isValid()) {
|
||||
qDebug() << q.lastError().text();
|
||||
|
|
|
|||
|
|
@ -40,9 +40,8 @@ void SqlModel::setRenderer(const std::function<QVariant (int, QVariant)> &render
|
|||
}
|
||||
|
||||
SqlModel::SqlModel(Database *database, TableSetBase *tableSet, QObject *parent) :
|
||||
QAbstractTableModel(parent), d_ptr(new SqlModelPrivate(this)), _renderer(nullptr)
|
||||
QAbstractTableModel(parent), d(new SqlModelPrivate(this)), _renderer(nullptr)
|
||||
{
|
||||
Q_D(SqlModel);
|
||||
d->model = database->model()
|
||||
.tableByClassName(tableSet->childClassName());
|
||||
d->tableName = d->model->name();
|
||||
|
|
@ -54,20 +53,17 @@ SqlModel::SqlModel(Database *database, TableSetBase *tableSet, QObject *parent)
|
|||
int SqlModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
Q_D(const SqlModel);
|
||||
return d->rows.count();
|
||||
}
|
||||
|
||||
int SqlModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
Q_D(const SqlModel);
|
||||
return d->model->fields().count();
|
||||
}
|
||||
|
||||
QVariant SqlModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
Q_D(const SqlModel);
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
|
|
@ -104,7 +100,7 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
void SqlModel::setRows(RowList<Table> rows)
|
||||
{
|
||||
Q_D(SqlModel);
|
||||
d.detach();
|
||||
beginRemoveRows(QModelIndex(), 0, d->rows.count());
|
||||
d->rows.clear();
|
||||
endRemoveRows();
|
||||
|
|
@ -115,7 +111,7 @@ void SqlModel::setRows(RowList<Table> rows)
|
|||
|
||||
void SqlModel::append(Row<Table> table)
|
||||
{
|
||||
Q_D(SqlModel);
|
||||
d.detach();
|
||||
beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count());
|
||||
d->rows.append(table);
|
||||
endInsertRows();
|
||||
|
|
@ -129,7 +125,6 @@ void SqlModel::append(Row<Table> table)
|
|||
QVariant SqlModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
Q_D(const SqlModel);
|
||||
return d->model->field(section)->displayName;
|
||||
}
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
|
|
@ -137,11 +132,10 @@ 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_ptr(parent)
|
||||
SqlModelPrivate::SqlModelPrivate(SqlModel *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <QtCore/QAbstractTableModel>
|
||||
#include "defines.h"
|
||||
#include "sqlmodel_p.h"
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
#include <QList>
|
||||
#include <functional>
|
||||
|
||||
|
|
@ -30,7 +32,6 @@ NUT_BEGIN_NAMESPACE
|
|||
|
||||
class Database;
|
||||
class TableSetBase;
|
||||
class SqlModelPrivate;
|
||||
class Table;
|
||||
class TableModel;
|
||||
|
||||
|
|
@ -60,8 +61,7 @@ public:
|
|||
void setRenderer(const std::function<QVariant (int, QVariant)> &renderer);
|
||||
|
||||
private:
|
||||
SqlModelPrivate *d_ptr;
|
||||
Q_DECLARE_PRIVATE(SqlModel)
|
||||
QExplicitlySharedDataPointer<SqlModelPrivate> d;
|
||||
|
||||
signals:
|
||||
void beforeShowText(int col, QVariant &value);
|
||||
|
|
@ -70,8 +70,6 @@ signals:
|
|||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE void SqlModel::setTable(RowList<T> rows)
|
||||
{
|
||||
Q_D(SqlModel);
|
||||
|
||||
RowList<Table> tab;
|
||||
foreach (auto t, rows)
|
||||
tab.append(t);
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ NUT_BEGIN_NAMESPACE
|
|||
class SqlModel;
|
||||
class Table;
|
||||
class TableModel;
|
||||
class SqlModelPrivate {
|
||||
SqlModel *q_ptr;
|
||||
Q_DECLARE_PUBLIC(SqlModel)
|
||||
class SqlModelPrivate : public QSharedData {
|
||||
public:
|
||||
explicit SqlModelPrivate(SqlModel *parent);
|
||||
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ public:
|
|||
|
||||
void append(Row<T> t);
|
||||
void append(RowList<T> t);
|
||||
void remove(T *t);
|
||||
void remove(QList<T *> t);
|
||||
void remove(Row<T> t);
|
||||
void remove(RowList<T> t);
|
||||
|
||||
int length() const;
|
||||
T *at(int i) const;
|
||||
|
|
@ -135,18 +135,19 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(RowList<T> t)
|
|||
}
|
||||
|
||||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
|
||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(Row<T> t)
|
||||
{
|
||||
data.detach();
|
||||
data->childs.removeOne(t.data());
|
||||
data->tables.remove(t.data());
|
||||
data->childs.removeOne(t);
|
||||
data->tables.remove(t);
|
||||
t->setStatus(Table::Deleted);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(QList<T *> t)
|
||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(RowList<T> t)
|
||||
{
|
||||
foreach (T* i, t)
|
||||
foreach (Row<T> i, t)
|
||||
remove(i);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue