bool DummyCommandPlugin::command(QString command, QList<QString> params) { QFile dst("DummyCommandPlugin.txt"); QDataStream sout; if(command == "append") { if(!dst.open(QIODevice::WriteOnly|QIODevice::Append)) { return false; } } else if(command == "overwrite") { if(!dst.open(QIODevice::WriteOnly|QIODevice::Truncate)) { return false; } } sout.setDevice(&dst); for(int i=0; i < params.size(); i++) { QString line(params[i] + QString("\n")); sout << line; } for(int i=0; i<100; i++) { qDebug() << "Doing nothing: " << i << "%"; QApplication::processEvents(); } dst.close(); return true; }
void MailFolder::saveIndex(IndexClass *index) { // open file QFile dataFile(indexFileName); QDataStream stream; stream.setDevice(&dataFile); // check to see if this is the first index and if so save the index version switch ( indexCollection.count() ) { case 0: // remove the file if there are not mails dataFile.remove(); break; case 1: dataFile.open(IO_WriteOnly); stream<<QString(AQ_VERSION); // save index stream<<(*index); // close file dataFile.close(); break; default: dataFile.open(IO_Append|IO_WriteOnly); // save index stream<<(*index); // close file dataFile.close(); break; } }
void cTelnet::loadReplay( QString & name ) { replayFile.setFileName( name ); QString msg = "loading replay " + name; postMessage( msg ); replayFile.open( QIODevice::ReadOnly ); replayStream.setDevice( &replayFile ); loadingReplay = true; mudlet::self()->replayStart(); _loadReplay(); }
/*数据读取函数*/ void ClientSocket::readData() { QDataStream in; in.setDevice(this); in.setVersion(QDataStream::Qt_4_7); QVariant v; AllAnswers allAnswers; Student student; /*如果还没有块大小信息则尝试去读取*/ if(_totalBytes == 0) { /*如果缓存区中可读数据的大小小于块大小信息的大小则返回*/ if(this->bytesAvailable()<sizeof(qint32)) return; /*写入块大小信息*/ in >> _totalBytes; } /*如果缓存区可读信息的大小小于块大小则返回*/ if(this->bytesAvailable()<_totalBytes) return; /*反之则说明完整的数据块已经到达缓存区,可以开始读取*/ /*写入信息类型*/ in >> _messageType; /*根据信息类型写入信息内容*/ switch(_messageType) { case MSG_NEWCONNECT: in >> student; v.setValue(student); break; case MSG_LOGIN: in >> student; student.setSockDescriptor(this->socketDescriptor()); v.setValue(student); break; case MSG_GETPAPER: in >> student; v.setValue(student); break; case MSG_ANSWER: in >> allAnswers; v.setValue(allAnswers); break; case MSG_ANSWERSINGLE: in >> allAnswers; v.setValue(allAnswers); break; } /*将块大小信息重置为0,准备接收下一个数据块*/ _totalBytes = 0; /*发送信息到达信号*/ emit this->messageArrive(this->socketDescriptor(),_messageType,v); }
bool huancun::readcfg(){ qDebug()<<"huancun::readcfg"; QFile file; QString cfg=dirpath+"/cfg"; file.setFileName(cfg); if(file.open(QIODevice::ReadOnly)) { QDataStream in; in.setDevice(&file); in>>all>>name>>goon>>playurl>>urls>>playrf>>U_A; return true; }
bool Titres::DB_Charger(void) { QFile file(SAVENAME); QDataStream out; if ( file.open(QIODevice::ReadOnly) ) { out.setDevice(&file); out >> T_List; file.close(); return true; }
void SessionManager::read() { QFile f(_sessionsPath); QDataStream in; QVariant tmp; Session *session(0); // Opening the saving file if (!f.open(QIODevice::ReadOnly)) return; in.setDevice(&f); // Reading of all sessions while (!in.atEnd()) { session = new Session(); // Retrieving of the access token in >> tmp; session->setAccessToken(tmp.toString()); tmp.clear(); // Retrieving of the client token in >> tmp; session->setClientToken(tmp.toString()); tmp.clear(); // Retrieving of the player's uuid in >> tmp; session->setUuid(tmp.toString()); tmp.clear(); // Retrieving of the player's username in >> tmp; session->setName(tmp.toString()); tmp.clear(); // Retrieving of the player's legacy in >> tmp; session->setLegacy(tmp.toBool()); tmp.clear(); } f.close(); }
bool QPicture::play( QPainter *painter ) { if ( pictb.size() == 0 ) // nothing recorded return TRUE; pictb.open( IO_ReadOnly ); // open buffer device QDataStream s; s.setDevice( &pictb ); // attach data stream to buffer if ( !formatOk ) { // first time we read it char mf_id[4]; // picture header tag s.readRawBytes( mf_id, 4 ); // read actual tag if ( memcmp(mf_id, mfhdr_tag, 4) != 0 ) { // wrong header id #if defined(CHECK_RANGE) qWarning( "QPicture::play: Incorrect header" ); #endif pictb.close(); return FALSE; } int cs_start = sizeof(Q_UINT32); // pos of checksum word int data_start = cs_start + sizeof(Q_UINT16); Q_UINT16 cs,ccs; QByteArray buf = pictb.buffer(); // pointer to data s >> cs; // read checksum ccs = qChecksum( buf.data() + data_start, buf.size() - data_start ); if ( ccs != cs ) { #if defined(CHECK_STATE) qWarning( "QPicture::play: Invalid checksum %x, %x expected", ccs, cs ); #endif pictb.close(); return FALSE; } Q_UINT16 major, minor; s >> major >> minor; // read version number if ( major > mfhdr_maj ) { // new, incompatible version #if defined(CHECK_RANGE) qWarning( "QPicture::play: Incompatible version %d.%d", major, minor); #endif pictb.close(); return FALSE; } formatOk = TRUE; // picture seems to be ok formatMajor = major; formatMinor = minor; } else {
//保存各试卷关系信息 int CardDoc::savePaperSetRelationFile(int courseIndex, QString fileName) { QList<QString> setId; QList<int> dpi; QList<int> pageCount; QList<QString> pageId; QList<bool> isPositive; vector<PaperSet>::iterator iter = m_course.at(courseIndex).set.begin(); for (; iter != m_course.at(courseIndex).set.end(); ++iter) { setId.push_back(iter->setId); dpi.push_back(iter->dpi); pageCount.push_back(iter->page.size()); vector<PaperPage>::iterator iter2 = iter->page.begin(); for (; iter2 != iter->page.end(); ++iter2) { pageId.push_back(iter2->pageId); isPositive.push_back(iter2->isPositive); } } QFile file(fileName); if (!file.open(QIODevice::WriteOnly)) { return 0; } QDataStream data; data.setDevice(&file); data.setVersion(QDataStream::Qt_4_8); //输出试卷关系信息 data << quint32(PAPERSET_MAGIC_NUM) << quint32(VERSION) << m_acType << m_course.at(courseIndex).courseName << m_course.at(courseIndex).set.size() << setId << dpi << pageCount << pageId << isPositive; if (file.isOpen()) { file.close(); } return 1; }
bool Titres::DB_Sauver(void) { QFile file(SAVENAME); QDataStream in; if ( file.open(QIODevice::WriteOnly) ) { in.setDevice(&file); in << T_List; file.close(); return true; } else return false; }
void ensureSerializesCorrectly(const QPicture &picture, QDataStream::Version version) { QDataStream stream; QBuffer buffer; buffer.open(QIODevice::WriteOnly); stream.setDevice(&buffer); stream.setVersion(version); stream << picture; buffer.close(); buffer.open(QIODevice::ReadOnly); QPicture readpicture; stream >> readpicture; QVERIFY2(memcmp(picture.data(), readpicture.data(), picture.size()) == 0, qPrintable(QString::fromLatin1("Picture data does not compare equal for QDataStream version %1").arg(version))); }
bool PackageReader::Login() { QDataStream socketStream; socketStream.setVersion(QDataStream::Qt_4_8); socketStream.setDevice(s); struct User *user; int nameLen,passwdLen; QString name,passwd; socketStream>>nameLen; if(nameLen<0||nameLen>MAX_STR_LEN) { socketStream<<FAULT; return 0; } name.resize(nameLen); socketStream>>name; socketStream>>passwdLen; if(passwdLen<0||passwdLen>MAX_STR_LEN) { socketStream<<FAULT; return 0; } passwd.resize(passwdLen); socketStream>>passwd; qDebug()<<"user name"<<name<<"passwd:"<<passwd; /*bala *bala *bala */ user = new struct User; user->name=name; user->add=s->peerAddress(); user->online=1; user->port=s->peerPort(); qDebug()<<user->name; if(-1==l->Insert(user)) { delete user; socketStream<<FAULT; return 0; } socketStream<<SUCCEED; return 1; }
void chmEditer::on_pushButton_clicked() { // chmHeader hd; QString fileName = QFileDialog::getOpenFileName(this, tr("Открыть chm"), ".", tr("Chm Files (*.chm)")); // fileName = "D:\\ferz\\chm1\\TestPrj.chm"; QFile f; f.setFileName(fileName); if (f.open(QIODevice::ReadOnly)) { QDataStream stream; stream.setDevice(&f); stream.setByteOrder(QDataStream::LittleEndian); char *tmp1; tmp1 = new char[4]; stream.readRawData(tmp1,4); hd.header = tmp1; delete tmp1; stream>> hd.version; stream>> hd.lenght; stream.skipRawData(4); stream>>hd.timestamp; stream>>hd.languageID; tmp1 = new char[10]; stream.readRawData(tmp1,10); hd.GUID1 = tmp1; delete tmp1; tmp1 = new char[10]; stream.readRawData(tmp1,10); hd.GUID2 = tmp1; delete tmp1; qDebug()<<hd.GUID1; ui->textEdit->append("<b>Заголовок</b>: "+hd.header); ui->textEdit->append("<b>Версия</b>: "+QString("%1").arg(hd.version)); ui->textEdit->append("<b>полный размер заголовка</b> : "+QString("%1").arg(hd.lenght)); ui->textEdit->append("<b>Язык</b> : "+QString("%1").arg(hd.languageID,0, 16)); }
void SessionManager::save() { QFile f(_sessionsPath); QDataStream out; // Opening the saving file if (!f.open(QIODevice::WriteOnly)) return; out.setDevice(&f); // Writing of all sessions for (auto key : _sessions.keys().toStdList()) { out << QVariant(_sessions[key]->accessToken().toString()) << QVariant(_sessions[key]->clientToken().toString()); out << QVariant(_sessions[key]->uuid().toString()) << QVariant(_sessions[key]->name()) << QVariant(_sessions[key]->legacy()); } // Closing the file f.close(); }
bool QPicture::play( QPainter *painter ) { if ( d->pictb.size() == 0 ) // nothing recorded return TRUE; if ( !d->formatOk && !d->checkFormat() ) return FALSE; d->pictb.open( IO_ReadOnly ); // open buffer device QDataStream s; s.setDevice( &d->pictb ); // attach data stream to buffer s.device()->at( 10 ); // go directly to the data s.setVersion( d->formatMajor == 4 ? 3 : d->formatMajor ); Q_UINT8 c, clen; Q_UINT32 nrecords; s >> c >> clen; Q_ASSERT( c == PdcBegin ); // bounding rect was introduced in ver 4. Read in checkFormat(). if ( d->formatMajor >= 4 ) { Q_INT32 dummy; s >> dummy >> dummy >> dummy >> dummy; }
void tst_QFont::serialize() { QFETCH(QFont, font); QFETCH(QDataStream::Version, minimumStreamVersion); QDataStream stream; const int thisVersion = stream.version(); for (int version = minimumStreamVersion; version <= thisVersion; ++version) { QBuffer buffer; buffer.open(QIODevice::WriteOnly); stream.setDevice(&buffer); stream.setVersion(version); stream << font; buffer.close(); buffer.open(QIODevice::ReadOnly); QFont readFont; stream >> readFont; QVERIFY2(readFont == font, qPrintable(QString::fromLatin1("Fonts do not compare equal for QDataStream version ") + QString::fromLatin1("%1:\nactual: %2\nexpected: %3").arg(version).arg(readFont.toString()).arg(font.toString()))); } }
void PackageReader::ReadData(QAbstractSocket *socket, UserList *list) { QDataStream socketStream; socketStream.setVersion(QDataStream::Qt_4_8); socketStream.setDevice(socket); l=list; s=socket; int cmd; socketStream>>cmd; QString data1,data2; switch (cmd) { case CMD_LOGIN: if(!Login()) qDebug()<<"login fault"; SendList(); break; case CMD_GET_LIST: qDebug()<<SendList(); default: break; } }
int PackageReader::SendList() { QDataStream socketStream; socketStream.setVersion(QDataStream::Qt_4_8); socketStream.setDevice(s); qDebug()<<__FUNCTION__; int count=0; struct User *user; QByteArray data; for(;;) { QDataStream stream(&data,QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_4_8); user=l->Next(); if(user==NULL) { qDebug()<<__FUNCTION__<<"end"; return count; } qDebug()<<user->name; stream<<VAL_USER <<user->name.length() <<user->name <<user->add.toIPv4Address() <<user->port <<user->online; socketStream.writeRawData(data.data(),data.size()); count++; qDebug()<<__FUNCTION__<<"count"<<count; } }
bool Nebula::readNGC(char *recordstr) { int rahr; float ramin; int dedeg; float demin; int nb; sscanf(&recordstr[1],"%d",&nb); if (recordstr[0] == 'I') { IC_nb = nb; } else { NGC_nb = nb; } sscanf(&recordstr[12],"%d %f",&rahr, &ramin); sscanf(&recordstr[22],"%d %f",&dedeg, &demin); float RaRad = (double)rahr+ramin/60; float DecRad = (float)dedeg+demin/60; if (recordstr[21] == '-') DecRad *= -1.; RaRad*=M_PI/12.; // Convert from hours to rad DecRad*=M_PI/180.; // Convert from deg to rad // Calc the Cartesian coord with RA and DE StelUtils::spheToRect(RaRad,DecRad,XYZ); sscanf(&recordstr[47],"%f",&mag); if (mag < 1) mag = 99; // Calc the angular size in radian : TODO this should be independant of tex_angular_size float size; sscanf(&recordstr[40],"%f",&size); angularSize = size/60; if (angularSize<0) angularSize=0; // this is a huge performance drag if called every frame, so cache here if (!strncmp(&recordstr[8],"Gx",2)) { nType = NebGx;} else if (!strncmp(&recordstr[8],"OC",2)) { nType = NebOc;} else if (!strncmp(&recordstr[8],"Gb",2)) { nType = NebGc;} else if (!strncmp(&recordstr[8],"Nb",2)) { nType = NebN;} else if (!strncmp(&recordstr[8],"Pl",2)) { nType = NebPn;} else if (!strncmp(&recordstr[8]," ",2)) { return false;} else if (!strncmp(&recordstr[8]," -",2)) { return false;} else if (!strncmp(&recordstr[8]," *",2)) { return false;} else if (!strncmp(&recordstr[8],"D*",2)) { return false;} else if (!strncmp(&recordstr[7],"***",3)) { return false;} else if (!strncmp(&recordstr[7],"C+N",3)) { nType = NebCn;} else if (!strncmp(&recordstr[8]," ?",2)) { nType = NebUnknown;} else { nType = NebUnknown;} if (!filess.isOpen()) { filess.open(QIODevice::WriteOnly); out.setDevice(&filess); } out << ((bool)(recordstr[0] == 'I')) << nb << RaRad << DecRad << mag << angularSize << ((unsigned int)nType); if (nb==5369 && recordstr[0] == 'I') filess.close(); return true; }
void HistoryManager::load() { loadSettings(); QFile historyFile(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1String("/history")); if (!historyFile.exists()) return; if (!historyFile.open(QFile::ReadOnly)) { qWarning() << "Unable to open history file" << historyFile.fileName(); return; } QList<HistoryItem> list; QDataStream in(&historyFile); // Double check that the history file is sorted as it is read in bool needToSort = false; HistoryItem lastInsertedItem; QByteArray data; QDataStream stream; QBuffer buffer; stream.setDevice(&buffer); while (!historyFile.atEnd()) { in >> data; buffer.close(); buffer.setBuffer(&data); buffer.open(QIODevice::ReadOnly); quint32 ver; stream >> ver; if (ver != HISTORY_VERSION) continue; HistoryItem item; stream >> item.url; stream >> item.dateTime; stream >> item.title; if (!item.dateTime.isValid()) continue; if (item == lastInsertedItem) { if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) list[0].title = item.title; continue; } if (!needToSort && !list.isEmpty() && lastInsertedItem < item) needToSort = true; list.prepend(item); lastInsertedItem = item; } if (needToSort) qSort(list.begin(), list.end()); setHistory(list, true); // If we had to sort re-write the whole history sorted if (needToSort) { m_lastSavedUrl = QString(); m_saveTimer->changeOccurred(); } }
//恢复数据 int CardDoc::resumeDataFromZip(const QString &zipPath) { // removeTempFile(); QDir dir; bool exist = dir.exists("tmp1"); if (!exist) { //创建tmp文件夹 dir.mkdir("tmp1"); } try { ACUnZip(zipPath.toStdString(), "tmp1\\"); QFile file("tmp1\\paperSet.dat"); if (!file.open(QIODevice::ReadOnly)) { file.close(); removeTempFile("tmp1"); return 0; } QDataStream data; data.setDevice(&file); data.setVersion(QDataStream::Qt_4_8); quint32 magic; data >> magic; //判断是否为可识别格式 if (magic != (quint32)PAPERSET_MAGIC_NUM) { file.close(); removeTempFile("tmp1"); return 0; } quint32 version; data >> version; //判断是否为可识别版本 if (version != (quint32)VERSION) { file.close(); removeTempFile("tmp1"); return 0; } int type; data >> type; if (type != m_acType) { removeTempFile("tmp1"); return 0; } //m_acType = type; QString courseName; data >> courseName; vector<PaperSet> paperSet; QList<QString> setId; QList<int> dpi; QList<int> pageCount; QList<QString> pageId; QList<bool> isPositive; int setSize; int pageIdx = 0; data >> setSize >> setId >> dpi >> pageCount >> pageId >> isPositive; for (int i = 0; i < setSize; ++i) { PaperSet set; set.setId = setId.at(i); set.dpi = dpi.at(i); for (int j = 0; j < pageCount.at(i); ++j, ++pageIdx) { PaperPage page; page.pageId = pageId.at(pageIdx); page.isPositive = isPositive.at(pageIdx); set.page.push_back(page); } paperSet.push_back(set); } int find = isCourseExist(courseName); if (find > -1) { m_course.at(find).set.clear(); m_course.at(find).set = paperSet; } else { Course course; course.courseName = courseName; course.set = paperSet; m_course.push_back(course); } file.close(); //文件确认无误后,将tmp1文件夹删除,并解压到tmp中 removeTempFile("tmp1"); ACUnZip(zipPath.toStdString(), "tmp\\"); QFile::remove("tmp\\paperSet.dat"); } catch (exception) { return 0; } return 1; }
void INDI_E::browseBlob() { QFile fp; QString filename; QString format; QDataStream binaryStream; int data64_size=0, pos=0; unsigned char *data_file; KUrl currentURL; currentURL = KFileDialog::getOpenUrl( QDir::homePath(), "*"); // if user presses cancel if (currentURL.isEmpty()) return; if ( currentURL.isValid() ) write_w->setText(currentURL.path()); fp.setFileName(currentURL.path()); if ( (pos = filename.lastIndexOf(".")) != -1) format = filename.mid (pos, filename.length()); //qDebug() << "Filename is " << fp.fileName() << endl; if (!fp.open(QIODevice::ReadOnly)) { KMessageBox::error(0, i18n("Cannot open file %1 for reading", filename)); return; } binaryStream.setDevice(&fp); data_file = new unsigned char[fp.size()]; bp->bloblen = fp.size(); if (data_file == NULL) { KMessageBox::error(0, i18n("Not enough memory to load %1", filename)); fp.close(); return; } binaryStream.readRawData((char*)data_file, fp.size()); bp->blob = new unsigned char[4*fp.size()/3+4]; if (bp->blob == NULL) { KMessageBox::error(0, i18n("Not enough memory to convert file %1 to base64", filename)); fp.close(); } data64_size = to64frombits ( ((unsigned char *) bp->blob), data_file, fp.size()); delete [] data_file; bp->size = data64_size; //qDebug() << "BLOB " << bp->name << " has size of " << bp->size << " and bloblen of " << bp->bloblen << endl; blobDirty = true; }
void KHTMLPluginKTTSD::slotReadOut() { // The parent is assumed to be a KHTMLPart if(!parent()->inherits("KHTMLPart")) QMessageBox::warning(0, i18n("Cannot Read source"), i18n("You cannot read anything except web pages with\n" "this plugin, sorry.")); else { // If KTTSD not running, start it. DCOPClient *client = kapp->dcopClient(); if(!client->isApplicationRegistered("kttsd")) { QString error; if(kapp->startServiceByDesktopName("kttsd", QStringList(), &error)) QMessageBox::warning(0, i18n("Starting KTTSD Failed"), error); } // Find out if KTTSD supports xhtml (rich speak). QByteArray data; QBuffer dataBuf(data); QDataStream arg; dataBuf.open(IO_WriteOnly); arg.setDevice(&dataBuf); arg << "" << KSpeech::mtHtml; QCString replyType; QByteArray replyData; bool supportsXhtml = false; if(!client->call("kttsd", "KSpeech", "supportsMarkup(QString,uint)", data, replyType, replyData, true)) QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call supportsMarkup failed.")); else { QDataStream reply(replyData, IO_ReadOnly); reply >> supportsXhtml; } KHTMLPart *part = (KHTMLPart *)parent(); QString query; if(supportsXhtml) { kdDebug() << "KTTS claims to support rich speak (XHTML to SSML)." << endl; if(part->hasSelection()) query = part->selectedTextAsHTML(); else { // TODO: Fooling around with the selection probably has unwanted // side effects, but until a method is supplied to get valid xhtml // from entire document.. // query = part->document().toString().string(); part->selectAll(); query = part->selectedTextAsHTML(); // Restore no selection. part->setSelection(part->document().createRange()); } } else { if(part->hasSelection()) query = part->selectedText(); else query = part->htmlDocument().body().innerText().string(); } // kdDebug() << "KHTMLPluginKTTSD::slotReadOut: query = " << query << endl; dataBuf.at(0); // reset data arg << query << ""; if(!client->call("kttsd", "KSpeech", "setText(QString,QString)", data, replyType, replyData, true)) QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call setText failed.")); dataBuf.at(0); arg << 0; if(!client->call("kttsd", "KSpeech", "startText(uint)", data, replyType, replyData, true)) QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call startText failed.")); } }
//--------------------------------------------------------------------- // TODO factor code out of here and into its own class for loading and // saving PLY files (additional code in stereo/multiviewstereo.cpp) // void MainWindow::on_actionView_PLY_File_triggered() { QString initialDir = userSettings.contains("InitialPLYDir") ? userSettings.value("InitialPLYDir").toString() : QDir::homePath(); // TODO sheets would be nice for Mac users :) QString fname = QFileDialog::getOpenFileName(this, tr("Open File"), initialDir, "PLY Files (*.ply)"); if(!fname.isNull()) { QFile file(fname); if(file.open(QFile::ReadOnly)) { userSettings.setValue("InitialPLYDir", QDir(fname).absolutePath()); QTextStream textStream(&file); // For now we'll ignore the header and assume a certain format QString line; bool hasNormal = false; bool hasColor = false; bool isBinary = false; unsigned int numVertices = 0; unsigned int numFaces = 0; static QRegExp typeTest("n[xyz]"); static QRegExp normalTest("n[xyz]"); static QRegExp colorTest("diffuse_(red|blue|green)"); static QRegExp elementTest("element (vertex|face) (\\d+)"); while((line = textStream.readLine().trimmed()) != "end_header") { if(line.startsWith("property")) { if( line.contains(normalTest) ) hasNormal = true; if( line.contains(colorTest) ) hasColor = true; } else if(elementTest.indexIn(line) != -1) { if(elementTest.cap(1) == "face") numFaces = elementTest.cap(2).toUInt(); else if(elementTest.cap(1) == "vertex") numVertices = elementTest.cap(2).toUInt(); } else if(line.startsWith("format")) { isBinary = line.contains("binary"); } } QDataStream dataStream; if(isBinary) { qint64 pos = textStream.pos(); file.close(); file.open(QFile::ReadOnly); dataStream.setDevice(&file); dataStream.skipRawData(pos); } // // Read in the verticies // GLfloat d[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; std::vector<GLfloat> vertices(numVertices * 9); std::vector<GLfloat>::iterator vertexIter = vertices.begin(); if(isBinary) { uint len = 12 + (hasNormal ? 12 : 0) + (hasColor ? 3 : 0); // TODO more efficient to read in larger chunk of data for(unsigned int vertex = 0; vertex < numVertices && !textStream.atEnd(); ++vertex) { dataStream.readRawData(reinterpret_cast<char *>(d), len); if(!hasNormal) d[3] = d[4] = d[5] = 0; if(!hasColor) d[6] = d[7] = d[8] = 1; if(dataStream.status() != QDataStream::ReadPastEnd) vertexIter = std::copy(d, d + 9, vertexIter); } } else { for(unsigned int vertex = 0; vertex < numVertices && !textStream.atEnd(); ++vertex) { textStream >> d[0] >> d[1] >> d[2]; if(hasNormal) textStream >> d[3] >> d[4] >> d[5]; else d[3] = d[4] = d[5] = 0.0f; if(hasColor) { textStream >> d[6] >> d[7] >> d[8]; d[6] /= 255.0; d[7] /= 255.0; d[8] /= 255.0; } else { d[6] = d[7] = d[8] = 0.5f; //d[6] = qrand() / (1.0*RAND_MAX); //d[7] = qrand() / (1.0*RAND_MAX); //d[8] = qrand() / (1.0*RAND_MAX); } if(textStream.status() != QTextStream::ReadPastEnd) vertexIter = std::copy(d, d + 9, vertexIter); textStream.readLine(); }