Skip to content

Commit ed34b13

Browse files
author
jef
committedSep 28, 2009
- 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@11729 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 43a13b6 commit ed34b13

File tree

8 files changed

+84
-23
lines changed

8 files changed

+84
-23
lines changed
 

‎python/core/qgsdatasourceuri.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public:
3838
const QString& aUsername,
3939
const QString& aPassword,
4040
SSLmode sslmode = SSLprefer );
41+
42+
//! Set database
43+
//! \note added in 1.4
44+
void setDatabase( const QString &database );
4145

4246
//! Set all data source related members at once
4347
void setDataSource(const QString& aSchema,

‎src/app/qgsprojectproperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
8383
radManual->setChecked( true );
8484
}
8585

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

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

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

378378
//set the colour for selections
379379
QColor myColour = pbnSelectionColour->color();

‎src/core/qgsdatasourceuri.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,8 @@ void QgsDataSourceURI::setDataSource( const QString &schema,
432432
mSql = sql;
433433
mKeyColumn = keyColumn;
434434
}
435+
436+
void QgsDataSourceURI::setDatabase( const QString &database )
437+
{
438+
mDatabase = database;
439+
}

‎src/core/qgsdatasourceuri.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class CORE_EXPORT QgsDataSourceURI
5757
const QString& aPassword,
5858
SSLmode sslmode = SSLprefer );
5959

60+
//! Set database
61+
// \note added in 1.4
62+
void setDatabase( const QString &database );
63+
6064
//! Set all data source related members at once
6165
void setDataSource( const QString& aSchema,
6266
const QString& aTable,

‎src/core/qgsmaplayer.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "qgsproject.h"
4141
#include "qgslogger.h"
4242
#include "qgsdatasourceuri.h"
43+
#include "qgsvectorlayer.h"
4344

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

146147
QDomElement element = layer_node.toElement();
147148

148-
// XXX not needed? QString type = element.attribute("type");
149+
QDomNode mnl;
150+
QDomElement mne;
151+
152+
// read provider
153+
QString provider;
154+
mnl = layer_node.namedItem( "provider" );
155+
mne = mnl.toElement();
156+
provider = mne.text();
149157

150158
// set data source
151-
QDomNode mnl = layer_node.namedItem( "datasource" );
152-
QDomElement mne = mnl.toElement();
159+
mnl = layer_node.namedItem( "datasource" );
160+
mne = mnl.toElement();
153161
mDataSource = mne.text();
154162

155-
mDataSource = QgsProject::instance()->readPath( mDataSource );
163+
if ( provider == "spatialite" )
164+
{
165+
QgsDataSourceURI uri( mDataSource );
166+
uri.setDatabase( QgsProject::instance()->readPath( uri.database() ) );
167+
mDataSource = uri.uri();
168+
}
169+
else
170+
{
171+
mDataSource = QgsProject::instance()->readPath( mDataSource );
172+
}
156173

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

269286
QString src = source();
270287

271-
src = QgsProject::instance()->writePath( src );
288+
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( this );
289+
if ( vlayer && vlayer->providerType() == "spatialite" )
290+
{
291+
QgsDataSourceURI uri( src );
292+
QString database = QgsProject::instance()->writePath( uri.database() );
293+
uri.setConnection( uri.host(), uri.port(), database, uri.username(), uri.password() );
294+
src = uri.uri();
295+
}
296+
else
297+
{
298+
src = QgsProject::instance()->writePath( src );
299+
}
272300

273301
QDomText dataSourceText = document.createTextNode( src );
274302
dataSource.appendChild( dataSourceText );

‎src/core/qgsproject.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,11 @@ QString QgsProject::readPath( QString src ) const
13731373
projElems.removeAt( pos - 1 );
13741374
}
13751375

1376+
#if !defined(Q_OS_WIN)
1377+
// make path absolute
1378+
projElems.prepend( "" );
1379+
#endif
1380+
13761381
return projElems.join( "/" );
13771382
}
13781383

‎src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,7 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri ): QgsVectorDat
4949
// parsing members from the uri structure
5050
mTableName = mUri.table();
5151
geometryColumn = mUri.geometryColumn();
52-
53-
// extracting the DB path
54-
int idx = uri.indexOf( "dbname='" );
55-
if ( idx >= 0 )
56-
mSqlitePath = uri.mid( idx + 8 );
57-
else
58-
mSqlitePath = uri;
59-
idx = mSqlitePath.indexOf( "' table=" );
60-
if ( idx > 0 )
61-
mSqlitePath.truncate( idx );
52+
mSqlitePath = mUri.database();
6253

6354
// trying to open the SQLite DB
6455
spatialite_init( 0 );

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,40 @@
138138
</property>
139139
</widget>
140140
</item>
141-
<item row="3" column="0" colspan="4">
142-
<widget class="QCheckBox" name="cbxAbsolutePath">
141+
<item row="3" column="3">
142+
<widget class="QComboBox" name="cbxAbsolutePath">
143+
<item>
144+
<property name="text">
145+
<string>absolute</string>
146+
</property>
147+
</item>
148+
<item>
149+
<property name="text">
150+
<string>relative</string>
151+
</property>
152+
</item>
153+
</widget>
154+
</item>
155+
<item row="3" column="0">
156+
<widget class="QLabel" name="label_3">
143157
<property name="text">
144-
<string>Save absolute paths</string>
158+
<string>Save paths</string>
145159
</property>
146160
</widget>
147161
</item>
162+
<item row="3" column="2">
163+
<spacer name="horizontalSpacer">
164+
<property name="orientation">
165+
<enum>Qt::Horizontal</enum>
166+
</property>
167+
<property name="sizeHint" stdset="0">
168+
<size>
169+
<width>40</width>
170+
<height>20</height>
171+
</size>
172+
</property>
173+
</spacer>
174+
</item>
148175
</layout>
149176
</widget>
150177
</item>
@@ -331,9 +358,6 @@
331358
<attribute name="horizontalHeaderStretchLastSection">
332359
<bool>true</bool>
333360
</attribute>
334-
<attribute name="horizontalHeaderVisible">
335-
<bool>false</bool>
336-
</attribute>
337361
<column>
338362
<property name="text">
339363
<string>Layer</string>

0 commit comments

Comments
 (0)