Hello,
If you have the possibility, I think it is better to sort on database side adding an
ORDER BY to the SQL query.
Otherwise, if you prefer to sort on C++ side, it should be quite easy : you just have to
write comparaison operators for your C++ persistent class.
Because you have a column named '
ordering' to sort your items, comparaison functions are very simple, for example :
- Code: Select all
bool operator < (const MyClass & s1, const MyClass & s2) {
return (s1.ordering < s2.ordering);
}
bool operator > (const MyClass & s1, const MyClass & s2) {
return (s1.ordering > s2.ordering);
}
Then, it depends on the container you use to store your items :
std::vector,
QList,
qx::QxCollection, etc...
If you are using
qx::QxCollection and have defined the comparaison operators, then you can use the
sortByValue() method.
NOTE : qx::QxCollection manages automatically pointers and smart-pointers.
That means that if you store pointers or smart-pointers in your collection, then
(* s1) < (* s2) will be used automatically to sort your items.