diff options
author | Eike Ziller <eike.ziller@qt.io> | 2020-02-26 08:35:05 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2020-02-26 08:35:05 +0100 |
commit | 61dc14b67f493aaed42f9fe34ddbd655eaf96b5e (patch) | |
tree | e97d965c71fdeb224a5567eae05e82360fdcd2f0 /src/plugins/vcsbase | |
parent | 23946de45755ce58d55004bf3e508a83d6299573 (diff) | |
parent | fa59e02f89cc581f27095fb63134a6eb3c554f95 (diff) |
Merge remote-tracking branch 'origin/4.12'
Change-Id: I3e7049da2c3da6f784e3cb3407c22ada556e5d24
Diffstat (limited to 'src/plugins/vcsbase')
-rw-r--r-- | src/plugins/vcsbase/cleandialog.cpp | 1 | ||||
-rw-r--r-- | src/plugins/vcsbase/diffandloghighlighter.cpp | 18 | ||||
-rw-r--r-- | src/plugins/vcsbase/diffandloghighlighter.h | 5 | ||||
-rw-r--r-- | src/plugins/vcsbase/nicknamedialog.cpp | 1 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbaseeditor.cpp | 96 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbaseeditor.h | 11 | ||||
-rw-r--r-- | src/plugins/vcsbase/vcsbasesubmiteditor.cpp | 1 |
7 files changed, 91 insertions, 42 deletions
diff --git a/src/plugins/vcsbase/cleandialog.cpp b/src/plugins/vcsbase/cleandialog.cpp index 95495d8ba3..0f358ab1de 100644 --- a/src/plugins/vcsbase/cleandialog.cpp +++ b/src/plugins/vcsbase/cleandialog.cpp @@ -145,7 +145,6 @@ CleanDialog::CleanDialog(QWidget *parent) : d(new Internal::CleanDialogPrivate) { setModal(true); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); d->ui.setupUi(this); d->ui.buttonBox->addButton(tr("Delete..."), QDialogButtonBox::AcceptRole); diff --git a/src/plugins/vcsbase/diffandloghighlighter.cpp b/src/plugins/vcsbase/diffandloghighlighter.cpp index afdc72cc67..a2f0836f35 100644 --- a/src/plugins/vcsbase/diffandloghighlighter.cpp +++ b/src/plugins/vcsbase/diffandloghighlighter.cpp @@ -30,7 +30,7 @@ #include <utils/qtcassert.h> #include <QDebug> -#include <QRegExp> +#include <QRegularExpression> /*! \class VcsBase::DiffAndLogHighlighter @@ -88,8 +88,9 @@ static inline QTextCharFormat invertedColorFormat(const QTextCharFormat &in) class DiffAndLogHighlighterPrivate { public: - DiffAndLogHighlighterPrivate(DiffAndLogHighlighter *q_, const QRegExp &filePattern, - const QRegExp &changePattern) : + DiffAndLogHighlighterPrivate(DiffAndLogHighlighter *q_, + const QRegularExpression &filePattern, + const QRegularExpression &changePattern) : q(q_), m_filePattern(filePattern), m_changePattern(changePattern), @@ -106,8 +107,8 @@ public: DiffAndLogHighlighter *const q; - mutable QRegExp m_filePattern; - mutable QRegExp m_changePattern; + const QRegularExpression m_filePattern; + const QRegularExpression m_changePattern; const QString m_locationIndicator; const QChar m_diffInIndicator; const QChar m_diffOutIndicator; @@ -120,9 +121,9 @@ TextEditor::TextStyle DiffAndLogHighlighterPrivate::analyzeLine(const QString &t { // Do not match on git "--- a/" as a deleted line, check // file first - if (m_filePattern.indexIn(text) == 0) + if (m_filePattern.match(text).capturedStart() == 0) return TextEditor::C_DIFF_FILE; - if (m_changePattern.indexIn(text) == 0) + if (m_changePattern.match(text).capturedStart() == 0) return TextEditor::C_LOG_CHANGE_LINE; if (text.startsWith(m_diffInIndicator)) return TextEditor::C_ADDED_LINE; @@ -141,7 +142,8 @@ void DiffAndLogHighlighterPrivate::updateOtherFormats() } // --- DiffAndLogHighlighter -DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern) : +DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegularExpression &filePattern, + const QRegularExpression &changePattern) : TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(nullptr)), d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern)) { diff --git a/src/plugins/vcsbase/diffandloghighlighter.h b/src/plugins/vcsbase/diffandloghighlighter.h index 3847f287ba..c43f4a510d 100644 --- a/src/plugins/vcsbase/diffandloghighlighter.h +++ b/src/plugins/vcsbase/diffandloghighlighter.h @@ -30,7 +30,7 @@ #include <texteditor/syntaxhighlighter.h> QT_BEGIN_NAMESPACE -class QRegExp; +class QRegularExpression; class QTextCharFormat; QT_END_NAMESPACE @@ -45,7 +45,8 @@ class VCSBASE_EXPORT DiffAndLogHighlighter : public TextEditor::SyntaxHighlighte Q_OBJECT public: - explicit DiffAndLogHighlighter(const QRegExp &filePattern, const QRegExp &changePattern); + explicit DiffAndLogHighlighter(const QRegularExpression &filePattern, + const QRegularExpression &changePattern); ~DiffAndLogHighlighter() override; void highlightBlock(const QString &text) override; diff --git a/src/plugins/vcsbase/nicknamedialog.cpp b/src/plugins/vcsbase/nicknamedialog.cpp index 11737ec08b..799ef29faf 100644 --- a/src/plugins/vcsbase/nicknamedialog.cpp +++ b/src/plugins/vcsbase/nicknamedialog.cpp @@ -169,7 +169,6 @@ NickNameDialog::NickNameDialog(QStandardItemModel *model, QWidget *parent) : m_model(model), m_filterModel(new QSortFilterProxyModel(this)) { - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); m_ui->setupUi(this); okButton()->setEnabled(false); diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 0471968dcf..aac8696c0e 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -50,7 +50,7 @@ #include <QDebug> #include <QFileInfo> #include <QFile> -#include <QRegExp> +#include <QRegularExpression> #include <QSet> #include <QTextCodec> #include <QUrl> @@ -402,7 +402,7 @@ private: }; UrlData m_urlData; - QRegExp m_pattern; + QRegularExpression m_pattern; }; UrlTextCursorHandler::UrlTextCursorHandler(VcsBaseEditorWidget *editorWidget) @@ -424,16 +424,17 @@ bool UrlTextCursorHandler::findContentsUnderCursor(const QTextCursor &cursor) const QString line = cursorForUrl.selectedText(); const int cursorCol = cursor.columnNumber(); int urlMatchIndex = -1; - do { - urlMatchIndex = m_pattern.indexIn(line, urlMatchIndex + 1); - if (urlMatchIndex != -1) { - const QString url = m_pattern.cap(0); - if (urlMatchIndex <= cursorCol && cursorCol <= urlMatchIndex + url.length()) { - m_urlData.startColumn = urlMatchIndex; - m_urlData.url = url; - } + QRegularExpressionMatchIterator i = m_pattern.globalMatch(line); + while (i.hasNext()) { + const QRegularExpressionMatch match = i.next(); + urlMatchIndex = match.capturedStart(); + const QString url = match.captured(0); + if (urlMatchIndex <= cursorCol && cursorCol <= urlMatchIndex + url.length()) { + m_urlData.startColumn = urlMatchIndex; + m_urlData.url = url; + break; } - } while (urlMatchIndex != -1 && m_urlData.startColumn == -1); + }; } return m_urlData.startColumn != -1; @@ -474,7 +475,7 @@ QString UrlTextCursorHandler::currentContents() const void UrlTextCursorHandler::setUrlPattern(const QString &pattern) { - m_pattern = QRegExp(pattern); + m_pattern = QRegularExpression(pattern); QTC_ASSERT(m_pattern.isValid(), return); } @@ -554,8 +555,10 @@ public: QString m_workingDirectory; - QRegExp m_diffFilePattern; - QRegExp m_logEntryPattern; + QRegularExpression m_diffFilePattern; + QRegularExpression 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; @@ -649,16 +652,34 @@ void VcsBaseEditorWidget::setParameters(const VcsBaseEditorParameters *parameter d->m_parameters = parameters; } -void VcsBaseEditorWidget::setDiffFilePattern(const QRegExp &pattern) +static void regexpFromString( + const QString &pattern, + QRegularExpression *regexp, + QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption) +{ + const QRegularExpression re(pattern, options); + QTC_ASSERT(re.isValid() && re.captureCount() >= 1, return); + *regexp = re; +} + +void VcsBaseEditorWidget::setDiffFilePattern(const QString &pattern) { - QTC_ASSERT(pattern.isValid() && pattern.captureCount() >= 1, return); - d->m_diffFilePattern = pattern; + regexpFromString(pattern, &d->m_diffFilePattern); } -void VcsBaseEditorWidget::setLogEntryPattern(const QRegExp &pattern) +void VcsBaseEditorWidget::setLogEntryPattern(const QString &pattern) { - QTC_ASSERT(pattern.isValid() && pattern.captureCount() >= 1, return); - d->m_logEntryPattern = pattern; + regexpFromString(pattern, &d->m_logEntryPattern); +} + +void VcsBaseEditorWidget::setAnnotationEntryPattern(const QString &pattern) +{ + regexpFromString(pattern, &d->m_annotationEntryPattern, QRegularExpression::MultilineOption); +} + +void VcsBaseEditorWidget::setAnnotationSeparatorPattern(const QString &pattern) +{ + regexpFromString(pattern, &d->m_annotationSeparatorPattern); } bool VcsBaseEditorWidget::supportChangeLinks() const @@ -864,7 +885,7 @@ void VcsBaseEditorWidget::slotPopulateDiffBrowser() for (QTextBlock it = document()->begin(); it != cend; it = it.next(), lineNumber++) { const QString text = it.text(); // Check for a new diff section (not repeating the last filename) - if (d->m_diffFilePattern.indexIn(text) == 0) { + if (d->m_diffFilePattern.match(text).capturedStart() == 0) { const QString file = fileNameFromDiffSpecification(it); if (!file.isEmpty() && lastFileName != file) { lastFileName = file; @@ -888,9 +909,10 @@ void VcsBaseEditorWidget::slotPopulateLogBrowser() for (QTextBlock it = document()->begin(); it != cend; it = it.next(), lineNumber++) { const QString text = it.text(); // Check for a new log section (not repeating the last filename) - if (d->m_logEntryPattern.indexIn(text) != -1) { + const QRegularExpressionMatch match = d->m_logEntryPattern.match(text); + if (match.hasMatch()) { d->m_entrySections.push_back(d->m_entrySections.empty() ? 0 : lineNumber); - QString entry = d->m_logEntryPattern.cap(1); + QString entry = match.captured(1); QString subject = revisionSubject(it); if (!subject.isEmpty()) { if (subject.length() > 100) { @@ -1198,7 +1220,8 @@ DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const unicode.append(QLatin1Char('\n')); for (block = block.next() ; block.isValid() ; block = block.next()) { const QString line = block.text(); - if (checkChunkLine(line, &chunkStart) || d->m_diffFilePattern.indexIn(line) == 0) { + if (checkChunkLine(line, &chunkStart) + || d->m_diffFilePattern.match(line).capturedStart() == 0) { break; } else { unicode += line; @@ -1518,8 +1541,9 @@ QString VcsBaseEditorWidget::fileNameFromDiffSpecification(const QTextBlock &inB QString fileName; for (QTextBlock block = inBlock; block.isValid(); block = block.previous()) { const QString line = block.text(); - if (d->m_diffFilePattern.indexIn(line) != -1) { - QString cap = d->m_diffFilePattern.cap(1); + const QRegularExpressionMatch match = d->m_diffFilePattern.match(line); + if (match.hasMatch()) { + QString cap = match.captured(1); if (header) header->prepend(line + QLatin1String("\n")); if (fileName.isEmpty() && !cap.isEmpty()) @@ -1537,6 +1561,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.pattern().isEmpty()) { + 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..6e32037b68 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.h +++ b/src/plugins/vcsbase/vcsbaseeditor.h @@ -32,7 +32,6 @@ #include <QSet> QT_BEGIN_NAMESPACE -class QRegExp; class QTextCodec; class QTextCursor; QT_END_NAMESPACE @@ -145,9 +144,13 @@ protected: // virtual functions). VcsBaseEditorWidget(); // Pattern for diff header. File name must be in the first capture group - void setDiffFilePattern(const QRegExp &pattern); + void setDiffFilePattern(const QString &pattern); // Pattern for log entry. hash/revision number must be in the first capture group - void setLogEntryPattern(const QRegExp &pattern); + void setLogEntryPattern(const QString &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 +249,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 diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp index 3dec0aeaef..fa0e19928d 100644 --- a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp +++ b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp @@ -163,6 +163,7 @@ VcsBaseSubmitEditorPrivate::VcsBaseSubmitEditorPrivate(SubmitEditorWidget *edito VcsBaseSubmitEditor::VcsBaseSubmitEditor(SubmitEditorWidget *editorWidget) { + setWidget(editorWidget); d = new VcsBaseSubmitEditorPrivate(editorWidget, this); } |