diff --git a/src/plugins/mesonprojectmanager/CMakeLists.txt b/src/plugins/mesonprojectmanager/CMakeLists.txt index d39aaebabee..c00334e188c 100644 --- a/src/plugins/mesonprojectmanager/CMakeLists.txt +++ b/src/plugins/mesonprojectmanager/CMakeLists.txt @@ -3,8 +3,6 @@ add_qtc_plugin(MesonProjectManager DEPENDS QmlJS PLUGIN_DEPENDS Core ProjectExplorer TextEditor QtSupport SOURCES - arrayoptionlineedit.cpp - arrayoptionlineedit.h buildoptions.h buildoptionsmodel.cpp buildoptionsmodel.h diff --git a/src/plugins/mesonprojectmanager/arrayoptionlineedit.cpp b/src/plugins/mesonprojectmanager/arrayoptionlineedit.cpp deleted file mode 100644 index 11aa45e31b5..00000000000 --- a/src/plugins/mesonprojectmanager/arrayoptionlineedit.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2020 Alexis Jeandet. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "arrayoptionlineedit.h" - -namespace MesonProjectManager::Internal { - -ArrayOptionLineEdit::ArrayOptionLineEdit(QWidget *parent) - : QPlainTextEdit(parent) -{ - m_highLighter = new RegexHighlighter(this); - m_highLighter->setDocument(this->document()); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setLineWrapMode(QPlainTextEdit::NoWrap); - QFontMetrics metrics(this->font()); - int lineHeight = metrics.lineSpacing(); - this->setFixedHeight(lineHeight * 1.5); -} - -QStringList ArrayOptionLineEdit::options() -{ - return m_highLighter->options(this->toPlainText()); -} - -void ArrayOptionLineEdit::keyPressEvent(QKeyEvent *e) -{ - if (e->key() != Qt::Key_Return) - return QPlainTextEdit::keyPressEvent(e); - e->accept(); -} - -RegexHighlighter::RegexHighlighter(QWidget *parent) - : QSyntaxHighlighter(parent) -{ - m_format.setUnderlineStyle(QTextCharFormat::SingleUnderline); - m_format.setUnderlineColor(QColor(180, 180, 180)); - m_format.setBackground(QBrush(QColor(180, 180, 230, 80))); -} - -QStringList RegexHighlighter::options(const QString &text) -{ - QRegularExpressionMatchIterator i = m_regex.globalMatch(text); - QStringList op; - while (i.hasNext()) { - QRegularExpressionMatch match = i.next(); - for (int j = 1; j <= match.lastCapturedIndex(); j++) { - auto str = match.captured(j); - if (!str.isEmpty()) - op.push_back(str); - } - } - return op; -} - -void RegexHighlighter::highlightBlock(const QString &text) -{ - QRegularExpressionMatchIterator i = m_regex.globalMatch(text); - while (i.hasNext()) { - QRegularExpressionMatch match = i.next(); - for (int j = 1; j <= match.lastCapturedIndex(); j++) { - setFormat(match.capturedStart(j), match.capturedLength(j), m_format); - } - } -} - -} // namespace MesonProjectManager::Internal diff --git a/src/plugins/mesonprojectmanager/arrayoptionlineedit.h b/src/plugins/mesonprojectmanager/arrayoptionlineedit.h deleted file mode 100644 index c9b8cb6b2c1..00000000000 --- a/src/plugins/mesonprojectmanager/arrayoptionlineedit.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2020 Alexis Jeandet. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include -#include -#include -#include - -namespace MesonProjectManager::Internal { - -class RegexHighlighter : public QSyntaxHighlighter -{ - const QRegularExpression m_regex{R"('([^']+)'+|([^', ]+)[, ]*)"}; - QTextCharFormat m_format; - -public: - RegexHighlighter(QWidget *parent); - void highlightBlock(const QString &text) override; - QStringList options(const QString &text); -}; - -class ArrayOptionLineEdit : public QPlainTextEdit -{ - Q_OBJECT - RegexHighlighter *m_highLighter; - -public: - ArrayOptionLineEdit(QWidget *parent = nullptr); - QStringList options(); - -protected: - void keyPressEvent(QKeyEvent *e) override; -}; - -} // namespace MesonProjectManager::Internal diff --git a/src/plugins/mesonprojectmanager/buildoptionsmodel.cpp b/src/plugins/mesonprojectmanager/buildoptionsmodel.cpp index 5dff5f66b28..702176b517a 100644 --- a/src/plugins/mesonprojectmanager/buildoptionsmodel.cpp +++ b/src/plugins/mesonprojectmanager/buildoptionsmodel.cpp @@ -3,18 +3,91 @@ #include "buildoptionsmodel.h" -#include "arrayoptionlineedit.h" #include "mesonprojectmanagertr.h" +#include #include #include #include -#include -#include -#include +#include +#include +#include namespace MesonProjectManager::Internal { +static QRegularExpression ®Exp() +{ + static QRegularExpression s_regexp{R"('([^']+)'+|([^', ]+)[, ]*)"}; + return s_regexp; +} + +class RegexHighlighter final : public QSyntaxHighlighter +{ +public: + RegexHighlighter(QWidget *parent) : QSyntaxHighlighter(parent) + { + m_format.setUnderlineStyle(QTextCharFormat::SingleUnderline); + m_format.setUnderlineColor(QColor(180, 180, 180)); + m_format.setBackground(QBrush(QColor(180, 180, 230, 80))); + } + + void highlightBlock(const QString &text) final + { + QRegularExpressionMatchIterator i = regExp().globalMatch(text); + while (i.hasNext()) { + const QRegularExpressionMatch match = i.next(); + for (int j = 1; j <= match.lastCapturedIndex(); j++) + setFormat(match.capturedStart(j), match.capturedLength(j), m_format); + } + } + + QStringList options(const QString &text) const + { + QRegularExpressionMatchIterator i = regExp().globalMatch(text); + QStringList op; + while (i.hasNext()) { + const QRegularExpressionMatch match = i.next(); + for (int j = 1; j <= match.lastCapturedIndex(); j++) { + auto str = match.captured(j); + if (!str.isEmpty()) + op.push_back(str); + } + } + return op; + } + +private: + QTextCharFormat m_format; +}; + +class ArrayOptionLineEdit final : public QPlainTextEdit +{ + Q_OBJECT + +public: + ArrayOptionLineEdit(QWidget *parent = nullptr) : QPlainTextEdit(parent) + { + m_highLighter = new RegexHighlighter(this); + m_highLighter->setDocument(document()); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setLineWrapMode(QPlainTextEdit::NoWrap); + setFixedHeight(QFontMetrics(font()).lineSpacing() * 1.5); + } + QStringList options() const { return m_highLighter->options(toPlainText()); } + +protected: + void keyPressEvent(QKeyEvent *e) final + { + if (e->key() != Qt::Key_Return) + return QPlainTextEdit::keyPressEvent(e); + e->accept(); + } + +private: + RegexHighlighter *m_highLighter = nullptr; +}; + // this could be relaxed once we have something able to link reliably meson build type // to QTC build type and update it, this must not break any features like tests/debug/profiling... static const QStringList lockedOptions = {"buildtype", "debug", "backend", "optimization"}; @@ -192,3 +265,5 @@ void BuildOptionDelegate::setModelData(QWidget *editor, } } // namespace MesonProjectManager::Internal + +#include "buildoptionsmodel.moc" diff --git a/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs b/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs index 7c93d86ec7f..ac82d811029 100644 --- a/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs +++ b/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs @@ -30,8 +30,6 @@ Project { "target.h", "mesonpluginconstants.h", "mesonprojectplugin.cpp", - "arrayoptionlineedit.cpp", - "arrayoptionlineedit.h", "buildoptionsmodel.cpp", "buildoptionsmodel.h", "mesonbuildconfiguration.cpp",