Nut  0.1
table.h
1 /**************************************************************************
2 **
3 ** This file is part of Nut project.
4 ** https://github.com/HamedMasafi/Nut
5 **
6 ** Nut is free software: you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation, either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** Nut is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU Lesser General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with Nut. If not, see <http://www.gnu.org/licenses/>.
18 **
19 **************************************************************************/
20 
21 #ifndef TABLE_H
22 #define TABLE_H
23 
24 #include <QtCore/QObject>
25 #include <QtCore/qglobal.h>
26 #include <QtCore/QSet>
27 
28 #include "tablemodel.h"
29 #include "defines.h"
30 #include "wherephrase.h"
31 
32 QT_BEGIN_NAMESPACE
33 
34 class Database;
35 class TableSetBase;
36 class NUT_EXPORT Table : public QObject
37 {
38  Q_OBJECT
39 
40 public:
41  explicit Table(QObject *tableSet = 0);
42 
43  enum Status{
44  NewCreated,
45  FeatchedFromDB,
46  Added,
47  Modified,
48  Deleted
49  };
50 
51  void add(TableSetBase *);
52  void save(Database *db);
53 
54  QString primaryKey() const;
55  bool isPrimaryKeyAutoIncrement() const;
56  QVariant primaryValue() const;
57  Status status() const;
58  void setStatus(const Status &status);
59 
60  TableSetBase *tableSet() const;
61  void setTableSet(TableSetBase *tableSet);
62 
63  QSet<QString> changedProperties() const;
64 
65  bool setParentTable(Table *master);
66 signals:
67 
68 public slots:
69 
70 protected:
71  void propertyChanged(QString propName);
72 
73 private:
74  Status _status;
75  QSet<QString> _changedProperties;
76  TableSetBase *_tableSet;
77 
78  QSet<TableSetBase*> tableSets;
79 
80  template<class T>
81  friend class Query;
82 };
83 
84 QT_END_NAMESPACE
85 
86 #endif // TABLE_H