QmlProfiler: Centralize timeline rowCount calculation

Change-Id: I0db3641c0d6e750459d815e25909babf8534a4f6
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-09-11 10:57:34 +02:00
parent 69743fef93
commit 2e11197bca
7 changed files with 22 additions and 42 deletions

View File

@@ -45,6 +45,8 @@ AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd,
d->displayName = displayName;
d->message = message;
d->rangeType = rangeType;
d->expandedRowCount = 1;
d->collapsedRowCount = 1;
}
AbstractTimelineModel::~AbstractTimelineModel()
@@ -229,9 +231,18 @@ QString AbstractTimelineModel::displayName() const
return d->displayName;
}
int AbstractTimelineModel::rowCount() const
{
Q_D(const AbstractTimelineModel);
if (isEmpty())
return d->modelManager->isEmpty() ? 1 : 0;
return d->expanded ? d->expandedRowCount : d->collapsedRowCount;
}
void AbstractTimelineModel::clear()
{
Q_D(AbstractTimelineModel);
d->collapsedRowCount = d->expandedRowCount = 1;
bool wasExpanded = d->expanded;
bool hadRowHeights = !d->rowOffsets.empty();
d->rowOffsets.clear();

View File

@@ -65,9 +65,9 @@ public:
bool expanded() const;
void setExpanded(bool expanded);
QString displayName() const;
int rowCount() const;
// Methods that have to be implemented by child models
virtual int rowCount() const = 0;
virtual int eventId(int index) const = 0;
virtual QColor color(int index) const = 0;
virtual QVariantList labels() const = 0;

View File

@@ -40,6 +40,8 @@ public:
QmlProfilerModelManager *modelManager;
int modelId;
bool expanded;
int expandedRowCount;
int collapsedRowCount;
QString displayName;
QmlDebug::Message message;
QmlDebug::RangeType rangeType;

View File

@@ -140,21 +140,13 @@ void PaintEventsModelProxy::loadData()
}
computeNesting();
d->expandedRowCount = d->collapsedRowCount =
(d->maxGuiThreadAnimations == 0 || d->maxRenderThreadAnimations == 0) ? 2 : 3;
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
}
/////////////////// QML interface
int PaintEventsModelProxy::rowCount() const
{
Q_D(const PaintEventsModelProxy);
if (isEmpty())
return 1;
else
return (d->maxGuiThreadAnimations == 0 || d->maxRenderThreadAnimations == 0) ? 2 : 3;
}
int PaintEventsModelProxy::PaintEventsModelProxyPrivate::rowFromThreadId(
QmlDebug::AnimationThread threadId) const
{

View File

@@ -66,7 +66,6 @@ public:
int rowMaxValue(int rowNumber) const;
int rowCount() const;
int eventId(int index) const;
int row(int index) const;

View File

@@ -54,8 +54,6 @@ public:
QVector<QmlRangeEventStartInstance> data;
QVector<int> expandedRowTypes;
int contractedRows;
bool seenPaintEvent;
private:
Q_DECLARE_PUBLIC(RangeTimelineModel)
};
@@ -65,9 +63,7 @@ RangeTimelineModel::RangeTimelineModel(QmlDebug::RangeType rangeType, QObject *p
QmlDebug::MaximumMessage, rangeType, parent)
{
Q_D(RangeTimelineModel);
d->seenPaintEvent = false;
d->expandedRowTypes << -1;
d->contractedRows = 1;
}
quint64 RangeTimelineModel::features() const
@@ -81,8 +77,6 @@ void RangeTimelineModel::clear()
Q_D(RangeTimelineModel);
d->expandedRowTypes.clear();
d->expandedRowTypes << -1;
d->contractedRows = 1;
d->seenPaintEvent = false;
d->data.clear();
AbstractTimelineModel::clear();
}
@@ -102,8 +96,6 @@ void RangeTimelineModel::loadData()
const QmlProfilerDataModel::QmlEventTypeData &type = typesList[event.typeIndex];
if (!accepted(type))
continue;
if (type.rangeType == QmlDebug::Painting)
d->seenPaintEvent = true;
// store starttime-based instance
d->data.insert(insert(event.startTime, event.duration),
@@ -140,7 +132,7 @@ void RangeTimelineModel::RangeTimelineModelPrivate::computeNestingContracted()
int eventCount = q->count();
int nestingLevels = QmlDebug::Constants::QML_MIN_LEVEL;
contractedRows = nestingLevels + 1;
collapsedRowCount = nestingLevels + 1;
QVector<qint64> nestingEndTimes;
nestingEndTimes.fill(0, nestingLevels + 1);
@@ -151,8 +143,8 @@ void RangeTimelineModel::RangeTimelineModelPrivate::computeNestingContracted()
if (nestingEndTimes[nestingLevels] > st) {
if (++nestingLevels == nestingEndTimes.size())
nestingEndTimes << 0;
if (nestingLevels == contractedRows)
++contractedRows;
if (nestingLevels == collapsedRowCount)
++collapsedRowCount;
} else {
while (nestingLevels > QmlDebug::Constants::QML_MIN_LEVEL &&
nestingEndTimes[nestingLevels-1] <= st)
@@ -177,6 +169,7 @@ void RangeTimelineModel::RangeTimelineModelPrivate::computeExpandedLevels()
}
data[i].displayRowExpanded = eventRow[eventId];
}
expandedRowCount = expandedRowTypes.size();
}
void RangeTimelineModel::RangeTimelineModelPrivate::findBindingLoops()
@@ -216,18 +209,6 @@ void RangeTimelineModel::RangeTimelineModelPrivate::findBindingLoops()
/////////////////// QML interface
int RangeTimelineModel::rowCount() const
{
Q_D(const RangeTimelineModel);
// special for paint events: show only when empty model or there's actual events
if (d->rangeType == QmlDebug::Painting && !d->seenPaintEvent)
return 0;
if (d->expanded)
return d->expandedRowTypes.size();
else
return d->contractedRows;
}
QString RangeTimelineModel::categoryLabel(QmlDebug::RangeType rangeType)
{
return QCoreApplication::translate("MainView",
@@ -268,8 +249,7 @@ QVariantList RangeTimelineModel::labels() const
if (d->expanded) {
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
d->modelManager->qmlModel()->getEventTypes();
int eventCount = d->expandedRowTypes.count();
for (int i = 1; i < eventCount; i++) { // Ignore the -1 for the first row
for (int i = 1; i < d->expandedRowCount; i++) { // Ignore the -1 for the first row
QVariantMap element;
int typeId = d->expandedRowTypes[i];
element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName));
@@ -332,7 +312,7 @@ int RangeTimelineModel::eventIdForLocation(const QString &filename, int line, in
// if this is called from v8 view, we don't have the column number, it will be -1
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
d->modelManager->qmlModel()->getEventTypes();
for (int i = 1; i < d->expandedRowTypes.size(); ++i) {
for (int i = 1; i < d->expandedRowCount; ++i) {
int typeId = d->expandedRowTypes[i];
const QmlProfilerDataModel::QmlEventTypeData &eventData = types[typeId];
if (eventData.location.filename == filename &&

View File

@@ -68,10 +68,6 @@ public:
void loadData();
void clear();
// QML interface
int rowCount() const;
static QString categoryLabel(QmlDebug::RangeType categoryIndex);
quint64 features() const;