aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmlprofiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2016-12-19 16:03:16 +0100
committerUlf Hermann <ulf.hermann@qt.io>2016-12-20 13:36:09 +0000
commitee766f6d52cbf55e3a112f0baee5daba670234a3 (patch)
tree72ef4272a0f1798165a9d33181f0837083be4343 /src/plugins/qmlprofiler
parent0a305951072dca73f4b528e01953825632a47f70 (diff)
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>
Diffstat (limited to 'src/plugins/qmlprofiler')
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp2
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp78
-rw-r--r--src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.h27
3 files changed, 44 insertions, 63 deletions
diff --git a/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp b/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp
index a036a20738..e67657540b 100644
--- a/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp
@@ -99,7 +99,7 @@ QmlProfilerDataModel::QmlProfilerDataModel(Utils::FileInProjectFinder *fileFinde
Q_D(QmlProfilerDataModel);
Q_ASSERT(parent);
d->modelManager = parent;
- d->detailsRewriter = new QmlProfilerDetailsRewriter(this, fileFinder);
+ d->detailsRewriter = new QmlProfilerDetailsRewriter(fileFinder, this);
d->modelId = d->modelManager->registerModelProxy();
connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::rewriteDetailsString,
this, &QmlProfilerDataModel::detailsChanged);
diff --git a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp
index 4877e40cbe..d4bac79ae9 100644
--- a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.cpp
@@ -34,12 +34,6 @@
namespace QmlProfiler {
namespace Internal {
-struct PendingEvent {
- QmlEventLocation location;
- QString localFile;
- int requestId;
-};
-
class PropertyVisitor: protected QmlJS::AST::Visitor
{
QmlJS::AST::Node * _lastValidNode;
@@ -91,30 +85,10 @@ protected:
}
};
-class QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriterPrivate
-{
-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()
+QmlProfilerDetailsRewriter::QmlProfilerDetailsRewriter(Utils::FileInProjectFinder *fileFinder,
+ QObject *parent)
+ : QObject(parent), m_projectFinder(fileFinder)
{
- delete d;
}
void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
@@ -122,11 +96,11 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
{
QString localFile;
const QString locationFile = location.filename();
- if (!d->m_filesCache.contains(locationFile)) {
- localFile = d->m_projectFinder->findFile(locationFile);
- d->m_filesCache[locationFile] = localFile;
+ if (!m_filesCache.contains(locationFile)) {
+ localFile = m_projectFinder->findFile(locationFile);
+ m_filesCache[locationFile] = localFile;
} else {
- localFile = d->m_filesCache[locationFile];
+ localFile = m_filesCache[locationFile];
}
QFileInfo fileInfo(localFile);
if (!fileInfo.exists() || !fileInfo.isReadable())
@@ -136,26 +110,25 @@ void QmlProfilerDetailsRewriter::requestDetailsForLocation(int requestId,
localFile = fileInfo.canonicalFilePath();
- PendingEvent ev = {location, localFile, requestId};
- d->m_pendingEvents << ev;
- if (!d->m_pendingDocs.contains(localFile)) {
- if (d->m_pendingDocs.isEmpty() && QmlJS::ModelManagerInterface::instance())
+ m_pendingEvents.append({location, localFile, requestId});
+ if (!m_pendingDocs.contains(localFile)) {
+ if (m_pendingDocs.isEmpty() && QmlJS::ModelManagerInterface::instance())
connect(QmlJS::ModelManagerInterface::instance(),
&QmlJS::ModelManagerInterface::documentUpdated,
this,
&QmlProfilerDetailsRewriter::documentReady);
- d->m_pendingDocs << localFile;
+ m_pendingDocs.append(localFile);
}
}
void QmlProfilerDetailsRewriter::reloadDocuments()
{
- if (!d->m_pendingDocs.isEmpty()) {
+ if (!m_pendingDocs.isEmpty()) {
if (QmlJS::ModelManagerInterface *manager = QmlJS::ModelManagerInterface::instance()) {
- manager->updateSourceFiles(d->m_pendingDocs, false);
+ manager->updateSourceFiles(m_pendingDocs, false);
} else {
- d->m_pendingDocs.clear();
+ m_pendingDocs.clear();
emit eventDetailsChanged();
}
} else {
@@ -163,8 +136,9 @@ void QmlProfilerDetailsRewriter::reloadDocuments()
}
}
-void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
- QmlJS::Document::Ptr doc, int requestId, const QmlEventLocation &location)
+void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(
+ QTextStream &textDoc, QmlJS::Document::Ptr doc, int requestId,
+ const QmlEventLocation &location)
{
PropertyVisitor propertyVisitor;
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line(), location.column());
@@ -183,14 +157,14 @@ void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
void QmlProfilerDetailsRewriter::clearRequests()
{
- d->m_filesCache.clear();
- d->m_pendingDocs.clear();
+ m_filesCache.clear();
+ m_pendingDocs.clear();
}
void QmlProfilerDetailsRewriter::documentReady(QmlJS::Document::Ptr doc)
{
// this could be triggered by an unrelated reload in Creator
- if (!d->m_pendingDocs.contains(doc->fileName()))
+ if (!m_pendingDocs.contains(doc->fileName()))
return;
// 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()) {
QTextStream st(&source, QIODevice::ReadOnly);
- for (int i = d->m_pendingEvents.count()-1; i>=0; i--) {
- PendingEvent ev = d->m_pendingEvents[i];
+ for (int i = m_pendingEvents.count() - 1; i >= 0; --i) {
+ PendingEvent ev = m_pendingEvents[i];
if (ev.localFile == doc->fileName()) {
- d->m_pendingEvents.removeAt(i);
+ m_pendingEvents.removeAt(i);
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(),
&QmlJS::ModelManagerInterface::documentUpdated,
this,
&QmlProfilerDetailsRewriter::documentReady);
emit eventDetailsChanged();
- d->m_filesCache.clear();
+ m_filesCache.clear();
}
}
diff --git a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.h b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.h
index e5cb2ec694..5747645978 100644
--- a/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.h
+++ b/src/plugins/qmlprofiler/qmlprofilerdetailsrewriter.h
@@ -39,25 +39,32 @@ class QmlProfilerDetailsRewriter : public QObject
{
Q_OBJECT
public:
- explicit QmlProfilerDetailsRewriter(QObject *parent, Utils::FileInProjectFinder *fileFinder);
- ~QmlProfilerDetailsRewriter();
+ explicit QmlProfilerDetailsRewriter(Utils::FileInProjectFinder *fileFinder,
+ QObject *parent = nullptr);
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 reloadDocuments();
void documentReady(QmlJS::Document::Ptr doc);
+
+ struct PendingEvent {
+ QmlEventLocation location;
+ QString localFile;
+ int requestId;
+ };
+
signals:
void rewriteDetailsString(int requestId, const QString &details);
void eventDetailsChanged();
+
private:
- class QmlProfilerDetailsRewriterPrivate;
- QmlProfilerDetailsRewriterPrivate *d;
+ QList<PendingEvent> m_pendingEvents;
+ 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