2015-04-10 17:21:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-04-10 17:21:15 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:55:33 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-04-10 17:21:15 +02:00
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-04-10 17:21:15 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
#include <QColor>
|
2018-05-03 09:50:11 +02:00
|
|
|
#include <tracing/timelinemodelaggregator.h>
|
|
|
|
|
#include <tracing/timelinenotesmodel.h>
|
2015-04-10 17:21:15 +02:00
|
|
|
|
|
|
|
|
class tst_TimelineNotesModel : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void timelineModel();
|
|
|
|
|
void addRemove();
|
|
|
|
|
void properties();
|
|
|
|
|
void selection();
|
|
|
|
|
void modify();
|
2018-03-28 15:40:13 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Timeline::TimelineModelAggregator aggregator;
|
2015-04-10 17:21:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestModel : public Timeline::TimelineModel {
|
|
|
|
|
public:
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel(Timeline::TimelineModelAggregator *parent) : TimelineModel(parent)
|
2015-04-10 17:21:15 +02:00
|
|
|
{
|
|
|
|
|
insert(0, 10, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int typeId(int) const
|
|
|
|
|
{
|
|
|
|
|
return 7;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestNotesModel : public Timeline::TimelineNotesModel {
|
|
|
|
|
friend class tst_TimelineNotesModel;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void tst_TimelineNotesModel::timelineModel()
|
|
|
|
|
{
|
|
|
|
|
TestNotesModel notes;
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel *model = new TestModel(&aggregator);
|
|
|
|
|
TestModel *model2 = new TestModel(&aggregator);
|
2015-04-10 17:21:15 +02:00
|
|
|
notes.addTimelineModel(model);
|
|
|
|
|
notes.addTimelineModel(model2);
|
2018-03-28 15:40:13 +02:00
|
|
|
QCOMPARE(notes.timelineModelByModelId(model->modelId()), model);
|
2015-04-10 17:21:15 +02:00
|
|
|
QCOMPARE(notes.timelineModels().count(), 2);
|
|
|
|
|
QVERIFY(notes.timelineModels().contains(model));
|
|
|
|
|
QVERIFY(notes.timelineModels().contains(model2));
|
|
|
|
|
QVERIFY(!notes.isModified());
|
|
|
|
|
notes.clear(); // clear() only clears the data, not the models
|
|
|
|
|
QCOMPARE(notes.timelineModels().count(), 2);
|
|
|
|
|
delete model; // notes model does monitor the destroyed() signal
|
|
|
|
|
QCOMPARE(notes.timelineModels().count(), 1);
|
|
|
|
|
delete model2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TimelineNotesModel::addRemove()
|
|
|
|
|
{
|
|
|
|
|
TestNotesModel notes;
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel model(&aggregator);
|
2015-04-10 17:21:15 +02:00
|
|
|
notes.addTimelineModel(&model);
|
|
|
|
|
|
|
|
|
|
QSignalSpy spy(¬es, SIGNAL(changed(int,int,int)));
|
2018-03-28 15:40:13 +02:00
|
|
|
int id = notes.add(model.modelId(), 0, QLatin1String("xyz"));
|
2015-04-10 17:21:15 +02:00
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
QCOMPARE(notes.isModified(), true);
|
|
|
|
|
QCOMPARE(notes.count(), 1);
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
QCOMPARE(notes.isModified(), false);
|
|
|
|
|
notes.remove(id);
|
|
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
|
QCOMPARE(notes.isModified(), true);
|
|
|
|
|
QCOMPARE(notes.count(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TimelineNotesModel::properties()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
TestNotesModel notes;
|
|
|
|
|
int id = -1;
|
2018-03-28 15:40:13 +02:00
|
|
|
int modelId = -1;
|
2015-04-10 17:21:15 +02:00
|
|
|
{
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel model(&aggregator);
|
|
|
|
|
modelId = model.modelId();
|
2015-04-10 17:21:15 +02:00
|
|
|
notes.addTimelineModel(&model);
|
|
|
|
|
|
2018-03-28 15:40:13 +02:00
|
|
|
id = notes.add(model.modelId(), 0, QLatin1String("xyz"));
|
2015-04-10 17:21:15 +02:00
|
|
|
QVERIFY(id >= 0);
|
|
|
|
|
QCOMPARE(notes.typeId(id), 7);
|
|
|
|
|
QCOMPARE(notes.timelineIndex(id), 0);
|
2018-03-28 15:40:13 +02:00
|
|
|
QCOMPARE(notes.timelineModel(id), modelId);
|
2015-04-10 17:21:15 +02:00
|
|
|
QCOMPARE(notes.text(id), QLatin1String("xyz"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QCOMPARE(notes.typeId(id), -1); // cannot ask the model anymore
|
|
|
|
|
QCOMPARE(notes.timelineIndex(id), 0);
|
2018-03-28 15:40:13 +02:00
|
|
|
QCOMPARE(notes.timelineModel(id), modelId);
|
2015-04-10 17:21:15 +02:00
|
|
|
QCOMPARE(notes.text(id), QLatin1String("xyz"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TimelineNotesModel::selection()
|
|
|
|
|
{
|
|
|
|
|
TestNotesModel notes;
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel model(&aggregator);
|
2015-04-10 17:21:15 +02:00
|
|
|
notes.addTimelineModel(&model);
|
2018-03-28 15:40:13 +02:00
|
|
|
int id1 = notes.add(model.modelId(), 0, QLatin1String("blablub"));
|
|
|
|
|
int id2 = notes.add(model.modelId(), 0, QLatin1String("xyz"));
|
|
|
|
|
QVariantList ids = notes.byTimelineModel(model.modelId());
|
2015-04-10 17:21:15 +02:00
|
|
|
QCOMPARE(ids.length(), 2);
|
|
|
|
|
QVERIFY(ids.contains(id1));
|
|
|
|
|
QVERIFY(ids.contains(id2));
|
|
|
|
|
|
|
|
|
|
ids = notes.byTypeId(7);
|
|
|
|
|
QCOMPARE(ids.length(), 2);
|
|
|
|
|
QVERIFY(ids.contains(id1));
|
|
|
|
|
QVERIFY(ids.contains(id2));
|
|
|
|
|
|
2018-03-28 15:40:13 +02:00
|
|
|
int got = notes.get(model.modelId(), 0);
|
2015-04-10 17:21:15 +02:00
|
|
|
QVERIFY(got == id1 || got == id2);
|
2018-03-28 15:40:13 +02:00
|
|
|
QCOMPARE(notes.get(model.modelId(), 20), -1);
|
|
|
|
|
QCOMPARE(notes.get(model.modelId() + 10, 10), -1);
|
2015-04-10 17:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tst_TimelineNotesModel::modify()
|
|
|
|
|
{
|
|
|
|
|
TestNotesModel notes;
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel model(&aggregator);
|
2015-04-10 17:21:15 +02:00
|
|
|
notes.addTimelineModel(&model);
|
|
|
|
|
QSignalSpy spy(¬es, SIGNAL(changed(int,int,int)));
|
2018-03-28 15:40:13 +02:00
|
|
|
int id = notes.add(model.modelId(), 0, QLatin1String("a"));
|
2015-04-10 17:21:15 +02:00
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
notes.update(id, QLatin1String("b"));
|
|
|
|
|
QVERIFY(notes.isModified());
|
|
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
|
QCOMPARE(notes.text(id), QLatin1String("b"));
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
notes.update(id, QLatin1String("b"));
|
|
|
|
|
QVERIFY(!notes.isModified());
|
|
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
|
QCOMPARE(notes.text(id), QLatin1String("b"));
|
|
|
|
|
|
|
|
|
|
notes.setText(id, QLatin1String("a"));
|
|
|
|
|
QVERIFY(notes.isModified());
|
|
|
|
|
QCOMPARE(spy.count(), 3);
|
|
|
|
|
QCOMPARE(notes.text(id), QLatin1String("a"));
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
|
2018-03-28 15:40:13 +02:00
|
|
|
notes.setText(model.modelId(), 0, QLatin1String("x"));
|
2015-04-10 17:21:15 +02:00
|
|
|
QVERIFY(notes.isModified());
|
|
|
|
|
QCOMPARE(spy.count(), 4);
|
|
|
|
|
QCOMPARE(notes.text(id), QLatin1String("x"));
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
|
2018-03-28 15:40:13 +02:00
|
|
|
TestModel model2(&aggregator);
|
2015-04-10 17:21:15 +02:00
|
|
|
notes.addTimelineModel(&model2);
|
2018-03-28 15:40:13 +02:00
|
|
|
notes.setText(model2.modelId(), 0, QLatin1String("hh"));
|
2015-04-10 17:21:15 +02:00
|
|
|
QVERIFY(notes.isModified());
|
|
|
|
|
QCOMPARE(spy.count(), 5);
|
|
|
|
|
QCOMPARE(notes.count(), 2);
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
|
|
|
|
|
notes.setText(id, QString());
|
|
|
|
|
QVERIFY(notes.isModified());
|
|
|
|
|
QCOMPARE(spy.count(), 6);
|
|
|
|
|
QCOMPARE(notes.count(), 1);
|
|
|
|
|
notes.resetModified();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_TimelineNotesModel)
|
|
|
|
|
|
|
|
|
|
#include "tst_timelinenotesmodel.moc"
|