00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <QDateTime>
00021 #include <QDomNode>
00022 #include <QFileInfo>
00023 #include <QSettings>
00024 #include <QDir>
00025 #include <QFile>
00026 #include <QFileInfo>
00027 #include <QDomDocument>
00028 #include <QDomElement>
00029 #include <QDomImplementation>
00030 #include <QTextStream>
00031
00032 #include <sqlite3.h>
00033
00034 #include "qgslogger.h"
00035 #include "qgsrectangle.h"
00036 #include "qgssymbol.h"
00037 #include "qgsmaplayer.h"
00038 #include "qgscoordinatereferencesystem.h"
00039 #include "qgsapplication.h"
00040 #include "qgsproject.h"
00041 #include "qgslogger.h"
00042 #include "qgsdatasourceuri.h"
00043 #include "qgsvectorlayer.h"
00044
00045 QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
00046 QString lyrname,
00047 QString source ) :
00048 mTransparencyLevel( 255 ),
00049 mValid( false ),
00050 mDataSource( source ),
00051 mID( "" ),
00052 mLayerType( type )
00053
00054 {
00055 QgsDebugMsg( "lyrname is '" + lyrname + "'" );
00056
00057 mCRS = new QgsCoordinateReferenceSystem();
00058
00059
00060 mLayerName = capitaliseLayerName( lyrname );
00061 QgsDebugMsg( "layerName is '" + mLayerName + "'" );
00062
00063
00064 QDateTime dt = QDateTime::currentDateTime();
00065 mID = lyrname + dt.toString( "yyyyMMddhhmmsszzz" );
00066
00067
00068
00069
00070
00071
00072 mID.replace( QRegExp( "[\\W]" ), "_" );
00073
00074
00075 mMinScale = 0;
00076 mMaxScale = 100000000;
00077 mScaleBasedVisibility = false;
00078 mpCacheImage = 0;
00079 }
00080
00081
00082
00083 QgsMapLayer::~QgsMapLayer()
00084 {
00085 delete mCRS;
00086 if ( mpCacheImage )
00087 {
00088 delete mpCacheImage;
00089 }
00090 }
00091
00092 QgsMapLayer::LayerType QgsMapLayer::type() const
00093 {
00094 return mLayerType;
00095 }
00096
00098 QString QgsMapLayer::getLayerID() const
00099 {
00100 return mID;
00101 }
00102
00104 void QgsMapLayer::setLayerName( const QString & name )
00105 {
00106 QgsDebugMsg( "new name is '" + name + "'" );
00107 mLayerName = capitaliseLayerName( name );
00108 emit layerNameChanged();
00109 }
00110
00112 QString const & QgsMapLayer::name() const
00113 {
00114 QgsDebugMsgLevel( "returning name '" + mLayerName + "'", 3 );
00115 return mLayerName;
00116 }
00117
00118 QString QgsMapLayer::publicSource() const
00119 {
00120
00121
00122 QString safeName = QgsDataSourceURI::removePassword( mDataSource );
00123 return safeName;
00124 }
00125
00126 QString const & QgsMapLayer::source() const
00127 {
00128 return mDataSource;
00129 }
00130
00131 QgsRectangle QgsMapLayer::extent() const
00132 {
00133 return mLayerExtent;
00134 }
00135
00136 bool QgsMapLayer::draw( QgsRenderContext& rendererContext )
00137 {
00138 return false;
00139 }
00140
00141 void QgsMapLayer::drawLabels( QgsRenderContext& rendererContext )
00142 {
00143
00144 }
00145
00146 bool QgsMapLayer::readXML( QDomNode & layer_node )
00147 {
00148 QgsCoordinateReferenceSystem savedCRS;
00149 CUSTOM_CRS_VALIDATION savedValidation;
00150 bool layerError;
00151
00152 QDomElement element = layer_node.toElement();
00153
00154 QDomNode mnl;
00155 QDomElement mne;
00156
00157
00158 QString provider;
00159 mnl = layer_node.namedItem( "provider" );
00160 mne = mnl.toElement();
00161 provider = mne.text();
00162
00163
00164 mnl = layer_node.namedItem( "datasource" );
00165 mne = mnl.toElement();
00166 mDataSource = mne.text();
00167
00168 if ( provider == "spatialite" )
00169 {
00170 QgsDataSourceURI uri( mDataSource );
00171 uri.setDatabase( QgsProject::instance()->readPath( uri.database() ) );
00172 mDataSource = uri.uri();
00173 }
00174 else if ( provider == "ogr" )
00175 {
00176 QStringList theURIParts = mDataSource.split( "|" );
00177 theURIParts[0] = QgsProject::instance()->readPath( theURIParts[0] );
00178 mDataSource = theURIParts.join( "|" );
00179 }
00180 else
00181 {
00182 mDataSource = QgsProject::instance()->readPath( mDataSource );
00183 }
00184
00185
00186
00187
00188
00189 mnl = layer_node.namedItem( "layername" );
00190 mne = mnl.toElement();
00191
00192 QDomNode srsNode = layer_node.namedItem( "srs" );
00193 mCRS->readXML( srsNode );
00194 mCRS->setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
00195 mCRS->validate();
00196 savedCRS = *mCRS;
00197
00198
00199
00200 savedValidation = QgsCoordinateReferenceSystem::customSrsValidation();
00201 QgsCoordinateReferenceSystem::setCustomSrsValidation( NULL );
00202
00203
00204 layerError = !readXml( layer_node );
00205
00206
00207
00208
00209 QgsCoordinateReferenceSystem::setCustomSrsValidation( savedValidation );
00210 *mCRS = savedCRS;
00211
00212
00213 if ( layerError )
00214 {
00215 return false;
00216 }
00217
00218
00219
00220
00221
00222
00223 mnl = layer_node.namedItem( "id" );
00224 if ( ! mnl.isNull() )
00225 {
00226 mne = mnl.toElement();
00227 if ( ! mne.isNull() && mne.text().length() > 10 )
00228 {
00229 mID = mne.text();
00230 }
00231 }
00232
00233
00234 toggleScaleBasedVisibility( element.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
00235 setMinimumScale( element.attribute( "minimumScale" ).toFloat() );
00236 setMaximumScale( element.attribute( "maximumScale" ).toFloat() );
00237
00238
00239 mnl = layer_node.namedItem( "layername" );
00240 mne = mnl.toElement();
00241 setLayerName( mne.text() );
00242
00243
00244 QDomNode transparencyNode = layer_node.namedItem( "transparencyLevelInt" );
00245 if ( ! transparencyNode.isNull() )
00246 {
00247
00248
00249 QDomElement myElement = transparencyNode.toElement();
00250 setTransparency( myElement.text().toInt() );
00251 }
00252
00253 readCustomProperties( layer_node );
00254
00255 return true;
00256 }
00257
00258
00259 bool QgsMapLayer::readXml( QDomNode & layer_node )
00260 {
00261
00262
00263 return true;
00264 }
00265
00266
00267
00268 bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
00269 {
00270
00271 QDomElement maplayer = document.createElement( "maplayer" );
00272
00273
00274 maplayer.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 );
00275 maplayer.setAttribute( "minimumScale", minimumScale() );
00276 maplayer.setAttribute( "maximumScale", maximumScale() );
00277
00278
00279 QDomElement id = document.createElement( "id" );
00280 QDomText idText = document.createTextNode( getLayerID() );
00281 id.appendChild( idText );
00282
00283 maplayer.appendChild( id );
00284
00285
00286 QDomElement dataSource = document.createElement( "datasource" );
00287
00288 QString src = source();
00289
00290 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
00291 if ( vlayer && vlayer->providerType() == "spatialite" )
00292 {
00293 QgsDataSourceURI uri( src );
00294 QString database = QgsProject::instance()->writePath( uri.database() );
00295 uri.setConnection( uri.host(), uri.port(), database, uri.username(), uri.password() );
00296 src = uri.uri();
00297 }
00298 else if ( vlayer && vlayer->providerType() == "ogr" )
00299 {
00300 QStringList theURIParts = src.split( "|" );
00301 theURIParts[0] = QgsProject::instance()->writePath( theURIParts[0] );
00302 src = theURIParts.join( "|" );
00303 }
00304 else
00305 {
00306 src = QgsProject::instance()->writePath( src );
00307 }
00308
00309 QDomText dataSourceText = document.createTextNode( src );
00310 dataSource.appendChild( dataSourceText );
00311
00312 maplayer.appendChild( dataSource );
00313
00314
00315
00316 QDomElement layerName = document.createElement( "layername" );
00317 QDomText layerNameText = document.createTextNode( name() );
00318 layerName.appendChild( layerNameText );
00319
00320 maplayer.appendChild( layerName );
00321
00322
00323
00324
00325
00326
00327 QDomElement mySrsElement = document.createElement( "srs" );
00328 mCRS->writeXML( mySrsElement, document );
00329 maplayer.appendChild( mySrsElement );
00330
00331
00332 QDomElement transparencyLevelIntElement = document.createElement( "transparencyLevelInt" );
00333 QDomText transparencyLevelIntText = document.createTextNode( QString::number( getTransparency() ) );
00334 transparencyLevelIntElement.appendChild( transparencyLevelIntText );
00335 maplayer.appendChild( transparencyLevelIntElement );
00336
00337
00338 layer_node.appendChild( maplayer );
00339
00340 writeCustomProperties( maplayer, document );
00341
00342 return writeXml( maplayer, document );
00343
00344 }
00345
00346
00347
00348 bool QgsMapLayer::writeXml( QDomNode & layer_node, QDomDocument & document )
00349 {
00350
00351
00352 return true;
00353 }
00354
00355
00356
00357
00358 bool QgsMapLayer::isValid()
00359 {
00360 return mValid;
00361 }
00362
00363
00364 void QgsMapLayer::invalidTransformInput()
00365 {
00366 QgsDebugMsg( "called" );
00367
00368 }
00369
00370
00371 QString QgsMapLayer::lastErrorTitle()
00372 {
00373 return QString();
00374 }
00375
00376 QString QgsMapLayer::lastError()
00377 {
00378 return QString();
00379 }
00380
00381 void QgsMapLayer::connectNotify( const char * signal )
00382 {
00383 QgsDebugMsgLevel( "QgsMapLayer connected to " + QString( signal ), 3 );
00384 }
00385
00386
00387
00388 void QgsMapLayer::toggleScaleBasedVisibility( bool theVisibilityFlag )
00389 {
00390 mScaleBasedVisibility = theVisibilityFlag;
00391 }
00392
00393 bool QgsMapLayer::hasScaleBasedVisibility()
00394 {
00395 return mScaleBasedVisibility;
00396 }
00397
00398 void QgsMapLayer::setMinimumScale( float theMinScale )
00399 {
00400 mMinScale = theMinScale;
00401 }
00402
00403 float QgsMapLayer::minimumScale()
00404 {
00405 return mMinScale;
00406 }
00407
00408
00409 void QgsMapLayer::setMaximumScale( float theMaxScale )
00410 {
00411 mMaxScale = theMaxScale;
00412 }
00413
00414 float QgsMapLayer::maximumScale()
00415 {
00416 return mMaxScale;
00417 }
00418
00419
00420 QStringList QgsMapLayer::subLayers()
00421 {
00422 return QStringList();
00423 }
00424
00425 void QgsMapLayer::setLayerOrder( QStringList layers )
00426 {
00427
00428 }
00429
00430 void QgsMapLayer::setSubLayerVisibility( QString name, bool vis )
00431 {
00432
00433 }
00434
00435 const QgsCoordinateReferenceSystem& QgsMapLayer::crs()
00436 {
00437 return *mCRS;
00438 }
00439
00440 const QgsCoordinateReferenceSystem& QgsMapLayer::srs()
00441 {
00442
00443
00444 return *mCRS;
00445 }
00446
00447 void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal )
00448 {
00449 *mCRS = srs;
00450 if ( emitSignal )
00451 emit layerCrsChanged();
00452 }
00453
00454 unsigned int QgsMapLayer::getTransparency()
00455 {
00456 return mTransparencyLevel;
00457 }
00458
00459 void QgsMapLayer::setTransparency( unsigned int theInt )
00460 {
00461 mTransparencyLevel = theInt;
00462 }
00463
00464 QString QgsMapLayer::capitaliseLayerName( const QString name )
00465 {
00466
00467 QSettings settings;
00468 bool capitaliseLayerName =
00469 settings.value( "qgis/capitaliseLayerName", QVariant( false ) ).toBool();
00470
00471 QString layerName( name );
00472
00473 if ( capitaliseLayerName )
00474 layerName = layerName.left( 1 ).toUpper() + layerName.mid( 1 );
00475
00476 return layerName;
00477 }
00478
00479 QString QgsMapLayer::loadDefaultStyle( bool & theResultFlag )
00480 {
00481 QString myURI = publicSource();
00482 QFileInfo myFileInfo( myURI );
00483 QString key;
00484 if ( myFileInfo.exists() )
00485 {
00486
00487 key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".qml";
00488 }
00489 else
00490 {
00491 key = myURI;
00492 }
00493 return loadNamedStyle( key, theResultFlag );
00494 }
00495
00496 bool QgsMapLayer::loadNamedStyleFromDb( const QString db, const QString theURI, QString &qml )
00497 {
00498 bool theResultFlag = false;
00499
00500
00501 sqlite3 *myDatabase;
00502 sqlite3_stmt *myPreparedStatement;
00503 const char *myTail;
00504 int myResult;
00505
00506 QgsDebugMsg( QString( "Trying to load style for \"%1\" from \"%2\"" ).arg( theURI ).arg( db ) );
00507
00508 if ( !QFile( db ).exists() )
00509 return false;
00510
00511 myResult = sqlite3_open( db.toUtf8().data(), &myDatabase );
00512 if ( myResult != SQLITE_OK )
00513 {
00514 return false;
00515 }
00516
00517 QString mySql = "select qml from tbl_styles where style=?";
00518 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
00519 if ( myResult == SQLITE_OK )
00520 {
00521 QByteArray param = theURI.toUtf8();
00522
00523 if ( sqlite3_bind_text( myPreparedStatement, 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
00524 sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
00525 {
00526 qml = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 0 ) );
00527 theResultFlag = true;
00528 }
00529
00530 sqlite3_finalize( myPreparedStatement );
00531 }
00532
00533 sqlite3_close( myDatabase );
00534
00535 return theResultFlag;
00536 }
00537
00538 QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
00539 {
00540 theResultFlag = false;
00541
00542 QDomDocument myDocument( "qgis" );
00543
00544
00545 int line, column;
00546 QString myErrorMessage;
00547
00548 QFile myFile( theURI );
00549 if ( myFile.open( QFile::ReadOnly ) )
00550 {
00551
00552 theResultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
00553 if ( !theResultFlag )
00554 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
00555 myFile.close();
00556 }
00557 else
00558 {
00559 QFileInfo project( QgsProject::instance()->fileName() );
00560 QgsDebugMsg( QString( "project fileName: %1" ).arg( project.absoluteFilePath() ) );
00561
00562 QString qml;
00563 if ( loadNamedStyleFromDb( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( "qgis.qmldb" ), theURI, qml ) ||
00564 ( project.exists() && loadNamedStyleFromDb( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), theURI, qml ) ) ||
00565 loadNamedStyleFromDb( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( "resources/qgis.qmldb" ), theURI, qml ) )
00566 {
00567 theResultFlag = myDocument.setContent( qml, &myErrorMessage, &line, &column );
00568 if ( !theResultFlag )
00569 {
00570 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
00571 }
00572 }
00573 else
00574 {
00575 myErrorMessage = tr( "style not found in database" );
00576 }
00577 }
00578
00579 if ( !theResultFlag )
00580 {
00581 return myErrorMessage;
00582 }
00583
00584
00585
00586 QDomElement myRoot = myDocument.firstChildElement( "qgis" );
00587 if ( myRoot.isNull() )
00588 {
00589 myErrorMessage = tr( "Error: qgis element could not be found in %1" ).arg( theURI );
00590 theResultFlag = false;
00591 return myErrorMessage;
00592 }
00593
00594
00595 toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
00596 setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
00597 setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );
00598
00599
00600 QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );
00601 if ( ! transparencyNode.isNull() )
00602 {
00603
00604
00605 QDomElement myElement = transparencyNode.toElement();
00606 setTransparency( myElement.text().toInt() );
00607 }
00608
00609 QString errorMsg;
00610 theResultFlag = readSymbology( myRoot, errorMsg );
00611 if ( !theResultFlag )
00612 {
00613 myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( theURI ).arg( errorMsg );
00614 return myErrorMessage;
00615 }
00616
00617 return "";
00618 }
00619
00620 QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )
00621 {
00622 return saveNamedStyle( publicSource(), theResultFlag );
00623 }
00624
00625 QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag )
00626 {
00627 QString myErrorMessage;
00628
00629 QDomImplementation DomImplementation;
00630 QDomDocumentType documentType =
00631 DomImplementation.createDocumentType(
00632 "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" );
00633 QDomDocument myDocument( documentType );
00634 QDomElement myRootNode = myDocument.createElement( "qgis" );
00635 myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
00636 myDocument.appendChild( myRootNode );
00637
00638
00639 myRootNode.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 );
00640 myRootNode.setAttribute( "minimumScale", minimumScale() );
00641 myRootNode.setAttribute( "maximumScale", maximumScale() );
00642
00643
00644 QDomElement transparencyLevelIntElement = myDocument.createElement( "transparencyLevelInt" );
00645 QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) );
00646 transparencyLevelIntElement.appendChild( transparencyLevelIntText );
00647 myRootNode.appendChild( transparencyLevelIntElement );
00648
00649
00650 QString errorMsg;
00651 if ( !writeSymbology( myRootNode, myDocument, errorMsg ) )
00652 {
00653 return tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
00654 }
00655
00656
00657
00658
00659 QString filename;
00660
00661 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
00662 if ( vlayer && vlayer->providerType() == "ogr" )
00663 {
00664 QStringList theURIParts = theURI.split( "|" );
00665 filename = theURIParts[0];
00666 }
00667 else
00668 {
00669 filename = theURI;
00670 }
00671
00672 QFileInfo myFileInfo( filename );
00673 if ( myFileInfo.exists() || filename.endsWith( ".qml", Qt::CaseInsensitive ) )
00674 {
00675 QFileInfo myDirInfo( myFileInfo.path() );
00676 if ( !myDirInfo.isWritable() )
00677 {
00678 return tr( "The directory containing your dataset needs to be writeable!" );
00679 }
00680
00681
00682 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".qml";
00683
00684 QFile myFile( myFileName );
00685 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
00686 {
00687 QTextStream myFileStream( &myFile );
00688
00689 myDocument.save( myFileStream, 2 );
00690 myFile.close();
00691 theResultFlag = true;
00692 return tr( "Created default style file as %1" ).arg( myFileName );
00693 }
00694 else
00695 {
00696 theResultFlag = false;
00697 return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
00698 }
00699 }
00700 else
00701 {
00702 QString qml = myDocument.toString();
00703
00704
00705 sqlite3 *myDatabase;
00706 sqlite3_stmt *myPreparedStatement;
00707 const char *myTail;
00708 int myResult;
00709
00710 myResult = sqlite3_open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( "qgis.qmldb" ).toUtf8().data(), &myDatabase );
00711 if ( myResult != SQLITE_OK )
00712 {
00713 return tr( "User database could not be opened." );
00714 }
00715
00716 QByteArray param0 = theURI.toUtf8();
00717 QByteArray param1 = qml.toUtf8();
00718
00719 QString mySql = "create table if not exists tbl_styles(style varchar primary key,qml varchar)";
00720 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
00721 if ( myResult == SQLITE_OK )
00722 {
00723 if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
00724 {
00725 sqlite3_finalize( myPreparedStatement );
00726 sqlite3_close( myDatabase );
00727 theResultFlag = false;
00728 return tr( "The style table could not be created." );
00729 }
00730 }
00731
00732 sqlite3_finalize( myPreparedStatement );
00733
00734 mySql = "insert into tbl_styles(style,qml) values (?,?)";
00735 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
00736 if ( myResult == SQLITE_OK )
00737 {
00738 if ( sqlite3_bind_text( myPreparedStatement, 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
00739 sqlite3_bind_text( myPreparedStatement, 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
00740 sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
00741 {
00742 theResultFlag = true;
00743 myErrorMessage = tr( "The style %1 was saved to database" ).arg( theURI );
00744 }
00745 }
00746
00747 sqlite3_finalize( myPreparedStatement );
00748
00749 if ( !theResultFlag )
00750 {
00751 QString mySql = "update tbl_styles set qml=? where style=?";
00752 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8().data(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
00753 if ( myResult == SQLITE_OK )
00754 {
00755 if ( sqlite3_bind_text( myPreparedStatement, 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
00756 sqlite3_bind_text( myPreparedStatement, 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
00757 sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
00758 {
00759 theResultFlag = true;
00760 myErrorMessage = tr( "The style %1 was updated in the database." ).arg( theURI );
00761 }
00762 else
00763 {
00764 theResultFlag = false;
00765 myErrorMessage = tr( "The style %1 could not be updated in the database." ).arg( theURI );
00766 }
00767 }
00768 else
00769 {
00770 theResultFlag = false;
00771 myErrorMessage = tr( "The style %1 could not be inserted into database." ).arg( theURI );
00772 }
00773
00774 sqlite3_finalize( myPreparedStatement );
00775 }
00776
00777 sqlite3_close( myDatabase );
00778 }
00779
00780 return myErrorMessage;
00781 }
00782
00783
00784
00785
00786 QUndoStack* QgsMapLayer::undoStack()
00787 {
00788 return &mUndoStack;
00789 }
00790
00791
00792 void QgsMapLayer::setCustomProperty( const QString& key, const QVariant& value )
00793 {
00794 mCustomProperties[key] = value;
00795 }
00796
00797 QVariant QgsMapLayer::customProperty( const QString& value, const QVariant& defaultValue ) const
00798 {
00799 return mCustomProperties.value( value, defaultValue );
00800 }
00801
00802 void QgsMapLayer::removeCustomProperty( const QString& key )
00803 {
00804 mCustomProperties.remove( key );
00805 }
00806
00807 void QgsMapLayer::readCustomProperties( QDomNode & layerNode )
00808 {
00809 QDomNode propsNode = layerNode.namedItem( "customproperties" );
00810 if ( propsNode.isNull() )
00811 return;
00812
00813 mCustomProperties.clear();
00814
00815 QDomNodeList nodes = propsNode.childNodes();
00816
00817 for ( int i = 0; i < nodes.size(); i++ )
00818 {
00819 QDomNode propNode = nodes.at( i );
00820 if ( propNode.isNull() || propNode.nodeName() != "property" )
00821 continue;
00822 QDomElement propElement = propNode.toElement();
00823
00824 QString key = propElement.attribute( "key" );
00825 QString value = propElement.attribute( "value" );
00826 mCustomProperties[key] = QVariant( value );
00827 }
00828
00829 }
00830
00831 void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & doc )
00832 {
00833 QDomElement propsElement = doc.createElement( "customproperties" );
00834
00835 for ( QMap<QString, QVariant>::const_iterator it = mCustomProperties.begin(); it != mCustomProperties.end(); ++it )
00836 {
00837 QDomElement propElement = doc.createElement( "property" );
00838 propElement.setAttribute( "key", it.key() );
00839 propElement.setAttribute( "value", it.value().toString() );
00840 propsElement.appendChild( propElement );
00841 }
00842
00843 layerNode.appendChild( propsElement );
00844 }
00845
00846 void QgsMapLayer::setCacheImage( QImage * thepImage )
00847 {
00848 QgsDebugMsg( "cache Image set!" );
00849 if ( mpCacheImage == thepImage )
00850 return;
00851
00852 if ( mpCacheImage )
00853 {
00854 delete mpCacheImage;
00855 }
00856 mpCacheImage = thepImage;
00857 }
00858
00859 bool QgsMapLayer::isEditable() const
00860 {
00861 return false;
00862 }
00863
00864 void QgsMapLayer::setValid( bool valid )
00865 {
00866 mValid = valid;
00867 }
00868
00869 void QgsMapLayer::clearCacheImage()
00870 {
00871 setCacheImage( 0 );
00872 }