-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
138 lines (104 loc) · 4.59 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Regular Expression Tester v0.2");
regExp = new QRegExp();
regExp->setPatternSyntax(QRegExp::RegExp2);
QStringList colors;
colors << "blueviolet" << "tomato" << "cyan" << "blue" << "magenta" << "yellowgreen"
<< "darkRed" << "darkBlue" << "darkMagenta" << "darkCyan" << "darkorange"
<< "thistle" << "skyblue" << "mediumvioletred" << "brown" << "peachpuff";
/*-------- Regual Expression input ---------*/
QPushButton *button = new QPushButton("Match");
button->setFixedWidth(50);
button->setShortcut(QKeySequence::QKeySequence("Ctrl+M"));
QLabel *label1 = new QLabel("Pattern Syntax:", this);
QComboBox *patternSyntaxSelector = new QComboBox(this);
QStringList patternList;
patternList << "RegExp" << "Wildcard" << "FixedString" << "RegExp2" << "WildcardUnix" << "W3CXmlSchema11";
patternSyntaxSelector->addItems(patternList);
patternSyntaxSelector->setCurrentIndex(3); //Default value
QLabel *label2 = new QLabel("Minimal Match:", this);
QComboBox *minMatchSelector = new QComboBox(this);
minMatchSelector->addItem("False"); //Default value
minMatchSelector->addItem("True");
QToolBar *toolBar = new QToolBar(this);
toolBar->addWidget(button);
toolBar->addWidget(label1);
toolBar->addWidget(patternSyntaxSelector);
toolBar->addSeparator();
toolBar->addWidget(label2);
toolBar->addWidget(minMatchSelector);
regExpInput = new RegExpEdit(this);
regExpInput->setColors(colors);
// regExpInput->setText("(\\d*) (.*)");
QWidget *tempWidget1 = new QWidget(this);
QVBoxLayout *tempWidget1Layout = new QVBoxLayout(tempWidget1);
tempWidget1Layout->setContentsMargins(0,0,0,0);
tempWidget1Layout->setSpacing(0);
tempWidget1Layout->addWidget(regExpInput);
tempWidget1Layout->addWidget(toolBar);
/*-------- Data input ---------------------*/
dataInput = new TextEdit(this);
dataInput->setColors(colors);
// dataInput->setText("123 abcd");
/*-------- Db Editor --------------------*/
RegExpDbEditor *dbEditor = new RegExpDbEditor(this);
/*-------- Status bar -------------*/
QStatusBar *statusBar = new QStatusBar(this);
QLabel *barLabel1 = new QLabel("Exact Match:", this);
exactMatchStatus = new QLabel(this);
exactMatchStatus->setFrameStyle(QFrame::Panel | QFrame::Sunken);
exactMatchStatus->setFixedWidth(70);
QLabel *barLabel2 = new QLabel("Capture Count:", this);
matchCount = new QLabel(this);
matchCount->setFrameStyle(QFrame::Panel | QFrame::Sunken);
matchCount->setFixedWidth(70);
statusBar->addPermanentWidget(barLabel1);
statusBar->addPermanentWidget(exactMatchStatus);
statusBar->addPermanentWidget(barLabel2);
statusBar->addPermanentWidget(matchCount);
setStatusBar(statusBar);
/*-------- Right splitter --------------------*/
QSplitter *splitter1 = new QSplitter(Qt::Vertical, this);
splitter1->addWidget(tempWidget1);
splitter1->addWidget(dataInput);
splitter1->setStretchFactor(0, 1);
splitter1->setStretchFactor(1, 3);
/*-------- Main splitter --------------------*/
QSplitter *splitter2 = new QSplitter(this);
splitter2->addWidget(dbEditor);
splitter2->addWidget(splitter1);
splitter2->setStretchFactor(0, 2);
splitter2->setStretchFactor(1, 4);
/*-------- Central widget ---------------------*/
setCentralWidget(splitter2);
connect(button, SIGNAL(pressed()), this, SLOT(match()));
connect(regExpInput, SIGNAL(returnPressed()), this, SLOT(match()));
connect(patternSyntaxSelector, SIGNAL(activated(int)), this, SLOT(setPatternSyntax(int)));
connect(minMatchSelector, SIGNAL(activated(int)), this, SLOT(setMinimal(int)));
connect(dbEditor, SIGNAL(insertRegExp(QString)), regExpInput, SLOT(insertPlainText(QString)));
}
MainWindow::~MainWindow()
{
}
void MainWindow::match()
{
regExpInput->highlight();
QString regExpStr = regExpInput->toPlainText();
regExp->setPattern(regExpStr);
QString result;
dataInput->exactMatch(regExp, &result);
exactMatchStatus->setText(result);
int captureCount = regExp->captureCount();
matchCount->setText(QString::number(captureCount));
}
void MainWindow::setPatternSyntax(int pattern)
{
regExp->setPatternSyntax((QRegExp::PatternSyntax)pattern);
}
void MainWindow::setMinimal(int minimal)
{
regExp->setMinimal(minimal);
}