forked from qt-creator/qt-creator
Timeline: Provide a method to set all timeline models at once
Setting a number of models one by one results in quadratic overhead when (re)building the UI. If there are many models this quickly gets out of hand. Change-Id: I7f017784c3f0a6a9d7e52c881eb1d8ca4cf70886 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -70,6 +70,30 @@ void TimelineModelAggregator::addModel(TimelineModel *m)
|
|||||||
emit heightChanged();
|
emit heightChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimelineModelAggregator::setModels(const QList<TimelineModel *> &models)
|
||||||
|
{
|
||||||
|
Q_D(TimelineModelAggregator);
|
||||||
|
if (d->modelList == models)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int prevHeight = height();
|
||||||
|
foreach (TimelineModel *m, d->modelList) {
|
||||||
|
disconnect(m, &TimelineModel::heightChanged, this, &TimelineModelAggregator::heightChanged);
|
||||||
|
if (d->notesModel)
|
||||||
|
d->notesModel->removeTimelineModel(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
d->modelList = models;
|
||||||
|
foreach (TimelineModel *m, models) {
|
||||||
|
connect(m, &TimelineModel::heightChanged, this, &TimelineModelAggregator::heightChanged);
|
||||||
|
if (d->notesModel)
|
||||||
|
d->notesModel->addTimelineModel(m);
|
||||||
|
}
|
||||||
|
emit modelsChanged();
|
||||||
|
if (height() != prevHeight)
|
||||||
|
emit heightChanged();
|
||||||
|
}
|
||||||
|
|
||||||
const TimelineModel *TimelineModelAggregator::model(int modelIndex) const
|
const TimelineModel *TimelineModelAggregator::model(int modelIndex) const
|
||||||
{
|
{
|
||||||
Q_D(const TimelineModelAggregator);
|
Q_D(const TimelineModelAggregator);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public:
|
|||||||
int height() const;
|
int height() const;
|
||||||
|
|
||||||
void addModel(TimelineModel *m);
|
void addModel(TimelineModel *m);
|
||||||
|
void setModels(const QList<TimelineModel *> &models);
|
||||||
const TimelineModel *model(int modelIndex) const;
|
const TimelineModel *model(int modelIndex) const;
|
||||||
QVariantList models() const;
|
QVariantList models() const;
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,9 @@ int TimelineNotesModel::count() const
|
|||||||
void TimelineNotesModel::addTimelineModel(const TimelineModel *timelineModel)
|
void TimelineNotesModel::addTimelineModel(const TimelineModel *timelineModel)
|
||||||
{
|
{
|
||||||
Q_D(TimelineNotesModel);
|
Q_D(TimelineNotesModel);
|
||||||
connect(timelineModel, SIGNAL(destroyed(QObject*)),
|
connect(timelineModel, &QObject::destroyed, this, [this](QObject *obj) {
|
||||||
this, SLOT(_q_removeTimelineModel(QObject*)));
|
removeTimelineModel(static_cast<TimelineModel *>(obj));
|
||||||
|
});
|
||||||
d->timelineModels.insert(timelineModel->modelId(), timelineModel);
|
d->timelineModels.insert(timelineModel->modelId(), timelineModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,11 +179,12 @@ void TimelineNotesModel::resetModified()
|
|||||||
d->modified = false;
|
d->modified = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineNotesModel::TimelineNotesModelPrivate::_q_removeTimelineModel(QObject *timelineModel)
|
void TimelineNotesModel::removeTimelineModel(const TimelineModel *timelineModel)
|
||||||
{
|
{
|
||||||
for (auto i = timelineModels.begin(); i != timelineModels.end();) {
|
Q_D(TimelineNotesModel);
|
||||||
|
for (auto i = d->timelineModels.begin(); i != d->timelineModels.end();) {
|
||||||
if (i.value() == timelineModel)
|
if (i.value() == timelineModel)
|
||||||
i = timelineModels.erase(i);
|
i = d->timelineModels.erase(i);
|
||||||
else
|
else
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
int count() const;
|
int count() const;
|
||||||
void addTimelineModel(const TimelineModel *timelineModel);
|
void addTimelineModel(const TimelineModel *timelineModel);
|
||||||
|
void removeTimelineModel(const TimelineModel *timelineModel);
|
||||||
QList<const TimelineModel *> timelineModels() const;
|
QList<const TimelineModel *> timelineModels() const;
|
||||||
|
|
||||||
Q_INVOKABLE int typeId(int index) const;
|
Q_INVOKABLE int typeId(int index) const;
|
||||||
@@ -73,7 +74,6 @@ private:
|
|||||||
TimelineNotesModelPrivate *d_ptr;
|
TimelineNotesModelPrivate *d_ptr;
|
||||||
|
|
||||||
Q_DECLARE_PRIVATE(TimelineNotesModel)
|
Q_DECLARE_PRIVATE(TimelineNotesModel)
|
||||||
Q_PRIVATE_SLOT(d_ptr, void _q_removeTimelineModel(QObject *timelineModel))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Timeline
|
} // namespace Timeline
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public:
|
|||||||
QHash<int, const TimelineModel *> timelineModels;
|
QHash<int, const TimelineModel *> timelineModels;
|
||||||
bool modified;
|
bool modified;
|
||||||
|
|
||||||
void _q_removeTimelineModel(QObject *model);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimelineNotesModel *q_ptr;
|
TimelineNotesModel *q_ptr;
|
||||||
Q_DECLARE_PUBLIC(TimelineNotesModel)
|
Q_DECLARE_PUBLIC(TimelineNotesModel)
|
||||||
|
|||||||
Reference in New Issue
Block a user