QmlProfiler: introduce properties for empty, hidden and displayName

Like this we can properly refer to them from QML.

Change-Id: I98378d543d307f78909191225e72c9d0404dfa1d
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-09-11 11:20:52 +02:00
parent 5799901bcc
commit 2b362de064
9 changed files with 78 additions and 5 deletions

View File

@@ -42,6 +42,7 @@ AbstractTimelineModel::AbstractTimelineModel(AbstractTimelineModelPrivate *dd,
d->modelId = 0; d->modelId = 0;
d->modelManager = 0; d->modelManager = 0;
d->expanded = false; d->expanded = false;
d->hidden = false;
d->displayName = displayName; d->displayName = displayName;
d->message = message; d->message = message;
d->rangeType = rangeType; d->rangeType = rangeType;
@@ -98,7 +99,7 @@ int AbstractTimelineModel::rowOffset(int rowNumber) const
void AbstractTimelineModel::setRowHeight(int rowNumber, int height) void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
{ {
Q_D(AbstractTimelineModel); Q_D(AbstractTimelineModel);
if (!expanded()) if (d->hidden || !d->expanded)
return; return;
if (height < DefaultRowHeight) if (height < DefaultRowHeight)
height = DefaultRowHeight; height = DefaultRowHeight;
@@ -120,7 +121,7 @@ int AbstractTimelineModel::height() const
{ {
Q_D(const AbstractTimelineModel); Q_D(const AbstractTimelineModel);
int depth = rowCount(); int depth = rowCount();
if (!expanded() || d->rowOffsets.empty()) if (d->hidden || !d->expanded || d->rowOffsets.empty())
return depth * DefaultRowHeight; return depth * DefaultRowHeight;
return d->rowOffsets.last() + (depth - d->rowOffsets.size()) * DefaultRowHeight; return d->rowOffsets.last() + (depth - d->rowOffsets.size()) * DefaultRowHeight;
@@ -192,6 +193,7 @@ int AbstractTimelineModel::rowMaxValue(int rowNumber) const
void AbstractTimelineModel::dataChanged() void AbstractTimelineModel::dataChanged()
{ {
Q_D(AbstractTimelineModel); Q_D(AbstractTimelineModel);
bool wasEmpty = isEmpty();
switch (d->modelManager->state()) { switch (d->modelManager->state()) {
case QmlProfilerDataState::ProcessingData: case QmlProfilerDataState::ProcessingData:
loadData(); loadData();
@@ -202,6 +204,8 @@ void AbstractTimelineModel::dataChanged()
default: default:
break; break;
} }
if (wasEmpty != isEmpty())
emit emptyChanged();
} }
bool AbstractTimelineModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const bool AbstractTimelineModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
@@ -225,6 +229,21 @@ void AbstractTimelineModel::setExpanded(bool expanded)
} }
} }
bool AbstractTimelineModel::hidden() const
{
Q_D(const AbstractTimelineModel);
return d->hidden;
}
void AbstractTimelineModel::setHidden(bool hidden)
{
Q_D(AbstractTimelineModel);
if (hidden != d->hidden) {
d->hidden = hidden;
emit hiddenChanged();
}
}
QString AbstractTimelineModel::displayName() const QString AbstractTimelineModel::displayName() const
{ {
Q_D(const AbstractTimelineModel); Q_D(const AbstractTimelineModel);
@@ -234,6 +253,8 @@ QString AbstractTimelineModel::displayName() const
int AbstractTimelineModel::rowCount() const int AbstractTimelineModel::rowCount() const
{ {
Q_D(const AbstractTimelineModel); Q_D(const AbstractTimelineModel);
if (d->hidden)
return 0;
if (isEmpty()) if (isEmpty())
return d->modelManager->isEmpty() ? 1 : 0; return d->modelManager->isEmpty() ? 1 : 0;
return d->expanded ? d->expandedRowCount : d->collapsedRowCount; return d->expanded ? d->expandedRowCount : d->collapsedRowCount;
@@ -244,14 +265,18 @@ void AbstractTimelineModel::clear()
Q_D(AbstractTimelineModel); Q_D(AbstractTimelineModel);
d->collapsedRowCount = d->expandedRowCount = 1; d->collapsedRowCount = d->expandedRowCount = 1;
bool wasExpanded = d->expanded; bool wasExpanded = d->expanded;
bool wasHidden = d->hidden;
bool hadRowHeights = !d->rowOffsets.empty(); bool hadRowHeights = !d->rowOffsets.empty();
d->rowOffsets.clear(); d->rowOffsets.clear();
d->expanded = false; d->expanded = false;
d->hidden = false;
SortedTimelineModel::clear(); SortedTimelineModel::clear();
if (hadRowHeights) if (hadRowHeights)
emit rowHeightChanged(); emit rowHeightChanged();
if (wasExpanded) if (wasExpanded)
emit expandedChanged(); emit expandedChanged();
if (wasHidden)
emit hiddenChanged();
d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1); d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1);
} }

View File

@@ -43,6 +43,9 @@ namespace QmlProfiler {
class QMLPROFILER_EXPORT AbstractTimelineModel : public SortedTimelineModel class QMLPROFILER_EXPORT AbstractTimelineModel : public SortedTimelineModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString displayName READ displayName CONSTANT)
Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
public: public:
class AbstractTimelineModelPrivate; class AbstractTimelineModelPrivate;
@@ -63,7 +66,9 @@ public:
qint64 traceDuration() const; qint64 traceDuration() const;
bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const; bool accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const;
bool expanded() const; bool expanded() const;
bool hidden() const;
void setExpanded(bool expanded); void setExpanded(bool expanded);
void setHidden(bool hidden);
QString displayName() const; QString displayName() const;
int rowCount() const; int rowCount() const;
@@ -87,7 +92,9 @@ public:
signals: signals:
void expandedChanged(); void expandedChanged();
void hiddenChanged();
void rowHeightChanged(); void rowHeightChanged();
void emptyChanged();
protected: protected:
static const int DefaultRowHeight = 30; static const int DefaultRowHeight = 30;

View File

@@ -40,6 +40,7 @@ public:
QmlProfilerModelManager *modelManager; QmlProfilerModelManager *modelManager;
int modelId; int modelId;
bool expanded; bool expanded;
bool hidden;
int expandedRowCount; int expandedRowCount;
int collapsedRowCount; int collapsedRowCount;
QString displayName; QString displayName;

View File

@@ -210,7 +210,7 @@ QVariantList PaintEventsModelProxy::labels() const
Q_D(const PaintEventsModelProxy); Q_D(const PaintEventsModelProxy);
QVariantList result; QVariantList result;
if (d->maxGuiThreadAnimations > 0) { if (!d->hidden && d->maxGuiThreadAnimations > 0) {
QVariantMap element; QVariantMap element;
element.insert(QLatin1String("displayName"), QVariant(tr("Animations"))); element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
element.insert(QLatin1String("description"), QVariant(tr("GUI Thread"))); element.insert(QLatin1String("description"), QVariant(tr("GUI Thread")));
@@ -218,7 +218,7 @@ QVariantList PaintEventsModelProxy::labels() const
result << element; result << element;
} }
if (d->maxRenderThreadAnimations > 0) { if (!d->hidden && d->maxRenderThreadAnimations > 0) {
QVariantMap element; QVariantMap element;
element.insert(QLatin1String("displayName"), QVariant(tr("Animations"))); element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
element.insert(QLatin1String("description"), QVariant(tr("Render Thread"))); element.insert(QLatin1String("description"), QVariant(tr("Render Thread")));

View File

@@ -246,7 +246,7 @@ QVariantList RangeTimelineModel::labels() const
Q_D(const RangeTimelineModel); Q_D(const RangeTimelineModel);
QVariantList result; QVariantList result;
if (d->expanded) { if (d->expanded && !d->hidden) {
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
d->modelManager->qmlModel()->getEventTypes(); d->modelManager->qmlModel()->getEventTypes();
for (int i = 1; i < d->expandedRowCount; i++) { // Ignore the -1 for the first row for (int i = 1; i < d->expandedRowCount; i++) { // Ignore the -1 for the first row

View File

@@ -91,6 +91,7 @@ void TimelineModelAggregator::addModel(AbstractTimelineModel *m)
{ {
d->modelList << m; d->modelList << m;
connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged())); connect(m,SIGNAL(expandedChanged()),this,SIGNAL(expandedChanged()));
connect(m,SIGNAL(hiddenChanged()),this,SIGNAL(hiddenChanged()));
connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged())); connect(m,SIGNAL(rowHeightChanged()),this,SIGNAL(rowHeightChanged()));
emit modelsChanged(d->modelList.length(), d->modelList.length()); emit modelsChanged(d->modelList.length(), d->modelList.length());
} }
@@ -154,6 +155,16 @@ void TimelineModelAggregator::setExpanded(int modelIndex, bool expanded)
d->modelList[modelIndex]->setExpanded(expanded); d->modelList[modelIndex]->setExpanded(expanded);
} }
bool TimelineModelAggregator::hidden(int modelIndex) const
{
return d->modelList[modelIndex]->hidden();
}
void TimelineModelAggregator::setHidden(int modelIndex, bool hidden)
{
d->modelList[modelIndex]->setHidden(hidden);
}
int TimelineModelAggregator::rowCount(int modelIndex) const int TimelineModelAggregator::rowCount(int modelIndex) const
{ {
return d->modelList[modelIndex]->rowCount(); return d->modelList[modelIndex]->rowCount();

View File

@@ -65,6 +65,10 @@ public:
Q_INVOKABLE bool expanded(int modelIndex) const; Q_INVOKABLE bool expanded(int modelIndex) const;
Q_INVOKABLE void setExpanded(int modelIndex, bool expanded); Q_INVOKABLE void setExpanded(int modelIndex, bool expanded);
Q_INVOKABLE bool hidden(int modelIndex) const;
Q_INVOKABLE void setHidden(int modelIndex, bool hidden);
Q_INVOKABLE int rowCount(int modelIndex) const; Q_INVOKABLE int rowCount(int modelIndex) const;
Q_INVOKABLE QString displayName(int modelIndex) const; Q_INVOKABLE QString displayName(int modelIndex) const;
Q_INVOKABLE int rowMinValue(int modelIndex, int row) const; Q_INVOKABLE int rowMinValue(int modelIndex, int row) const;
@@ -98,6 +102,7 @@ signals:
void dataAvailable(); void dataAvailable();
void stateChanged(); void stateChanged();
void expandedChanged(); void expandedChanged();
void hiddenChanged();
void rowHeightChanged(); void rowHeightChanged();
void modelsChanged(int modelIndex1, int modelIndex2); void modelsChanged(int modelIndex1, int modelIndex2);

View File

@@ -55,6 +55,7 @@ void TimelineRenderer::setProfilerModelProxy(QObject *profilerModelProxy)
{ {
if (m_profilerModelProxy) { if (m_profilerModelProxy) {
disconnect(m_profilerModelProxy, SIGNAL(expandedChanged()), this, SLOT(requestPaint())); disconnect(m_profilerModelProxy, SIGNAL(expandedChanged()), this, SLOT(requestPaint()));
disconnect(m_profilerModelProxy, SIGNAL(hiddenChanged()), this, SLOT(requestPaint()));
disconnect(m_profilerModelProxy, SIGNAL(rowHeightChanged()), this, SLOT(requestPaint())); disconnect(m_profilerModelProxy, SIGNAL(rowHeightChanged()), this, SLOT(requestPaint()));
disconnect(m_profilerModelProxy, SIGNAL(modelsChanged(int,int)), disconnect(m_profilerModelProxy, SIGNAL(modelsChanged(int,int)),
this, SLOT(swapSelections(int,int))); this, SLOT(swapSelections(int,int)));
@@ -63,6 +64,7 @@ void TimelineRenderer::setProfilerModelProxy(QObject *profilerModelProxy)
if (m_profilerModelProxy) { if (m_profilerModelProxy) {
connect(m_profilerModelProxy, SIGNAL(expandedChanged()), this, SLOT(requestPaint())); connect(m_profilerModelProxy, SIGNAL(expandedChanged()), this, SLOT(requestPaint()));
connect(m_profilerModelProxy, SIGNAL(hiddenChanged()), this, SLOT(requestPaint()));
connect(m_profilerModelProxy, SIGNAL(rowHeightChanged()), this, SLOT(requestPaint())); connect(m_profilerModelProxy, SIGNAL(rowHeightChanged()), this, SLOT(requestPaint()));
connect(m_profilerModelProxy, SIGNAL(modelsChanged(int,int)), connect(m_profilerModelProxy, SIGNAL(modelsChanged(int,int)),
this, SLOT(swapSelections(int,int))); this, SLOT(swapSelections(int,int)));
@@ -141,6 +143,8 @@ void TimelineRenderer::paint(QPainter *p)
p->setPen(Qt::transparent); p->setPen(Qt::transparent);
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) { for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
if (m_profilerModelProxy->hidden(modelIndex))
continue;
int lastIndex = m_profilerModelProxy->lastIndex(modelIndex, m_endTime); int lastIndex = m_profilerModelProxy->lastIndex(modelIndex, m_endTime);
if (lastIndex >= 0 && lastIndex < m_profilerModelProxy->count(modelIndex)) { if (lastIndex >= 0 && lastIndex < m_profilerModelProxy->count(modelIndex)) {
int firstIndex = m_profilerModelProxy->firstIndex(modelIndex, m_startTime); int firstIndex = m_profilerModelProxy->firstIndex(modelIndex, m_startTime);

View File

@@ -91,6 +91,7 @@ private slots:
void traceTime(); void traceTime();
void accepted(); void accepted();
void expand(); void expand();
void hide();
void displayName(); void displayName();
void defaultValues(); void defaultValues();
void colorByHue(); void colorByHue();
@@ -265,6 +266,25 @@ void tst_AbstractTimelineModel::expand()
QCOMPARE(spy.count(), 2); QCOMPARE(spy.count(), 2);
} }
void tst_AbstractTimelineModel::hide()
{
DummyModel dummy;
QSignalSpy spy(&dummy, SIGNAL(hiddenChanged()));
QVERIFY(!dummy.hidden());
dummy.setHidden(true);
QVERIFY(dummy.hidden());
QCOMPARE(spy.count(), 1);
dummy.setHidden(true);
QVERIFY(dummy.hidden());
QCOMPARE(spy.count(), 1);
dummy.setHidden(false);
QVERIFY(!dummy.hidden());
QCOMPARE(spy.count(), 2);
dummy.setHidden(false);
QVERIFY(!dummy.hidden());
QCOMPARE(spy.count(), 2);
}
void tst_AbstractTimelineModel::displayName() void tst_AbstractTimelineModel::displayName()
{ {
QLatin1String name("testest"); QLatin1String name("testest");