本文整理汇总了C++中QTextStream::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream::pos方法的具体用法?C++ QTextStream::pos怎么用?C++ QTextStream::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextStream
的用法示例。
在下文中一共展示了QTextStream::pos方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: firstColumnIsIncrimental
bool text_helper::firstColumnIsIncrimental(QTextStream &stream, const QString &delimiter)
{
qint64 streamStartingPosition = stream.pos();
double firstColumnValue, prevFirstColumnValue = 0;
bool firstColumnIsIncrimental = true;
QString line = QString();
QStringList strings;
bool ok;
//Read out the first line (possibly header)
line = QString(stream.readLine());
while (!stream.atEnd()) {
line = QString(stream.readLine());
QStringList strings = line.split(delimiter);
//Lets determine if we can use the first column as an X-axis
firstColumnValue = strings.value(0).toDouble(&ok);
if (!ok || (firstColumnValue < prevFirstColumnValue)) {
firstColumnIsIncrimental = false;
break;
}
prevFirstColumnValue = firstColumnValue;
}
//Reposition the stream
stream.seek(streamStartingPosition);
return firstColumnIsIncrimental;
}
示例2: handleTag
void Entity::handleTag( const Comment* openingTag, const Comment* closingTag, QTextStream& file, QIODevice& output) {
file.seek(openingTag->getCommentEnd()+1);
while (!file.atEnd()) {
qint64 pos=file.pos();
if (pos>=closingTag->getCommentStart()){
file.seek(closingTag->getCommentEnd()+1);
break;
}
QChar c1;
file >> c1;
const Comment* p= isSpecial(pos);
if (p!=nullptr){
if (p->isAutoClosing()){
// output.write(p->comment);
// output.write("<!--REMOVESTART-->");
p->output(this,output);
// output.write("<!--REMOVEEND-->");
} else {
const Comment* closingTag=findClosingTag(p,file);
if (closingTag != nullptr){
QBuffer buf;
buf.open(QBuffer::WriteOnly|QBuffer::Text);
handleTag(p,closingTag,file,buf);
buf.close();
if (false /*p->getTag()==STYLE_START*/){
//embedded_styles.append(buf.buffer());
} else {
output.write(buf.buffer());
}
}
}
} else if (isInOuput(pos)){
if (openingTag->isHTML() && c1=='\n'){
output.write(QString("<BR/>").toUtf8());
} else {
if (!c1.isNonCharacter()) output.write(QString(c1).toUtf8());
}
}
}
return ;
}
示例3: checkAndProcessColumnHeaders
void text_helper::checkAndProcessColumnHeaders( QTextStream &stream, const QString &delimiter,
QList<QVariantMap> &metaData, int firstDataColumn )
{
qint64 streamStartingPosition = stream.pos();
QString line = QString(stream.readLine());
QStringList strings = line.split(delimiter);
bool headerFound = true;
int column;
QVariantMap variantMap;
//Check if the first line is not a header (only contains spaces, numbers, decimal points)
QRegExp re("^[ .0-9]*$");
if (re.exactMatch(line)) {
//reset stream and return
stream.seek(streamStartingPosition);
headerFound = false;
}
for (column = firstDataColumn; column < strings.size(); column++) {
variantMap.clear();
if (headerFound) {
if (strings.value(column).size() != 0) {
variantMap["Key Field"] = strings.value(column);
variantMap["Data Source"] = column;
}
} else {
//Use column number as the header
variantMap["Key Field"] = QString(tr("Column ")) + QString::number(column);
variantMap["Data Source"] = column;
}
if (!variantMap.isEmpty())
metaData.append(variantMap);
}
}
示例4: autoDetectDelimiter
QString text_helper::autoDetectDelimiter(QTextStream &stream)
{
const QString delimiters[] = {"\t", ",", " "};
qint64 streamStartingPosition = stream.pos();
QVector<QString> possibleDelimiters;
QString line = QString();
QStringList strings;
int i;
while (!stream.atEnd() && (possibleDelimiters.size() != 1)) {
line = QString(stream.readLine());
possibleDelimiters.clear();
if (line.isEmpty())
continue;
for (i = 0; i < 3; i++) {
strings.clear();
strings = line.split(delimiters[i]);
if ( strings.size() != 1 ) {
possibleDelimiters.append(delimiters[i]);
}
}
}
//qDebug() << "Best guess from auto delim format->" << possibleDelimiters.first() << possibleDelimiters.size();
//Reposition the stream
stream.seek(streamStartingPosition);
if (!possibleDelimiters.empty()) {
return possibleDelimiters.first();
}
//Something went wrong, lets pick whatever is first and run with it. Maybe there is only 1 column
return delimiters[0];
}
示例5: parse
//.........这里部分代码省略.........
addRow(record);
}
}
else if(c == '\n')
{
addColumn(record, fieldbuf, m_bTrimFields);
addRow(record);
}
else
{
fieldbuf.append(c);
}
}
break;
case StateInQuote:
{
if(c == m_cQuoteChar)
{
state = StateEndQuote;
}
else
{
fieldbuf.append(c);
}
}
break;
case StateEndQuote:
{
if(c == m_cQuoteChar)
{
state = StateInQuote;
fieldbuf.append(c);
}
else if(c == m_cFieldSeparator)
{
state = StateNormal;
addColumn(record, fieldbuf, m_bTrimFields);
}
else if(c == '\n')
{
state = StateNormal;
addColumn(record, fieldbuf, m_bTrimFields);
addRow(record);
}
else if(c == '\r')
{
// look ahead to check for linefeed
QString::iterator nit = it + 1;
// See above for details on this.
if(nit == sBuffer.end() && !stream.atEnd())
{
sBuffer.append(stream.read(1));
it = sBuffer.end() - 2;
nit = sBuffer.end() - 1;
}
// no linefeed, so assume that CR represents a newline
if(nit != sBuffer.end() && *nit != '\n')
{
addColumn(record, fieldbuf, m_bTrimFields);
addRow(record);
}
}
else
{
state = StateNormal;
fieldbuf.append(c);
}
}
break;
}
if(nMaxRecords != -1 && m_vCSVData.size() >= nMaxRecords)
return true;
}
if(m_pCSVProgress && m_vCSVData.size() % 100 == 0)
{
if(!m_pCSVProgress->update(stream.pos()))
return false;
}
}
if(!record.isEmpty())
{
addColumn(record, fieldbuf, m_bTrimFields);
addRow(record);
}
if(m_pCSVProgress)
m_pCSVProgress->end();
return state == StateNormal;
}
示例6: loadOptData
/*!
\brief Load opt file
\param in QTextStream which holds the opt.txt file
NOTICE(panqing): Before loading opt data, dat and prn data are already loaded. mainEdgeAttrList is filled.
TODO(panqing): showNameList and attrNameList are needed to be set
*/
int DataIO::loadOptData(QTextStream &in)
{
QString line; // One line of the file
QStringList lineList; // Items in one line, seperated by some delimiters
const int lengthThreshold = 10; // Recognize one line as a recording by its length
quint16 xPos, yPos, halfSceneWidth, halfSceneHeight, maxX=0, maxY=0, minX=50000, minY=50000;
quint32 subSegPartID = 0, lastSubSegPartID = 0;
while (!(line = in.readLine()).contains("SegmentId"))
;
qint64 filePos=in.pos(); // 当前文件位置
while ((line = in.readLine()).length() >= lengthThreshold)
{
lineList = line.split(",", QString::SkipEmptyParts);
// 先遍历所有血管段一遍,得到最大/最小坐标
xPos = lineList.at(5).toInt();
yPos = lineList.at(6).toInt();
if (xPos>maxX)
maxX=xPos;
if (yPos>maxY)
maxY=yPos;
if (xPos<minX)
minX=xPos;
if (yPos<minY)
minY=yPos;
xPos = lineList.at(9).toInt();
yPos = lineList.at(10).toInt();
if (xPos>maxX)
maxX=xPos;
if (yPos>maxY)
maxY=yPos;
if (xPos<minX)
minX=xPos;
if (yPos<minY)
minY=yPos;
}
halfSceneWidth=(maxX-minX)/2;
halfSceneHeight=(maxY-minY)/2;
ResManager::getSceneRect().setRect(0,0,halfSceneWidth*2*1.1,halfSceneHeight*2*1.1);
in.seek(filePos);
while ((line = in.readLine()).length() >= lengthThreshold)
{
EdgeAttr *edgeAttr = NULL;
lineList = line.split(",", QString::SkipEmptyParts);
quint16 segName = lineList.at(0).toInt();
for (int i=0;i<edgeAttrList.size();++i)
{
if (segName==edgeAttrList[i]->getIntAttr(EdgeAttr::SEGNAME))
{
edgeAttr=edgeAttrList[i];
break;
}
}
lastSubSegPartID = subSegPartID; // Store the last sub segment part id
subSegPartID = lineList.at(1).toInt(); // Acquire the sub segment part id of the new line
// The last sub segment part id is 99
// Change the last sub segment part id to its previous id plus 1
// For example, 0, 1, 2, 99 --> 0, 1, 2, 3
if (subSegPartID == 99)
subSegPartID = lastSubSegPartID + 1;
quint32 startNodeIndex, endNodeIndex;
// StartNode
// if the node is an subNodeItem, the index of the node is set as coeff*subIndex+nodeIndex
if (lineList.at(4).toInt() >= 0)
startNodeIndex = lineList.at(4).toInt();
else
startNodeIndex = lineList.at(0).toInt() + coeff*subSegPartID;
if (!nodeHash.contains(startNodeIndex))
{
xPos = lineList.at(5).toInt();
yPos = lineList.at(6).toInt();
if (startNodeIndex < coeff)
{
MainNodeItem *mainNodeItem = new MainNodeItem(NULL, startNodeIndex);
mainNodeItem->setPos(xPos-halfSceneWidth-minX, yPos-halfSceneHeight-minY);
nodeHash.insert(startNodeIndex, mainNodeItem);
}
else
{
SubNodeItem *subNodeItem = new SubNodeItem(NULL, startNodeIndex);
subNodeItem->setPos(xPos-halfSceneWidth-minX, yPos-halfSceneHeight-minY);
nodeHash.insert(startNodeIndex, subNodeItem);
}
}
// EndNode
if (lineList.at(8).toInt() >= 0)
//.........这里部分代码省略.........