DbStruct Pile   version 0.0.1
This pile contains classes that can be used to
dbcolumn.h
Go to the documentation of this file.
1 
10 #ifndef GUARD_DBCOLUMN_H_INCLUDE
11 #define GUARD_DBCOLUMN_H_INCLUDE
12 
13 #include <dbstruct/dbstruct-config.h>
14 #include <dbstruct/dbobject.h>
15 
16 #include <QString>
17 #include <QVariant>
18 
19 QT_BEGIN_NAMESPACE
20 class QSqlTableModel;
21 class QSqlRecord;
22 QT_END_NAMESPACE
23 
24 class DbTaew;
25 
27 class DBSTRUCT_EXPORT DbColumn : public DbObject {
28 
29 public:
30 
33  FB_CHOOSE_ADD
34  };
35 
36  enum DataType {
37  DTY_INVALID = -1,
39  DTY_BIGINT,
40  DTY_BINARY,
41  DTY_BIT,
42  DTY_TRISTATE,
43  DTY_CHAR,
44  DTY_DATE,
45  DTY_DATETIME,
46  DTY_DATETIME2,
47  DTY_DATETIMEOFFSET,
48  DTY_DECIMAL,
49  DTY_DECIMALSCALE,
50  DTY_FLOAT,
51  DTY_HIERARCHYID,
52  DTY_IMAGE,
53  DTY_INTEGER,
54  DTY_MONEY,
55  DTY_NCHAR,
56  DTY_NTEXT,
57  DTY_NUMERIC,
58  DTY_NUMERICSCALE,
59  DTY_NVARCHAR,
60  DTY_REAL,
61  DTY_ROWVERSION,
62  DTY_SMALLDATETIME,
63  DTY_SMALLINT,
64  DTY_SMALLMONEY,
65  DTY_SQL,
66  DTY_TEXT,
67  DTY_TIME,
68  DTY_TINYINT,
69  DTY_UNIQUEIDENTIFIER,
70  DTY_VARBINARY,
71  DTY_VARCHAR,
72  DTY_XML,
73 
76  DTY_MAX
77  };
78 
79  enum BoolFormat {
80  BF_Y_UPPER,
81  BF_T_UPPER,
82 
83  BF_YES_CAMEL,
84  BF_YES_LOWER,
85  BF_YES_UPPER,
86 
87  BF_ON_CAMEL,
88  BF_ON_LOWER,
89  BF_ON_UPPER,
90 
91  BF_TRUE_CAMEL,
92  BF_TRUE_LOWER,
93  BF_TRUE_UPPER,
94 
95  BF_STRING_ON
96  };
97 
99  typedef QVariant (*Callback) (
100  const DbTaew & table,
101  const DbColumn & colorig,
102  const QSqlRecord & rec,
103  int role,
104  void * user_data);
105 
106  union ColFormat {
107  BoolFormat bit_;
108  int width_;
109  Callback callback_;
110  };
111 
112  QString col_name_;
113  int col_id_;
114  int real_col_id_;
115  int length_;
116  QString col_label_;
117  DataType datatype_;
118  bool nulls_;
119  bool autoincrement_;
120  QString default_value_;
121  bool read_only_;
122  int virtrefcol_;
123  QString foreign_table_;
124  QString foreign_key_;
125  QString foreign_ref_;
129  // following values are extracted from original_format_ in constructor
131  QChar fill_char_;
132  char nr_format_;
135  DbColumn ();
137 
139  DbColumn (
140  const QString & col_name,
141  int col_id,
142  int real_col_id,
143  int length,
144  const QString & col_label,
145  DataType datatype,
146  bool nulls,
147  bool autoincrement,
148  const QString & default_value,
149  const QString & format,
150  bool read_only,
151  int virtrefcol,
152  const QString & foreign_table,
153  const QString & foreign_key,
154  const QString & foreign_ref,
155  ForeignBehaviour foreign_behaviour) ;
156 
158  virtual ~DbColumn();
159 
161  virtual Type
162  type () const {
163  return DBO_COLUMN;
164  }
165 
167  inline bool
168  isForeignKey () const {
169  return !foreign_table_.isEmpty();
170  }
171 
173  inline bool
174  isVirtual () const {
175  return virtrefcol_ != -1;
176  }
177 
179  inline bool
180  isDynamic () const {
181  return datatype_ == DTY_CALLBACK;
182  }
183 
185  QVariant kbData (
186  const DbTaew & table,
187  const QSqlRecord & rec,
188  int role = Qt::DisplayRole,
189  void * user_data = NULL) const;
190 
191  QVariant
192  formattedData (
193  const QVariant &original_value) const;
194 
195 protected:
196 
197 private:
198 
199 };
200 
201 #endif // GUARD_DBCOLUMN_H_INCLUDE
DataType
Definition: dbcolumn.h:36
virtual Type type() const
The type of this object.
Definition: dbcolumn.h:162
QString foreign_table_
Definition: dbcolumn.h:123
QChar fill_char_
Definition: dbcolumn.h:131
Definition: dbcolumn.h:32
QString original_format_
Definition: dbcolumn.h:128
Definition: dbcolumn.h:106
ForeignBehaviour
Definition: dbcolumn.h:31
ForeignBehaviour foreign_behaviour_
Definition: dbcolumn.h:126
bool isDynamic() const
Tell if this column is a virtual one.
Definition: dbcolumn.h:180
int width_
Definition: dbcolumn.h:108
ColFormat format_
Definition: dbcolumn.h:130
Declarations for DbObject class.
Type
The types of objects that use this class as a base.
Definition: dbobject.h:33
QString foreign_key_
Definition: dbcolumn.h:124
BoolFormat bit_
Definition: dbcolumn.h:107
The columnure of a database.
Definition: dbcolumn.h:27
char nr_format_
Definition: dbcolumn.h:132
bool isVirtual() const
Tell if this column is a virtual one.
Definition: dbcolumn.h:174
bool isForeignKey() const
Tell if this column has a foreign key.
Definition: dbcolumn.h:168
A table or view in a database.
Definition: dbtaew.h:24
int precision_
Definition: dbcolumn.h:133
Callback callback_
Definition: dbcolumn.h:109
QString foreign_ref_
Definition: dbcolumn.h:125
Definition: dbobject.h:37
The objecture of a database.
Definition: dbobject.h:28
Definition: dbcolumn.h:74