#include #include #include #include #include #include #include #include //void add(qint64 time, int duration) //{ // qint64 time = 1505292189000; // time += time_offset; // ttm->addTestEvent(new LtsEventTimeline::Event(0, (int)ProjectDataManagement::EventType_def::Hit, time, 0, 0, 0, 0, // QStringList() << QStringLiteral("Test"), // LtsEventTimeline::Event::drawCustomEventGraphicEllipse, QColor("green"), QString())); //} using namespace LtsTimeline; class AbstractStuff { public: virtual void thing() = 0; }; class TheStuff : public AbstractStuff { void thing() override { fprintf(stderr, "thing() !\n"); } }; std::unique_ptr get() { return std::make_unique(std::move(TheStuff())); } std::vector> test; void move(std::unique_ptr &&stuff) { test.push_back(std::move(stuff)); } void populateModel(LtsTimeline::TimelineModel *model) { { std::unique_ptr asp = get(); move(std::move(asp)); } { AbstractStuff &as = *test.front(); as.thing(); } #define l() qCritical() qint64 rtlnau = QDateTime::currentMSecsSinceEpoch(); class TestItem : public Item { public: TestItem(qint64 startTime, int duration, const QColor &color, bool isEditable = true) : Item(startTime, duration, color, isEditable) , m_1234(1234) {} int get1234() const { return m_1234; } private: int m_1234 { 9876 }; }; int trackId; int itemId; /* |=====================| <= between test 1 |=======================| <= between test 2 /30 /60 /90 /120 /150 /180 /210 /240 | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | T1 000000000 >T2 111111111 T3 333333333 22222222222222222 T4 55555555 44444444444444444 */ // NOTE: T0 is already assigned to the root track! /*T1*/model->addTrack(0, Track(QStringLiteral("1st Track"))); // 1 (has one child! id = 2) /*I0*/model->addItem(1, Item(rtlnau + 120'000, 30'000, Qt::green)); int firstChildId = /*T2*/model->addTrack(1, Track(QStringLiteral("1st Track's 1st Child"))); /*I1*/model->addItem(2, Item(rtlnau + 180'000, 30'000, Qt::magenta)); l() << "firstChildId:" << firstChildId; /*T3*/model->addTrack(0, Track(QStringLiteral("2nd Track"))); /*I2*/model->addItem(3, Item(rtlnau + 120'000, 60'000, Qt::blue)); /*I3*/model->addItem(3, Item(rtlnau + 60'000, 30'000, Qt::red)); /*T4*/model->addTrack(0, Track(QStringLiteral("3rd Track"))); /*I4*/model->addItem(4, Item(rtlnau + 150'000, 60'000, Qt::yellow)); /*I5*/model->addItem(4, TestItem(rtlnau + 90'000, 30'000, Qt::cyan)); model->print(true); try { const TestItem &testItem = dynamic_cast(model->item(5)); // l() << "TestItem id:" << testItem.id() << "- okay?" << (testItem.get1234() == 1234); } catch(const std::exception &ex) { l() << "dynamic_cast back to TestItem failed!" << ex.what(); } (void)itemId; (void)trackId; // l() << "itemIds" << model->itemIds(); qint64 now = rtlnau; { #define non_strict false #define strict true #define recursive true #define sorted true #define unsorted false QVector x; bool y; // l() << "between test 1:"; x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, non_strict, recursive); // l() << "itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, non_strict, resursive)" << x << "- okay?" << (x == QVector({ 0, 2, 3, 5 })); x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, strict, recursive); // l() << "itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, strict, resursive)" << x << "- okay?" << (x == QVector({ 5 })); y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, non_strict, recursive); // l() << "isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, non_strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, strict, recursive); // l() << "isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, non_strict, recursive); // l() << "isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, non_strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, strict, recursive); // l() << "isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, strict, resursive)" << "- okay?" << !y; // l() << "between test 2:"; x = model->itemIdsBetween(now + 60'000, now + 150'000, non_strict, recursive); // l() << "itemIdsBetween(now + 60'000, now + 150'000, non_strict, resursive)" << x << "- okay?" << (x == QVector({ 0, 2, 3, 4, 5 })); x = model->itemIdsBetween(now + 60'000, now + 150'000, strict, recursive); // l() << "itemIdsBetween(now + 60'000, now + 150'000, strict, resursive)" << x << "- okay?" << (x == QVector({ 0, 3, 5 })); y = model->isItemsBetween(now + 60'000, now + 150'000, -1, non_strict, recursive); // l() << "isItemsBetween(now + 60'000, now + 150'000, -1, non_strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000, now + 150'000, -1, strict, recursive); // l() << "isItemsBetween(now + 60'000, now + 150'000, -1, strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000, now + 150'000, 5, non_strict, recursive); // l() << "isItemsBetween(now + 60'000, now + 150'000, 5, non_strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000, now + 150'000, 5, strict, recursive); // l() << "isItemsBetween(now + 60'000, now + 150'000, 5, strict, resursive)" << "- okay?" << y; y = model->isItemsBetween(now + 60'000, now + 150'000, QVector({ 0, 3, 5 }), strict, recursive); // l() << "isItemsBetween(now + 60'000, now + 150'000, QVector({ 0, 3, 5 }), strict, resursive)" << "- okay?" << !y; y = model->isItemsBetween(now + 60'000, now + 150'000, QVector({ 0, 5 }), strict, recursive); // l() << "isItemsBetween(now + 60'000, now + 150'000, QVector({ 0, 5 }), strict, resursive)" << "- okay?" << y; x = model->itemIdsBetween(0, now + 999'000, non_strict, recursive, sorted); // l() << "itemIdsBetween(0, now + 999'000, non_strict, recursive, sorted)" << x << "- okay?" << (x == QVector({ 3, 5, 0, 2, 4, 1 })); #undef non_strict #undef strict #undef recursive #undef unsorted #undef sorted } try { // item 1 von track 2 auf track 3, zu startTime 210'000 model->moveItemToTrack(1, 3, now + 210'000); } catch(...) { fprintf(stderr, "That didn't work. %s:%d\n", __FUNCTION__, __LINE__); } model->print(true); try { // item 3 von track 3 auf track 2, zu startTime 150'000 model->moveItemToTrack(3, 2, now + 150'000); } catch(...) { fprintf(stderr, "That didn't work. %s:%d\n", __FUNCTION__, __LINE__); } /* now /30 /60 /90 /120 /150 /180 /210 /240 | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | ' ' ' | T1 000000000 >T2 333333333 T3 2222222222222222111111111 T4 55555555 44444444444444444 */ model->print(true); #undef l } int main(int argc, char *argv[]) { // qputenv("TDS_DEVEL", "yes, of course"); qWarning() << "LtsTimeline - Test"; NGLApplication app(argc, argv); app.createLogger("Timeline", "log4cxx_timeline.props"); STARTUP_LOG(app.baseLogger()); int ret = 0; LtsTimeline::TimelineWidget *timeline = new LtsTimeline::TimelineWidget(); LtsTimeline::TimelineModel *model = new LtsTimeline::TimelineModel(timeline->view()); model->setSnapEnabled(true); populateModel(model); timeline->setModel(model); timeline->showDebugWidget(); timeline->setWindowState(Qt::WindowMaximized); timeline->show(); // timeline->setMaximumZoomFactor(LtsTimeline::ZoomFactor::ThirtyMinutes); timeline->setZoomFactor(LtsTimeline::ZoomFactor::SixtyMinutes); timeline->setStartTime(QDateTime::currentMSecsSinceEpoch()); timeline->setDuration(12 * 60 * 60 * 1000); ret = app.exec(); SHUTDOWN_LOG(app.baseLogger()); return ret; }