Skip to content

Commit

Permalink
Project file transform from 1.4 to 1.5. Improved project loading for …
Browse files Browse the repository at this point in the history
…composers and annotation items to use the modified dom, not the original file. Fixes ticket #2751

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13598 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 29, 2010
1 parent bd6c887 commit 5ead969
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 39 deletions.
41 changes: 8 additions & 33 deletions src/app/qgisapp.cpp
Expand Up @@ -1989,6 +1989,9 @@ void QgisApp::setupConnections()
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
//
Expand Down Expand Up @@ -3145,10 +3148,6 @@ void QgisApp::fileOpen()
// 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 );

Expand Down Expand Up @@ -3203,9 +3202,6 @@ bool QgisApp::addProject( QString projectFile )
// 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 );
Expand Down Expand Up @@ -4019,28 +4015,20 @@ void QgisApp::deleteComposer( QgsComposer* c )
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 ) )
{
return false;
}

if ( !projectDom.setContent( &projectFile, false ) )
if ( doc.isNull() )
{
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
Expand Down Expand Up @@ -4068,21 +4056,8 @@ void QgisApp::deletePrintComposers()
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;
Expand Down
14 changes: 8 additions & 6 deletions src/app/qgisapp.h
Expand Up @@ -500,10 +500,10 @@ class QgisApp : public QMainWindow
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();
Expand Down Expand Up @@ -694,6 +694,11 @@ class QgisApp : public QMainWindow

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) */
Expand Down Expand Up @@ -762,8 +767,7 @@ class QgisApp : public QMainWindow

/**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 );

Expand All @@ -772,8 +776,6 @@ class QgisApp : public QMainWindow
/**Removes annotation items in the canvas*/
void removeAnnotationItems();

bool loadAnnotationItemsFromProject( const QString& projectFilePath );

/// QgisApp aren't copyable
QgisApp( QgisApp const & );
/// QgisApp aren't copyable
Expand Down
64 changes: 64 additions & 0 deletions src/core/qgsprojectfiletransform.cpp
Expand Up @@ -43,6 +43,9 @@ QgsProjectFileTransform::transform QgsProjectFileTransform::transformers[] =
{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 )
Expand Down Expand Up @@ -384,3 +387,64 @@ void QgsProjectFileTransform::transform1100to1200()
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 );
}
}
}
1 change: 1 addition & 0 deletions src/core/qgsprojectfiletransform.h
Expand Up @@ -81,6 +81,7 @@ class QgsProjectFileTransform
void transform0100to0110();
void transform0110to1000();
void transform1100to1200();
void transform1400to1500();
};


Expand Down

0 comments on commit 5ead969

Please sign in to comment.