Nut/src/table.h

105 lines
2.4 KiB
C
Raw Normal View History

2016-05-12 14:08:58 +08:00
/**************************************************************************
**
** 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 TABLE_H
#define TABLE_H
#include <QtCore/QObject>
#include <QtCore/qglobal.h>
#include <QtCore/QSet>
2016-05-21 16:09:03 +08:00
#include "tablemodel.h"
2016-05-12 14:08:58 +08:00
#include "defines.h"
2018-02-17 23:44:39 +08:00
#include "phrase.h"
2016-05-12 14:08:58 +08:00
2017-02-01 18:01:21 +08:00
NUT_BEGIN_NAMESPACE
2016-05-12 14:08:58 +08:00
class Database;
class TableSetBase;
2018-01-16 04:04:42 +08:00
class TableModel;
2019-02-28 16:10:41 +08:00
class TablePrivate;
2016-05-12 14:08:58 +08:00
class NUT_EXPORT Table : public QObject
{
Q_OBJECT
2019-02-28 16:10:41 +08:00
TablePrivate *d_ptr;
Q_DECLARE_PRIVATE(Table)
2016-05-12 14:08:58 +08:00
public:
2018-10-15 22:34:50 +08:00
explicit Table(QObject *parentTableSet = nullptr);
virtual ~Table();
2016-05-12 14:08:58 +08:00
enum Status{
NewCreated,
FeatchedFromDB,
Added,
Modified,
Deleted
};
2017-05-28 23:08:59 +08:00
int save(Database *db);
2016-05-12 14:08:58 +08:00
2019-06-06 21:00:03 +08:00
Q_DECL_DEPRECATED
2016-05-12 14:08:58 +08:00
QString primaryKey() const;
2019-06-06 21:00:03 +08:00
Q_DECL_DEPRECATED
2016-05-21 16:09:03 +08:00
bool isPrimaryKeyAutoIncrement() const;
2019-06-06 21:00:03 +08:00
Q_DECL_DEPRECATED
2016-05-12 14:08:58 +08:00
QVariant primaryValue() const;
2019-06-06 21:00:03 +08:00
2016-05-12 14:08:58 +08:00
Status status() const;
void setStatus(const Status &status);
2018-01-15 06:12:46 +08:00
TableSetBase *parentTableSet() const;
void setParentTableSet(TableSetBase *parentTableSet);
TableSetBase *childTableSet(const QString &name) const;
2016-05-12 14:08:58 +08:00
QSet<QString> changedProperties() const;
bool setParentTable(Table *master);
signals:
public slots:
protected:
2019-02-10 22:11:22 +08:00
void propertyChanged(const QString &propName);
2016-05-12 14:08:58 +08:00
private:
2019-02-28 16:10:41 +08:00
// TableModel *myModel;
// Status _status;
// QSet<QString> _changedProperties;
2018-01-13 23:59:55 +08:00
//TODO: is this removable?
2019-02-28 16:10:41 +08:00
// TableSetBase *_parentTableSet;
2016-05-12 14:08:58 +08:00
2019-02-28 16:10:41 +08:00
// QSet<TableSetBase*> childTableSets;
2017-06-05 00:04:17 +08:00
void clear();
2017-09-10 22:18:20 +08:00
void add(TableSetBase *);
2016-05-12 14:08:58 +08:00
template<class T>
friend class Query;
2017-09-10 22:18:20 +08:00
friend class TableSetBase;
2016-05-12 14:08:58 +08:00
};
2017-02-01 18:01:21 +08:00
NUT_END_NAMESPACE
2016-05-12 14:08:58 +08:00
#endif // TABLE_H