forked from qt-creator/qt-creator
QmlProfiler: Sanitize AbstractTimelineModel public interface
Remove things we don't need and add some more methods to allow specialized models to operate without access to private class. Change-Id: I1f42c4299825f581361a79dd0a0e00c1c08b79e7 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
@@ -115,6 +115,30 @@ void AbstractTimelineModel::computeNesting()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AbstractTimelineModel::collapsedRowCount() const
|
||||||
|
{
|
||||||
|
Q_D(const AbstractTimelineModel);
|
||||||
|
return d->collapsedRowCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractTimelineModel::setCollapsedRowCount(int rows)
|
||||||
|
{
|
||||||
|
Q_D(AbstractTimelineModel);
|
||||||
|
d->collapsedRowCount = rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AbstractTimelineModel::expandedRowCount() const
|
||||||
|
{
|
||||||
|
Q_D(const AbstractTimelineModel);
|
||||||
|
return d->expandedRowCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QmlProfiler::AbstractTimelineModel::setExpandedRowCount(int rows)
|
||||||
|
{
|
||||||
|
Q_D(AbstractTimelineModel);
|
||||||
|
d->expandedRowCount = rows;
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractTimelineModel::AbstractTimelineModelPrivate::init(AbstractTimelineModel *q,
|
void AbstractTimelineModel::AbstractTimelineModelPrivate::init(AbstractTimelineModel *q,
|
||||||
const QString &newDisplayName,
|
const QString &newDisplayName,
|
||||||
QmlDebug::Message newMessage,
|
QmlDebug::Message newMessage,
|
||||||
@@ -160,10 +184,26 @@ AbstractTimelineModel::~AbstractTimelineModel()
|
|||||||
void AbstractTimelineModel::setModelManager(QmlProfilerModelManager *modelManager)
|
void AbstractTimelineModel::setModelManager(QmlProfilerModelManager *modelManager)
|
||||||
{
|
{
|
||||||
Q_D(AbstractTimelineModel);
|
Q_D(AbstractTimelineModel);
|
||||||
d->modelManager = modelManager;
|
if (modelManager != d->modelManager) {
|
||||||
connect(d->modelManager->qmlModel(),SIGNAL(changed()),this,SLOT(dataChanged()));
|
if (d->modelManager != 0) {
|
||||||
d->modelId = d->modelManager->registerModelProxy();
|
disconnect(d->modelManager->qmlModel(), SIGNAL(changed()),
|
||||||
d->modelManager->announceFeatures(d->modelId, features());
|
this, SLOT(_q_dataChanged()));
|
||||||
|
// completely unregistering is not supported
|
||||||
|
d->modelManager->setProxyCountWeight(d->modelId, 0);
|
||||||
|
}
|
||||||
|
d->modelManager = modelManager;
|
||||||
|
connect(d->modelManager->qmlModel(), SIGNAL(changed()),
|
||||||
|
this, SLOT(_q_dataChanged()));
|
||||||
|
d->modelId = d->modelManager->registerModelProxy();
|
||||||
|
d->modelManager->announceFeatures(d->modelId, features());
|
||||||
|
emit modelManagerChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QmlProfilerModelManager *AbstractTimelineModel::modelManager() const
|
||||||
|
{
|
||||||
|
Q_D(const AbstractTimelineModel);
|
||||||
|
return d->modelManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractTimelineModel::isEmpty() const
|
bool AbstractTimelineModel::isEmpty() const
|
||||||
@@ -181,11 +221,11 @@ int AbstractTimelineModel::rowHeight(int rowNumber) const
|
|||||||
{
|
{
|
||||||
Q_D(const AbstractTimelineModel);
|
Q_D(const AbstractTimelineModel);
|
||||||
if (!expanded())
|
if (!expanded())
|
||||||
return DefaultRowHeight;
|
return AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
|
|
||||||
if (d->rowOffsets.size() > rowNumber)
|
if (d->rowOffsets.size() > rowNumber)
|
||||||
return d->rowOffsets[rowNumber] - (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
|
return d->rowOffsets[rowNumber] - (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
|
||||||
return DefaultRowHeight;
|
return AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AbstractTimelineModel::rowOffset(int rowNumber) const
|
int AbstractTimelineModel::rowOffset(int rowNumber) const
|
||||||
@@ -194,13 +234,14 @@ int AbstractTimelineModel::rowOffset(int rowNumber) const
|
|||||||
if (rowNumber == 0)
|
if (rowNumber == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (!expanded())
|
if (!expanded())
|
||||||
return DefaultRowHeight * rowNumber;
|
return AbstractTimelineModelPrivate::DefaultRowHeight * rowNumber;
|
||||||
|
|
||||||
if (d->rowOffsets.size() >= rowNumber)
|
if (d->rowOffsets.size() >= rowNumber)
|
||||||
return d->rowOffsets[rowNumber - 1];
|
return d->rowOffsets[rowNumber - 1];
|
||||||
if (!d->rowOffsets.empty())
|
if (!d->rowOffsets.empty())
|
||||||
return d->rowOffsets.last() + (rowNumber - d->rowOffsets.size()) * DefaultRowHeight;
|
return d->rowOffsets.last() + (rowNumber - d->rowOffsets.size()) *
|
||||||
return rowNumber * DefaultRowHeight;
|
AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
|
return rowNumber * AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
|
void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
|
||||||
@@ -208,12 +249,12 @@ void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
|
|||||||
Q_D(AbstractTimelineModel);
|
Q_D(AbstractTimelineModel);
|
||||||
if (d->hidden || !d->expanded)
|
if (d->hidden || !d->expanded)
|
||||||
return;
|
return;
|
||||||
if (height < DefaultRowHeight)
|
if (height < AbstractTimelineModelPrivate::DefaultRowHeight)
|
||||||
height = DefaultRowHeight;
|
height = AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
|
|
||||||
int nextOffset = d->rowOffsets.empty() ? 0 : d->rowOffsets.last();
|
int nextOffset = d->rowOffsets.empty() ? 0 : d->rowOffsets.last();
|
||||||
while (d->rowOffsets.size() <= rowNumber)
|
while (d->rowOffsets.size() <= rowNumber)
|
||||||
d->rowOffsets << (nextOffset += DefaultRowHeight);
|
d->rowOffsets << (nextOffset += AbstractTimelineModelPrivate::DefaultRowHeight);
|
||||||
int difference = height - d->rowOffsets[rowNumber] +
|
int difference = height - d->rowOffsets[rowNumber] +
|
||||||
(rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
|
(rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
|
||||||
if (difference != 0) {
|
if (difference != 0) {
|
||||||
@@ -229,9 +270,10 @@ int AbstractTimelineModel::height() const
|
|||||||
Q_D(const AbstractTimelineModel);
|
Q_D(const AbstractTimelineModel);
|
||||||
int depth = rowCount();
|
int depth = rowCount();
|
||||||
if (d->hidden || !d->expanded || d->rowOffsets.empty())
|
if (d->hidden || !d->expanded || d->rowOffsets.empty())
|
||||||
return depth * DefaultRowHeight;
|
return depth * AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
|
|
||||||
return d->rowOffsets.last() + (depth - d->rowOffsets.size()) * DefaultRowHeight;
|
return d->rowOffsets.last() + (depth - d->rowOffsets.size()) *
|
||||||
|
AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -370,6 +412,46 @@ int AbstractTimelineModel::rowMaxValue(int rowNumber) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AbstractTimelineModel::defaultRowHeight()
|
||||||
|
{
|
||||||
|
return AbstractTimelineModelPrivate::DefaultRowHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
QmlDebug::RangeType AbstractTimelineModel::rangeType() const
|
||||||
|
{
|
||||||
|
Q_D(const AbstractTimelineModel);
|
||||||
|
return d->rangeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QmlDebug::Message AbstractTimelineModel::message() const
|
||||||
|
{
|
||||||
|
Q_D(const AbstractTimelineModel);
|
||||||
|
return d->message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractTimelineModel::updateProgress(qint64 count, qint64 max) const
|
||||||
|
{
|
||||||
|
Q_D(const AbstractTimelineModel);
|
||||||
|
d->modelManager->modelProxyCountUpdated(d->modelId, count, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor AbstractTimelineModel::colorBySelectionId(int index) const
|
||||||
|
{
|
||||||
|
return colorByHue(selectionId(index) * AbstractTimelineModelPrivate::SelectionIdHueMultiplier);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor AbstractTimelineModel::colorByFraction(double fraction) const
|
||||||
|
{
|
||||||
|
return colorByHue(fraction * AbstractTimelineModelPrivate::FractionHueMultiplier +
|
||||||
|
AbstractTimelineModelPrivate::FractionHueMininimum);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor AbstractTimelineModel::colorByHue(int hue) const
|
||||||
|
{
|
||||||
|
return QColor::fromHsl(hue % 360, AbstractTimelineModelPrivate::Saturation,
|
||||||
|
AbstractTimelineModelPrivate::Lightness);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn int AbstractTimelineModel::insert(qint64 startTime, qint64 duration)
|
\fn int AbstractTimelineModel::insert(qint64 startTime, qint64 duration)
|
||||||
Inserts a range at the given time position and returns its index.
|
Inserts a range at the given time position and returns its index.
|
||||||
@@ -415,22 +497,22 @@ void AbstractTimelineModel::insertEnd(int index, qint64 duration)
|
|||||||
d->ranges[index].start + duration));
|
d->ranges[index].start + duration));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTimelineModel::dataChanged()
|
void AbstractTimelineModel::AbstractTimelineModelPrivate::_q_dataChanged()
|
||||||
{
|
{
|
||||||
Q_D(AbstractTimelineModel);
|
Q_Q(AbstractTimelineModel);
|
||||||
bool wasEmpty = isEmpty();
|
bool wasEmpty = q->isEmpty();
|
||||||
switch (d->modelManager->state()) {
|
switch (modelManager->state()) {
|
||||||
case QmlProfilerDataState::ProcessingData:
|
case QmlProfilerDataState::ProcessingData:
|
||||||
loadData();
|
q->loadData();
|
||||||
break;
|
break;
|
||||||
case QmlProfilerDataState::ClearingData:
|
case QmlProfilerDataState::ClearingData:
|
||||||
clear();
|
q->clear();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (wasEmpty != isEmpty())
|
if (wasEmpty != q->isEmpty())
|
||||||
emit emptyChanged();
|
emit q->emptyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractTimelineModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
|
bool AbstractTimelineModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
|
||||||
@@ -509,7 +591,9 @@ void AbstractTimelineModel::clear()
|
|||||||
emit expandedChanged();
|
emit expandedChanged();
|
||||||
if (wasHidden)
|
if (wasHidden)
|
||||||
emit hiddenChanged();
|
emit hiddenChanged();
|
||||||
d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1);
|
updateProgress(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "moc_abstracttimelinemodel.cpp"
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ class QMLPROFILER_EXPORT AbstractTimelineModel : public QObject
|
|||||||
Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
|
Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged)
|
||||||
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
|
Q_PROPERTY(bool hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
|
||||||
Q_PROPERTY(int height READ height NOTIFY heightChanged)
|
Q_PROPERTY(int height READ height NOTIFY heightChanged)
|
||||||
|
Q_PROPERTY(QmlProfilerModelManager *modelManager READ modelManager WRITE setModelManager
|
||||||
|
NOTIFY modelManagerChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class AbstractTimelineModelPrivate;
|
class AbstractTimelineModelPrivate;
|
||||||
@@ -57,6 +59,8 @@ public:
|
|||||||
|
|
||||||
// Trivial methods implemented by the abstract model itself
|
// Trivial methods implemented by the abstract model itself
|
||||||
void setModelManager(QmlProfilerModelManager *modelManager);
|
void setModelManager(QmlProfilerModelManager *modelManager);
|
||||||
|
QmlProfilerModelManager *modelManager() const;
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
int modelId() const;
|
int modelId() const;
|
||||||
|
|
||||||
@@ -101,44 +105,37 @@ public:
|
|||||||
virtual int rowMinValue(int rowNumber) const;
|
virtual int rowMinValue(int rowNumber) const;
|
||||||
virtual int rowMaxValue(int rowNumber) const;
|
virtual int rowMaxValue(int rowNumber) const;
|
||||||
|
|
||||||
|
static int defaultRowHeight();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void expandedChanged();
|
void expandedChanged();
|
||||||
void hiddenChanged();
|
void hiddenChanged();
|
||||||
void rowHeightChanged();
|
void rowHeightChanged();
|
||||||
void emptyChanged();
|
void emptyChanged();
|
||||||
void heightChanged();
|
void heightChanged();
|
||||||
|
void modelManagerChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const int DefaultRowHeight = 30;
|
QColor colorBySelectionId(int index) const;
|
||||||
|
QColor colorByFraction(double fraction) const;
|
||||||
enum BoxColorProperties {
|
QColor colorByHue(int hue) const;
|
||||||
SelectionIdHueMultiplier = 25,
|
|
||||||
FractionHueMultiplier = 96,
|
|
||||||
FractionHueMininimum = 10,
|
|
||||||
Saturation = 150,
|
|
||||||
Lightness = 166
|
|
||||||
};
|
|
||||||
|
|
||||||
QColor colorBySelectionId(int index) const
|
|
||||||
{
|
|
||||||
return colorByHue(selectionId(index) * SelectionIdHueMultiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor colorByFraction(double fraction) const
|
|
||||||
{
|
|
||||||
return colorByHue(fraction * FractionHueMultiplier + FractionHueMininimum);
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor colorByHue(int hue) const
|
|
||||||
{
|
|
||||||
return QColor::fromHsl(hue % 360, Saturation, Lightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
int insert(qint64 startTime, qint64 duration, int typeId);
|
int insert(qint64 startTime, qint64 duration, int typeId);
|
||||||
int insertStart(qint64 startTime, int typeId);
|
int insertStart(qint64 startTime, int typeId);
|
||||||
void insertEnd(int index, qint64 duration);
|
void insertEnd(int index, qint64 duration);
|
||||||
void computeNesting();
|
void computeNesting();
|
||||||
|
|
||||||
|
int collapsedRowCount() const;
|
||||||
|
void setCollapsedRowCount(int rows);
|
||||||
|
|
||||||
|
int expandedRowCount() const;
|
||||||
|
void setExpandedRowCount(int rows);
|
||||||
|
|
||||||
|
QmlDebug::RangeType rangeType() const;
|
||||||
|
QmlDebug::Message message() const;
|
||||||
|
|
||||||
|
void updateProgress(qint64 count, qint64 max) const;
|
||||||
|
|
||||||
explicit AbstractTimelineModel(AbstractTimelineModelPrivate *dd, const QString &displayName,
|
explicit AbstractTimelineModel(AbstractTimelineModelPrivate *dd, const QString &displayName,
|
||||||
QmlDebug::Message message, QmlDebug::RangeType rangeType,
|
QmlDebug::Message message, QmlDebug::RangeType rangeType,
|
||||||
QObject *parent);
|
QObject *parent);
|
||||||
@@ -147,11 +144,9 @@ protected:
|
|||||||
virtual void loadData() = 0;
|
virtual void loadData() = 0;
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void dataChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(AbstractTimelineModel)
|
Q_DECLARE_PRIVATE(AbstractTimelineModel)
|
||||||
|
Q_PRIVATE_SLOT(d_func(), void _q_dataChanged())
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,16 @@ namespace QmlProfiler {
|
|||||||
|
|
||||||
class QMLPROFILER_EXPORT AbstractTimelineModel::AbstractTimelineModelPrivate {
|
class QMLPROFILER_EXPORT AbstractTimelineModel::AbstractTimelineModelPrivate {
|
||||||
public:
|
public:
|
||||||
|
static const int DefaultRowHeight = 30;
|
||||||
|
|
||||||
|
enum BoxColorProperties {
|
||||||
|
SelectionIdHueMultiplier = 25,
|
||||||
|
FractionHueMultiplier = 96,
|
||||||
|
FractionHueMininimum = 10,
|
||||||
|
Saturation = 150,
|
||||||
|
Lightness = 166
|
||||||
|
};
|
||||||
|
|
||||||
struct Range {
|
struct Range {
|
||||||
Range() : start(-1), duration(-1), typeId(-1), parent(-1) {}
|
Range() : start(-1), duration(-1), typeId(-1), parent(-1) {}
|
||||||
Range(qint64 start, qint64 duration, int typeId) :
|
Range(qint64 start, qint64 duration, int typeId) :
|
||||||
@@ -102,6 +112,8 @@ public:
|
|||||||
return fromIndex;
|
return fromIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _q_dataChanged();
|
||||||
|
|
||||||
QVector<Range> ranges;
|
QVector<Range> ranges;
|
||||||
QVector<RangeEnd> endTimes;
|
QVector<RangeEnd> endTimes;
|
||||||
|
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ float QmlProfilerAnimationsModel::relativeHeight(int index) const
|
|||||||
|
|
||||||
// Add some height to the events if we're far from the scale threshold of 2 * DefaultRowHeight.
|
// Add some height to the events if we're far from the scale threshold of 2 * DefaultRowHeight.
|
||||||
// Like that you can see the smaller events more easily.
|
// Like that you can see the smaller events more easily.
|
||||||
int scaleThreshold = 2 * DefaultRowHeight - rowHeight(d->rowFromThreadId(data.threadId));
|
int scaleThreshold = 2 * defaultRowHeight() - rowHeight(d->rowFromThreadId(data.threadId));
|
||||||
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / DefaultRowHeight) : 0;
|
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / defaultRowHeight()) : 0;
|
||||||
|
|
||||||
return boost + (1.0 - boost) * (float)data.animationcount /
|
return boost + (1.0 - boost) * (float)data.animationcount /
|
||||||
(float)(data.threadId == QmlDebug::GuiThread ? d->maxGuiThreadAnimations :
|
(float)(data.threadId == QmlDebug::GuiThread ? d->maxGuiThreadAnimations :
|
||||||
|
|||||||
Reference in New Issue
Block a user