219 lines
6.0 KiB
C++
219 lines
6.0 KiB
C++
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QtCore/QDateTime>
|
|
#include <QtCore/QDebug>
|
|
#include <item.h>
|
|
#include <nglapplication/nglapplication.h>
|
|
#include <timeline_model.h>
|
|
#include <timeline_widget.h>
|
|
#include <track.h>
|
|
|
|
using namespace LtsTimeline;
|
|
|
|
class AbstractStuff
|
|
{
|
|
public:
|
|
virtual void thing() = 0;
|
|
};
|
|
|
|
class TheStuff : public AbstractStuff
|
|
{
|
|
void thing() override
|
|
{
|
|
fprintf(stderr, "thing() !\n");
|
|
}
|
|
};
|
|
|
|
std::unique_ptr<AbstractStuff> get()
|
|
{
|
|
return std::make_unique<TheStuff>(std::move(TheStuff()));
|
|
}
|
|
|
|
std::vector<std::unique_ptr<AbstractStuff>> test;
|
|
|
|
void move(std::unique_ptr<AbstractStuff>&& stuff)
|
|
{
|
|
test.push_back(std::move(stuff));
|
|
}
|
|
|
|
void populateModel(LtsTimeline::TimelineModel* model)
|
|
{
|
|
{
|
|
std::unique_ptr<AbstractStuff> 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;
|
|
|
|
model->addTrack<Track>(0, Track(QStringLiteral("1st Track")));
|
|
model->addItem<Item>(1, Item(rtlnau + 120'000, 30'000, Qt::green));
|
|
|
|
int firstChildId = model->addTrack(1, Track(QStringLiteral("1st Track's 1st Child")));
|
|
model->addItem<LtsTimeline::Item>(2, Item(rtlnau + 180'000, 30'000, Qt::magenta));
|
|
l() << "firstChildId:" << firstChildId;
|
|
|
|
model->addTrack<Track>(0, Track(QStringLiteral("2nd Track")));
|
|
model->addItem<Item>(3, Item(rtlnau + 120'000, 60'000, Qt::blue));
|
|
model->addItem<Item>(3, Item(rtlnau + 60'000, 30'000, Qt::red));
|
|
|
|
model->addTrack<Track>(0, Track(QStringLiteral("3rd Track")));
|
|
model->addItem<Item>(4, Item(rtlnau + 150'000, 60'000, Qt::yellow));
|
|
model->addItem<TestItem>(4, TestItem(rtlnau + 90'000, 30'000, Qt::cyan));
|
|
|
|
model->print(true);
|
|
|
|
try
|
|
{
|
|
}
|
|
catch (const std::exception& ex)
|
|
{
|
|
l() << "dynamic_cast back to TestItem failed!" << ex.what();
|
|
}
|
|
|
|
(void)itemId;
|
|
(void)trackId;
|
|
|
|
qint64 now = rtlnau;
|
|
|
|
{
|
|
#define non_strict false
|
|
#define strict true
|
|
#define recursive true
|
|
#define sorted true
|
|
#define unsorted false
|
|
QVector<int> x;
|
|
bool y;
|
|
(void)y;
|
|
|
|
x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, non_strict, recursive);
|
|
|
|
x = model->itemIdsBetween(now + 60'000 + 1, now + 150'000 - 1, strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, non_strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, -1, strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, non_strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000 + 1, now + 150'000 - 1, 5, strict, recursive);
|
|
|
|
x = model->itemIdsBetween(now + 60'000, now + 150'000, non_strict, recursive);
|
|
|
|
x = model->itemIdsBetween(now + 60'000, now + 150'000, strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000, now + 150'000, -1, non_strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000, now + 150'000, -1, strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000, now + 150'000, 5, non_strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000, now + 150'000, 5, strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000, now + 150'000, QVector<int>({0, 3, 5}), strict, recursive);
|
|
|
|
y = model->isItemsBetween(now + 60'000, now + 150'000, QVector<int>({0, 5}), strict, recursive);
|
|
|
|
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<int>({ 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;
|
|
}
|