forked from qt-creator/qt-creator
QmlProfiler: Separate expanded and collapsed row heights and counts
We'll need to access both of them when building the scene graph. This change also clarifies the dynamics between expanding categories and row heights and offsets. Change-Id: I2e2bf488ad973c95d05f230bf6fff63598f39bf2 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
@@ -174,7 +174,7 @@ Item {
|
||||
|
||||
onMouseYChanged: {
|
||||
if (resizing) {
|
||||
column.parentModel.setRowHeight(index + 1, y + mouseY);
|
||||
column.parentModel.setExpandedRowHeight(index + 1, y + mouseY);
|
||||
parent.height = column.parentModel.rowHeight(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ Item {
|
||||
|
||||
Connections {
|
||||
target: model
|
||||
onRowHeightChanged: {
|
||||
if (row >= 0)
|
||||
onExpandedRowHeightChanged: {
|
||||
if (model && model.expanded && row >= 0)
|
||||
rowRepeater.itemAt(row).height = height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,11 +135,6 @@ int QmlProfilerAnimationsModel::rowFromThreadId(int threadId) const
|
||||
return (threadId == QmlDebug::GuiThread || m_maxGuiThreadAnimations == 0) ? 1 : 2;
|
||||
}
|
||||
|
||||
int QmlProfilerAnimationsModel::row(int index) const
|
||||
{
|
||||
return rowFromThreadId(selectionId(index));
|
||||
}
|
||||
|
||||
int QmlProfilerAnimationsModel::rowMaxValue(int rowNumber) const
|
||||
{
|
||||
switch (rowNumber) {
|
||||
@@ -157,6 +152,16 @@ int QmlProfilerAnimationsModel::typeId(int index) const
|
||||
return m_data[index].typeId;
|
||||
}
|
||||
|
||||
int QmlProfilerAnimationsModel::expandedRow(int index) const
|
||||
{
|
||||
return rowFromThreadId(selectionId(index));
|
||||
}
|
||||
|
||||
int QmlProfilerAnimationsModel::collapsedRow(int index) const
|
||||
{
|
||||
return rowFromThreadId(selectionId(index));
|
||||
}
|
||||
|
||||
QColor QmlProfilerAnimationsModel::color(int index) const
|
||||
{
|
||||
double fpsFraction = m_data[index].framerate / 60.0;
|
||||
|
||||
@@ -65,7 +65,8 @@ public:
|
||||
int rowMaxValue(int rowNumber) const;
|
||||
|
||||
int typeId(int index) const;
|
||||
int row(int index) const;
|
||||
Q_INVOKABLE int expandedRow(int index) const;
|
||||
Q_INVOKABLE int collapsedRow(int index) const;
|
||||
|
||||
QColor color(int index) const;
|
||||
float relativeHeight(int index) const;
|
||||
|
||||
@@ -188,11 +188,13 @@ QString QmlProfilerRangeModel::categoryLabel(QmlDebug::RangeType rangeType)
|
||||
QmlProfilerModelManager::featureName(QmlDebug::featureFromRangeType(rangeType)));
|
||||
}
|
||||
|
||||
int QmlProfilerRangeModel::row(int index) const
|
||||
int QmlProfilerRangeModel::expandedRow(int index) const
|
||||
{
|
||||
if (expanded())
|
||||
return m_data[index].displayRowExpanded;
|
||||
else
|
||||
}
|
||||
|
||||
int QmlProfilerRangeModel::collapsedRow(int index) const
|
||||
{
|
||||
return m_data[index].displayRowCollapsed;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ public:
|
||||
|
||||
static QString categoryLabel(QmlDebug::RangeType categoryIndex);
|
||||
|
||||
int row(int index) const;
|
||||
Q_INVOKABLE int expandedRow(int index) const;
|
||||
Q_INVOKABLE int collapsedRow(int index) const;
|
||||
int bindingLoopDest(int index) const;
|
||||
QColor color(int index) const;
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ void TimelineModel::setCollapsedRowCount(int rows)
|
||||
Q_D(TimelineModel);
|
||||
if (d->collapsedRowCount != rows) {
|
||||
d->collapsedRowCount = rows;
|
||||
emit collapsedRowCountChanged();
|
||||
if (!d->expanded)
|
||||
emit rowCountChanged();
|
||||
}
|
||||
@@ -120,16 +121,21 @@ int TimelineModel::expandedRowCount() const
|
||||
return d->expandedRowCount;
|
||||
}
|
||||
|
||||
void QmlProfiler::TimelineModel::setExpandedRowCount(int rows)
|
||||
void TimelineModel::setExpandedRowCount(int rows)
|
||||
{
|
||||
Q_D(TimelineModel);
|
||||
if (d->expandedRowCount != rows) {
|
||||
d->expandedRowCount = rows;
|
||||
emit expandedRowCountChanged();
|
||||
if (d->expanded)
|
||||
emit rowCountChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int TimelineModel::row(int index) const
|
||||
{
|
||||
return expanded() ? expandedRow(index) : collapsedRow(index);
|
||||
}
|
||||
|
||||
TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId, const QString &displayName) :
|
||||
modelId(modelId), displayName(displayName), expanded(false), hidden(false),
|
||||
@@ -140,7 +146,6 @@ TimelineModel::TimelineModelPrivate::TimelineModelPrivate(int modelId, const QSt
|
||||
void TimelineModel::TimelineModelPrivate::init(TimelineModel *q)
|
||||
{
|
||||
q_ptr = q;
|
||||
connect(q,SIGNAL(rowHeightChanged(int,int)),q,SIGNAL(heightChanged()));
|
||||
connect(q,SIGNAL(expandedChanged()),q,SIGNAL(heightChanged()));
|
||||
connect(q,SIGNAL(hiddenChanged()),q,SIGNAL(heightChanged()));
|
||||
connect(q,SIGNAL(emptyChanged()),q,SIGNAL(heightChanged()));
|
||||
@@ -176,24 +181,30 @@ int TimelineModel::modelId() const
|
||||
return d->modelId;
|
||||
}
|
||||
|
||||
int TimelineModel::rowHeight(int rowNumber) const
|
||||
int TimelineModel::collapsedRowHeight(int rowNumber) const
|
||||
{
|
||||
Q_UNUSED(rowNumber);
|
||||
return TimelineModelPrivate::DefaultRowHeight;
|
||||
}
|
||||
|
||||
int TimelineModel::collapsedRowOffset(int rowNumber) const
|
||||
{
|
||||
return rowNumber * TimelineModelPrivate::DefaultRowHeight;
|
||||
}
|
||||
|
||||
int TimelineModel::expandedRowHeight(int rowNumber) const
|
||||
{
|
||||
Q_D(const TimelineModel);
|
||||
if (!expanded())
|
||||
return TimelineModelPrivate::DefaultRowHeight;
|
||||
|
||||
if (d->rowOffsets.size() > rowNumber)
|
||||
return d->rowOffsets[rowNumber] - (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
|
||||
return TimelineModelPrivate::DefaultRowHeight;
|
||||
}
|
||||
|
||||
int TimelineModel::rowOffset(int rowNumber) const
|
||||
int TimelineModel::expandedRowOffset(int rowNumber) const
|
||||
{
|
||||
Q_D(const TimelineModel);
|
||||
if (rowNumber == 0)
|
||||
return 0;
|
||||
if (!expanded())
|
||||
return TimelineModelPrivate::DefaultRowHeight * rowNumber;
|
||||
|
||||
if (d->rowOffsets.size() >= rowNumber)
|
||||
return d->rowOffsets[rowNumber - 1];
|
||||
@@ -203,11 +214,9 @@ int TimelineModel::rowOffset(int rowNumber) const
|
||||
return rowNumber * TimelineModelPrivate::DefaultRowHeight;
|
||||
}
|
||||
|
||||
void TimelineModel::setRowHeight(int rowNumber, int height)
|
||||
void TimelineModel::setExpandedRowHeight(int rowNumber, int height)
|
||||
{
|
||||
Q_D(TimelineModel);
|
||||
if (d->hidden || !d->expanded)
|
||||
return;
|
||||
if (height < TimelineModelPrivate::DefaultRowHeight)
|
||||
height = TimelineModelPrivate::DefaultRowHeight;
|
||||
|
||||
@@ -220,20 +229,34 @@ void TimelineModel::setRowHeight(int rowNumber, int height)
|
||||
for (int offsetRow = rowNumber; offsetRow < d->rowOffsets.size(); ++offsetRow) {
|
||||
d->rowOffsets[offsetRow] += difference;
|
||||
}
|
||||
emit rowHeightChanged(rowNumber, height);
|
||||
emit expandedRowHeightChanged(rowNumber, height);
|
||||
if (d->expanded)
|
||||
emit heightChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int TimelineModel::rowOffset(int rowNumber) const
|
||||
{
|
||||
return expanded() ? expandedRowOffset(rowNumber) : collapsedRowOffset(rowNumber);
|
||||
}
|
||||
|
||||
int TimelineModel::rowHeight(int rowNumber) const
|
||||
{
|
||||
return expanded() ? expandedRowHeight(rowNumber) : collapsedRowHeight(rowNumber);
|
||||
}
|
||||
|
||||
int TimelineModel::height() const
|
||||
{
|
||||
Q_D(const TimelineModel);
|
||||
if (d->hidden || isEmpty())
|
||||
return 0;
|
||||
|
||||
if (!d->expanded || d->rowOffsets.empty())
|
||||
return rowCount() * TimelineModelPrivate::DefaultRowHeight;
|
||||
if (!d->expanded)
|
||||
return collapsedRowCount() * TimelineModelPrivate::DefaultRowHeight;
|
||||
if (d->rowOffsets.empty())
|
||||
return expandedRowCount() * TimelineModelPrivate::DefaultRowHeight;
|
||||
|
||||
return d->rowOffsets.last() + (rowCount() - d->rowOffsets.size()) *
|
||||
return d->rowOffsets.last() + (expandedRowCount() - d->rowOffsets.size()) *
|
||||
TimelineModelPrivate::DefaultRowHeight;
|
||||
}
|
||||
|
||||
@@ -499,25 +522,17 @@ int TimelineModel::selectionId(int index) const
|
||||
void TimelineModel::clear()
|
||||
{
|
||||
Q_D(TimelineModel);
|
||||
bool hadRows = (rowCount() != 1);
|
||||
bool wasExpanded = d->expanded;
|
||||
bool wasHidden = d->hidden;
|
||||
bool hadRowHeights = !d->rowOffsets.empty();
|
||||
bool wasEmpty = isEmpty();
|
||||
d->collapsedRowCount = d->expandedRowCount = 1;
|
||||
setExpandedRowCount(1);
|
||||
setCollapsedRowCount(1);
|
||||
setExpanded(false);
|
||||
setHidden(false);
|
||||
d->rowOffsets.clear();
|
||||
d->expanded = false;
|
||||
d->hidden = false;
|
||||
d->ranges.clear();
|
||||
d->endTimes.clear();
|
||||
if (hadRowHeights)
|
||||
emit rowHeightChanged(-1, -1);
|
||||
if (wasExpanded)
|
||||
emit expandedChanged();
|
||||
if (wasHidden)
|
||||
emit hiddenChanged();
|
||||
if (hadRows)
|
||||
emit rowCountChanged();
|
||||
emit expandedRowHeightChanged(-1, -1);
|
||||
if (!wasEmpty)
|
||||
emit emptyChanged();
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ class QMLPROFILER_EXPORT TimelineModel : public QObject
|
||||
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
|
||||
Q_PROPERTY(bool expanded READ expanded WRITE setExpanded NOTIFY expandedChanged)
|
||||
Q_PROPERTY(int height READ height NOTIFY heightChanged)
|
||||
Q_PROPERTY(int expandedRowCount READ expandedRowCount NOTIFY expandedRowCountChanged)
|
||||
Q_PROPERTY(int collapsedRowCount READ collapsedRowCount NOTIFY collapsedRowCountChanged)
|
||||
Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
|
||||
Q_PROPERTY(QVariantList labels READ labels NOTIFY labelsChanged)
|
||||
Q_PROPERTY(int count READ count NOTIFY emptyChanged)
|
||||
@@ -63,9 +65,16 @@ public:
|
||||
// Methods implemented by the abstract model itself
|
||||
bool isEmpty() const;
|
||||
int modelId() const;
|
||||
|
||||
Q_INVOKABLE int collapsedRowHeight(int rowNumber) const;
|
||||
Q_INVOKABLE int expandedRowHeight(int rowNumber) const;
|
||||
Q_INVOKABLE int rowHeight(int rowNumber) const;
|
||||
Q_INVOKABLE void setExpandedRowHeight(int rowNumber, int height);
|
||||
|
||||
Q_INVOKABLE int collapsedRowOffset(int rowNumber) const;
|
||||
Q_INVOKABLE int expandedRowOffset(int rowNumber) const;
|
||||
Q_INVOKABLE int rowOffset(int rowNumber) const;
|
||||
Q_INVOKABLE void setRowHeight(int rowNumber, int height);
|
||||
|
||||
int height() const;
|
||||
int count() const;
|
||||
Q_INVOKABLE qint64 duration(int index) const;
|
||||
@@ -81,13 +90,17 @@ public:
|
||||
void setExpanded(bool expanded);
|
||||
void setHidden(bool hidden);
|
||||
QString displayName() const;
|
||||
int expandedRowCount() const;
|
||||
int collapsedRowCount() const;
|
||||
int rowCount() const;
|
||||
|
||||
// Methods that have to be implemented by child models
|
||||
Q_INVOKABLE virtual QColor color(int index) const = 0;
|
||||
virtual QVariantList labels() const = 0;
|
||||
Q_INVOKABLE virtual QVariantMap details(int index) const = 0;
|
||||
Q_INVOKABLE virtual int row(int index) const = 0;
|
||||
Q_INVOKABLE virtual int expandedRow(int index) const = 0;
|
||||
Q_INVOKABLE virtual int collapsedRow(int index) const = 0;
|
||||
Q_INVOKABLE int row(int index) const;
|
||||
|
||||
// Methods which can optionally be implemented by child models.
|
||||
// returned map should contain "file", "line", "column" properties, or be empty
|
||||
@@ -110,9 +123,11 @@ public:
|
||||
signals:
|
||||
void expandedChanged();
|
||||
void hiddenChanged();
|
||||
void rowHeightChanged(int row, int height);
|
||||
void expandedRowHeightChanged(int row, int height);
|
||||
void emptyChanged();
|
||||
void heightChanged();
|
||||
void expandedRowCountChanged();
|
||||
void collapsedRowCountChanged();
|
||||
void rowCountChanged();
|
||||
void labelsChanged();
|
||||
|
||||
@@ -126,10 +141,7 @@ protected:
|
||||
void insertEnd(int index, qint64 duration);
|
||||
void computeNesting();
|
||||
|
||||
int collapsedRowCount() const;
|
||||
void setCollapsedRowCount(int rows);
|
||||
|
||||
int expandedRowCount() const;
|
||||
void setExpandedRowCount(int rows);
|
||||
|
||||
virtual void clear();
|
||||
|
||||
@@ -66,14 +66,14 @@ void TimelineRenderer::setModel(QmlProfilerTimelineModel *model)
|
||||
if (m_model) {
|
||||
disconnect(m_model, SIGNAL(expandedChanged()), this, SLOT(requestPaint()));
|
||||
disconnect(m_model, SIGNAL(hiddenChanged()), this, SLOT(requestPaint()));
|
||||
disconnect(m_model, SIGNAL(rowHeightChanged(int,int)), this, SLOT(requestPaint()));
|
||||
disconnect(m_model, SIGNAL(expandedRowHeightChanged(int,int)), this, SLOT(requestPaint()));
|
||||
}
|
||||
|
||||
m_model = model;
|
||||
if (m_model) {
|
||||
connect(m_model, SIGNAL(expandedChanged()), this, SLOT(requestPaint()));
|
||||
connect(m_model, SIGNAL(hiddenChanged()), this, SLOT(requestPaint()));
|
||||
connect(m_model, SIGNAL(rowHeightChanged(int,int)), this, SLOT(requestPaint()));
|
||||
connect(m_model, SIGNAL(expandedRowHeightChanged(int,int)), this, SLOT(requestPaint()));
|
||||
}
|
||||
|
||||
emit modelChanged(m_model);
|
||||
|
||||
@@ -49,7 +49,8 @@ public:
|
||||
QColor color(int) const { return QColor(); }
|
||||
QVariantList labels() const { return QVariantList(); }
|
||||
QVariantMap details(int) const { return QVariantMap(); }
|
||||
int row(int) const { return 1; }
|
||||
int expandedRow(int) const { return 1; }
|
||||
int collapsedRow(int) const { return 1; }
|
||||
quint64 features() const { return 0; }
|
||||
|
||||
protected:
|
||||
@@ -102,22 +103,21 @@ void tst_TimelineModel::rowHeight()
|
||||
DummyModel dummy;
|
||||
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
|
||||
|
||||
// Cannot set while not expanded
|
||||
dummy.setRowHeight(0, 100);
|
||||
dummy.setExpandedRowHeight(0, 100);
|
||||
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
|
||||
|
||||
dummy.setExpanded(true);
|
||||
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
|
||||
QCOMPARE(dummy.rowHeight(0), 100);
|
||||
|
||||
// Cannot set smaller than default
|
||||
dummy.setRowHeight(0, DefaultRowHeight - 1);
|
||||
dummy.setExpandedRowHeight(0, DefaultRowHeight - 1);
|
||||
QCOMPARE(dummy.rowHeight(0), DefaultRowHeight);
|
||||
|
||||
dummy.setRowHeight(0, 100);
|
||||
dummy.setExpandedRowHeight(0, 100);
|
||||
QCOMPARE(dummy.rowHeight(0), 100);
|
||||
|
||||
dummy.loadData();
|
||||
dummy.setRowHeight(1, 50);
|
||||
dummy.setExpandedRowHeight(1, 50);
|
||||
QCOMPARE(dummy.rowHeight(0), 100);
|
||||
QCOMPARE(dummy.rowHeight(1), 50);
|
||||
|
||||
@@ -142,11 +142,11 @@ void tst_TimelineModel::rowOffset()
|
||||
QCOMPARE(dummy.rowOffset(0), 0);
|
||||
QCOMPARE(dummy.rowOffset(1), DefaultRowHeight);
|
||||
|
||||
dummy.setRowHeight(0, 100);
|
||||
dummy.setExpandedRowHeight(0, 100);
|
||||
QCOMPARE(dummy.rowOffset(0), 0);
|
||||
QCOMPARE(dummy.rowOffset(1), 100);
|
||||
|
||||
dummy.setRowHeight(1, 50);
|
||||
dummy.setExpandedRowHeight(1, 50);
|
||||
QCOMPARE(dummy.rowOffset(0), 0);
|
||||
QCOMPARE(dummy.rowOffset(1), 100);
|
||||
|
||||
@@ -169,7 +169,7 @@ void tst_TimelineModel::height()
|
||||
QCOMPARE(dummy.height(), 2 * DefaultRowHeight);
|
||||
dummy.setExpanded(true);
|
||||
QCOMPARE(dummy.height(), 2 * DefaultRowHeight);
|
||||
dummy.setRowHeight(0, 80);
|
||||
dummy.setExpandedRowHeight(0, 80);
|
||||
QCOMPARE(dummy.height(), DefaultRowHeight + 80);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user