11 changed files with 372 additions and 148 deletions
-
1CMakeLists.txt
-
2CMakeLists.txt.user
-
2ify_hrs_protocol
-
26libzqt/widgetplot2d.cpp
-
127libzqt/zcsv.cpp
-
47libzqt/zcsv.hpp
-
53mainwindow.cpp
-
4mainwindow.h
-
215mainwindow.ui
-
25src/electrocardiograph_tester.cpp
-
2src/electrocardiograph_tester.hpp
@ -1 +1 @@ |
|||
Subproject commit 391a9551d21fd8b591e1eb4a5c8555ec2d59ff3c |
|||
Subproject commit a1fda58c30f6bb892c9f503280b3896c67e00dda |
@ -0,0 +1,127 @@ |
|||
|
|||
#include "zcsv.hpp"
|
|||
using namespace std; |
|||
using namespace iflytop; |
|||
|
|||
ZCSV::ZCSV() {} |
|||
|
|||
bool ZCSV::parseCSV(string filename) { |
|||
csvData.clear(); |
|||
ifstream file(filename); |
|||
string line; |
|||
|
|||
if (!file.is_open()) { |
|||
return false; |
|||
} |
|||
|
|||
int rowNum = 0; |
|||
while (getline(file, line)) { |
|||
rowNum = rowNum + 1; |
|||
stringstream linestream(line); |
|||
string cell; |
|||
ZCSVCell csvCell; |
|||
csvCell.rowNum = rowNum; |
|||
int colNum = 0; |
|||
|
|||
while (getline(linestream, cell, ',')) { |
|||
colNum = colNum + 1; |
|||
csvCell.colNum = colNum; |
|||
csvCell.data = cell; |
|||
csvData.push_back(csvCell); |
|||
} |
|||
|
|||
csvData.push_back(csvCell); |
|||
} |
|||
|
|||
// 找到最大行数
|
|||
int maxRowNum = 0; |
|||
for (list<ZCSVCell>::iterator it = csvData.begin(); it != csvData.end(); it++) { |
|||
if (it->rowNum > maxRowNum) { |
|||
maxRowNum = it->rowNum; |
|||
} |
|||
} |
|||
|
|||
// 找到最大列数
|
|||
int maxColNum = 0; |
|||
for (list<ZCSVCell>::iterator it = csvData.begin(); it != csvData.end(); it++) { |
|||
if (it->colNum > maxColNum) { |
|||
maxColNum = it->colNum; |
|||
} |
|||
} |
|||
|
|||
m_maxRowNum = maxRowNum; |
|||
m_maxColNum = maxColNum; |
|||
return true; |
|||
} |
|||
|
|||
ZCSVCell* ZCSV::findCell(int rowNum, int colNum) { |
|||
for (list<ZCSVCell>::iterator it = csvData.begin(); it != csvData.end(); it++) { |
|||
if (it->rowNum == rowNum && it->colNum == colNum) { |
|||
return &(*it); |
|||
} |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
void ZCSV::setdata(int rowNum, int colNum, string data) { |
|||
ZCSVCell* cell = findCell(rowNum, colNum); |
|||
if (cell != NULL) { |
|||
cell->data = data; |
|||
} else { |
|||
ZCSVCell newCell; |
|||
newCell.rowNum = rowNum; |
|||
newCell.colNum = colNum; |
|||
newCell.data = data; |
|||
|
|||
if (rowNum > m_maxRowNum) { |
|||
m_maxRowNum = rowNum; |
|||
} |
|||
|
|||
if (colNum > m_maxColNum) { |
|||
m_maxColNum = colNum; |
|||
} |
|||
|
|||
csvData.push_back(newCell); |
|||
} |
|||
} |
|||
string ZCSV::getdata(int rowNum, int colNum) { |
|||
ZCSVCell* cell = findCell(rowNum, colNum); |
|||
if (cell != NULL) { |
|||
return cell->data; |
|||
} else { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
void ZCSV::dumpCSV(string filename) { |
|||
ofstream file; |
|||
file.open(filename, ios::out | ios::trunc); |
|||
|
|||
// 找到最大行数
|
|||
int maxRowNum = 0; |
|||
for (list<ZCSVCell>::iterator it = csvData.begin(); it != csvData.end(); it++) { |
|||
if (it->rowNum > maxRowNum) { |
|||
maxRowNum = it->rowNum; |
|||
} |
|||
} |
|||
|
|||
// 找到最大列数
|
|||
int maxColNum = 0; |
|||
for (list<ZCSVCell>::iterator it = csvData.begin(); it != csvData.end(); it++) { |
|||
if (it->colNum > maxColNum) { |
|||
maxColNum = it->colNum; |
|||
} |
|||
} |
|||
|
|||
// 足个点插入数据
|
|||
for (int i = 1; i <= maxRowNum; i++) { |
|||
for (int j = 1; j <= maxColNum; j++) { |
|||
ZCSVCell* cell = findCell(i, j); |
|||
if (cell != NULL) { |
|||
file << cell->data; |
|||
} |
|||
file << ","; |
|||
} |
|||
file << endl; |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <functional>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
class ZCSVCell { |
|||
public: |
|||
int rowNum; |
|||
int colNum; |
|||
string data; |
|||
}; |
|||
|
|||
class ZCSV { |
|||
private: |
|||
list<ZCSVCell> csvData; |
|||
|
|||
int m_maxRowNum = 0; |
|||
int m_maxColNum = 0; |
|||
|
|||
public: |
|||
ZCSV(); |
|||
|
|||
bool parseCSV(string filename); |
|||
|
|||
void setdata(int rowNum, int colNum, string data); |
|||
string getdata(int rowNum, int colNum); |
|||
|
|||
int maxRowNum() { return m_maxRowNum; } |
|||
int maxColNum() { return m_maxColNum; } |
|||
|
|||
void dumpCSV(string filename); |
|||
|
|||
private: |
|||
ZCSVCell* findCell(int rowNum, int colNum); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue