void TestKoShapeFactory::testOdfElement()
{
    KoShapeFactoryBase * factory = new KoPathShapeFactory(QStringList());
    QVERIFY(factory->odfElements().front().second.contains("path"));
    QVERIFY(factory->odfElements().front().second.contains("line"));
    QVERIFY(factory->odfElements().front().second.contains("polyline"));
    QVERIFY(factory->odfElements().front().second.contains("polygon"));
    QVERIFY(factory->odfElements().front().first == KoXmlNS::draw);

    QBuffer xmldevice;
    xmldevice.open(QIODevice::WriteOnly);
    QTextStream xmlstream(&xmldevice);

    xmlstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    xmlstream << "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:koffice=\"http://www.koffice.org/2005/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
    xmlstream << "<office:body>";
    xmlstream << "<office:text>";
    xmlstream << "<text:p text:style-name=\"P1\"><?opendocument cursor-position?></text:p>";
    xmlstream << "<draw:path svg:d=\"M10,10L100,100\"></draw:path>";
    xmlstream << "</office:text>";
    xmlstream << "</office:body>";
    xmlstream << "</office:document-content>";
    xmldevice.close();

    KoXmlDocument doc;
    QString errorMsg;
    int errorLine = 0;
    int errorColumn = 0;

    QCOMPARE(doc.setContent(&xmldevice, true, &errorMsg, &errorLine, &errorColumn), true);
    QCOMPARE(errorMsg.isEmpty(), true);
    QCOMPARE(errorLine, 0);
    QCOMPARE(errorColumn, 0);

    KoXmlElement contentElement = doc.documentElement();
    KoXmlElement bodyElement = contentElement.firstChild().toElement();

    // XXX: When loading is implemented, these no doubt have to be
    // sensibly filled.
    KoOdfStylesReader stylesReader;
    KoOdfLoadingContext odfContext(stylesReader, 0);
    KoShapeLoadingContext shapeContext(odfContext, 0);

    KoXmlElement textElement = bodyElement.firstChild().firstChild().toElement();
    QVERIFY(textElement.tagName() == "p");
    QCOMPARE(factory->supports(textElement, shapeContext), false);

    KoXmlElement pathElement = bodyElement.firstChild().lastChild().toElement();
    QVERIFY(pathElement.tagName() == "path");
    QCOMPARE(factory->supports(pathElement, shapeContext), true);

    KoShape *shape = factory->createDefaultShape();
    QVERIFY(shape);

    QVERIFY(shape->loadOdf(pathElement, shapeContext));

    delete shape;
    delete factory;
}
Example #2
0
TEST_F(TransformQueryTest, OmeTransformsXML)
{
  boost::filesystem::path xmlfile = PROJECT_BINARY_DIR "/ome-xml/src/test/cpp/data/ome-transforms.xml";
  boost::filesystem::path xmldir = xmlfile.parent_path();
  if (!exists(xmldir) && !is_directory(xmldir) && !create_directories(xmldir))
    throw std::runtime_error("Data directory unavailable and could not be created");

  std::ofstream xmlstream(xmlfile.string().c_str());

  write_ome_transforms(resolver, xmlstream);
  write_ome_transforms(resolver, std::cout);
}
Example #3
0
void MainWindow::on_actionSave_As_activated()
{
    ui->statusBar->showMessage("Waiting for a name and location to save file to.");
    QString fileName = QFileDialog::getSaveFileName(this,
             tr("Save As"), "",
             tr("XML Files (*.xml);;All Files (*)"));
    QFile outfile( fileName );
    if ( !outfile.open( QFile::WriteOnly | QFile::Truncate ) )
    {
        qDebug() <<"Cannot open file for writing.";
            ui->statusBar->showMessage("Album not saved");
    }

    QTextStream xmlstream( &outfile );
    xmlstream << "<?xml version = '1.0' encoding = 'us-ascii'?>\n<album>\n";

    int count = 0;
    // traverse to begining
    while (!album.previousSibling().isNull())
    {
        count = count + 1;
        album = album.previousSibling();
    }

    //save until end
    while (!album.nextSibling().isNull())
    {
        album.save (xmlstream, 4);
        album = album.nextSibling();
    }
    album.save (xmlstream,4);

    //return to old position
    while (!album.previousSibling().isNull())
        album = album.previousSibling();

    while (count != 0)
    {
        count = count -1;
        album = album.nextSibling();
    }

    xmlstream << "</album>";
    outfile.close();
    ui->statusBar->showMessage("Album saved");
}
Example #4
0
void TestKoShapeRegistry::testCreateFramedShapes()
{
    QBuffer xmldevice;
    xmldevice.open(QIODevice::WriteOnly);
    QTextStream xmlstream(&xmldevice);

    xmlstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    xmlstream << "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:calligra=\"http://www.calligra.org/2005/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
    xmlstream << "<office:body>";
    xmlstream << "<office:text>";
    xmlstream << "<draw:path svg:d=\"M0,0L100,100\"></draw:path>";
    xmlstream << "</office:text>";
    xmlstream << "</office:body>";
    xmlstream << "</office:document-content>";
    xmldevice.close();

    KoXmlDocument doc;
    QString errorMsg;
    int errorLine = 0;
    int errorColumn = 0;

    QCOMPARE(doc.setContent(&xmldevice, true, &errorMsg, &errorLine, &errorColumn), true);
    QCOMPARE(errorMsg.isEmpty(), true);
    QCOMPARE(errorLine, 0);
    QCOMPARE(errorColumn, 0);

    KoXmlElement contentElement = doc.documentElement();
    KoXmlElement bodyElement = contentElement.firstChild().toElement();

    KoShapeRegistry * registry = KoShapeRegistry::instance();

    // XXX: When loading is implemented, these no doubt have to be
    // sensibly filled.
    KoOdfStylesReader stylesReader;
    KoOdfLoadingContext odfContext(stylesReader, 0);
    KoShapeLoadingContext shapeContext(odfContext, 0);

    KoShape * shape = registry->createShapeFromOdf(bodyElement, shapeContext);
    QVERIFY(shape == 0);

    KoXmlElement pathElement = bodyElement.firstChild().firstChild().toElement();
    shape = registry->createShapeFromOdf(pathElement, shapeContext);
    QVERIFY(shape != 0);
    QVERIFY(shape->shapeId() == KoPathShapeId);
}
Example #5
0
bool CCanalConfObj::parseDriverInfo( wxString& xmldata )
{
    bool rv = true;
    wxStringInputStream xmlstream( xmldata );
    wxXmlDocument doc;

    // Empty old MDF information
    //clearStorage();

    if ( !doc.Load( xmlstream ) ) {
        return false;
    }

    // start processing the XML file
    if ( doc.GetRoot()->GetName() != wxT( "config" ) ) {
        return false;
    }

    wxXmlNode *child1 = doc.GetRoot()->GetChildren();
    while ( child1 ) {
        if ( child1->GetName() == wxT( "description" ) ) {  
            
            m_decription = child1->GetNodeContent();

            wxString str = child1->GetAttribute( _( "type" ), _( "text" ) );
            str.Trim();
            str.Trim( false );
            str.MakeUpper();

            m_TypeDescription = type_text;
            if ( wxNOT_FOUND != str.Find( _( "HTML" ) ) ) {
                m_TypeDescription = type_html;
            }
        }
        else if ( child1->GetName() == wxT( "level" ) ) {
            m_level = vscp_readStringValue( child1->GetNodeContent() );
        }
        else if ( child1->GetName() == wxT( "blocking" ) ) {

            wxString str = child1->GetNodeContent();
            str.Trim();
            str.Trim( false );
            str.MakeUpper();

            m_bBlocking = true;
            if ( wxNOT_FOUND != str.Find( _( "NO" ) ) ) {
                m_bBlocking = false;
            }
        }
        else if ( child1->GetName() == wxT( "infourl" ) ) {
            m_infourl = child1->GetNodeContent();
        }
        else if ( child1->GetName() == wxT( "items" ) ) {
            
            wxXmlNode *child2 = child1->GetChildren();
            while ( child2 ) {

                if ( child2->GetName() == wxT( "item" ) ) {
                    
                    wxString str;

                    CCanalObj_OneItem *pOneItem = new CCanalObj_OneItem;
                    wxASSERT( NULL != pOneItem );
                    m_listItem.Append( pOneItem );
                    
                    pOneItem->m_pos = vscp_readStringValue( child2->GetAttribute( _( "pos" ), _( "0" ) ) );
                    pOneItem->m_description = child2->GetAttribute( _( "description" ), _( "" ) );
                    pOneItem->m_infourl = child2->GetAttribute( _( "infourl" ), _( "" ) );
                    
                    str = child2->GetAttribute( _( "optional" ), _( "false" ) );
                    str.MakeUpper();
                    pOneItem->m_bOptional = false;
                    if ( wxNOT_FOUND != str.Find( _( "TRUE" ) ) ) {
                        m_bBlocking = true;
                    }

                    pOneItem->m_type = type_unknown;
                    str = child2->GetAttribute( _( "type" ), _( "string" ) );
                    str.MakeUpper();
                    if ( wxNOT_FOUND != str.Find( _( "STRING" ) ) ) {
                        pOneItem->m_type = type_string;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "BOOLEAN" ) ) ) {
                        pOneItem->m_type = type_boolean;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "INT32" ) ) ) {
                        pOneItem->m_type = type_int32;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "UINT32" ) ) ) {
                        pOneItem->m_type = type_uint32;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "FLOAT" ) ) ) {
                        pOneItem->m_type = type_float;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "CHOICE" ) ) ) {
                        pOneItem->m_type = type_choice;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "ISOTIME" ) ) ) {
                        pOneItem->m_type = type_isotime;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "ISODATE" ) ) ) {
                        pOneItem->m_type = type_isodate;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "ISODATETIME" ) ) ) {
                        pOneItem->m_type = type_isodatetime;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "GUID" ) ) ) {
                        pOneItem->m_type = type_guid;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "EVENT" ) ) ) {
                        pOneItem->m_type = type_event;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "FILTER" ) ) ) {
                        pOneItem->m_type = type_filter;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "MASK" ) ) ) {
                        pOneItem->m_type = type_filter;
                    }

                    pOneItem->m_strValue = child2->GetAttribute( _( "value" ), _( "" ) );

                    wxXmlNode *child3 = child2->GetChildren();
                    while ( child3 ) {

                        if ( child3->GetName() == wxT( "choice" ) ) {

                            CCanalObj_Choice *pChoice = new CCanalObj_Choice;
                            wxASSERT( NULL != pChoice );
                            pOneItem->m_listChoice.Append( pChoice );

                            pChoice->m_description = 
                                        child3->GetAttribute( _( "description" ), _( "" ) );
                            pChoice->m_value = child3->GetAttribute( _( "value" ), _( "" ) );

                        } // choice

                        child3 = child3->GetNext();
                    }

                } // item

                child2 = child2->GetNext();
            } // while

        }
        else if ( child1->GetName() == wxT( "flags" ) ) {

            wxXmlNode *child2 = child1->GetChildren();
            while ( child2 ) {

                if ( ( child2->GetName() == wxT( "bit" )  ) || 
                        ( child2->GetName() == wxT( "flag" ) ) ) {

                    wxString str;

                    CCanalObj_FlagBit *pFlagBit = new CCanalObj_FlagBit;
                    wxASSERT( NULL != pFlagBit );
                    m_listFlagBits.Append( pFlagBit );

                    pFlagBit->m_pos = vscp_readStringValue( child2->GetAttribute( _( "pos" ), _( "0" ) ) );
                    pFlagBit->m_width = vscp_readStringValue( child2->GetAttribute( _( "width" ), _( "1" ) ) );
                    pFlagBit->m_defaultVal = vscp_readStringValue( child2->GetAttribute( _( "default" ), _( "0" ) ) );
                    pFlagBit->m_description = child2->GetAttribute( _( "description" ), _( "" ) );
                    pFlagBit->m_infourl = child2->GetAttribute( _( "infourl" ), _( "" ) );

                    pFlagBit->m_type = flagtype_bool;
                    str = child2->GetAttribute( _( "type" ), _( "BOOL" ) );
                    str.MakeUpper();
                    if ( wxNOT_FOUND != str.Find( _( "CHOICE" ) ) ) {
                        pFlagBit->m_type = flagtype_choice;
                    }
                    else if ( wxNOT_FOUND != str.Find( _( "VALUE" ) ) ) {
                        pFlagBit->m_type = flagtype_value;
                    }

                    wxXmlNode *child3 = child2->GetChildren();
                    while ( child3 ) {

                        if ( child3->GetName() == wxT( "choice" ) ) {

                            CCanalObj_Choice *pChoice = new CCanalObj_Choice;
                            wxASSERT( NULL != pChoice );
                            pFlagBit->m_listChoice.Append( pChoice );

                            pChoice->m_description = child3->GetAttribute( _( "description" ), _( "" ) );
                            pChoice->m_value = child3->GetAttribute( _( "value" ), _( "" ) );

                        } // choice

                        child3 = child3->GetNext();
                    }

                }
       
                child2 = child2->GetNext();
            }

        }

        child1 = child1->GetNext();
    }

    return rv;
}
Example #6
0
void MainWindow::on_actionSave_activated()
{

    QMessageBox msgBox;
    msgBox.setWindowTitle("Save");
    msgBox.setText("Do you wish to save all unsaved changes?");
    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    msgBox.setDefaultButton(QMessageBox::Yes);
    int ret = msgBox.exec();
    switch(ret){
    case QMessageBox::No:
        ui->statusBar->showMessage("File Save Canceled");
        break;
    case QMessageBox::Yes:
        QString fileName = currentWorkingFile;
        QFile outfile( fileName );
        if ( !outfile.open( QFile::WriteOnly | QFile::Truncate ) )
        {
            qDebug() <<"Cannot open file for writing.";
        }

        QTextStream xmlstream( &outfile );
        xmlstream << "<?xml version = '1.0' encoding = 'us-ascii'?>\n<album>\n";

        int count = 0;
        // traverse to begining
        while (!album.previousSibling().isNull())
        {
            count = count + 1;
            album = album.previousSibling();
        }

        //save until end
        while (!album.nextSibling().isNull())
        {
            album.save (xmlstream, 4);
            album = album.nextSibling();
        }
        album.save (xmlstream,4);

        //return to old position
        while (!album.previousSibling().isNull())
            album = album.previousSibling();

        while (count != 0)
        {
            count = count -1;
            album = album.nextSibling();
        }

        xmlstream << "</album>";
        outfile.close();
        currentWorkingFile = fileName;

        ui->horizontalSlider->setEnabled(false);
        ui->horizontalSlider->setVisible(false);
        ui->pushButton->setVisible(false);
        ui->pushButton->setEnabled(false);
        ui->statusBar->showMessage("Album saved");
        break;
    }
}