From 32dafbe8a2aaf2230b55dfd0840f70ff7909b5e1 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 21 Apr 2011 09:30:16 +0200 Subject: Add qt/container usage to Qt example --- qt/README | 10 ++++++---- qt/driver.cxx | 30 +++++++++++++++++++++++------- qt/employee.hxx | 26 +++++++++++++++++++++----- 3 files changed, 50 insertions(+), 16 deletions(-) (limited to 'qt') diff --git a/qt/README b/qt/README index 111a39b..978e8aa 100644 --- a/qt/README +++ b/qt/README @@ -8,10 +8,12 @@ employee.hxx Header file defining the 'employee' and 'employer' persistent classes. We use QSharedPointer/QWeakPointer smart pointers provided by Qt (as well as their lazy versions provided by the Qt profile library) to - establish a bidirectional employee-employer relationship. We also use - the QDateTime type to store the employee's date of birth and QString - to store the employee's first and last name. Finally we use QByteArray - to store the person's public key. + establish a bidirectional employee-employer relationship. The QList + type is used to store the collection of employees employed by the + employer. We also use the QDateTime type to store the employee's date + of birth and QString to store the employee's first and last name. A + QSet instance keeps track of the employee's email addresses. Finally + we use QByteArray to store the person's public key. employee-odb.hxx employee-odb.ixx diff --git a/qt/driver.cxx b/qt/driver.cxx index 395f0b5..79d4b4a 100644 --- a/qt/driver.cxx +++ b/qt/driver.cxx @@ -45,11 +45,16 @@ main (int argc, char* argv[]) QSharedPointer jane ( new employee ("Jane", - "Doe", + "Smith", QDate (1983, 1, 18), QByteArray ("\0xD7\0x00\0x14", 3), er)); + john->emails ().insert ("john_d@example.com"); + john->emails ().insert ("john.doe@simple.com"); + jane->emails ().insert ("jane_s@example.com"); + jane->emails ().insert ("jane.smith@simple.com"); + // Set the inverse side of the employee-employer relationship. // er->employees ().push_back (john); @@ -84,6 +89,11 @@ main (int argc, char* argv[]) QByteArray ("0x00\0x32\0x00\0x01\0x00", 5), er)); + john->emails ().insert ("john_d@example.com"); + john->emails ().insert ("john.doe@complex.com"); + jane->emails ().insert ("jane_s@example.com"); + jane->emails ().insert ("jane.smith@complex.com"); + // Set the inverse side of the employee-employer relationship. // er->employees ().push_back (john); @@ -121,12 +131,18 @@ main (int argc, char* argv[]) QSharedPointer pe (p->employer ().load ()); cout << p->first () << " " << p->last () << endl - << " born: " << p->born ().toString () << endl - << " public key length: " << p->public_key ().size () << endl - << " employer: " - << pe->name ().toAscii ().data () << endl; - - cout << endl; + << " born: " << p->born ().toString () << endl; + + for (emails::const_iterator j (p->emails ().begin ()), + e (p->emails ().end ()); j != e; ++j) + { + cout << " email: " << *j << endl; + } + + cout << " public key length: " << p->public_key ().size () << endl + << " employer: " + << pe->name () << endl + << endl; } t.commit (); diff --git a/qt/employee.hxx b/qt/employee.hxx index f921a97..37ad0c9 100644 --- a/qt/employee.hxx +++ b/qt/employee.hxx @@ -5,12 +5,12 @@ #ifndef EMPLOYEE_HXX #define EMPLOYEE_HXX -#include - #include #include #include #include +#include +#include #include @@ -21,7 +21,8 @@ class employer; class employee; -typedef std::vector > employees; +typedef QSet emails; +typedef QList > employees; #pragma db object class employer @@ -107,6 +108,22 @@ public: return born_; } + // Emails. + // + typedef ::emails emails_type; + + const emails_type& + emails () const + { + return emails_; + } + + emails_type& + emails () + { + return emails_; + } + // Public key. // const QByteArray& @@ -139,9 +156,8 @@ private: QString first_; QString last_; - QDate born_; - + emails_type emails_; QByteArray public_key_; #pragma db not_null -- cgit v1.1