本文整理汇总了C++中QTextStream::seek方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextStream::seek方法的具体用法?C++ QTextStream::seek怎么用?C++ QTextStream::seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextStream
的用法示例。
在下文中一共展示了QTextStream::seek方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: readFile
bool Csv::readFile()
{
QFile file(fullPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return false;
QString str;
QTextStream in;
QTextStream in1(&file);
str = in1.readAll();
file.close();
in.setString(&str);
//set progressBar max value
maxValueProgbar = str.length();
//Parser
QStringList outList;
LexerCsv mylex;
connect(&mylex, SIGNAL(returnedToken(int)), this, SLOT(checkProgressStream(int)),
Qt::DirectConnection);
QString header = in.readLine();
if (header.startsWith("CALIBRATION VALUES V"))
{
char ch;
//parse "Description Header" for "unit delimiter, string delimiter, comment
in.seek(20);
mylex.getNextToken(in);
if (mylex.getToken() == Float)
{
mylex.getNextToken(in);
if (mylex.getToken() == ValueSeparator && (mylex.getLexem() == "," || mylex.getLexem() == ";" || mylex.getLexem() == "\t"))
{
mylex.valueSeparator = mylex.getLexem().at(0);
mylex.getNextToken(in);
if (mylex.getToken() == Text && (mylex.getLexem() == "," || mylex.getLexem() == "."))
{
mylex.decimalPointSeparator = mylex.getLexem().at(0);
in >> ch;
if (ch == mylex.valueSeparator)
{
in >> mylex.commentIndicator;
in >> ch;
if (ch == mylex.valueSeparator)
{
char c1, c2;
in >> c1;
in >> c2;
if (c1 == c2)
mylex.stringDelimiter = c1;
else
{
showError("CSV description Header : parser error at line " + QString::number(mylex.getLine())
+ " with lexem " + QString(mylex.getLexem().c_str()));
return false;
}
}
示例3: loadTPL
bool loadTPL(Translator &translator, QIODevice &dev, ConversionData &cd)
{
// Hack: Check if the template is utf8
QTextStream testStream;
testStream.setDevice( &dev );
QString testContent = testStream.readAll();
if ( ( testContent.startsWith( QLatin1String("{*?template charset="), Qt::CaseInsensitive ) &&
( testContent.startsWith( QLatin1String("{*?template charset=utf8?*}"), Qt::CaseInsensitive ) ||
testContent.startsWith( QLatin1String("{*?template charset=utf-8?*}"), Qt::CaseInsensitive ) ) ) ||
cd.m_assumeUtf8 )
{
stream.setCodec( QTextCodec::codecForName("UTF-8") );
stream.setAutoDetectUnicode( true );
}
else
{
stream.setCodec( QTextCodec::codecForLocale() );
stream.setAutoDetectUnicode( false );
}
stream.setDevice( &dev );
stream.seek( 0 ); // we need to rewind it because the testStream has read all data on the QIODevice
parse( &translator, cd.m_sourceDir.path() + QDir::separator() + cd.m_sourceFileName );
return true;
}
示例4: 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 ;
}
示例5: openDefaults
int MathTest::openDefaults(QpFile& inFile, QTextStream& stream, bool builtin)
{
// Default Test Parameters
// =====================================================
//
// Test Selection, number of problems, and time allowed
//
// Number of Time in
// Test Problems Seconds
// Add 2 10 10
// Subtract 2 10 15
// Multiply 2 10 25
// Divide 2 10 30
//
// Grade Level 1 (2nd grade level)
//
// userName "" (NULL)
//
QString defStr = QString(
"2 10 10 \n"
"2 10 15 \n"
"2 10 25 \n"
"2 10 30 \n"
"1 \n "
);
QString defaultFileName;
int status;
if(userNameEdit->text() != "")
defaultFileName = "mt-" % userNameEdit->text() % ".txt";
else
defaultFileName = "mt-default.txt";
QFlags<QIODevice::OpenModeFlag>
flags = QIODevice::ReadWrite | QIODevice::Text;
inFile.setQuietOnSuccess(true);
if((status = inFile.get(defaultFileName, flags)) != qpfile::fFailed)
stream.setDevice(&inFile);
else {
stream.setString(&defStr);
pMsg->sendInfo("Using built-in default test parameters.");
}
if((status == qpfile::fCreated) && builtin)
stream << defStr;
stream.seek(0);
return status;
}
示例6: rewriteDetailsForLocation
void QmlProfilerDetailsRewriter::rewriteDetailsForLocation(QTextStream &textDoc,
QmlJS::Document::Ptr doc, int requestId, const QmlDebug::QmlEventLocation &location)
{
PropertyVisitor propertyVisitor;
QmlJS::AST::Node *node = propertyVisitor(doc->ast(), location.line, location.column);
if (!node)
return;
qint64 startPos = node->firstSourceLocation().begin();
qint64 len = node->lastSourceLocation().end() - startPos;
textDoc.seek(startPos);
QString details = textDoc.read(len).replace(QLatin1Char('\n'), QLatin1Char(' ')).simplified();
emit rewriteDetailsString(requestId, details);
}
示例7: loadConfig
void loadConfig(const QString &fileName)
{
QFile file(configDir + fileName);
file.open(QIODevice::ReadOnly);
QString line, property;
QTextStream stream;
stream.setString(&line, QIODevice::ReadOnly);
while (!file.atEnd()) {
line = file.readLine();
if (line.isEmpty() || line[0] == '#' || line[0] == '\n' || (line[0] == '\r' && line[1] == '\n')) continue;
if (line[0] == '[') {
property = line.mid(1, line.indexOf(']') - 1);
} else {
stream.seek(0);
loadProperty(property, stream);
}
}
file.close();
}
示例8: 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);
}
}
示例9: 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];
}
示例10: progress
///
/// \brief SpecMap::SpecMap
/// Main function for processing data from text files to create SpecMap objects.
/// Currently written to accept files in "wide" format, will be expanded to deal
/// with different ASCII formats later with conditionals.
/// \param inputstream a text stream derived from the input file
/// \param main_window the main window of the app
/// \param directory the working directory
///
SpecMap::SpecMap(QTextStream &inputstream, QMainWindow *main_window, QString *directory)
{
//Set up variables unrelated to hyperspectral data:
map_list_widget_ = main_window->findChild<QListWidget *>("mapsListWidget");
map_loading_count_ = 0;
principal_components_calculated_ = false;
partial_least_squares_calculated_ = false;
z_scores_calculated_ = false;
directory_ = directory;
int i, j;
wall_clock timer;
/*Read the first line to get the wavelength*/
inputstream.seek(0);
cout << "Loading wavelength vector..." << endl;
timer.tic();
QString wavelength_string = inputstream.readLine();
QStringList wavelength_string_list =
wavelength_string.split("\t", QString::SkipEmptyParts);
int columns = wavelength_string_list.size();
wavelength_.set_size(columns);
for(i=0; i<columns; ++i){
wavelength_(i) = wavelength_string_list.at(i).toDouble();
}
double seconds = timer.toc();
cout << "Reading wavelength took " << seconds <<" s." << endl;
i=0;
j=0;
QString spectra_string;
QStringList spectra_string_list;
QProgressDialog progress("Counting rows...", "Cancel", 0, 100, NULL);
progress.setWindowTitle("Loading Dataset");
progress.setWindowModality(Qt::WindowModal);
int rows = 0;
cout << "Counting rows..." << endl;
timer.tic();
while(inputstream.readLine()!=NULL){
++rows;
}
progress.setValue(1);
progress.setRange(0,rows+1);
spectra_.set_size(rows, columns);
x_.set_size(rows);
y_.set_size(rows);
seconds = timer.toc();
cout << "Counting rows and resizing took " << seconds << " s." << endl;
cout << "Reading spectra, x, and y..." << endl;
progress.setLabelText("Parsing spectra...");
timer.tic();
inputstream.seek(0);
inputstream.readLine(); //discard it to advance to next line
for(i=0; i<rows; ++i){
spectra_string=inputstream.readLine();
spectra_string_list =
spectra_string.split("\t", QString::SkipEmptyParts);
x_(i) = spectra_string_list.at(0).toDouble();
spectra_string_list.removeAt(0);
y_(i) = spectra_string_list.at(0).toDouble();
spectra_string_list.removeAt(0);
for (j=0; j<columns; ++j){
spectra_(i,j) = spectra_string_list.at(j).toDouble();
}
if (progress.wasCanceled()){
constructor_canceled_ = true;
return;
}
progress.setValue(i);
}
seconds = timer.toc();
constructor_canceled_ = false;
cout << "Reading x, y, and spectra took " << seconds << " s." << endl;
}
示例11: 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)
//.........这里部分代码省略.........
示例12: ExtractMIBfromRFC
//.........这里部分代码省略.........
else
{
// Finish skipping, if we find a non-empty line, but not before
// we have skipped four lines. remember the miminum of lines
// we have ever skipped to keep empty lines in a modules that
// appear near the top of a page.
if ((skipped >= 4) && (blank_regexp.indexIn(line) != -1))
{
if (skipped < skip)
skip = skipped;
skipped = -1;
}
}
}
// So, if we are not skipping and inside a module, remember the line.
if ((skipped == -1) && (module.length() > 0))
{
n++;
tmpout << line << endl;
}
// Remember when we enter a macro definition
if (macro_regexp.indexIn(line) != -1)
macro = 1;
// End of module
if (end_regexp.indexIn(line) != -1)
{
if (macro == 0)
{
tmpout.flush();
tmpout.seek(0);
int strip = 99, p = 0;
while (tmpout.atEnd() != true)
{
line = tmpout.readLine();
// Find the minimum column that contains non-blank
// characters in order to cut a blank prefix off.
// Ignore lines that only contain white spaces.
if (blankline_regexp.indexIn(line) == -1)
{
if (leadingspaces_regexp.indexIn(line) != -1)
{
p = leadingspaces_regexp.cap(1).length();
if ((p < strip) && (line.length() > p))
strip = p;
}
}
}
tmpout.seek(0);
if (!skipmibfile)
{
int num_bl = 0;
while (tmpout.atEnd() != true)
{
line = tmpout.readLine();
// For each block of consecutive blank lines,
// remove all lines but one.
示例13: getMaxops
void MathTest::getMaxops()
{
// The following are the default maxima for left and right operands
// for the respective arithmetic operations and grade levels.
//
// Max Operand Values for the given grade levels
//
// Grade Level 1 2 3 4
//
// Add Lop 10 50 100 1000
// Rop 10 10 100 500
// Sub Lop 10 20 100 1000
// Rop 10 10 100 500
// Mul Lop 3 10 13 20
// Rop 3 10 13 20
// Div Lop 3 10 13 20
// Rop 3 10 13 20
//
QString qsMaxops = QString(
"10 10 50 10 100 100 1000 500 \n"
"10 10 50 10 100 100 1000 500 \n"
"10 3 10 10 15 15 20 20 \n"
"10 3 10 10 15 15 20 20 \n"
);
int status;
QString buff;
QTextStream stream;
QpFile maxopsFile(pMsg);
QString maxopsFileName = "mt-maxops.txt";
QFlags<QIODevice::OpenModeFlag>
flags = QIODevice::ReadWrite | QIODevice::Text;
if((status = maxopsFile.get(maxopsFileName, flags, true)) != qpfile::fFailed)
stream.setDevice(&maxopsFile);
else {
stream.setString(&qsMaxops);
//pMsg->sendInfo("Using built-in default test parameters.");
}
if(status == qpfile::fCreated)
stream << qsMaxops;
stream.seek(0);
// Get the Operand Maxima
//
int j, k;
for(j = 0; j < op_boundary; ++j) {
for(k = 0; k < gl_boundary; ++k) {
TESTPARM *pt = &testMatrix[j];
stream >> buff;
pt->maxops.iaLop[k] = QString(buff).toInt();
stream >> buff;
pt->maxops.iaRop[k] = QString(buff).toInt();
}
}
if(maxopsFile.exists())
maxopsFile.close();
}