[QGIS Commit] r13598 - in trunk/qgis/src: app core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat May 29 18:10:56 EDT 2010
Author: mhugent
Date: 2010-05-29 18:10:55 -0400 (Sat, 29 May 2010)
New Revision: 13598
Modified:
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/app/qgisapp.h
trunk/qgis/src/core/qgsprojectfiletransform.cpp
trunk/qgis/src/core/qgsprojectfiletransform.h
Log:
Project file transform from 1.4 to 1.5. Improved project loading for composers and annotation items to use the modified dom, not the original file. Fixes ticket #2751
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2010-05-29 18:41:56 UTC (rev 13597)
+++ trunk/qgis/src/app/qgisapp.cpp 2010-05-29 22:10:55 UTC (rev 13598)
@@ -1989,6 +1989,9 @@
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument& ) ),
this, SLOT( writeAnnotationItemsToProject( QDomDocument& ) ) );
+ connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( loadComposersFromProject( const QDomDocument& ) ) );
+ connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( loadAnnotationItemsFromProject( const QDomDocument& ) ) );
+
//
// Do we really need this ??? - its already connected to the esc key...TS
//
@@ -3145,10 +3148,6 @@
// project so that they can check any project
// specific plug-in state
- //load the composers in the project
- loadComposersFromProject( fullPath );
- loadAnnotationItemsFromProject( fullPath );
-
// add this to the list of recently used project files
saveRecentProjectPath( fullPath, settings );
@@ -3203,9 +3202,6 @@
// project so that they can check any project
// specific plug-in state
- loadComposersFromProject( projectFile );
- loadAnnotationItemsFromProject( projectFile );
-
// add this to the list of recently used project files
QSettings settings;
saveRecentProjectPath( projectFile, settings );
@@ -4019,28 +4015,20 @@
delete c;
}
-bool QgisApp::loadComposersFromProject( const QString& projectFilePath )
+bool QgisApp::loadComposersFromProject( const QDomDocument& doc )
{
- //create dom document from file
- QDomDocument projectDom;
- QFile projectFile( projectFilePath );
- if ( !projectFile.open( QIODevice::ReadOnly ) )
+ if ( doc.isNull() )
{
return false;
}
- if ( !projectDom.setContent( &projectFile, false ) )
- {
- return false;
- }
-
//restore each composer
- QDomNodeList composerNodes = projectDom.elementsByTagName( "Composer" );
+ QDomNodeList composerNodes = doc.elementsByTagName( "Composer" );
for ( int i = 0; i < composerNodes.size(); ++i )
{
++mLastComposerId;
QgsComposer* composer = new QgsComposer( this, tr( "Composer %1" ).arg( mLastComposerId ) );
- composer->readXML( composerNodes.at( i ).toElement(), projectDom );
+ composer->readXML( composerNodes.at( i ).toElement(), doc );
mPrintComposers.insert( composer );
mPrintComposersMenu->addAction( composer->windowAction() );
#ifndef Q_OS_MACX
@@ -4068,21 +4056,8 @@
mLastComposerId = 0;
}
-bool QgisApp::loadAnnotationItemsFromProject( const QString& projectFilePath )
+bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
{
- //create dom document from file
- QDomDocument doc;
- QFile projectFile( projectFilePath );
- if ( !projectFile.open( QIODevice::ReadOnly ) )
- {
- return false;
- }
-
- if ( !doc.setContent( &projectFile, false ) )
- {
- return false;
- }
-
if ( !mMapCanvas )
{
return false;
Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h 2010-05-29 18:41:56 UTC (rev 13597)
+++ trunk/qgis/src/app/qgisapp.h 2010-05-29 22:10:55 UTC (rev 13598)
@@ -500,10 +500,10 @@
void fileNew( bool thePromptToSaveFlag );
//! Create a new empty vector layer
void newVectorLayer();
- #ifdef HAVE_SPATIALITE
+#ifdef HAVE_SPATIALITE
//! Create a new empty spatialite layer
void newSpatialiteLayer();
- #endif
+#endif
//! Print the current map view frame
void newPrintComposer();
void showComposerManager();
@@ -694,6 +694,11 @@
void writeAnnotationItemsToProject( QDomDocument& doc );
+ /**Creates the composer instances in a project file and adds them to the menu*/
+ bool loadComposersFromProject( const QDomDocument& doc );
+
+ bool loadAnnotationItemsFromProject( const QDomDocument& doc );
+
signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -762,9 +767,8 @@
/**Deletes all the composer objects and clears mPrintComposers*/
void deletePrintComposers();
- /**Creates the composer instances in a project file and adds them to the menu*/
- bool loadComposersFromProject( const QString& projectFilePath );
+
void saveAsVectorFileGeneral( bool saveOnlySelection );
/**Returns all annotation items in the canvas*/
@@ -772,8 +776,6 @@
/**Removes annotation items in the canvas*/
void removeAnnotationItems();
- bool loadAnnotationItemsFromProject( const QString& projectFilePath );
-
/// QgisApp aren't copyable
QgisApp( QgisApp const & );
/// QgisApp aren't copyable
Modified: trunk/qgis/src/core/qgsprojectfiletransform.cpp
===================================================================
--- trunk/qgis/src/core/qgsprojectfiletransform.cpp 2010-05-29 18:41:56 UTC (rev 13597)
+++ trunk/qgis/src/core/qgsprojectfiletransform.cpp 2010-05-29 22:10:55 UTC (rev 13598)
@@ -43,6 +43,9 @@
{PFV( 1, 0, 0 ), PFV( 1, 1, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 1, 0, 2 ), PFV( 1, 1, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 1, 1, 0 ), PFV( 1, 2, 0 ), &QgsProjectFileTransform::transform1100to1200},
+ {PFV( 1, 2, 0 ), PFV( 1, 3, 0 ), &QgsProjectFileTransform::transformNull},
+ {PFV( 1, 3, 0 ), PFV( 1, 4, 0 ), &QgsProjectFileTransform::transformNull},
+ {PFV( 1, 4, 0 ), PFV( 1, 5, 0 ), &QgsProjectFileTransform::transform1400to1500},
};
bool QgsProjectFileTransform::updateRevision( QgsProjectVersion newVersion )
@@ -384,3 +387,64 @@
QgsPropertyValue value( units );
value.writeXML( "LayerSnappingToleranceUnitList", digitizing, mDom );
}
+
+void QgsProjectFileTransform::transform1400to1500()
+{
+ //Adapt the XML description of the composer legend model to version 1.5
+ if ( mDom.isNull() )
+ {
+ return;
+ }
+ //Add layer id to <VectorClassificationItem>
+ QDomNodeList layerItemList = mDom.elementsByTagName( "LayerItem" );
+ QDomElement currentLayerItemElem;
+ QString currentLayerId;
+
+ for ( int i = 0; i < layerItemList.size(); ++i )
+ {
+ currentLayerItemElem = layerItemList.at( i ).toElement();
+ if ( currentLayerItemElem.isNull() )
+ {
+ continue;
+ }
+ currentLayerId = currentLayerItemElem.attribute( "layerId" );
+
+ QDomNodeList vectorClassificationList = currentLayerItemElem.elementsByTagName( "VectorClassificationItem" );
+ QDomElement currentClassificationElem;
+ for ( int j = 0; j < vectorClassificationList.size(); ++j )
+ {
+ currentClassificationElem = vectorClassificationList.at( j ).toElement();
+ if ( !currentClassificationElem.isNull() )
+ {
+ currentClassificationElem.setAttribute( "layerId", currentLayerId );
+ }
+ }
+
+ //replace the text items with VectorClassification or RasterClassification items
+ QDomNodeList textItemList = currentLayerItemElem.elementsByTagName( "TextItem" );
+ QDomElement currentTextItem;
+
+ for ( int j = 0; j < textItemList.size(); ++j )
+ {
+ currentTextItem = textItemList.at( j ).toElement();
+ if ( currentTextItem.isNull() )
+ {
+ continue;
+ }
+
+ QDomElement classificationElement;
+ if ( vectorClassificationList.size() > 0 ) //we guess it is a vector layer
+ {
+ classificationElement = mDom.createElement( "VectorClassificationItem" );
+ }
+ else
+ {
+ classificationElement = mDom.createElement( "RasterClassificationItem" );
+ }
+
+ classificationElement.setAttribute( "layerId", currentLayerId );
+ classificationElement.setAttribute( "text", currentTextItem.attribute( "text" ) );
+ currentLayerItemElem.replaceChild( classificationElement, currentTextItem );
+ }
+ }
+}
Modified: trunk/qgis/src/core/qgsprojectfiletransform.h
===================================================================
--- trunk/qgis/src/core/qgsprojectfiletransform.h 2010-05-29 18:41:56 UTC (rev 13597)
+++ trunk/qgis/src/core/qgsprojectfiletransform.h 2010-05-29 22:10:55 UTC (rev 13598)
@@ -81,6 +81,7 @@
void transform0100to0110();
void transform0110to1000();
void transform1100to1200();
+ void transform1400to1500();
};
More information about the QGIS-commit
mailing list