Skip to content
Permalink
Browse files
- fix load of layers saved with relative paths on *x
- also save relative paths to spatialite databases
- show path mode as combobox
- add QgsDataSourceURI::setDatabase()


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11729 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 28, 2009
1 parent 01267f2 commit 233ab3650c2f7a3834027a92c986e096481ad1a0
@@ -38,6 +38,10 @@ public:
const QString& aUsername,
const QString& aPassword,
SSLmode sslmode = SSLprefer );

//! Set database
//! \note added in 1.4
void setDatabase( const QString &database );

//! Set all data source related members at once
void setDataSource(const QString& aSchema,
@@ -83,7 +83,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
radManual->setChecked( true );
}

cbxAbsolutePath->setChecked( QgsProject::instance()->readBoolEntry( "Paths", "/Absolute", true ) );
cbxAbsolutePath->setCurrentIndex( QgsProject::instance()->readBoolEntry( "Paths", "/Absolute", true ) ? 0 : 1 );

int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" );
spinBoxDP->setValue( dp );
@@ -373,7 +373,7 @@ void QgsProjectProperties::apply()
// Announce that we may have a new display precision setting
emit displayPrecisionChanged();

QgsProject::instance()->writeEntry( "Paths", "/Absolute", cbxAbsolutePath->isChecked() );
QgsProject::instance()->writeEntry( "Paths", "/Absolute", cbxAbsolutePath->currentIndex()==0 );

//set the colour for selections
QColor myColour = pbnSelectionColour->color();
@@ -432,3 +432,8 @@ void QgsDataSourceURI::setDataSource( const QString &schema,
mSql = sql;
mKeyColumn = keyColumn;
}

void QgsDataSourceURI::setDatabase( const QString &database )
{
mDatabase = database;
}
@@ -57,6 +57,10 @@ class CORE_EXPORT QgsDataSourceURI
const QString& aPassword,
SSLmode sslmode = SSLprefer );

//! Set database
// \note added in 1.4
void setDatabase( const QString &database );

//! Set all data source related members at once
void setDataSource( const QString& aSchema,
const QString& aTable,
@@ -40,6 +40,7 @@
#include "qgsproject.h"
#include "qgslogger.h"
#include "qgsdatasourceuri.h"
#include "qgsvectorlayer.h"

QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
QString lyrname,
@@ -145,14 +146,30 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )

QDomElement element = layer_node.toElement();

// XXX not needed? QString type = element.attribute("type");
QDomNode mnl;
QDomElement mne;

// read provider
QString provider;
mnl = layer_node.namedItem( "provider" );
mne = mnl.toElement();
provider = mne.text();

// set data source
QDomNode mnl = layer_node.namedItem( "datasource" );
QDomElement mne = mnl.toElement();
mnl = layer_node.namedItem( "datasource" );
mne = mnl.toElement();
mDataSource = mne.text();

mDataSource = QgsProject::instance()->readPath( mDataSource );
if ( provider == "spatialite" )
{
QgsDataSourceURI uri( mDataSource );
uri.setDatabase( QgsProject::instance()->readPath( uri.database() ) );
mDataSource = uri.uri();
}
else
{
mDataSource = QgsProject::instance()->readPath( mDataSource );
}

// Set the CRS from project file, asking the user if necessary.
// Make it the saved CRS to have WMS layer projected correctly.
@@ -268,7 +285,18 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )

QString src = source();

src = QgsProject::instance()->writePath( src );
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( this );
if ( vlayer && vlayer->providerType() == "spatialite" )
{
QgsDataSourceURI uri( src );
QString database = QgsProject::instance()->writePath( uri.database() );
uri.setConnection( uri.host(), uri.port(), database, uri.username(), uri.password() );
src = uri.uri();
}
else
{
src = QgsProject::instance()->writePath( src );
}

QDomText dataSourceText = document.createTextNode( src );
dataSource.appendChild( dataSourceText );
@@ -1373,6 +1373,11 @@ QString QgsProject::readPath( QString src ) const
projElems.removeAt( pos - 1 );
}

#if !defined(Q_OS_WIN)
// make path absolute
projElems.prepend( "" );
#endif

return projElems.join( "/" );
}

@@ -49,16 +49,7 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri ): QgsVectorDat
// parsing members from the uri structure
mTableName = mUri.table();
geometryColumn = mUri.geometryColumn();

// extracting the DB path
int idx = uri.indexOf( "dbname='" );
if ( idx >= 0 )
mSqlitePath = uri.mid( idx + 8 );
else
mSqlitePath = uri;
idx = mSqlitePath.indexOf( "' table=" );
if ( idx > 0 )
mSqlitePath.truncate( idx );
mSqlitePath = mUri.database();

// trying to open the SQLite DB
spatialite_init( 0 );
@@ -138,13 +138,40 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QCheckBox" name="cbxAbsolutePath">
<item row="3" column="3">
<widget class="QComboBox" name="cbxAbsolutePath">
<item>
<property name="text">
<string>absolute</string>
</property>
</item>
<item>
<property name="text">
<string>relative</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Save absolute paths</string>
<string>Save paths</string>
</property>
</widget>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@@ -331,9 +358,6 @@
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Layer</string>

0 comments on commit 233ab36

Please sign in to comment.