diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2020-02-19 23:23:36 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2020-02-20 10:42:31 +0000 |
commit | 3c0b89f697c8f9dbfbf1b4582250b84eb4853d9d (patch) | |
tree | 932663cfc156b33fbd3d943f63c274e9290c4101 /src/plugins/vcsbase | |
parent | 3cdbd8683d3cec1e4adc60bd10cede5fa5b4d866 (diff) |
VCS: Refactor annotationChanges() in VcsBaseEditor
Devirtualize the function, and use QRegularExpression with globalMatch.
Change-Id: I18c92cb37b535c616f03f45dff8b18249c961d5d
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/vcsbase')
-rw-r--r-- | src/plugins/vcsbase/vcsbaseeditor.cpp | 37 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbaseeditor.h | 6 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 0471968dcf..aae366dcb4 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -50,6 +50,7 @@ #include <QDebug> #include <QFileInfo> #include <QFile> +#include <QRegularExpression> #include <QRegExp> #include <QSet> #include <QTextCodec> @@ -556,6 +557,8 @@ public: QRegExp m_diffFilePattern; QRegExp m_logEntryPattern; + QRegularExpression m_annotationEntryPattern; + QRegularExpression m_annotationSeparatorPattern; QList<int> m_entrySections; // line number where this section starts int m_cursorLine = -1; int m_firstLineNumber = -1; @@ -661,6 +664,20 @@ void VcsBaseEditorWidget::setLogEntryPattern(const QRegExp &pattern) d->m_logEntryPattern = pattern; } +void VcsBaseEditorWidget::setAnnotationEntryPattern(const QString &pattern) +{ + const QRegularExpression re(pattern, QRegularExpression::MultilineOption); + QTC_ASSERT(re.isValid() && re.captureCount() >= 1, return); + d->m_annotationEntryPattern = re; +} + +void VcsBaseEditorWidget::setAnnotationSeparatorPattern(const QString &pattern) +{ + const QRegularExpression re(pattern); + QTC_ASSERT(re.isValid() && re.captureCount() >= 1, return); + d->m_annotationSeparatorPattern = re; +} + bool VcsBaseEditorWidget::supportChangeLinks() const { switch (d->m_parameters->type) { @@ -1537,6 +1554,26 @@ void VcsBaseEditorWidget::addChangeActions(QMenu *, const QString &) { } +QSet<QString> VcsBaseEditorWidget::annotationChanges() const +{ + QSet<QString> changes; + QString text = toPlainText(); + QStringRef txt(&text); + if (txt.isEmpty()) + return changes; + if (d->m_annotationSeparatorPattern.isValid()) { + const QRegularExpressionMatch match = d->m_annotationSeparatorPattern.match(txt); + if (match.hasMatch()) + txt.truncate(match.capturedStart()); + } + QRegularExpressionMatchIterator i = d->m_annotationEntryPattern.globalMatch(txt); + while (i.hasNext()) { + const QRegularExpressionMatch match = i.next(); + changes.insert(match.captured(1)); + } + return changes; +} + QString VcsBaseEditorWidget::decorateVersion(const QString &revision) const { return revision; diff --git a/src/plugins/vcsbase/vcsbaseeditor.h b/src/plugins/vcsbase/vcsbaseeditor.h index 863d300d62..caf2d4575d 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.h +++ b/src/plugins/vcsbase/vcsbaseeditor.h @@ -148,6 +148,10 @@ protected: void setDiffFilePattern(const QRegExp &pattern); // Pattern for log entry. hash/revision number must be in the first capture group void setLogEntryPattern(const QRegExp &pattern); + // Pattern for annotation entry. hash/revision number must be in the first capture group + void setAnnotationEntryPattern(const QString &pattern); + // Pattern for annotation separator. Lookup will stop on match. + void setAnnotationSeparatorPattern(const QString &pattern); virtual bool supportChangeLinks() const; virtual QString fileNameForLine(int line) const; @@ -246,7 +250,7 @@ protected: // Implement to return a set of change identifiers in // annotation mode - virtual QSet<QString> annotationChanges() const = 0; + QSet<QString> annotationChanges() const; // Implement to identify a change number at the cursor position virtual QString changeUnderCursor(const QTextCursor &) const = 0; // Factory functions for highlighters |