Skip to content

Commit

Permalink
- fix load of layers saved with relative paths on *x
Browse files Browse the repository at this point in the history
- also save relative paths to spatialite databases
- show path mode as combobox
- add QgsDataSourceURI::setDatabase()


git-svn-id: http://svn.osgeo.org/qgis/trunk@11729 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 28, 2009
1 parent 43a13b6 commit ed34b13
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 23 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsdatasourceuri.sip
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsdatasourceuri.cpp
Expand Up @@ -432,3 +432,8 @@ void QgsDataSourceURI::setDataSource( const QString &schema,
mSql = sql;
mKeyColumn = keyColumn;
}

void QgsDataSourceURI::setDatabase( const QString &database )
{
mDatabase = database;
}
4 changes: 4 additions & 0 deletions src/core/qgsdatasourceuri.h
Expand Up @@ -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,
Expand Down
38 changes: 33 additions & 5 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -40,6 +40,7 @@
#include "qgsproject.h"
#include "qgslogger.h"
#include "qgsdatasourceuri.h"
#include "qgsvectorlayer.h"

QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
QString lyrname,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -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( "/" );
}

Expand Down
11 changes: 1 addition & 10 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -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 );
Expand Down
36 changes: 30 additions & 6 deletions src/ui/qgsprojectpropertiesbase.ui
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit ed34b13

Please sign in to comment.