Commit b2c8e701 authored by Ulf Hermann's avatar Ulf Hermann Committed by Ulf Hermann
Browse files

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: default avatarKai Koehne <kai.koehne@theqtcompany.com>
parent b7742f79
......@@ -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,
const QString &newDisplayName,
QmlDebug::Message newMessage,
......@@ -160,10 +184,26 @@ AbstractTimelineModel::~AbstractTimelineModel()
void AbstractTimelineModel::setModelManager(QmlProfilerModelManager *modelManager)
{
Q_D(AbstractTimelineModel);
d->modelManager = modelManager;
connect(d->modelManager->qmlModel(),SIGNAL(changed()),this,SLOT(dataChanged()));
d->modelId = d->modelManager->registerModelProxy();
d->modelManager->announceFeatures(d->modelId, features());
if (modelManager != d->modelManager) {
if (d->modelManager != 0) {
disconnect(d->modelManager->qmlModel(), SIGNAL(changed()),
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
......@@ -181,11 +221,11 @@ int AbstractTimelineModel::rowHeight(int rowNumber) const
{
Q_D(const AbstractTimelineModel);
if (!expanded())
return DefaultRowHeight;
return AbstractTimelineModelPrivate::DefaultRowHeight;
if (d->rowOffsets.size() > rowNumber)
return d->rowOffsets[rowNumber] - (rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
return DefaultRowHeight;
return AbstractTimelineModelPrivate::DefaultRowHeight;
}
int AbstractTimelineModel::rowOffset(int rowNumber) const
......@@ -194,13 +234,14 @@ int AbstractTimelineModel::rowOffset(int rowNumber) const
if (rowNumber == 0)
return 0;
if (!expanded())
return DefaultRowHeight * rowNumber;
return AbstractTimelineModelPrivate::DefaultRowHeight * rowNumber;
if (d->rowOffsets.size() >= rowNumber)
return d->rowOffsets[rowNumber - 1];
if (!d->rowOffsets.empty())
return d->rowOffsets.last() + (rowNumber - d->rowOffsets.size()) * DefaultRowHeight;
return rowNumber * DefaultRowHeight;
return d->rowOffsets.last() + (rowNumber - d->rowOffsets.size()) *
AbstractTimelineModelPrivate::DefaultRowHeight;
return rowNumber * AbstractTimelineModelPrivate::DefaultRowHeight;
}
void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
......@@ -208,12 +249,12 @@ void AbstractTimelineModel::setRowHeight(int rowNumber, int height)
Q_D(AbstractTimelineModel);
if (d->hidden || !d->expanded)
return;
if (height < DefaultRowHeight)
height = DefaultRowHeight;
if (height < AbstractTimelineModelPrivate::DefaultRowHeight)
height = AbstractTimelineModelPrivate::DefaultRowHeight;
int nextOffset = d->rowOffsets.empty() ? 0 : d->rowOffsets.last();
while (d->rowOffsets.size() <= rowNumber)
d->rowOffsets << (nextOffset += DefaultRowHeight);
d->rowOffsets << (nextOffset += AbstractTimelineModelPrivate::DefaultRowHeight);
int difference = height - d->rowOffsets[rowNumber] +
(rowNumber > 0 ? d->rowOffsets[rowNumber - 1] : 0);
if (difference != 0) {
......@@ -229,9 +270,10 @@ int AbstractTimelineModel::height() const
Q_D(const AbstractTimelineModel);
int depth = rowCount();
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;
}
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)
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));
}
void AbstractTimelineModel::dataChanged()
void AbstractTimelineModel::AbstractTimelineModelPrivate::_q_dataChanged()
{
Q_D(AbstractTimelineModel);
bool wasEmpty = isEmpty();
switch (d->modelManager->state()) {
Q_Q(AbstractTimelineModel);
bool wasEmpty = q->isEmpty();
switch (modelManager->state()) {
case QmlProfilerDataState::ProcessingData:
loadData();
q->loadData();
break;
case QmlProfilerDataState::ClearingData:
clear();
q->clear();
break;
default:
break;
}
if (wasEmpty != isEmpty())
emit emptyChanged();
if (wasEmpty != q->isEmpty())
emit q->emptyChanged();
}
bool AbstractTimelineModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
......@@ -509,7 +591,9 @@ void AbstractTimelineModel::clear()
emit expandedChanged();
if (wasHidden)
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 hidden READ hidden WRITE setHidden NOTIFY hiddenChanged)
Q_PROPERTY(int height READ height NOTIFY heightChanged)
Q_PROPERTY(QmlProfilerModelManager *modelManager READ modelManager WRITE setModelManager
NOTIFY modelManagerChanged)
public:
class AbstractTimelineModelPrivate;
......@@ -57,6 +59,8 @@ public:
// Trivial methods implemented by the abstract model itself
void setModelManager(QmlProfilerModelManager *modelManager);
QmlProfilerModelManager *modelManager() const;
bool isEmpty() const;
int modelId() const;
......@@ -101,44 +105,37 @@ public:
virtual int rowMinValue(int rowNumber) const;
virtual int rowMaxValue(int rowNumber) const;
static int defaultRowHeight();
signals:
void expandedChanged();
void hiddenChanged();
void rowHeightChanged();
void emptyChanged();
void heightChanged();
void modelManagerChanged();
protected:
static const int DefaultRowHeight = 30;
enum BoxColorProperties {
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);
}
QColor colorBySelectionId(int index) const;
QColor colorByFraction(double fraction) const;
QColor colorByHue(int hue) const;
int insert(qint64 startTime, qint64 duration, int typeId);
int insertStart(qint64 startTime, int typeId);
void insertEnd(int index, qint64 duration);
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,
QmlDebug::Message message, QmlDebug::RangeType rangeType,
QObject *parent);
......@@ -147,11 +144,9 @@ protected:
virtual void loadData() = 0;
virtual void clear();
protected slots:
void dataChanged();
private:
Q_DECLARE_PRIVATE(AbstractTimelineModel)
Q_PRIVATE_SLOT(d_func(), void _q_dataChanged())
};
}
......
......@@ -37,6 +37,16 @@ namespace QmlProfiler {
class QMLPROFILER_EXPORT AbstractTimelineModel::AbstractTimelineModelPrivate {
public:
static const int DefaultRowHeight = 30;
enum BoxColorProperties {
SelectionIdHueMultiplier = 25,
FractionHueMultiplier = 96,
FractionHueMininimum = 10,
Saturation = 150,
Lightness = 166
};
struct Range {
Range() : start(-1), duration(-1), typeId(-1), parent(-1) {}
Range(qint64 start, qint64 duration, int typeId) :
......@@ -102,6 +112,8 @@ public:
return fromIndex;
}
void _q_dataChanged();
QVector<Range> ranges;
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.
// Like that you can see the smaller events more easily.
int scaleThreshold = 2 * DefaultRowHeight - rowHeight(d->rowFromThreadId(data.threadId));
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / DefaultRowHeight) : 0;
int scaleThreshold = 2 * defaultRowHeight() - rowHeight(d->rowFromThreadId(data.threadId));
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / defaultRowHeight()) : 0;
return boost + (1.0 - boost) * (float)data.animationcount /
(float)(data.threadId == QmlDebug::GuiThread ? d->maxGuiThreadAnimations :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment