#include #include class AObject; class AObject { public: char t{' '}; int x{0}; int y{0}; }; class ScribusDoc { public: void swap() { QList items{}; for (auto &a: AObjects) { items.append(&a); } qSort(items.begin(), items.end(), compareAObject); auto itBegin = items.begin(); auto itEnd = items.end(); --itEnd; while (itBegin < itEnd) { auto swapX = (*itBegin)->x; auto swapY = (*itBegin)->y; (*itBegin)->x = (*itEnd)->x; (*itBegin)->y = (*itEnd)->y; (*itEnd)->x = swapX; (*itEnd)->y = swapY; ++itBegin; --itEnd; } } void cycleRight() { QList items{}; for (auto &a: AObjects) { items.append(&a); } qSort(items.begin(), items.end(), compareAObject); auto it = items.begin(); auto swapX = (*it)->x; auto swapY = (*it)->y; auto prevIt = it; ++it; while (it != items.end()) { (*prevIt)->x = (*it)->x; (*prevIt)->y = (*it)->y; prevIt = it; ++it; } it = --items.end(); (*it)->x = swapX; (*it)->y = swapY; } void render() { qDebug() << "-----"; for (auto a: AObjects) { qDebug() << a.t << a.x << a.y; } } private: QList AObjects{{'c',3,4},{'a',2,1},{'b',2,2}}; static bool compareAObject(const AObject* a, const AObject* b) { return a->x < b->x || (a->x == b->x && a->y < b->y); } }; int main() { ScribusDoc doc; doc.render(); qDebug() << "a b c > c a b > b c a > a b c"; doc.cycleRight(); doc.render(); doc.cycleRight(); doc.render(); doc.cycleRight(); doc.render(); qDebug() << "a b c > c a b > a b c"; doc.swap(); doc.render(); doc.swap(); doc.render(); }