QmjJSEditor: Some style.

q and d are special, no need to allocate private timers dynamically.

Change-Id: Ide121c59d17c3129296651b360c8b173efadeedb
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
hjk
2014-02-10 14:18:32 +01:00
parent 74aa5e998f
commit b60fb8aeab
3 changed files with 45 additions and 48 deletions

View File

@@ -414,7 +414,7 @@ namespace QmlJSEditor {
namespace Internal { namespace Internal {
QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *parent) QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *parent)
: m_q(parent), : q(parent),
m_semanticInfoDocRevision(-1), m_semanticInfoDocRevision(-1),
m_semanticHighlighter(new SemanticHighlighter(parent)), m_semanticHighlighter(new SemanticHighlighter(parent)),
m_semanticHighlightingNecessary(false), m_semanticHighlightingNecessary(false),
@@ -424,11 +424,10 @@ QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *pare
ModelManagerInterface *modelManager = ModelManagerInterface::instance(); ModelManagerInterface *modelManager = ModelManagerInterface::instance();
// code model // code model
m_updateDocumentTimer = new QTimer(this); m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_updateDocumentTimer.setSingleShot(true);
m_updateDocumentTimer->setSingleShot(true); connect(q->document(), SIGNAL(contentsChanged()), &m_updateDocumentTimer, SLOT(start()));
connect(m_q->document(), SIGNAL(contentsChanged()), m_updateDocumentTimer, SLOT(start())); connect(&m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(reparseDocument()));
connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(reparseDocument()));
connect(modelManager, SIGNAL(documentUpdated(QmlJS::Document::Ptr)), connect(modelManager, SIGNAL(documentUpdated(QmlJS::Document::Ptr)),
this, SLOT(onDocumentUpdated(QmlJS::Document::Ptr))); this, SLOT(onDocumentUpdated(QmlJS::Document::Ptr)));
@@ -439,18 +438,16 @@ QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *pare
m_semanticInfoUpdater->start(); m_semanticInfoUpdater->start();
// library info changes // library info changes
m_reupdateSemanticInfoTimer = new QTimer(this); m_reupdateSemanticInfoTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_reupdateSemanticInfoTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_reupdateSemanticInfoTimer.setSingleShot(true);
m_reupdateSemanticInfoTimer->setSingleShot(true); connect(&m_reupdateSemanticInfoTimer, SIGNAL(timeout()), this, SLOT(reupdateSemanticInfo()));
connect(m_reupdateSemanticInfoTimer, SIGNAL(timeout()), this, SLOT(reupdateSemanticInfo()));
connect(modelManager, SIGNAL(libraryInfoUpdated(QString,QmlJS::LibraryInfo)), connect(modelManager, SIGNAL(libraryInfoUpdated(QString,QmlJS::LibraryInfo)),
m_reupdateSemanticInfoTimer, SLOT(start())); &m_reupdateSemanticInfoTimer, SLOT(start()));
// outline model // outline model
m_updateOutlineModelTimer = new QTimer(this); m_updateOutlineModelTimer.setInterval(UPDATE_OUTLINE_INTERVAL);
m_updateOutlineModelTimer->setInterval(UPDATE_OUTLINE_INTERVAL); m_updateOutlineModelTimer.setSingleShot(true);
m_updateOutlineModelTimer->setSingleShot(true); connect(&m_updateOutlineModelTimer, SIGNAL(timeout()), this, SLOT(updateOutlineModel()));
connect(m_updateOutlineModelTimer, SIGNAL(timeout()), this, SLOT(updateOutlineModel()));
} }
QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate() QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate()
@@ -461,23 +458,23 @@ QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate()
void QmlJSEditorDocumentPrivate::invalidateFormatterCache() void QmlJSEditorDocumentPrivate::invalidateFormatterCache()
{ {
CreatorCodeFormatter formatter(m_q->tabSettings()); CreatorCodeFormatter formatter(q->tabSettings());
formatter.invalidateCache(m_q->document()); formatter.invalidateCache(q->document());
} }
void QmlJSEditorDocumentPrivate::reparseDocument() void QmlJSEditorDocumentPrivate::reparseDocument()
{ {
ModelManagerInterface::instance()->updateSourceFiles(QStringList() << m_q->filePath(), ModelManagerInterface::instance()->updateSourceFiles(QStringList() << q->filePath(),
false); false);
} }
void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc) void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc)
{ {
if (m_q->filePath() != doc->fileName()) if (q->filePath() != doc->fileName())
return; return;
// text document has changed, simply wait for the next onDocumentUpdated // text document has changed, simply wait for the next onDocumentUpdated
if (doc->editorRevision() != m_q->document()->revision()) if (doc->editorRevision() != q->document()->revision())
return; return;
if (doc->ast()) { if (doc->ast()) {
@@ -485,14 +482,14 @@ void QmlJSEditorDocumentPrivate::onDocumentUpdated(Document::Ptr doc)
m_semanticInfoDocRevision = doc->editorRevision(); m_semanticInfoDocRevision = doc->editorRevision();
m_semanticInfoUpdater->update(doc, ModelManagerInterface::instance()->snapshot()); m_semanticInfoUpdater->update(doc, ModelManagerInterface::instance()->snapshot());
} }
emit m_q->updateCodeWarnings(doc); emit q->updateCodeWarnings(doc);
} }
void QmlJSEditorDocumentPrivate::reupdateSemanticInfo() void QmlJSEditorDocumentPrivate::reupdateSemanticInfo()
{ {
// If the editor is newer than the semantic info (possibly with update in progress), // If the editor is newer than the semantic info (possibly with update in progress),
// new semantic infos won't be accepted anyway. We'll get a onDocumentUpdated anyhow. // new semantic infos won't be accepted anyway. We'll get a onDocumentUpdated anyhow.
if (m_q->document()->revision() != m_semanticInfoDocRevision) if (q->document()->revision() != m_semanticInfoDocRevision)
return; return;
m_semanticInfoUpdater->reupdate(ModelManagerInterface::instance()->snapshot()); m_semanticInfoUpdater->reupdate(ModelManagerInterface::instance()->snapshot());
@@ -500,7 +497,7 @@ void QmlJSEditorDocumentPrivate::reupdateSemanticInfo()
void QmlJSEditorDocumentPrivate::acceptNewSemanticInfo(const SemanticInfo &semanticInfo) void QmlJSEditorDocumentPrivate::acceptNewSemanticInfo(const SemanticInfo &semanticInfo)
{ {
if (semanticInfo.revision() != m_q->document()->revision()) { if (semanticInfo.revision() != q->document()->revision()) {
// ignore outdated semantic infos // ignore outdated semantic infos
return; return;
} }
@@ -510,7 +507,7 @@ void QmlJSEditorDocumentPrivate::acceptNewSemanticInfo(const SemanticInfo &seman
// create the ranges // create the ranges
CreateRanges createRanges; CreateRanges createRanges;
m_semanticInfo.ranges = createRanges(m_q->document(), doc); m_semanticInfo.ranges = createRanges(q->document(), doc);
// Refresh the ids // Refresh the ids
FindIdDeclarations updateIds; FindIdDeclarations updateIds;
@@ -519,12 +516,12 @@ void QmlJSEditorDocumentPrivate::acceptNewSemanticInfo(const SemanticInfo &seman
m_outlineModelNeedsUpdate = true; m_outlineModelNeedsUpdate = true;
m_semanticHighlightingNecessary = true; m_semanticHighlightingNecessary = true;
emit m_q->semanticInfoUpdated(m_semanticInfo); // calls triggerPendingUpdates as necessary emit q->semanticInfoUpdated(m_semanticInfo); // calls triggerPendingUpdates as necessary
} }
void QmlJSEditorDocumentPrivate::updateOutlineModel() void QmlJSEditorDocumentPrivate::updateOutlineModel()
{ {
if (m_q->isSemanticInfoOutdated()) if (q->isSemanticInfoOutdated())
return; // outline update will be retriggered when semantic info is updated return; // outline update will be retriggered when semantic info is updated
m_outlineModel->update(m_semanticInfo); m_outlineModel->update(m_semanticInfo);
@@ -533,51 +530,51 @@ void QmlJSEditorDocumentPrivate::updateOutlineModel()
} // Internal } // Internal
QmlJSEditorDocument::QmlJSEditorDocument() QmlJSEditorDocument::QmlJSEditorDocument()
: m_d(new Internal::QmlJSEditorDocumentPrivate(this)) : d(new Internal::QmlJSEditorDocumentPrivate(this))
{ {
connect(this, SIGNAL(tabSettingsChanged()), connect(this, SIGNAL(tabSettingsChanged()),
m_d, SLOT(invalidateFormatterCache())); d, SLOT(invalidateFormatterCache()));
setSyntaxHighlighter(new Highlighter(document())); setSyntaxHighlighter(new Highlighter(document()));
setIndenter(new Internal::Indenter); setIndenter(new Internal::Indenter);
} }
QmlJSEditorDocument::~QmlJSEditorDocument() QmlJSEditorDocument::~QmlJSEditorDocument()
{ {
delete m_d; delete d;
} }
const SemanticInfo &QmlJSEditorDocument::semanticInfo() const const SemanticInfo &QmlJSEditorDocument::semanticInfo() const
{ {
return m_d->m_semanticInfo; return d->m_semanticInfo;
} }
bool QmlJSEditorDocument::isSemanticInfoOutdated() const bool QmlJSEditorDocument::isSemanticInfoOutdated() const
{ {
return m_d->m_semanticInfo.revision() != document()->revision(); return d->m_semanticInfo.revision() != document()->revision();
} }
QVector<QTextLayout::FormatRange> QmlJSEditorDocument::diagnosticRanges() const QVector<QTextLayout::FormatRange> QmlJSEditorDocument::diagnosticRanges() const
{ {
return m_d->m_diagnosticRanges; return d->m_diagnosticRanges;
} }
Internal::QmlOutlineModel *QmlJSEditorDocument::outlineModel() const Internal::QmlOutlineModel *QmlJSEditorDocument::outlineModel() const
{ {
return m_d->m_outlineModel; return d->m_outlineModel;
} }
void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges) void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges)
{ {
m_d->m_diagnosticRanges = ranges; d->m_diagnosticRanges = ranges;
} }
void QmlJSEditorDocument::applyFontSettings() void QmlJSEditorDocument::applyFontSettings()
{ {
BaseTextDocument::applyFontSettings(); BaseTextDocument::applyFontSettings();
m_d->m_semanticHighlighter->updateFontSettings(fontSettings()); d->m_semanticHighlighter->updateFontSettings(fontSettings());
if (!isSemanticInfoOutdated()) { if (!isSemanticInfoOutdated()) {
m_d->m_semanticHighlightingNecessary = false; d->m_semanticHighlightingNecessary = false;
m_d->m_semanticHighlighter->rerun(m_d->m_semanticInfo); d->m_semanticHighlighter->rerun(d->m_semanticInfo);
} }
} }
@@ -585,13 +582,13 @@ void QmlJSEditorDocument::triggerPendingUpdates()
{ {
BaseTextDocument::triggerPendingUpdates(); // calls applyFontSettings if necessary BaseTextDocument::triggerPendingUpdates(); // calls applyFontSettings if necessary
// might still need to rehighlight if font settings did not change // might still need to rehighlight if font settings did not change
if (m_d->m_semanticHighlightingNecessary && !isSemanticInfoOutdated()) { if (d->m_semanticHighlightingNecessary && !isSemanticInfoOutdated()) {
m_d->m_semanticHighlightingNecessary = false; d->m_semanticHighlightingNecessary = false;
m_d->m_semanticHighlighter->rerun(m_d->m_semanticInfo); d->m_semanticHighlighter->rerun(d->m_semanticInfo);
} }
if (m_d->m_outlineModelNeedsUpdate && !isSemanticInfoOutdated()) { if (d->m_outlineModelNeedsUpdate && !isSemanticInfoOutdated()) {
m_d->m_outlineModelNeedsUpdate = false; d->m_outlineModelNeedsUpdate = false;
m_d->m_updateOutlineModelTimer->start(); d->m_updateOutlineModelTimer.start();
} }
} }

View File

@@ -68,7 +68,7 @@ protected:
private: private:
friend class Internal::QmlJSEditorDocumentPrivate; // sending signals friend class Internal::QmlJSEditorDocumentPrivate; // sending signals
Internal::QmlJSEditorDocumentPrivate *m_d; Internal::QmlJSEditorDocumentPrivate *d;
}; };
} // QmlJSEditor } // QmlJSEditor

