Merge remote-tracking branch 'origin/4.0'

Change-Id: I89c52ca2145a43c94d3366367ba72fde605dd577
This commit is contained in:
Eike Ziller
2016-05-31 12:01:58 +02:00
23 changed files with 148 additions and 95 deletions

View File

@@ -127,7 +127,8 @@ QObject *FlameGraph::appendChild(QObject *parentObject, QQuickItem *parentItem,
}
int FlameGraph::buildNode(const QModelIndex &parentIndex, QObject *parentObject, int depth)
int FlameGraph::buildNode(const QModelIndex &parentIndex, QObject *parentObject, int depth,
int maximumDepth)
{
qreal position = 0;
qreal skipped = 0;
@@ -136,18 +137,23 @@ int FlameGraph::buildNode(const QModelIndex &parentIndex, QObject *parentObject,
QQmlContext *context = qmlContext(this);
int rowCount = m_model->rowCount(parentIndex);
int childrenDepth = depth;
for (int row = 0; row < rowCount; ++row) {
QModelIndex childIndex = m_model->index(row, 0, parentIndex);
qreal size = m_model->data(childIndex, m_sizeRole).toReal();
if (size / m_model->data(QModelIndex(), m_sizeRole).toReal() < m_sizeThreshold) {
skipped += size;
continue;
}
if (depth == maximumDepth - 1) {
skipped = parentSize;
} else {
for (int row = 0; row < rowCount; ++row) {
QModelIndex childIndex = m_model->index(row, 0, parentIndex);
qreal size = m_model->data(childIndex, m_sizeRole).toReal();
if (size / m_model->data(QModelIndex(), m_sizeRole).toReal() < m_sizeThreshold) {
skipped += size;
continue;
}
QObject *childObject = appendChild(parentObject, parentItem, context, childIndex,
position / parentSize, size / parentSize);
position += size;
childrenDepth = qMax(childrenDepth, buildNode(childIndex, childObject, depth + 1));
QObject *childObject = appendChild(parentObject, parentItem, context, childIndex,
position / parentSize, size / parentSize);
position += size;
childrenDepth = qMax(childrenDepth, buildNode(childIndex, childObject, depth + 1,
maximumDepth));
}
}
if (skipped > 0) {
@@ -170,7 +176,7 @@ void FlameGraph::rebuild()
return;
}
m_depth = buildNode(QModelIndex(), this, 0);
m_depth = buildNode(QModelIndex(), this, 0, m_maximumDepth);
emit depthChanged(m_depth);
}

View File

@@ -108,6 +108,8 @@ class FlameGraph : public QQuickItem
Q_PROPERTY(int sizeRole READ sizeRole WRITE setSizeRole NOTIFY sizeRoleChanged)
Q_PROPERTY(qreal sizeThreshold READ sizeThreshold WRITE setSizeThreshold
NOTIFY sizeThresholdChanged)
Q_PROPERTY(int maximumDepth READ maximumDepth WRITE setMaximumDepth
NOTIFY maximumDepthChanged)
Q_PROPERTY(int depth READ depth NOTIFY depthChanged)
public:
@@ -127,6 +129,19 @@ public:
int depth() const;
int maximumDepth() const
{
return m_maximumDepth;
}
void setMaximumDepth(int maximumDepth)
{
if (maximumDepth != m_maximumDepth) {
m_maximumDepth = maximumDepth;
emit maximumDepthChanged();
}
}
static FlameGraphAttached *qmlAttachedProperties(QObject *object);
signals:
@@ -135,6 +150,7 @@ signals:
void sizeRoleChanged(int role);
void sizeThresholdChanged(qreal threshold);
void depthChanged(int depth);
void maximumDepthChanged();
private slots:
void rebuild();
@@ -145,8 +161,10 @@ private:
int m_sizeRole = 0;
int m_depth = 0;
qreal m_sizeThreshold = 0;
int m_maximumDepth = std::numeric_limits<int>::max();
int buildNode(const QModelIndex &parentIndex, QObject *parentObject, int depth);
int buildNode(const QModelIndex &parentIndex, QObject *parentObject, int depth,
int maximumDepth);
QObject *appendChild(QObject *parentObject, QQuickItem *parentItem, QQmlContext *context,
const QModelIndex &childIndex, qreal position, qreal size);
};

View File

@@ -61,6 +61,7 @@ ScrollView {
model: flameGraphModel
sizeRole: FlameGraphModel.DurationRole
sizeThreshold: 0.002
maximumDepth: 25
y: flickable.height > height ? flickable.height - height : 0
delegate: Item {