// 从原始文件导入测线数据
CORE_EXPORT
bool gImportSurveyLines(const QString& filename, QVector<GSurveyLine*>& surveyLines);
bool gImportSurveyLines(const QString& filename, QVector<GSurveyLine*>& surveyLines)
{
//创建文件对象
QFile file(filename);
//判断文件是否能被打开,打开方式为只读,如不是,则退出
if (!file.open(QFile::ReadOnly)) return false;
//创建文件流对象
QTextStream stream(&file);
//文件里的线号
QString lineNum = "";
//测线
GSurveyLine* pSurveyLine = NULL;
//测点
GSurveyPoint* pSurveyPoint = NULL;
int ptNum = 0;
//有名字的列,直接固定死
const int FIXED_COL_NUM = 13;
//开始读文件
while (!stream.atEnd())
{
//读取每一行,去除首位空格
QString line = stream.readLine().trimmed();
//特殊标记的提示信息,直接跳过不读
if (line.isEmpty() || line.startsWith("#")) continue;
//将每一行的信息按字符串进行分割,QRegExp("\\s+")以空格作为拆分!SkipEmptyParts跳过空格
QStringList strs = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
//线号,同一个线号下的数据,全部存起来,直到出if循环,ptNum++即线号变了
if (strs[0] != lineNum)
{
lineNum = strs[0];
pSurveyLine = new GSurveyLine(lineNum);
surveyLines.append(pSurveyLine);
ptNum = 1;
}
pSurveyPoint = new GSurveyPoint();
pSurveyLine->getSurveyPoints() << pSurveyPoint;
pSurveyPoint->mPointNum = ptNum++;
pSurveyPoint->mInvalidMask = 1;
pSurveyPoint->mDateTime &
QT读取文件
于 2022-08-14 21:24:10 首次发布