[companion][logsDialog]A 50% improvement performance on open file.
This commit is contained in:
@@ -445,15 +445,11 @@ void logsDialog::on_fileOpen_BT_clicked()
|
|||||||
ui->logTable->setColumnCount(csvlog.at(0).count());
|
ui->logTable->setColumnCount(csvlog.at(0).count());
|
||||||
ui->logTable->setRowCount(csvlog.count()-1);
|
ui->logTable->setRowCount(csvlog.count()-1);
|
||||||
ui->logTable->setHorizontalHeaderLabels(csvlog.at(0));
|
ui->logTable->setHorizontalHeaderLabels(csvlog.at(0));
|
||||||
|
|
||||||
|
QAbstractItemModel *model = ui->logTable->model();
|
||||||
for (int i=1; i<csvlog.count(); i++) {
|
for (int i=1; i<csvlog.count(); i++) {
|
||||||
for (int j=0; j<csvlog.at(0).count(); j++) {
|
for (int j=0; j<csvlog.at(0).count(); j++) {
|
||||||
QTableWidgetItem* item= new QTableWidgetItem(csvlog.at(i).at(j));
|
model->setData(model->index(i - 1, j, QModelIndex()), csvlog.at(i).at(j));
|
||||||
if (j>1) {
|
|
||||||
item->setTextAlignment(Qt::AlignRight);
|
|
||||||
} else {
|
|
||||||
item->setTextAlignment(Qt::AlignCenter);
|
|
||||||
}
|
|
||||||
ui->logTable->setItem(i-1,j,item );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,53 +479,29 @@ bool logsDialog::cvsFileParse()
|
|||||||
csvlog.clear();
|
csvlog.clear();
|
||||||
logFilename.clear();
|
logFilename.clear();
|
||||||
QTextStream inputStream(&file);
|
QTextStream inputStream(&file);
|
||||||
QRegExp rx2("(?:\"([^\"]*)\";?)|(?:([^,]*),?)");
|
|
||||||
QStringList list;
|
|
||||||
QString buffer = file.readLine();
|
QString buffer = file.readLine();
|
||||||
|
|
||||||
if (buffer.startsWith("Date,Time")) {
|
if (buffer.startsWith("Date,Time")) {
|
||||||
file.reset();
|
file.reset();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numfields=-1;
|
int numfields=-1;
|
||||||
while (!file.atEnd()) {
|
while (!file.atEnd()) {
|
||||||
int pos2 = 0;
|
QString line = file.readLine().trimmed();
|
||||||
QString buffer = file.readLine();
|
QStringList columns = line.split(',');
|
||||||
QString line=buffer.trimmed();
|
|
||||||
list.clear();
|
|
||||||
if(line.size()<1){
|
|
||||||
list << "";
|
|
||||||
} else {
|
|
||||||
while (line.size()>pos2 && (pos2 = rx2.indexIn(line, pos2)) != -1) {
|
|
||||||
QString col;
|
|
||||||
if(rx2.cap(1).size()>0) {
|
|
||||||
col = rx2.cap(1);
|
|
||||||
} else if(rx2.cap(2).size()>0) {
|
|
||||||
col = rx2.cap(2);
|
|
||||||
}
|
|
||||||
if (col.contains(".")) {
|
|
||||||
if (col.indexOf(".")==(col.length()-3)) {
|
|
||||||
col.append("0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
list<<col;
|
|
||||||
if(col.size()) {
|
|
||||||
pos2 += rx2.matchedLength();
|
|
||||||
} else {
|
|
||||||
pos2++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numfields==-1) {
|
if (numfields==-1) {
|
||||||
numfields=list.count();
|
numfields=columns.count();
|
||||||
}
|
}
|
||||||
if (list.count()==numfields) {
|
if (columns.count()==numfields) {
|
||||||
csvlog.append(list);
|
csvlog.append(columns);
|
||||||
} else {
|
} else {
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
lines++;
|
lines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
logFilename=QFileInfo(file.fileName()).baseName();
|
logFilename=QFileInfo(file.fileName()).baseName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user