[odb-users] Persist container derived class as value type
Henning Becker
henning.becker at apworks.de
Mon Mar 7 10:23:58 EST 2016
Am Montag, 7. März 2016, 16:03:43 schrieben Sie:
> Hi Henning,
>
> Henning Becker <henning.becker at apworks.de> writes:
> > I'm trying to persist QPolygon from Qt as a value type. QPolygon
> > inherits from QVector<QPoint> and no data will be lost, if it is
> > handled just as a QVector<QPoint>.
> >
> > I have defined QPoint as a composite value type:
> > #pragma db value(QPoint) transient
> > #pragma db member(QPoint::x_) virtual(int) get(x) set(setX)
> > #pragma db member(QPoint::y_) virtual(int) get(y) set(setY)
> >
> > But how can I make odb handle QPolygon as a QVector<QPoint>?
>
> There are two ways: "quick and dirty" and "slow but clean" ;-).
>
> The "quick and dirty" approach is to map QPolygon to a composite value
> with a QVector<QPoint> member:
>
> using QPolygonBase = QVector<QPoint>;
> #pragma db value(QPolygon) transient
> #pragma db member(QPolygon::points) virtual(QPolygonBase) access(this)
>
> class Object
> {
> ...
>
> QPolygon perimeter;
> };
>
> The major drawback of this approach is that the database table name for
> perimeter will be called "object_perimeter_points" and not just
> "object_perimeter".
>
> The "slow but clean" approach is to define an odb:container_traits<QPolygon>
> specialization, similar to the one defined from QVector<T> (in fact, you
> can just derive from it). See the Qt profile for details on how this is
> done.
Hi Boris,
thanks for your answer. It seems to work perfectly. I've written a trait,
which just derives from QVector<QPoint>.
Here is the code, maybe anybode else needs it:
namespace odb {
template <>
class access::container_traits<QPolygon> : public
access::container_traits<QVector<QPoint>>
{};
}
Cheers,
Henning
>
> Boris
--
_______________________________________
Henning Becker
Development Engineer
AIRBUS APWORKS GmbH
Willy-Messerschmitt-Str. 1
82024 Taufkirchen - Germany
T: +49 (0) 89 607 29771
F: +49 (0) 89 607 28239
M: +49 (0) 174 9818097
henning.becker at apworks.de
AIRBUS APWORKS GmbH
Registered Office: Ottobrunn
District Court of Munich: HRB 141734
Managing Director: Joachim Zettler
Internet: www.apworks.de
_______________________________________
More information about the odb-users
mailing list