bool QDomImplementationProto::isNull() { QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject()); if (item) return item->isNull(); return false; }
QDomDocument *XmlWriter::toXml() { QDomImplementation implementation; QDomDocumentType docType = implementation.createDocumentType( "scribe-document", "scribe", "qt.nokia.com/scribe"); document = new QDomDocument(docType); // ### This processing instruction is required to ensure that any kind // of encoding is given when the document is written. QDomProcessingInstruction process = document->createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"utf-8\""); document->appendChild(process); QDomElement documentElement = document->createElement("document"); document->appendChild(documentElement); //! [0] QTextFrame *root = textDocument->rootFrame(); //! [0] if (root) processFrame(documentElement, root); return document; }
static PyObject *meth_QDomImplementation_hasFeature(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QString * a0; int a0State = 0; const QString * a1; int a1State = 0; QDomImplementation *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ1J1", &sipSelf, sipType_QDomImplementation, &sipCpp, sipType_QString,&a0, &a0State, sipType_QString,&a1, &a1State)) { bool sipRes; Py_BEGIN_ALLOW_THREADS sipRes = sipCpp->hasFeature(*a0,*a1); Py_END_ALLOW_THREADS sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State); sipReleaseType(const_cast<QString *>(a1),sipType_QString,a1State); return PyBool_FromLong(sipRes); } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QDomImplementation, sipName_hasFeature, NULL); return NULL; }
void TestQgsDataDefined::xmlMethods() { //create a test dom element QDomImplementation DomImplementation; QDomDocumentType documentType = DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" ); QDomDocument doc( documentType ); QgsDataDefined dd1; dd1.setActive( true ); dd1.setField( QString( "field" ) ); dd1.setExpressionString( QString( "expression" ) ); dd1.setUseExpression( true ); QDomElement ddElem = dd1.toXmlElement( doc, "test" ); //test reading QgsDataDefined dd2; QVERIFY( dd2 != dd1 ); QVERIFY( dd2.setFromXmlElement( ddElem ) ); QVERIFY( dd2 == dd1 ); //test reading from null element QDomElement badElem; QVERIFY( !dd2.setFromXmlElement( badElem ) ); }
int QDomImplementationProto::invalidDataPolicy() { QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject()); if (item) return item->invalidDataPolicy(); return 0; }
void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg ) { QDomImplementation DomImplementation; QDomDocumentType documentType = DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" ); QDomDocument myDocument( documentType ); QDomElement myRootNode = myDocument.createElement( "qgis" ); myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) ); myDocument.appendChild( myRootNode ); myRootNode.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 ); myRootNode.setAttribute( "minimumScale", QString::number( minimumScale() ) ); myRootNode.setAttribute( "maximumScale", QString::number( maximumScale() ) ); #if 0 // <transparencyLevelInt> QDomElement transparencyLevelIntElement = myDocument.createElement( "transparencyLevelInt" ); QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) ); transparencyLevelIntElement.appendChild( transparencyLevelIntText ); myRootNode.appendChild( transparencyLevelIntElement ); #endif if ( !writeSymbology( myRootNode, myDocument, errorMsg ) ) { errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg ); return; } doc = myDocument; }
QDomDocumentType QDomImplementationProto:: createDocumentType(const QString& qName, const QString& publicId, const QString& systemId) { QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject()); if (item) return item->createDocumentType(qName, publicId, systemId); return QDomDocumentType(); }
bool QDomImplementationProto:: hasFeature(const QString& feature, const QString& version) const { QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject()); if (item) return item->hasFeature(feature, version); return false; }
static PyObject *meth_QDomImplementation_createDocumentType(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QString * a0; int a0State = 0; const QString * a1; int a1State = 0; const QString * a2; int a2State = 0; QDomImplementation *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ1J1J1", &sipSelf, sipType_QDomImplementation, &sipCpp, sipType_QString,&a0, &a0State, sipType_QString,&a1, &a1State, sipType_QString,&a2, &a2State)) { QDomDocumentType *sipRes; Py_BEGIN_ALLOW_THREADS sipRes = new QDomDocumentType(sipCpp->createDocumentType(*a0,*a1,*a2)); Py_END_ALLOW_THREADS sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State); sipReleaseType(const_cast<QString *>(a1),sipType_QString,a1State); sipReleaseType(const_cast<QString *>(a2),sipType_QString,a2State); return sipConvertFromNewType(sipRes,sipType_QDomDocumentType,NULL); } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QDomImplementation, sipName_createDocumentType, NULL); return NULL; }
QDomDocument QDomImplementationProto:: createDocument(const QString& nsURI, const QString& qName, const QDomDocumentType& doctype) { QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject()); if (item) return item->createDocument(nsURI, qName, doctype); return QDomDocument(); }
void Browser::save(void) { std::cout << qPrintable(tr("Saving data")) << std::endl; QFile file( CFG_FILE ); QDir::setCurrent( CFG_DIR ); if( !file.open( QIODevice::WriteOnly ) ) { QString strErr = QObject::tr("Error: Can't save config file !"); std::cerr << " " << qPrintable(strErr) << std::endl; QMessageBox::warning(0, QObject::tr("Saving config file"), strErr ); file.close(); return; } std::cout << qPrintable(tr(" ")) << qPrintable(tr("Saving...")) << std::endl; QDomImplementation impl = QDomDocument().implementation(); QString name_ml = QLatin1String("BrowserML"); QString publicId = QLatin1String("-//CELLES//DTD Browser 0.1 //EN"); QString systemId = QLatin1String("http://www.celles.net/dtd/browser/browser_data-0_1.dtd"); QDomDocument doc(impl.createDocumentType(name_ml,publicId,systemId)); // add some XML comment at the beginning doc.appendChild(doc.createComment(QLatin1String("This file describe data for a very light browser for dynamic display"))); doc.appendChild(doc.createTextNode(QLatin1String("\n"))); // for nicer output doc.appendChild(doc.createComment(QLatin1String("http://www.celles.net/wiki/Browser"))); doc.appendChild(doc.createTextNode(QLatin1String("\n"))); // for nicer output QDomElement root = doc.createElement(QLatin1String("browser")); // racine root.setAttribute( QLatin1String("timer"), timer->interval() ); //std::cout << "timer=" << timer->interval() << std::endl; doc.appendChild(root); for (int i=0 ; i<url_list.count() ; i++) { QDomElement dom_elt = doc.createElement( QLatin1String("url") ); QDomText dom_txt = doc.createTextNode(url_list[i].toString()); dom_elt.appendChild(dom_txt); root.appendChild( dom_elt ); } QTextStream ts( &file ); ts << doc.toString(); file.close(); std::cout << qPrintable(tr(" ")) << qPrintable(tr("Data saved")) << std::endl; }
QDomDocument QLCFile::getXMLHeader(const QString& content, const QString& author) { if (content.isEmpty() == true) return QDomDocument(); QDomImplementation dom; QDomDocument doc(dom.createDocumentType(content, QString(), QString())); QDomProcessingInstruction instr = doc.createProcessingInstruction( "xml", "version='1.0' encoding='UTF-8'"); doc.appendChild(instr); QDomElement root; QDomElement tag; QDomElement subtag; QDomText text; root = doc.createElement(content); root.setAttribute("xmlns", KXMLQLCplusNamespace + content); doc.appendChild(root); /* Creator tag */ tag = doc.createElement(KXMLQLCCreator); root.appendChild(tag); /* Creator name */ subtag = doc.createElement(KXMLQLCCreatorName); tag.appendChild(subtag); text = doc.createTextNode(APPNAME); subtag.appendChild(text); /* Creator version */ subtag = doc.createElement(KXMLQLCCreatorVersion); tag.appendChild(subtag); text = doc.createTextNode(QString(APPVERSION)); subtag.appendChild(text); /* Author */ subtag = doc.createElement(KXMLQLCCreatorAuthor); tag.appendChild(subtag); if (author.isEmpty() == true) text = doc.createTextNode(currentUserName()); else text = doc.createTextNode(author); subtag.appendChild(text); return doc; }
void Data::save(void) { std::cout << qPrintable(tr("Saving data")) << std::endl; QFile file( OC_CFG_FILE ); QDir::setCurrent( OC_CFG_DIR ); if( !file.open( QIODevice::WriteOnly ) ) { QString strErr = QObject::tr("Error: Can't save config file !"); std::cerr << " " << qPrintable(strErr) << std::endl; QMessageBox::warning(0, QObject::tr("Saving config file"), strErr ); file.close(); return; } std::cout << qPrintable(tr(" ")) << qPrintable(tr("Saving...")) << std::endl; QDomImplementation impl = QDomDocument().implementation(); QString name_ml = QLatin1String("OpenChronoML"); QString publicId = QLatin1String("-//CELLES//DTD OpenChrono 0.1 //EN"); QString systemId = QLatin1String("http://www.celles.net/dtd/openchrono/openchrono_data-0_1.dtd"); QDomDocument doc(impl.createDocumentType(name_ml,publicId,systemId)); // add some XML comment at the beginning doc.appendChild(doc.createComment(QLatin1String("This file describe data for OpenChrono a chronometer for mechanical sports"))); doc.appendChild(doc.createTextNode(QLatin1String("\n"))); // for nicer output doc.appendChild(doc.createComment(QLatin1String("http://www.celles.net/wikini/wakka.php?wiki=OpenChrono"))); doc.appendChild(doc.createTextNode(QLatin1String("\n"))); // for nicer output QDomElement root = doc.createElement(QLatin1String("ocdata")); // racine doc.appendChild(root); root.appendChild( track.to_node(doc) ); root.appendChild( position.to_node(doc) ); root.appendChild( vehicule.to_node(doc) ); root.appendChild( chrono.to_node(doc) ); QTextStream ts( &file ); ts << doc.toString(); //std::cout << doc.toString(); file.close(); std::cout << qPrintable(tr(" ")) << qPrintable(tr("Data saved")) << std::endl; }
//--------------------------------------------------------------------------- // asXml // //! Return an XML string representing the search spec. // //! @return the XML string representation //--------------------------------------------------------------------------- QString SearchSpec::asXml() const { QDomImplementation implementation; QDomDocument document(implementation.createDocumentType( "zyzzyva-search", QString(), "http://pietdepsi.com/dtd/zyzzyva-search.dtd")); document.appendChild(asDomElement()); //// XXX: There should be a programmatic way to write the <?xml?> header //// based on the QDomImplementation, shouldn't there? return QString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n") + document.toString(); }
void QgsLayerTreeUtils::storeOriginalLayersProperties( QgsLayerTreeGroup *group, const QDomDocument *doc ) { const QDomNodeList mlNodeList( doc->documentElement() .firstChildElement( QStringLiteral( "projectlayers" ) ) .elementsByTagName( QStringLiteral( "maplayer" ) ) ); std::function<void ( QgsLayerTreeNode * )> _store = [ & ]( QgsLayerTreeNode * node ) { if ( QgsLayerTree::isLayer( node ) ) { QgsMapLayer *l( QgsLayerTree::toLayer( node )->layer() ); if ( l ) { for ( int i = 0; i < mlNodeList.count(); i++ ) { QDomNode mlNode( mlNodeList.at( i ) ); QString id( mlNode.firstChildElement( QStringLiteral( "id" ) ).firstChild().nodeValue() ); if ( id == l->id() ) { QDomImplementation DomImplementation; QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) ); QDomDocument document( documentType ); QDomElement element = mlNode.toElement(); document.appendChild( element ); QString str; QTextStream stream( &str ); document.save( stream, 4 /*indent*/ ); l->setOriginalXmlProperties( str ); } } } } else if ( QgsLayerTree::isGroup( node ) ) { const QList<QgsLayerTreeNode *> constChildren( node->children( ) ); for ( const auto &childNode : constChildren ) { _store( childNode ); } } }; for ( QgsLayerTreeNode *node : group->children() ) { _store( node ); } }
static PyObject *meth_QDomImplementation_isNull(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { QDomImplementation *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QDomImplementation, &sipCpp)) { bool sipRes; Py_BEGIN_ALLOW_THREADS sipRes = sipCpp->isNull(); Py_END_ALLOW_THREADS return PyBool_FromLong(sipRes); } }
bool QLCFile::getXMLHeader(QString content, QDomDocument** doc) { QDomImplementation dom; QDomDocumentType doctype; QDomElement root; QDomElement tag; QDomElement subtag; QDomText text; if (doc == NULL || content == NULL) return false; doctype = dom.createDocumentType(content, QString::null, QString::null); *doc = new QDomDocument(doctype); root = (*doc)->createElement(content); (*doc)->appendChild(root); /* Creator tag */ tag = (*doc)->createElement(KXMLQLCCreator); root.appendChild(tag); /* Creator name */ subtag = (*doc)->createElement(KXMLQLCCreatorName); tag.appendChild(subtag); text = (*doc)->createTextNode("Q Light Controller"); subtag.appendChild(text); /* Creator version */ subtag = (*doc)->createElement(KXMLQLCCreatorVersion); tag.appendChild(subtag); text = (*doc)->createTextNode(QString(VERSION)); subtag.appendChild(text); /* Author */ subtag = (*doc)->createElement(KXMLQLCCreatorAuthor); tag.appendChild(subtag); text = (*doc)->createTextNode(QString(getenv("USER"))); subtag.appendChild(text); return true; }
QDomDocument *XmlWriter::toXml() { QDomImplementation implementation; QDomDocumentType docType = implementation.createDocumentType( "scribe-document", "scribe", "www.trolltech.com/scribe"); document = new QDomDocument(docType); // ### This processing instruction is required to ensure that any kind // of encoding is given when the document is written. QDomProcessingInstruction process = document->createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"utf-8\""); document->appendChild(process); QDomElement documentElement = document->createElement("document"); document->appendChild(documentElement); QTextBlock firstBlock = textDocument->begin(); createItems(documentElement, firstBlock); return document; }
QDomDocument *XmlWriter::toXml() { QDomImplementation implementation; QDomDocumentType docType = implementation.createDocumentType( "scribe-document", "scribe", "qt.nokia.com/scribe"); document = new QDomDocument(docType); // ### This processing instruction is required to ensure that any kind // of encoding is given when the document is written. QDomProcessingInstruction process = document->createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"utf-8\""); document->appendChild(process); QDomElement documentElement = document->createElement("document"); document->appendChild(documentElement); //! [0] QTextBlock currentBlock = textDocument->begin(); while (currentBlock.isValid()) { //! [0] QDomElement blockElement = document->createElement("block"); document->appendChild(blockElement); readFragment(currentBlock, blockElement, document); //! [1] processBlock(currentBlock); //! [1] //! [2] currentBlock = currentBlock.next(); } //! [2] return document; }
void PListConfigBackend::save(const QString &file, const QVariant &entry) { QDomImplementation domImpl; QDomDocumentType type = domImpl.createDocumentType(QLatin1String("plist"), QLatin1String("-//Apple Computer//DTD PLIST 1.0//EN"), QLatin1String("http://www.apple.com/DTDs/PropertyList-1.0.dtd") ); QDomDocument root(type); QDomElement plist = root.createElement("plist"); plist.setAttribute("version","1.0"); plist.appendChild(generateQDomElement(entry, root)); root.appendChild(plist); QSaveFile output (file); if (!output.open(QIODevice::WriteOnly)) { qWarning() << tr("Cannot write to file %1").arg(file); return; } QTextStream out(&output); static QTextCodec *utf8 = QTextCodec::codecForName("utf-8"); out.setCodec(utf8); out << QLatin1String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //hack root.save(out, 2, QDomNode::EncodingFromDocument); output.commit(); }
void QDomImplementationProto::setInvalidDataPolicy(int policy) { QDomImplementation *item = qscriptvalue_cast<QDomImplementation*>(thisObject()); if (item) item->setInvalidDataPolicy((QDomImplementation::InvalidDataPolicy)policy); }
bool QgsProject::write() { clearError(); // if we have problems creating or otherwise writing to the project file, // let's find out up front before we go through all the hand-waving // necessary to create all the Dom objects if ( !imp_->file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) ) { imp_->file.close(); // even though we got an error, let's make // sure it's closed anyway setError( tr( "Unable to save to file %1" ).arg( imp_->file.fileName() ) ); return false; } QFileInfo myFileInfo( imp_->file ); if ( !myFileInfo.isWritable() ) { // even though we got an error, let's make // sure it's closed anyway imp_->file.close(); setError( tr( "%1 is not writable. Please adjust permissions (if possible) and try again." ) .arg( imp_->file.fileName() ) ); return false; } QDomImplementation DomImplementation; QDomDocumentType documentType = DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" ); std::auto_ptr < QDomDocument > doc = std::auto_ptr < QDomDocument > ( new QDomDocument( documentType ) ); QDomElement qgisNode = doc->createElement( "qgis" ); qgisNode.setAttribute( "projectname", title() ); qgisNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) ); doc->appendChild( qgisNode ); // title QDomElement titleNode = doc->createElement( "title" ); qgisNode.appendChild( titleNode ); QDomText titleText = doc->createTextNode( title() ); // XXX why have title TWICE? titleNode.appendChild( titleText ); // let map canvas and legend write their information emit writeProject( *doc ); // within top level node save list of layers QMap<QString, QgsMapLayer*> & layers = QgsMapLayerRegistry::instance()->mapLayers(); // Iterate over layers in zOrder // Call writeXML() on each QDomElement projectLayersNode = doc->createElement( "projectlayers" ); projectLayersNode.setAttribute( "layercount", qulonglong( layers.size() ) ); QMap<QString, QgsMapLayer*>::iterator li = layers.begin(); while ( li != layers.end() ) { //QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer(*li); QgsMapLayer* ml = li.value(); if ( ml ) { QString externalProjectFile = layerIsEmbedded( ml->id() ); QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.find( ml->id() ); if ( emIt == mEmbeddedLayers.constEnd() ) { ml->writeXML( projectLayersNode, *doc ); } else //layer defined in an external project file { //only save embedded layer if not managed by a legend group if ( emIt.value().second ) { QDomElement mapLayerElem = doc->createElement( "maplayer" ); mapLayerElem.setAttribute( "embedded", 1 ); mapLayerElem.setAttribute( "project", writePath( emIt.value().first ) ); mapLayerElem.setAttribute( "id", ml->id() ); projectLayersNode.appendChild( mapLayerElem ); } } } li++; } qgisNode.appendChild( projectLayersNode ); // now add the optional extra properties dump_( imp_->properties_ ); QgsDebugMsg( QString( "there are %1 property scopes" ).arg( static_cast<int>( imp_->properties_.count() ) ) ); if ( !imp_->properties_.isEmpty() ) // only worry about properties if we // actually have any properties { imp_->properties_.writeXML( "properties", qgisNode, *doc ); } // now wrap it up and ship it to the project file doc->normalize(); // XXX I'm not entirely sure what this does //QString xml = doc->toString(4); // write to string with indentation of four characters // (yes, four is arbitrary) // const char * xmlString = xml; // debugger probe point // qDebug( "project file output:\n\n" + xml ); QTextStream projectFileStream( &imp_->file ); //projectFileStream << xml << endl; doc->save( projectFileStream, 4 ); // save as utf-8 imp_->file.close(); // check if the text stream had no error - if it does // the user will get a message so they can try to resolve the // situation e.g. by saving project to a volume with more space // if ( projectFileStream.pos() == -1 || imp_->file.error() != QFile::NoError ) { setError( tr( "Unable to save to file %1. Your project " "may be corrupted on disk. Try clearing some space on the volume and " "check file permissions before pressing save again." ) .arg( imp_->file.fileName() ) ); return false; } dirty( false ); // reset to pristine state emit projectSaved(); return true; } // QgsProject::write
void MenuFile::create() { QDomImplementation impl; QDomDocumentType docType = impl.createDocumentType( MF_MENU, MF_PUBLIC_ID, MF_SYSTEM_ID ); m_doc = impl.createDocument(QString(), MF_MENU, docType); }
QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag ) { QString myErrorMessage; QDomImplementation DomImplementation; QDomDocumentType documentType = DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" ); QDomDocument myDocument( documentType ); QDomElement myRootNode = myDocument.createElement( "qgis" ); myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) ); myDocument.appendChild( myRootNode ); // use scale dependent visibility flag myRootNode.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 ); myRootNode.setAttribute( "minimumScale", minimumScale() ); myRootNode.setAttribute( "maximumScale", maximumScale() ); // <transparencyLevelInt> QDomElement transparencyLevelIntElement = myDocument.createElement( "transparencyLevelInt" ); QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) ); transparencyLevelIntElement.appendChild( transparencyLevelIntText ); myRootNode.appendChild( transparencyLevelIntElement ); // now append layer node to map layer node QString errorMsg; if ( !writeSymbology( myRootNode, myDocument, errorMsg ) ) { return tr( "Could not save symbology because:\n%1" ).arg( errorMsg ); } // check if the uri is a file or ends with .qml, // which indicates that it should become one // everything else goes to the database QString filename; QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this ); if ( vlayer && vlayer->providerType() == "ogr" ) { QStringList theURIParts = theURI.split( "|" ); filename = theURIParts[0]; } else if ( vlayer && vlayer->providerType() == "delimitedtext" ) { filename = QUrl::fromEncoded( theURI.toAscii() ).toLocalFile(); } else { filename = theURI; } QFileInfo myFileInfo( filename ); if ( myFileInfo.exists() || filename.endsWith( ".qml", Qt::CaseInsensitive ) ) { QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name if ( !myDirInfo.isWritable() ) { return tr( "The directory containing your dataset needs to be writable!" ); } // now construct the file name for our .qml style file QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".qml"; QFile myFile( myFileName ); if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) ) { QTextStream myFileStream( &myFile ); // save as utf-8 with 2 spaces for indents myDocument.save( myFileStream, 2 ); myFile.close(); theResultFlag = true; return tr( "Created default style file as %1" ).arg( myFileName ); } else { theResultFlag = false; return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName ); } } else { QString qml = myDocument.toString(); // read from database sqlite3 *myDatabase; sqlite3_stmt *myPreparedStatement; const char *myTail; int myResult; myResult = sqlite3_open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( "qgis.qmldb" ).toUtf8().data(), &myDatabase ); if ( myResult != SQLITE_OK ) { return tr( "User database could not be opened." ); } QByteArray param0 = theURI.toUtf8(); QByteArray param1 = qml.toUtf8(); QString mySql = "create table if not exists tbl_styles(style varchar primary key,qml varchar)"; myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail ); if ( myResult == SQLITE_OK ) { if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE ) { sqlite3_finalize( myPreparedStatement ); sqlite3_close( myDatabase ); theResultFlag = false; return tr( "The style table could not be created." ); } } sqlite3_finalize( myPreparedStatement ); mySql = "insert into tbl_styles(style,qml) values (?,?)"; myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail ); if ( myResult == SQLITE_OK ) { if ( sqlite3_bind_text( myPreparedStatement, 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK && sqlite3_bind_text( myPreparedStatement, 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_DONE ) { theResultFlag = true; myErrorMessage = tr( "The style %1 was saved to database" ).arg( theURI ); } } sqlite3_finalize( myPreparedStatement ); if ( !theResultFlag ) { QString mySql = "update tbl_styles set qml=? where style=?"; myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail ); if ( myResult == SQLITE_OK ) { if ( sqlite3_bind_text( myPreparedStatement, 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK && sqlite3_bind_text( myPreparedStatement, 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_DONE ) { theResultFlag = true; myErrorMessage = tr( "The style %1 was updated in the database." ).arg( theURI ); } else { theResultFlag = false; myErrorMessage = tr( "The style %1 could not be updated in the database." ).arg( theURI ); } } else { theResultFlag = false; myErrorMessage = tr( "The style %1 could not be inserted into database." ).arg( theURI ); } sqlite3_finalize( myPreparedStatement ); } sqlite3_close( myDatabase ); } return myErrorMessage; }