-
Notifications
You must be signed in to change notification settings - Fork 19
/
wfilterword.cpp
251 lines (205 loc) · 6.92 KB
/
wfilterword.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include "wfilterword.h"
#include "ui_wfilterword.h"
WfilterWord::WfilterWord(QWidget *parent) :
QWidget(parent),
ui(new Ui::WfilterWord)
{
ui->setupUi(this);
//ini文件
this->iniFile = QCoreApplication::applicationDirPath() + "/data/filter_signal.ini";
//输入限制
//ui->lineEdit_linenum->setValidator(new QIntValidator(0, 100, this));
ui->lineEdit_wordnum->setValidator(new QIntValidator(0, 1500, this));
//ui->lineEdit_time->setValidator(new QDoubleValidator(0.01, 10.00, 2));
//控件临时
ui->pushButton_send->setEnabled(false);
//ui->lineEdit_time->setEnabled(false);
//读取配置文件
this->readIni();
//slot
connect(ui->listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectItemFIle(QListWidgetItem*)));
//connect(ui->checkBox_dingshi, SIGNAL(clicked(bool)), this, SLOT(checkInputTime(bool)));
connect(ui->lineEdit_fenge, SIGNAL(textChanged(QString)), this, SLOT(saveIni()));
//connect(ui->lineEdit_time, SIGNAL(textChanged(QString)), this, SLOT(saveIni()));
connect(ui->lineEdit_wordnum, SIGNAL(textChanged(QString)), this, SLOT(saveIni()));
connect(ui->radioButton_order_shunxu, SIGNAL(toggled(bool)), this, SLOT(saveIni()));
//connect(ui->checkBox_dingshi, SIGNAL(toggled(bool)), this, SLOT(saveIni()));
}
WfilterWord::~WfilterWord()
{
delete ui;
}
//添加文件列表
void WfilterWord::on_pushButton_addFile_clicked()
{
WFileInfo *fileInfo = new WFileInfo;
fileInfo->openFile();
QString filePath = fileInfo->getFilePath();
if (filePath.length() > 0) {
bool isHas = this->fileList.contains(filePath);
if (isHas) {
QMessageBox::information(this, "提示", "文件已存在");
return;
}
//ui->listView->add2
QListWidgetItem *item = new QListWidgetItem;
item->setText(filePath);
ui->listWidget->addItem(item);
this->fileList<<filePath;
}
this->saveIni();
}
//选择文件
void WfilterWord::selectItemFIle(QListWidgetItem *item){
QString filePath = item->text();
QFileInfo *fileInfo = new QFileInfo(filePath);
WFileInfo *wfileInfo = new WFileInfo;
if (fileInfo->fileName().length() > 0){
WfilePipi::filePath = filePath;
QString contents = wfileInfo->getFileContents(filePath);
if (contents.length() > 0){
ui->label_select_file_name->setText(fileInfo->fileName());
ui->pushButton_send->setEnabled(true);
ui->plainTextEdit->setPlainText(contents);
} else {
int index = this->fileList.indexOf(filePath);
qDebug() << index;
this->fileList.removeAt(index);
ui->listWidget->removeItemWidget(item);
}
}
this->saveIni();
}
//点击发送按钮,组合数据,传递给全局类
void WfilterWord::on_pushButton_send_clicked()
{
this->saveIni();
//filePath
//WfilePipi::filePath = ui->label_select_file_name->text();
//contents
WFileInfo *fileInfo = new WFileInfo;
//fileInfo->setFilePath(WfilePipi::filePath);
WfilePipi::fileContents = fileInfo->getFileContents(WfilePipi::filePath);
WfilePipi::fileName = fileInfo->getFileName(WfilePipi::filePath);
//清除空格
//isTimeLimit
if (ui->checkBox_dingshi->isChecked()){
WfilePipi::isLimit = true;
} else {
WfilePipi::isLimit = false;
}
//contentList
//tempStrList 临时列表
QString fileContents = WfilePipi::fileContents;
QStringList tempStrList = fileContents.split(ui->lineEdit_fenge->text(), QString::SkipEmptyParts);
int contentsLength = tempStrList.length();
//是否随机
if (true == ui->radioButton_order_suiji->isChecked()){
for(int i = 0; i< contentsLength; i++){
int randIndex = qrand() % contentsLength;
int currentIndex = i % contentsLength;
if (randIndex != currentIndex) {
qSwap(tempStrList[randIndex], tempStrList[currentIndex]);
}
}
}
//是否是练习模式
if (true == ui->checkBox_dingshi->isChecked()){
WfilePipi::isPricatce = true;
} else {
WfilePipi::isPricatce = false;
}
int wordNum = ui->lineEdit_wordnum->text().toInt();
int wordCount = 0;
int totalCount = 0;//除去空白字符后所有的字数
QString lineInfo = "";
QString tmpStr = "";
WfilePipi::contentList.clear();
for(int i = 0; i < contentsLength;i++){
tmpStr = tempStrList[i];
tmpStr = tmpStr.simplified().trimmed();
if (tmpStr.length() == 0){
continue;
}
if (wordCount >= wordNum){
WfilePipi::contentList << lineInfo;
lineInfo = "";
wordCount = 0;
}
wordCount++;
totalCount++;
lineInfo += tmpStr;
}
if (lineInfo.length() > 0){
WfilePipi::contentList << lineInfo;
lineInfo = "";
}
//index
WfilePipi::index = 0;
//contentType
WfilePipi::contentType = "单字";
//contentCount
WfilePipi::contentCount = WfilePipi::contentList.join("").length();
//totaltime
//WfilePipi::totalTime = totalCount * (ui->lineEdit_time->text().toDouble());
//emit
emit noticeMainStart();
//close
this->saveIni();
this->close();
}
//选择不限时间的按钮时,禁止时间输入框
void WfilterWord::checkInputTime(bool isSelect){
}
void WfilterWord::readIni(){
QFile file(this->iniFile);
if(!file.exists()){
return;
}
QDataStream in(&file);
if (!file.open(QIODevice::ReadOnly)){
qDebug() << "读入文件错误,请检查权限";
return;
}
QString inputFenge;
QString inputWordNum;
QString inputTime;
bool isSuiji;
bool isShunxu;
bool isLimit;
in >> this->fileList
>> inputFenge
>> inputWordNum
>> inputTime
>> isShunxu
>> isSuiji
>> isLimit;
ui->lineEdit_fenge->setText(inputFenge);
//ui->lineEdit_time->setText(inputTime);
ui->lineEdit_wordnum->setText(inputWordNum);
ui->radioButton_order_suiji->setChecked(isSuiji);
ui->radioButton_order_shunxu->setChecked(isShunxu);
ui->checkBox_dingshi->setChecked(isLimit);
for(int i = 0; i < this->fileList.length(); i++){
QListWidgetItem *item = new QListWidgetItem;
item->setText(this->fileList[i]);
ui->listWidget->addItem(item);
}
file.close();
}
void WfilterWord::saveIni(){
QFile file(this->iniFile);
QDataStream out(&file);
if (!file.open(QIODevice::WriteOnly)){
qDebug() << iniFile << "写入文件错误,请检查权限";
return;
}
out << this->fileList
<< ui->lineEdit_fenge->text()
<< ui->lineEdit_wordnum->text()
<< 0 //lineEdit_time.text
<< ui->radioButton_order_shunxu->isChecked()
<< ui->radioButton_order_suiji->isChecked()
<<ui->checkBox_dingshi->isChecked();
file.close();
}