-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex_find.cpp
166 lines (128 loc) · 4.77 KB
/
regex_find.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "regex_find.h"
#include "ui_regex_find.h"
#include <iostream>
#include <qDebug>
#include <QRegularExpression>
#include "global.h"
#include <QSettings>
#include "load_thread.h"
regex_find::regex_find(QWidget *parent) :
QWidget(parent),
ui(new Ui::regex_find)
{
ui->setupUi(this);
// QImage image("close.png");
// ui->label_2->setPixmap(QPixmap::fromImage(image));
ui->textEdit_2->setVisible(false);
//ui->pushButton->setVisible(false);
ui->textEdit->setStyleSheet("selection-background-color: #0078d7;selection-color: white;");
// QSettings *mysetting = new QSettings("setting.ini", QSettings::IniFormat);
// QString str1 = mysetting->value("regexFind/RegularExpressionStr").toString();
// if(str1!="")ui->lineEdit->setText(str1);
// QString str2 = mysetting->value("regexFind/SearchStr").toString();
// if(str2!="")ui->textEdit->setText(str2);
QObject::connect(&load2, SIGNAL(loadback()), this, SLOT(myload2()));
load2.start();
}
regex_find::~regex_find()
{
// QSettings *mysetting = new QSettings("setting.ini", QSettings::IniFormat);
// QString str1 = ui->lineEdit->text();
// mysetting->setValue("regexFind/regularExpressionStr",str1);
// QString str2 = ui->textEdit->toPlainText();
// mysetting->setValue("regexFind/SearchStr",str2);
//myconfig->setValue("mainwindow/tagList",tagList.join(","));
//myMainWindow->saveTag();
//alwaysSaveContent();
delete ui;
}
void regex_find::on_pushButton_2_clicked()
{
search();
QString myRegularExpressionStr = ui->lineEdit->text();
QRegularExpression regularExpression(myRegularExpressionStr);
ui->textEdit->find(regularExpression,QTextDocument::FindBackward);
}
void regex_find::on_pushButton_3_clicked()
{
search();
QString myRegularExpressionStr = ui->lineEdit->text();
QRegularExpression regularExpression(myRegularExpressionStr);
ui->textEdit->find(regularExpression);
}
//void regex_find::on_pushButton_clicked()
//{
// search();
//}
void regex_find::on_lineEdit_textChanged(const QString &arg1)
{
regularExpressionStr = ui->lineEdit->text();
isRegularExpressionStrChange = true;
// save_thread saveThread;
// saveThread.threadId=nextThreadId++;
// threadList.append(&saveThread);
// QString idString = QString::number(id);
// saveThread.configName=idString+"regexFind/RegularExpressionStr";
// saveThread.configContent=ui->lineEdit->text();
// saveThread.start();
}
void regex_find::on_textEdit_textChanged()
{
searchStr = ui->textEdit->toPlainText();
isSearchStrChange = true;
// save_thread saveThread;
// saveThread.threadId=nextThreadId++;
// threadList.append(&saveThread);
// QString idString = QString::number(id);
// saveThread.configName=idString+"regexFind/SearchStr";
// saveThread.configContent=ui->textEdit->toPlainText();
// saveThread.start();
}
void regex_find::search()
{
QString myRegularExpressionStr = ui->lineEdit->text();
QString myInputStr = ui->textEdit->toPlainText();
QString myRegularExpressionStr2 = "("+myRegularExpressionStr+")";
QRegularExpression regularExpression(myRegularExpressionStr2);
myInputStr.replace(regularExpression,"<b id=\"result\">\\1</b>");
myInputStr.replace("\n","<br/>");
QString style = "<style>#result{color: red;background-color: yellow;}</style>";
myInputStr = style + myInputStr;
QString str1 = ui->textEdit->toHtml();
ui->textEdit_2->setHtml(myInputStr);
if(ui->textEdit->toHtml()!= ui->textEdit_2->toHtml()){
ui->textEdit->setHtml(myInputStr);
//qDebug()<<"change!";
}
}
void regex_find::saveContent(){
if (isRegularExpressionStrChange){
isRegularExpressionStrChange=false;
QString configName = QString::number(id)+"-regexFind/RegularExpressionStr";
myconfig->setValue(configName,regularExpressionStr);
}
if (isSearchStrChange){
isSearchStrChange=false;
QString configName = QString::number(id)+"-regexFind/SearchStr";
myconfig->setValue(configName,searchStr);
}
}
void regex_find::alwaysSaveContent(){
QString configName = QString::number(id)+"-regexFind/RegularExpressionStr";
myconfig->setValue(configName,regularExpressionStr);
QString configName2 = QString::number(id)+"-regexFind/SearchStr";
myconfig->setValue(configName2,searchStr);
}
void regex_find::myload2()
{
QString str1 = myconfig->value(QString::number(id)+"-regexFind/RegularExpressionStr").toString();
if(str1!="")ui->lineEdit->setText(str1);
regularExpressionStr = str1;
QString str2 = myconfig->value(QString::number(id)+"-regexFind/SearchStr").toString();
if(str2!="")ui->textEdit->setText(str2);
searchStr = str2;
}
void regex_find::closeEvent(QCloseEvent *event)
{
myMainWindow->removeid(id);
}