bool writeXml(const QString &fileName, QTreeWidget *treeWidget)
{
    QFile file(fileName);
    if (!file.open(QFile::WriteOnly | QFile::Text)) {
        std::cerr << "Error: Cannot write file "
                  << qPrintable(fileName) << ": "
                  << qPrintable(file.errorString()) << std::endl;
        return false;
    }

    QXmlStreamWriter xmlWriter(&file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("bookindex");
    for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
        writeIndexEntry(&xmlWriter, treeWidget->topLevelItem(i));
    xmlWriter.writeEndDocument();

    file.close();
    if (file.error()) {
        std::cerr << "Error: Cannot write file "
                  << qPrintable(fileName) << ": "
                  << qPrintable(file.errorString()) << std::endl;
        return false;
    }
    return true;
}
示例#2
0
void XbelTree::writeIndexEntry(QXmlStreamWriter *xmlWriter, QTreeWidgetItem *item)
{
    xmlWriter->writeStartElement("folder");
    xmlWriter->writeAttribute("title",item->text(0));
    xmlWriter->writeAttribute("value_ergo",item->text(1));
    xmlWriter->writeAttribute("value_ves",item->text(2));
    xmlWriter->writeAttribute("value_number",item->text(3));
    xmlWriter->writeAttribute("folded",item->text(4));
    for(int i =0; i<item->childCount(); ++i)
        writeIndexEntry(xmlWriter,item->child(i));
    xmlWriter->writeEndElement();
}
void writeIndexEntry(QXmlStreamWriter *xmlWriter, QTreeWidgetItem *item)
{
    xmlWriter->writeStartElement("entry");
    xmlWriter->writeAttribute("term", item->text(0));
    QString pageString = item->text(1);
    if (!pageString.isEmpty()) {
        QStringList pages = pageString.split(", ");
        foreach (QString page, pages)
            xmlWriter->writeTextElement("page", page);
    }
    for (int i = 0; i < item->childCount(); ++i)
        writeIndexEntry(xmlWriter, item->child(i));
    xmlWriter->writeEndElement();
}
示例#4
0
bool XbelTree::write(QFile *file)
{

    QXmlStreamWriter xmlWriter(file);
    xmlWriter.setAutoFormatting(true);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("xbel");
    xmlWriter.writeAttribute(tr("version"),tr("1.0"));

    for(int i =0; i <XbelTree::topLevelItemCount(); ++i)
    {
        writeIndexEntry(&xmlWriter, XbelTree::topLevelItem(i));
    }
    xmlWriter.writeEndDocument();
    file->close();
    if(file->error())
    {

       return false;
    }
    return true;
}
示例#5
0
文件: profile.cpp 项目: Snodig/Nagios
bool rpnoc::Profile::writeXml( const QString &iFilename, QStringList *iItem )
{
	QString oFileName = iFilename.toLower();
	QFile oFile( oFileName );
	if( !oFile.open( QFile::ReadWrite | QFile::Text ) ) {
		log_e( "Failed to open file '" + iFilename + "'." + log_endl + oFile.errorString() );
		return false;
	}

	QXmlStreamWriter oWriter( &oFile );
	oWriter.setAutoFormatting( true );
	oWriter.writeStartDocument();
	oWriter.writeStartElement( "Profile" );
	writeIndexEntry( &oWriter, iItem );
	oWriter.writeEndDocument();
	
	oFile.close();
	if( oFile.error() ) {
		log_e( "Failed to close file '" + iFilename + "'." + log_endl + oFile.errorString() );
		return false;
	}
	return true;
}
示例#6
0
int main(int argc, char *argv[]) {

    /* === Declarations === */

    int ret, i, exitflag;
    long int lim;

    double Mag;

    unsigned long us_header_offset;
    unsigned long usf_trix_begin;
    unsigned long usf_trix_count;
    unsigned long ntrixels;
    int16_t maglim;
    u_int8_t htm_level;
    u_int16_t MSpT_unnamed;

    char query[512];
    u_int32_t current_trixel;

    /* File streams */
    FILE *f;                 /* Pointer to "current" file */
    FILE *usf;               /* Handle to star data file */
    FILE *usfhead;           /* Handle to star header file */

    /* deepStarData structure */
    deepStarData data;

    /* MySQL structures */
    MYSQL link;
    MYSQL_RES *result;
    MYSQL_ROW row;

    /* Check the number of arguments */
    if( argc <= 6 ) {
        fprintf(stderr, 
                "USAGE %s DataFile HeaderFile InputDataFilePrefix\n", 
                argv[0]);
        fprintf(stderr, "The database used is a MySQL DB on localhost. The default table name is `nomad`\n");
    }

    /* == Open all file streams required == */
    /* Unnamed Star Handling */
    usf = fopen(argv[1], "wb");
    if(usf == NULL) {
        fprintf(stderr, "ERROR: Could not open %s [Data File] for binary write.\n", argv[1]);
        return 1;
    }

    usfhead = fopen(argv[2], "wb");
    if(usfhead == NULL) {
        fprintf(stderr, "ERROR: Could not open %s [Header File] for binary write.\n", argv[2]);
        fcloseall();
        return 1;
    }

    if( VERBOSE )
        fprintf( stdout, "Size of deepStarData structure: %d\n", sizeof( deepStarData ) );

    /* Write file headers */
    writeDataFileHeader(usfhead);
    us_header_offset = ftell(usfhead);

    /* Leave space in the data file for certain catalog information */
    /* Leave space for / write a deep magnitude limit specification in the data files */
    maglim = (int)(-5.0 * 100);
    fwrite(&maglim, 2, 1, usf); // Bogus entry

    /* Write a HTM level specification in the data file */
    htm_level = HTM_LEVEL;
    fwrite(&htm_level, 1, 1, usf);

    /* Leave space for a specification of MSpT (Maximum Stars per Trixel) in the data files */
    MSpT_unnamed = 0;
    fwrite(&MSpT_unnamed, 2, 1, usf); // Bogus entry

    /* Initialize some variables */
    usf_trix_begin = 2 + 1 + 2; // The 2 + 1 + 2 is to leave space for deep magnitude limit, HTM Level and MSpT specification. TODO: Change this if things change.
    ntrixels = 0;

    for( current_trixel = 0; current_trixel < NTRIXELS; ++current_trixel ) {
        char fname[256];
        sprintf( fname, "%s%d", argv[3], current_trixel );
        FILE *trixdump;
        trixdump = fopen( fname, "rb" );
        if( trixdump == NULL ) {
            fprintf( stderr, "ERROR: Could not open %s for binary read! Exiting with INCOMPLETE data files.\n", fname );
            fcloseall();
            return 1;
        }
        usf_trix_count = 0;
        while( !feof( trixdump ) ) {
            if( !fread( &data, sizeof( deepStarData ), 1, trixdump ) ) {
                if( VERBOSE ) 
                    fprintf( stdout, "Finished transferring trixel %d (%d records)\n", current_trixel, usf_trix_count );
                break;
            }
            usf_trix_count++;

            int16_t B = data.B;
            int16_t V = data.V;

            if( V == 30000 ) {
                if( B - 1600 > maglim && B != 30000 ) {
                    maglim = B - 1600;
                }
            }
            else {
                if( V > maglim ) {
                    maglim = V;
                }
            }
            fwrite(&data, sizeof(deepStarData), 1, usf);
        }

        fclose( trixdump );        

        /* Write index entries if we've changed trixel */
        if(VERBOSE) { fprintf(stderr, "Done with trixel %d!\n", current_trixel ); }
        writeIndexEntry(usfhead, current_trixel, us_header_offset + NTRIXELS * INDEX_ENTRY_SIZE + usf_trix_begin, usf_trix_count);
        usf_trix_begin += usf_trix_count * sizeof( deepStarData );
        if( usf_trix_count > MSpT_unnamed )
            MSpT_unnamed = usf_trix_count;
        ntrixels++;
        usf_trix_count = 0;
    }
    
    
    if(ntrixels != NTRIXELS) {
        fprintf(stderr, "ERROR: Expected %u trixels, but found %u instead. Please redefine NTRIXELS in this program, or check the source database for bogus trixels\n", NTRIXELS, ntrixels);
    }
    
    rewind(usf);
    fwrite(&maglim, 2, 1, usf);
    fwrite(&htm_level, 1, 1, usf);
    fwrite(&MSpT_unnamed, 2, 1, usf);

    fcloseall();
    
    return 0;
}