forked from qt-creator/qt-creator
QmlProfiler: Remove pimpl pattern from details rewriter
It's internal, so we don't need to hide it behind a d pointer. Change-Id: Ib5b7ac790a1c143414a7ed11e06a5d8a9464de55 Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
This commit is contained in:
@@ -99,7 +99,7 @@ QmlProfilerDataModel::QmlProfilerDataModel(Utils::FileInProjectFinder *fileFinde
|
|||||||
Q_D(QmlProfilerDataModel);
|
Q_D(QmlProfilerDataModel);
|
||||||
Q_ASSERT(parent);
|
Q_ASSERT(parent);
|
||||||
d->modelManager = parent;
|
d->modelManager = parent;
|
||||||
d->detailsRewriter = new QmlProfilerDetailsRewriter(this, fileFinder);
|
d->detailsRewriter = new QmlProfilerDetailsRewriter(fileFinder, this);
|
||||||
d->modelId = d->modelManager->registerModelProxy();
|
d->modelId = d->modelManager->registerModelProxy();
|
||||||
connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::rewriteDetailsString,
|
connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::rewriteDetailsString,
|
||||||
this, &QmlProfilerDataModel::detailsChanged);
|
this, &QmlProfilerDataModel::detailsChanged);
|
||||||
|
|||||||
@@ -34,12 +34,6 @@
|
|||||||
namespace QmlProfiler {
|
namespace QmlProfiler {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
struct PendingEvent {
|
|
||||||
QmlEventLocation location;
|
|
||||||
QString localFile;
|
|
||||||
int requestId;
|
|
||||||
};
|
|
||||||
|
|
||||||
class PropertyVisitor: protected QmlJS::AST::Visitor
|
class PropertyVisitor: protected QmlJS::AST::Visitor
|
||||||
{
|
{
|
||||||
QmlJS::AST::Node * _lastValidNode;
|
QmlJS::AST::Node * _lastValidNode;
|
||||||
@@ -91,30 +85,10 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriterPrivate
|
QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(Utils::FileInProjectFinder *fileFinder,
|
||||||
|
QObject *parent)
|
||||||
|
: QObject(parent), m_projectFinder(fileFinder)
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
QmlProfilerDetailsRewriterPrivate(QmlProfilerDetailsRewriter *qq,
|
|
||||||
Utils::FileInProjectFinder *fileFinder)
|
|
||||||
: m_projectFinder(fileFinder), q(qq) {}
|
|
||||||
~QmlProfilerDetailsRewriterPrivate() {}
|
|
||||||
|
|
||||||
QList <PendingEvent> m_pendingEvents;
|
|
||||||
QStringList m_pendingDocs;
|
|
||||||
Utils::FileInProjectFinder *m_projectFinder;
|
|
||||||
QMap<QString, QString> m_filesCache;
|
|
||||||
|
|
||||||
QmlProfilerDetailsRewriter *q;
|
|
||||||
};
|
|
||||||
|
|
||||||
QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(
|
|
||||||
QObject *parent, Utils::FileInProjectFinder *fileFinder)
|
|
||||||
: QObject(parent), d(new QmlProfilerDetailsRewriterPrivate(this, fileFinder))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
QmlProfilerDetailsRewriter::~QmlProfilerDetailsRewriter()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
|
void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
|
||||||
@@ -122,11 +96,11 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
|
|||||||
{
|
{
|
||||||
QString localFile;
|
QString localFile;
|
||||||
const QString locationFile = location.filename();
|
const QString locationFile = location.filename();
|
||||||
if (!d->m_filesCache.contains(locationFile)) {
|
if (!m_filesCache.contains(locationFile)) {
|
||||||
localFile = d->m_projectFinder->findFile(locationFile);
|
localFile = m_projectFinder->findFile(locationFile);
|
||||||
d->m_filesCache[locationFile] = localFile;
|
m_filesCache[locationFile] = localFile;
|
||||||
} else {
|
} else {
|
||||||
localFile = d->m_filesCache[locationFile];
|
localFile = m_filesCache[locationFile];
|
||||||
}
|
}
|
||||||
QFileInfo fileInfo(localFile);
|
QFileInfo fileInfo(localFile);
|
||||||
if (!fileInfo.exists() || !fileInfo.isReadable())
|
if (!fileInfo.exists() || !fileInfo.isReadable())
|
||||||
@@ -136,26 +110,25 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
|
|||||||
|
|
||||||
localFile = fileInfo.canonicalFilePath();
|
localFile = fileInfo.canonicalFilePath();
|
||||||
|
|
||||||
PendingEvent ev = {location, localFile, requestId};
|
m_pendingEvents.append({location, localFile, requestId});
|
||||||
d->m_pendingEvents << ev;
|
if (!m_pendingDocs.contains(localFile)) {
|
||||||
if (!d->m_pendingDocs.contains(localFile)) {
|
if (m_pendingDocs.isEmpty() && QmlJS::ModelManagerInterface::instance())
|
||||||
if (d->m_pendingDocs.isEmpty() && QmlJS::ModelManagerInterface::instance())
|
|
||||||
connect(QmlJS::ModelManagerInterface::instance(),
|
connect(QmlJS::ModelManagerInterface::instance(),
|
||||||
&QmlJS::ModelManagerInterface::documentUpdated,
|
&QmlJS::ModelManagerInterface::documentUpdated,
|
||||||
this,
|
this,
|
||||||
&QmlProfilerDetailsRewriter::documentReady);
|
&QmlProfilerDetailsRewriter::documentReady);
|
||||||
|
|
||||||
d->m_pendingDocs << localFile;
|
m_pendingDocs.append(localFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerDetailsRewriter::reloadDocuments()
|
void QmlProfilerDetailsRewriter::reloadDocuments()
|
||||||
{
|
{
|
||||||
if (!d->m_pendingDocs.isEmpty()) {
|
if (!m_pendingDocs.isEmpty()) {
|
||||||
if (QmlJS::ModelManagerInterface *manager = QmlJS::ModelManagerInterface::instance()) {
|
if (QmlJS::ModelManagerInterface *manager = QmlJS::ModelManagerInterface::instance()) {
|
||||||
manager->updateSourceFiles(d->m_pendingDocs, false);
|
manager->updateSourceFiles(m_pendingDocs, false);
|
||||||
} else {
|
} else {
|
||||||
d->m_pendingDocs.clear();
|
m_pendingDocs.clear();
|
||||||
emit eventDetailsChanged();
|
emit eventDetailsChanged();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -163,8 +136,9 @@ void QmlProfilerDetailsRewriter::reloadDocuments()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
|
void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(
|
||||||
QmlJS::Document::Ptr doc, int requestId, const QmlEventLocation &location)
|
QTextStream &textDoc, QmlJS::Document::Ptr doc, int requestId,
|
||||||
|
const QmlEventLocation &location)
|
||||||
{
|
{
|
||||||
PropertyVisitor propertyVisitor;
|
PropertyVisitor propertyVisitor;
|
||||||
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line(), location.column());
|
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line(), location.column());
|
||||||
@@ -183,14 +157,14 @@ void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
|
|||||||
|
|
||||||
void QmlProfilerDetailsRewriter::clearRequests()
|
void QmlProfilerDetailsRewriter::clearRequests()
|
||||||
{
|
{
|
||||||
d->m_filesCache.clear();
|
m_filesCache.clear();
|
||||||
d->m_pendingDocs.clear();
|
m_pendingDocs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc)
|
void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc)
|
||||||
{
|
{
|
||||||
// this could be triggered by an unrelated reload in Creator
|
// this could be triggered by an unrelated reload in Creator
|
||||||
if (!d->m_pendingDocs.contains(doc->fileName()))
|
if (!m_pendingDocs.contains(doc->fileName()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if the file could not be opened this slot is still triggered but source will be an empty string
|
// if the file could not be opened this slot is still triggered but source will be an empty string
|
||||||
@@ -198,24 +172,24 @@ void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc)
|
|||||||
if (!source.isEmpty()) {
|
if (!source.isEmpty()) {
|
||||||
QTextStream st(&source, QIODevice::ReadOnly);
|
QTextStream st(&source, QIODevice::ReadOnly);
|
||||||
|
|
||||||
for (int i = d->m_pendingEvents.count()-1; i>=0; i--) {
|
for (int i = m_pendingEvents.count() - 1; i >= 0; --i) {
|
||||||
PendingEvent ev = d->m_pendingEvents[i];
|
PendingEvent ev = m_pendingEvents[i];
|
||||||
if (ev.localFile == doc->fileName()) {
|
if (ev.localFile == doc->fileName()) {
|
||||||
d->m_pendingEvents.removeAt(i);
|
m_pendingEvents.removeAt(i);
|
||||||
rewriteDetailsForLocation(st, doc, ev.requestId, ev.location);
|
rewriteDetailsForLocation(st, doc, ev.requestId, ev.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_pendingDocs.removeOne(doc->fileName());
|
m_pendingDocs.removeOne(doc->fileName());
|
||||||
|
|
||||||
if (d->m_pendingDocs.isEmpty()) {
|
if (m_pendingDocs.isEmpty()) {
|
||||||
disconnect(QmlJS::ModelManagerInterface::instance(),
|
disconnect(QmlJS::ModelManagerInterface::instance(),
|
||||||
&QmlJS::ModelManagerInterface::documentUpdated,
|
&QmlJS::ModelManagerInterface::documentUpdated,
|
||||||
this,
|
this,
|
||||||
&QmlProfilerDetailsRewriter::documentReady);
|
&QmlProfilerDetailsRewriter::documentReady);
|
||||||
emit eventDetailsChanged();
|
emit eventDetailsChanged();
|
||||||
d->m_filesCache.clear();
|
m_filesCache.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,25 +39,32 @@ class QmlProfilerDetailsRewriter : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QmlProfilerDetailsRewriter(QObject *parent, Utils::FileInProjectFinder *fileFinder);
|
explicit QmlProfilerDetailsRewriter(Utils::FileInProjectFinder *fileFinder,
|
||||||
~QmlProfilerDetailsRewriter();
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
void clearRequests();
|
void clearRequests();
|
||||||
|
|
||||||
private:
|
|
||||||
void rewriteDetailsForLocation(QTextStream &textDoc, QmlJS::Document::Ptr doc, int requestId,
|
|
||||||
const QmlEventLocation &location);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void requestDetailsForLocation(int requestId, const QmlEventLocation &location);
|
void requestDetailsForLocation(int requestId, const QmlEventLocation &location);
|
||||||
void reloadDocuments();
|
void reloadDocuments();
|
||||||
void documentReady(QmlJS::Document::Ptr doc);
|
void documentReady(QmlJS::Document::Ptr doc);
|
||||||
|
|
||||||
|
struct PendingEvent {
|
||||||
|
QmlEventLocation location;
|
||||||
|
QString localFile;
|
||||||
|
int requestId;
|
||||||
|
};
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void rewriteDetailsString(int requestId, const QString &details);
|
void rewriteDetailsString(int requestId, const QString &details);
|
||||||
void eventDetailsChanged();
|
void eventDetailsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class QmlProfilerDetailsRewriterPrivate;
|
QList<PendingEvent> m_pendingEvents;
|
||||||
QmlProfilerDetailsRewriterPrivate *d;
|
QStringList m_pendingDocs;
|
||||||
|
Utils::FileInProjectFinder *m_projectFinder;
|
||||||
|
QHash<QString, QString> m_filesCache;
|
||||||
|
|
||||||
|
void rewriteDetailsForLocation(QTextStream &textDoc, QmlJS::Document::Ptr doc, int requestId,
|
||||||
|
const QmlEventLocation &location);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user