View File

@@ -64,9 +64,9 @@ public slots:
void updateOutlineModel(); void updateOutlineModel();
public: public:
QmlJSEditorDocument *m_q; QmlJSEditorDocument *q;
QTimer *m_updateDocumentTimer; // used to compress multiple document changes QTimer m_updateDocumentTimer; // used to compress multiple document changes
QTimer *m_reupdateSemanticInfoTimer; // used to compress multiple libraryInfo changes QTimer m_reupdateSemanticInfoTimer; // used to compress multiple libraryInfo changes
int m_semanticInfoDocRevision; // document revision to which the semantic info is currently updated to int m_semanticInfoDocRevision; // document revision to which the semantic info is currently updated to
SemanticInfoUpdater *m_semanticInfoUpdater; SemanticInfoUpdater *m_semanticInfoUpdater;
QmlJSTools::SemanticInfo m_semanticInfo; QmlJSTools::SemanticInfo m_semanticInfo;
@@ -74,7 +74,7 @@ public:
Internal::SemanticHighlighter *m_semanticHighlighter; Internal::SemanticHighlighter *m_semanticHighlighter;
bool m_semanticHighlightingNecessary; bool m_semanticHighlightingNecessary;
bool m_outlineModelNeedsUpdate; bool m_outlineModelNeedsUpdate;
QTimer *m_updateOutlineModelTimer; QTimer m_updateOutlineModelTimer;
Internal::QmlOutlineModel *m_outlineModel; Internal::QmlOutlineModel *m_outlineModel;
}; };