420 |
420 |
return loadNamedStyle ( key, theResultFlag );
|
421 |
421 |
}
|
422 |
422 |
|
423 |
|
QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFlag )
|
|
423 |
bool QgsMapLayer::loadNamedStyleFromDb(const QString db, const QString theURI, QString &qml)
|
424 |
424 |
{
|
425 |
|
theResultFlag = false;
|
|
425 |
bool theResultFlag = false;
|
426 |
426 |
|
427 |
|
QDomDocument myDocument ( "qgis" );
|
428 |
|
|
429 |
|
// location of problem associated with errorMsg
|
430 |
|
int line, column;
|
431 |
|
QString myErrorMessage;
|
432 |
|
|
433 |
|
QFile myFile ( theURI );
|
434 |
|
if ( myFile.open(QFile::ReadOnly ) )
|
435 |
|
{
|
436 |
|
// read file
|
437 |
|
theResultFlag = myDocument.setContent ( &myFile, &myErrorMessage, &line, &column );
|
438 |
|
if(!theResultFlag)
|
439 |
|
myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
|
440 |
|
myFile.close();
|
441 |
|
}
|
442 |
|
else
|
443 |
|
{
|
444 |
427 |
// read from database
|
445 |
428 |
sqlite3 *myDatabase;
|
446 |
429 |
sqlite3_stmt *myPreparedStatement;
|
447 |
430 |
const char *myTail;
|
448 |
431 |
int myResult;
|
449 |
432 |
|
450 |
|
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase);
|
451 |
|
if (myResult)
|
|
433 |
myResult = sqlite3_open(db.toUtf8().data(), &myDatabase);
|
|
434 |
if (!myResult)
|
452 |
435 |
{
|
453 |
|
return tr("could not open user database");
|
|
436 |
return false;
|
454 |
437 |
}
|
455 |
438 |
|
456 |
439 |
QString mySql = "select qml from tbl_styles where style=?";
|
... | ... | |
462 |
445 |
if( sqlite3_bind_text(myPreparedStatement, 1, param.data(), param.length(), SQLITE_STATIC)==SQLITE_OK &&
|
463 |
446 |
sqlite3_step(myPreparedStatement)==SQLITE_ROW )
|
464 |
447 |
{
|
465 |
|
QString qml = QString::fromUtf8( (char *)sqlite3_column_text(myPreparedStatement, 0) );
|
466 |
|
theResultFlag = myDocument.setContent ( qml, &myErrorMessage, &line, &column );
|
467 |
|
if(!theResultFlag)
|
468 |
|
myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
|
|
448 |
qml = QString::fromUtf8( (char *)sqlite3_column_text(myPreparedStatement, 0) );
|
|
449 |
theResultFlag = true;
|
469 |
450 |
}
|
470 |
451 |
}
|
471 |
|
else
|
472 |
|
{
|
473 |
|
theResultFlag = false;
|
474 |
|
myErrorMessage = tr("style %1 not found in database").arg(theURI);
|
475 |
|
}
|
476 |
452 |
|
477 |
453 |
sqlite3_finalize(myPreparedStatement);
|
478 |
454 |
sqlite3_close(myDatabase);
|
|
455 |
|
|
456 |
return theResultFlag;
|
|
457 |
}
|
|
458 |
|
|
459 |
QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFlag )
|
|
460 |
{
|
|
461 |
theResultFlag = false;
|
|
462 |
|
|
463 |
QDomDocument myDocument ( "qgis" );
|
|
464 |
|
|
465 |
// location of problem associated with errorMsg
|
|
466 |
int line, column;
|
|
467 |
QString myErrorMessage;
|
|
468 |
|
|
469 |
QFile myFile ( theURI );
|
|
470 |
if ( myFile.open(QFile::ReadOnly ) )
|
|
471 |
{
|
|
472 |
// read file
|
|
473 |
theResultFlag = myDocument.setContent ( &myFile, &myErrorMessage, &line, &column );
|
|
474 |
if(!theResultFlag)
|
|
475 |
myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
|
|
476 |
myFile.close();
|
479 |
477 |
}
|
|
478 |
else
|
|
479 |
{
|
|
480 |
QString qml;
|
|
481 |
if( loadNamedStyleFromDb( theURI, QgsApplication::qgisUserDbFilePath(), qml ) ||
|
|
482 |
loadNamedStyleFromDb( theURI, QgsApplication::qgisMasterDbFilePath(), qml ) )
|
|
483 |
{
|
|
484 |
theResultFlag = myDocument.setContent ( qml, &myErrorMessage, &line, &column );
|
|
485 |
if(!theResultFlag)
|
|
486 |
myErrorMessage = tr("%1 at line %2 column %3").arg( myErrorMessage ).arg( line ).arg(column);
|
|
487 |
}
|
|
488 |
else
|
|
489 |
{
|
|
490 |
myErrorMessage = tr("style not found in databases");
|
|
491 |
}
|
|
492 |
}
|
480 |
493 |
|
481 |
494 |
if(!theResultFlag)
|
482 |
495 |
return myErrorMessage;
|