Tools: extend RegExp utility
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <qlabel.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qvalidator.h>
|
||||
|
||||
RegExpDialog::RegExpDialog(QWidget* parent)
|
||||
: QDialog(parent), ui(new Ui_RegExpDialog())
|
||||
@@ -35,8 +36,25 @@ RegExpDialog::RegExpDialog(QWidget* parent)
|
||||
ui->setupUi(this);
|
||||
rxhilighter = new RegExpSyntaxHighlighter(ui->textEdit1);
|
||||
|
||||
connect(ui->lineEdit1, SIGNAL(textChanged(const QString &)),
|
||||
this, SLOT(performRegExp()));
|
||||
validator = new QRegularExpressionValidator(this);
|
||||
ui->lineEdit->setValidator(validator);
|
||||
|
||||
connect(ui->lineEditRegExp, &QLineEdit::textChanged,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->caseInsensitiveOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->invertedGreedinessOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->dotMatchesEverythingOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->multilineOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->extendedPatternSyntaxOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->dontCaptureOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
connect(ui->useUnicodePropertiesOption, &QCheckBox::toggled,
|
||||
this, &RegExpDialog::performRegExp);
|
||||
}
|
||||
|
||||
RegExpDialog::~RegExpDialog()
|
||||
@@ -46,20 +64,41 @@ RegExpDialog::~RegExpDialog()
|
||||
|
||||
void RegExpDialog::performRegExp()
|
||||
{
|
||||
QString txt = ui->lineEdit1->text();
|
||||
QString txt = ui->lineEditRegExp->text();
|
||||
if (txt.isEmpty()) {
|
||||
rxhilighter->resethighlight();
|
||||
return;
|
||||
}
|
||||
|
||||
QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
|
||||
if (ui->checkBox1->isChecked()) {
|
||||
if (ui->caseInsensitiveOption->isChecked()) {
|
||||
options |= QRegularExpression::CaseInsensitiveOption;
|
||||
}
|
||||
if (ui->checkBox3->isChecked()) {
|
||||
|
||||
if (ui->invertedGreedinessOption->isChecked()) {
|
||||
options |= QRegularExpression::InvertedGreedinessOption;
|
||||
}
|
||||
|
||||
if (ui->dotMatchesEverythingOption->isChecked()) {
|
||||
options |= QRegularExpression::DotMatchesEverythingOption;
|
||||
}
|
||||
|
||||
if (ui->multilineOption->isChecked()) {
|
||||
options |= QRegularExpression::MultilineOption;
|
||||
}
|
||||
|
||||
if (ui->extendedPatternSyntaxOption->isChecked()) {
|
||||
options |= QRegularExpression::ExtendedPatternSyntaxOption;
|
||||
}
|
||||
|
||||
if (ui->dontCaptureOption->isChecked()) {
|
||||
options |= QRegularExpression::DontCaptureOption;
|
||||
}
|
||||
|
||||
if (ui->useUnicodePropertiesOption->isChecked()) {
|
||||
options |= QRegularExpression::UseUnicodePropertiesOption;
|
||||
}
|
||||
|
||||
QRegularExpression rx(txt, options);
|
||||
|
||||
// evaluate regular expression
|
||||
@@ -70,6 +109,7 @@ void RegExpDialog::performRegExp()
|
||||
}
|
||||
|
||||
rxhilighter->highlightMatchedText(rx);
|
||||
validator->setRegularExpression(rx);
|
||||
}
|
||||
|
||||
void RegExpDialog::about()
|
||||
@@ -117,36 +157,7 @@ void RegExpSyntaxHighlighter::highlightBlock (const QString & text)
|
||||
last = pos;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
int RegExpSyntaxHighlighter::highlightParagraph ( const QString & text, int /*endStateOfLastPara*/ )
|
||||
{
|
||||
// reset format
|
||||
QFont font = textEdit()->font();
|
||||
font.setBold( false );
|
||||
setFormat(0, text.length(), font, Qt::black );
|
||||
|
||||
if (regexp.isEmpty())
|
||||
return 0; // empty regular expression
|
||||
|
||||
int pos = 0;
|
||||
int last = -1;
|
||||
font.setBold(true);
|
||||
|
||||
while ( (pos = regexp.indexIn(text, pos)) != -1 ) {
|
||||
if (last == pos)
|
||||
break;
|
||||
QString sub = text.mid( pos, regexp.matchedLength());
|
||||
if (!sub.isEmpty()) {
|
||||
setFormat(pos, sub.length(), font, Qt::blue );
|
||||
}
|
||||
|
||||
pos += regexp.matchedLength();
|
||||
last=pos;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
void RegExpSyntaxHighlighter::highlightMatchedText(const QRegularExpression& rx)
|
||||
{
|
||||
regexp = rx;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <qsyntaxhighlighter.h>
|
||||
#include <qtextedit.h>
|
||||
|
||||
class QRegularExpressionValidator;
|
||||
class RegExpSyntaxHighlighter;
|
||||
class Ui_RegExpDialog;
|
||||
class RegExpDialog : public QDialog
|
||||
@@ -45,6 +46,7 @@ protected Q_SLOTS:
|
||||
|
||||
private:
|
||||
RegExpSyntaxHighlighter* rxhilighter;
|
||||
QRegularExpressionValidator* validator;
|
||||
Ui_RegExpDialog* ui;
|
||||
};
|
||||
|
||||
@@ -57,7 +59,6 @@ public:
|
||||
~RegExpSyntaxHighlighter();
|
||||
|
||||
void highlightBlock (const QString & text);
|
||||
//int highlightParagraph ( const QString & text, int endStateOfLastPara );
|
||||
void highlightMatchedText( const QRegularExpression& );
|
||||
void resethighlight();
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>519</width>
|
||||
<height>285</height>
|
||||
<width>693</width>
|
||||
<height>563</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -16,63 +16,104 @@
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<property name="margin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel1">
|
||||
<property name="text">
|
||||
<string>Text:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QTextEdit" name="textEdit1"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Case insensitive</string>
|
||||
<string>Validator</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox3">
|
||||
<property name="text">
|
||||
<string>Minimal</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="textLabel2">
|
||||
<property name="text">
|
||||
<string>Regular Expression:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLineEdit" name="lineEdit1"/>
|
||||
<item row="3" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Pattern options</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="caseInsensitiveOption">
|
||||
<property name="text">
|
||||
<string>Case insensitive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QCheckBox" name="multilineOption">
|
||||
<property name="text">
|
||||
<string>Multiline</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="invertedGreedinessOption">
|
||||
<property name="text">
|
||||
<string>Inverted greediness</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="dotMatchesEverythingOption">
|
||||
<property name="text">
|
||||
<string>Dot matches everything</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="extendedPatternSyntaxOption">
|
||||
<property name="text">
|
||||
<string>Extended pattern syntax</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QCheckBox" name="dontCaptureOption">
|
||||
<property name="text">
|
||||
<string>Don't capture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QCheckBox" name="useUnicodePropertiesOption">
|
||||
<property name="text">
|
||||
<string>Unicode properties</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="6" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@@ -121,29 +162,33 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonHelp">
|
||||
<property name="text">
|
||||
<string>&Help</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLineEdit" name="lineEditRegExp"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="textLabel1">
|
||||
<property name="text">
|
||||
<string>Text:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<tabstops>
|
||||
<tabstop>textEdit1</tabstop>
|
||||
<tabstop>checkBox1</tabstop>
|
||||
<tabstop>checkBox2</tabstop>
|
||||
<tabstop>checkBox3</tabstop>
|
||||
<tabstop>lineEdit1</tabstop>
|
||||
<tabstop>lineEdit</tabstop>
|
||||
<tabstop>caseInsensitiveOption</tabstop>
|
||||
<tabstop>invertedGreedinessOption</tabstop>
|
||||
<tabstop>dotMatchesEverythingOption</tabstop>
|
||||
<tabstop>multilineOption</tabstop>
|
||||
<tabstop>extendedPatternSyntaxOption</tabstop>
|
||||
<tabstop>dontCaptureOption</tabstop>
|
||||
<tabstop>useUnicodePropertiesOption</tabstop>
|
||||
<tabstop>lineEditRegExp</tabstop>
|
||||
<tabstop>buttonClose</tabstop>
|
||||
<tabstop>buttonHelp</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
||||
Reference in New Issue
Block a user