MagicSmoke  $VERSION$
orderauditdlg_p.h
Go to the documentation of this file.
1 //
2 // C++ Interface: orderaudit dialog
3 //
4 // Description:
5 //
6 //
7 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2010-2011
8 //
9 // Copyright: See README/COPYING.GPL files that come with this distribution
10 //
11 //
12 
13 #ifndef MAGICSMOKE_ORDERAUDITDLG_P_H
14 #define MAGICSMOKE_ORDERAUDITDLG_P_H
15 
16 #include "orderauditdlg.h"
17 
18 #include <MTGetOrderAudit>
19 #include <QMetaMethod>
20 #include <TimeStamp>
21 
22 template<class T>
23 static bool hasMetaValue(T*obj,QString n)
24 {
25  Q_UNUSED(obj);
26  const QMetaObject mobj=T::staticMetaObject;
27  //look for property
28  int id=mobj.indexOfProperty(n.toLatin1().data());
29  if(id>=0)return true;
30  //look for method
31  id=mobj.indexOfMethod(n.toLatin1().data());
32  if(id<0)return false;
33  QMetaMethod mm=mobj.method(id);
34  if(mm.parameterNames().size()!=0)return false;
35  if(QString(mm.typeName()).isEmpty())return false;
36  return true;
37 }
38 
39 template<class T>
40 static QVariant getMetaValue(T*obj,QString n)
41 {
42  const QMetaObject mobj=T::staticMetaObject;
43  //look for property
44  int id=mobj.indexOfProperty(n.toLatin1().data());
45  if(id>=0)return mobj.property(id).readOnGadget(obj);
46  //look for method
47  id=mobj.indexOfMethod(n.toLatin1().data());
48  if(id<0)return QVariant();
49  QMetaMethod mm=mobj.method(id);
50  if(mm.parameterNames().size()!=0)return QVariant();
51  if(QString(mm.typeName()).isEmpty())return QVariant();
52  //try to invoke
53  int dataid=QMetaType::type(mm.typeName());
54  void *data=QMetaType::create(dataid);
55  QVariant ret;
56  if(mm.invokeOnGadget(obj, QGenericReturnArgument(mm.typeName(),data)))
57  ret=QVariant(dataid,data);
58  QMetaType::destroy(dataid,data);
59  return ret;
60 }
61 
62 class MOADynamicObject:public QObject
63 {
64  public:
65  virtual bool hasValue(QString n)//{return hasMetaValue(this,n);}
66  {
67  const QMetaObject*mobj=metaObject();
68  //look for property
69  int id=mobj->indexOfProperty(n.toLatin1().data());
70  if(id>=0)return true;
71  //look for method
72  id=mobj->indexOfMethod(n.toLatin1().data());
73  if(id<0)return false;
74  QMetaMethod mm=mobj->method(id);
75  if(mm.parameterNames().size()!=0)return false;
76  if(QString(mm.typeName()).isEmpty())return false;
77  return true;
78  }
79  virtual QVariant getValue(QString n)//{return getMetaValue(this,n);}
80  {
81  const QMetaObject*mobj=metaObject();
82  //look for property
83  int id=mobj->indexOfProperty(n.toLatin1().data());
84  if(id>=0)return mobj->property(id).read(this);
85  //look for method
86  id=mobj->indexOfMethod(n.toLatin1().data());
87  if(id<0)return QVariant();
88  QMetaMethod mm=mobj->method(id);
89  if(mm.parameterNames().size()!=0)return QVariant();
90  if(QString(mm.typeName()).isEmpty())return QVariant();
91  //try to invoke
92  int dataid=QMetaType::type(mm.typeName());
93  void *data=QMetaType::create(dataid);
94  QVariant ret;
95  if(mm.invoke(this, Qt::DirectConnection, QGenericReturnArgument(mm.typeName(),data)))
96  ret=QVariant(dataid,data);
97  QMetaType::destroy(dataid,data);
98  return ret;
99  }
100 };
101 
103 {
104  Q_OBJECT
105  Q_PROPERTY(qint64 auditTime READ auditTime)
106  Q_PROPERTY(QString auditUser READ auditUser)
107  Q_PROPERTY(QString auditTransaction READ auditTransaction)
108  Q_PROPERTY(QString itemID READ itemID)
109  Q_PROPERTY(QString itemTypeString READ itemTypeString)
110  public:
112  ItemType itemType()const{return mtype;}
113 
114  MOAItem(){mtype=None;}
115  MOAItem(const MOOrderAudit&a){morder=a;mtype=Order;}
116  MOAItem(const MOTicketAudit&a){mticket=a;mtype=Ticket;}
117  MOAItem(const MOVoucherAudit&a){mvoucher=a;mtype=Voucher;}
118  MOAItem(const MOAItem&i){operator=(i);}
120  {
121  mtype=i.mtype;
122  morder=i.morder;mticket=i.mticket;mvoucher=i.mvoucher;
123  return *this;
124  }
125 
126  virtual bool hasValue(QString n){
127  if(hasMetaValue(this,n))return true;
128  switch(mtype){
129  case Order:return hasMetaValue(&morder,n);
130  case Ticket:return hasMetaValue(&mticket,n);
131  case Voucher:return hasMetaValue(&mvoucher,n);
132  default: return false;
133  }
134  }
135  virtual QVariant getValue(QString n){
136  if(hasMetaValue(this,n))return getMetaValue(this,n);
137  switch(mtype){
138  case Order:return getMetaValue(&morder,n);
139  case Ticket:return getMetaValue(&mticket,n);
140  case Voucher:return getMetaValue(&mvoucher,n);
141  default: return false;
142  }
143  }
144  public slots:
145  MOOrderAudit order()const{return morder;}
146  MOTicketAudit ticket()const{return mticket;}
147  MOVoucherAudit voucher()const{return mvoucher;}
148 
149  qint64 auditTime()const{switch(mtype){
150  case Order:return (qint64)morder.audittime();
151  case Ticket:return (qint64)mticket.audittime();
152  case Voucher:return (qint64)mvoucher.audittime();
153  default: return 0;
154  }}
155  QString auditUser()const{switch(mtype){
156  case Order:return morder.audituname();
157  case Ticket:return mticket.audituname();
158  case Voucher:return mvoucher.audituname();
159  default: return QString();
160  }}
161  QString auditTransaction()const{switch(mtype){
162  case Order:return morder.audittransaction();
163  case Ticket:return mticket.audittransaction();
164  case Voucher:return mvoucher.audittransaction();
165  default: return QString();
166  }}
167 
168  bool isSameTransaction(const MOAItem&i)const{
169  if(mtype==None || i.mtype==None)return false;
170  return auditTime() == i.auditTime() &&
171  auditUser() == i.auditUser() &&
172  auditTransaction() == i.auditTransaction();
173  }
174 
175  QString itemID()const{switch(mtype){
176  case Order:return QString::number(morder.orderid());
177  case Ticket:return mticket.ticketid();
178  case Voucher:return mvoucher.voucherid();
179  default:return QString();
180  }}
181 
182  QString itemTypeString()const{switch(mtype){
183  case Order:return QCoreApplication::translate("MOAItem","Order");
184  case Ticket:return QCoreApplication::translate("MOAItem","Ticket");
185  case Voucher:return QCoreApplication::translate("MOAItem","Voucher");
186  default:return QString();
187  }}
188 
189  private:
190  ItemType mtype;
191  MOOrderAudit morder;
192  MOTicketAudit mticket;
193  MOVoucherAudit mvoucher;
194 };
195 
197 {
198  Q_OBJECT
199  Q_PROPERTY(qint64 auditTime READ auditTime)
200  Q_PROPERTY(QString auditUser READ auditUser)
201  Q_PROPERTY(QString auditTransaction READ auditTransaction)
202  Q_PROPERTY(qint64 size READ size)
203  Q_PROPERTY(qint64 totalPrice READ totalPrice)
204  public:
205  MOAParcel(){mprice=0;}
206  MOAParcel(const MOAParcel&p){mitems=p.mitems;mprice=p.mprice;}
207  MOAParcel(const MOAItem&i){mitems<<i;mprice=0;}
209  mitems=p.mitems;mprice=p.mprice;
210  return *this;}
211 
212  public slots:
213  qint64 auditTime()const{
214  if(mitems.size()>0)return mitems[0].auditTime();
215  else return 0;
216  }
217  QString auditUser()const{
218  if(mitems.size()>0)return mitems[0].auditUser();
219  else return QString();
220  }
221  QString auditTransaction()const{
222  if(mitems.size()>0)return mitems[0].auditTransaction();
223  else return QString();
224  }
225 
226  bool isSameTransaction(const MOAItem&i)const{
227  if(mitems.size()!=0)
228  return mitems[0].isSameTransaction(i);
229  else
230  return true;
231  }
232  bool addItem(const MOAItem&i){
233  if(isSameTransaction(i)){
234  mitems<<i;
235  return true;
236  }else return false;
237  }
238 
239  qint64 size()const{return mitems.size();}
240 
241  qint64 totalPrice()const{return mprice;}
242  public:
243  MOAItem item(int i)const{return mitems.value(i);}
244  MOAItem operator[](int i)const{return mitems[i];}
245  MOAItem& operator[](int i){return mitems[i];}
246  MOAItem& item(int i){return mitems[i];}
247 
248  void setPrice(qint64 p){mprice=p;}
249 
250  //used for sorting
251  bool operator<(const MOAParcel&p)const{return auditTime()<p.auditTime();}
252 
253  private:
254  QList<MOAItem>mitems;
255  qint64 mprice;
256 };
257 
258 #endif
MOAItem(const MOVoucherAudit &a)
Definition: orderauditdlg_p.h:117
Nullable< QString > audittransaction
Definition: srcMOOrderAudit.h:64
Definition: srcMOVoucherAudit.h:14
QString itemID() const
Definition: orderauditdlg_p.h:175
MOAItem & operator[](int i)
Definition: orderauditdlg_p.h:245
MOAParcel(const MOAItem &i)
Definition: orderauditdlg_p.h:207
Nullable< QString > ticketid
uniquely identifies the ticket, this ID is automatically generated when the ticket is created by the ...
Definition: srcMOTicketAbstract.h:53
QString auditUser() const
Definition: orderauditdlg_p.h:217
MOAItem operator[](int i) const
Definition: orderauditdlg_p.h:244
virtual bool hasValue(QString n)
Definition: orderauditdlg_p.h:126
Nullable< qint64 > audittime
Definition: srcMOOrderAudit.h:60
MOAParcel & operator=(const MOAParcel &p)
Definition: orderauditdlg_p.h:208
bool isSameTransaction(const MOAItem &i) const
Definition: orderauditdlg_p.h:168
MOAItem item(int i) const
Definition: orderauditdlg_p.h:243
Nullable< QString > voucherid
Definition: srcMOVoucherAbstract.h:39
qint64 totalPrice() const
Definition: orderauditdlg_p.h:241
qint64 size() const
Definition: orderauditdlg_p.h:239
MOAItem(const MOTicketAudit &a)
Definition: orderauditdlg_p.h:116
MOAItem(const MOOrderAudit &a)
Definition: orderauditdlg_p.h:115
Definition: orderauditdlg_p.h:111
Definition: orderauditdlg_p.h:102
Definition: orderauditdlg_p.h:111
static QVariant getMetaValue(T *obj, QString n)
Definition: orderauditdlg_p.h:40
Nullable< QString > audituname
Definition: srcMOOrderAudit.h:62
QString auditTransaction() const
Definition: orderauditdlg_p.h:161
This class represents the audit information about an order.
Definition: srcMOOrderAudit.h:15
MOAItem & item(int i)
Definition: orderauditdlg_p.h:246
QString auditUser() const
Definition: orderauditdlg_p.h:155
MOAParcel(const MOAParcel &p)
Definition: orderauditdlg_p.h:206
Definition: orderauditdlg_p.h:62
static bool hasMetaValue(T *obj, QString n)
Definition: orderauditdlg_p.h:23
Definition: orderauditdlg_p.h:111
virtual bool hasValue(QString n)
Definition: orderauditdlg_p.h:65
void setPrice(qint64 p)
Definition: orderauditdlg_p.h:248
MOOrderAudit order() const
Definition: orderauditdlg_p.h:145
ItemType
Definition: orderauditdlg_p.h:111
MOAItem(const MOAItem &i)
Definition: orderauditdlg_p.h:118
qint64 auditTime() const
Definition: orderauditdlg_p.h:213
MOAItem & operator=(const MOAItem &i)
Definition: orderauditdlg_p.h:119
MOAItem()
Definition: orderauditdlg_p.h:114
MOTicketAudit ticket() const
Definition: orderauditdlg_p.h:146
Nullable< qint64 > orderid
Definition: srcMOOrderAudit.h:44
virtual QVariant getValue(QString n)
Definition: orderauditdlg_p.h:135
bool isSameTransaction(const MOAItem &i) const
Definition: orderauditdlg_p.h:226
Definition: orderauditdlg_p.h:111
ItemType itemType() const
Definition: orderauditdlg_p.h:112
virtual QVariant getValue(QString n)
Definition: orderauditdlg_p.h:79
QString itemTypeString() const
Definition: orderauditdlg_p.h:182
QString auditTransaction() const
Definition: orderauditdlg_p.h:221
MOAParcel()
Definition: orderauditdlg_p.h:205
MOVoucherAudit voucher() const
Definition: orderauditdlg_p.h:147
Definition: srcMOTicketAudit.h:14
qint64 auditTime() const
Definition: orderauditdlg_p.h:149
bool addItem(const MOAItem &i)
Definition: orderauditdlg_p.h:232
bool operator<(const MOAParcel &p) const
Definition: orderauditdlg_p.h:251
Definition: orderauditdlg_p.h:196