Skip to content

Commit

Permalink
QgsProject: cleanup of read/write method + removal of unused bad laye…
Browse files Browse the repository at this point in the history
…r handler class
  • Loading branch information
wonder-sk committed Jan 4, 2017
1 parent 8a16632 commit 6c5956b
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 389 deletions.
5 changes: 5 additions & 0 deletions doc/api_break.dox
Expand Up @@ -262,6 +262,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat
- QgsMapLayerRegistry. Its functionality has been moved to QgsProject.
- QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.
- QgsPseudoColorShader. This shader has been broken for some time and was replaced by QgsSingleBandPseudoColorRenderer.
- QgsProjectBadLayerGuiHandler was removed. It was unused in QGIS code and barely useful. Implement your own QgsProjectBadLayerHandler subclass if needed.
- QgsRendererV2DataDefinedMenus was removed. Use QgsDataDefinedButton instead.
- QgsLegacyHelpers.
- QgsProviderCountCalcEvent and QgsProviderExtentCalcEvent. These classes were unused in QGIS core and unmaintained.
Expand Down Expand Up @@ -1381,6 +1382,10 @@ QgsProject {#qgis_api_break_3_0_QgsProject}
- title( const QString & title ) was removed. Use setTitle() instead.
- dirty( bool b ) was removed. Use setDirty() instead.
- clearProperties() was removed. Use clear() instead.
- read( QDomNode& layerNode ) was renamed to readLayer( const QDomNode& layerNode ).
- read( const QFileInfo& file ) was replaced by read( const QString& filename ).
- write( const QFileInfo& file ) was replaced by write( const QString& filename ).


QgsProjectPropertyValue {#qgis_api_break_3_0_QgsProjectPropertyValue}
-----------------------
Expand Down
48 changes: 16 additions & 32 deletions python/core/qgsproject.sip
Expand Up @@ -106,53 +106,37 @@ class QgsProject : QObject, QgsExpressionContextGenerator
*/
void clear();

/** Reads a project file.
/** Reads given project file from the given file.
* @param file name of project file to read
* @note Any current plug-in state is erased
* @note Calling read() performs the following operations:
*
* - Gets the extents
* - Creates maplayers
* - Registers maplayers
*
* @note it's presumed that the caller has already reset the map canvas, map registry, and legend
* @returns true if project file has been read successfully
*/
bool read( const QFileInfo& file );
bool read( const QString& filename );

/** Reads the current project file.
* @note Any current plug-in state is erased
* @note Calling read() performs the following operations:
*
* - Gets the extents
* - Creates maplayers
* - Registers maplayers
*
* @note it's presumed that the caller has already reset the map canvas, map registry, and legend
/** Reads the project from its currently associated file (see fileName() ).
* @returns true if project file has been read successfully
*/
bool read();

/** Reads the layer described in the associated DOM node.
*
* @param layerNode represents a QgsProject DOM node that encodes a specific layer.
*
* QgsProject raises an exception when one of the QgsProject::read()
* implementations fails. Since the read()s are invoked from qgisapp,
* then qgisapp handles the exception. It prompts the user for the new
* location of the data, if any. If there is a new location, the DOM
* node associated with the layer has its datasource tag corrected.
* Then that node is passed to this member function to be re-opened.
* @note This method is mainly for use by QgsProjectBadLayerHandler subclasses
* that may fix definition of bad layers with the user's help in GUI. Calling
* this method with corrected DOM node adds the layer back to the project.
*
* @param layerNode represents a QgsProject DOM node that encodes a specific layer.
*/
bool read( QDomNode& layerNode );
bool write(const QString& filename);
bool readLayer( const QDomNode& layerNode );

/** Writes the project to a file.
* @param file destination file
/**
* Writes the project to a file.
* @param filename destination file
* @note calling this implicitly sets the project's filename (see setFileName() )
* @note isDirty() will be set to false if project is successfully written
* @returns true if project was written successfully
*
* \note Added in QGIS 3.0
*/
bool write( const QFileInfo& file );
bool write( const QString& filename );

/** Writes the project to its current associated file (see fileName() ).
* @note isDirty() will be set to false if project is successfully written
Expand Down
1 change: 0 additions & 1 deletion python/core/qgsprojectbadlayerhandler.sip
Expand Up @@ -32,7 +32,6 @@ class QgsProjectBadLayerHandler
* log.
*
* @note Added in QGIS 3.0
* @see QgsProjectBadLayerGuiHandler
*/
virtual void handleBadLayers( const QList<QDomNode>& layers );
virtual ~QgsProjectBadLayerHandler();
Expand Down
1 change: 0 additions & 1 deletion python/gui/gui.sip
Expand Up @@ -140,7 +140,6 @@
%Include qgspluginmanagerinterface.sip
%Include qgspresetcolorrampdialog.sip
%Include qgsprevieweffect.sip
%Include qgsprojectbadlayerguihandler.sip
%Include qgsprojectionselectionwidget.sip
%Include qgsprojectionselector.sip
%Include qgsquerybuilder.sip
Expand Down
47 changes: 0 additions & 47 deletions python/gui/qgsprojectbadlayerguihandler.sip

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/qgshandlebadlayers.cpp
Expand Up @@ -369,7 +369,7 @@ void QgsHandleBadLayers::apply()
QString datasource = item->text();

node.namedItem( QStringLiteral( "datasource" ) ).toElement().firstChild().toText().setData( datasource );
if ( QgsProject::instance()->read( node ) )
if ( QgsProject::instance()->readLayer( node ) )
{
mLayerList->removeRow( i-- );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -973,7 +973,7 @@ void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )
void QgsOptions::on_pbnProjectDefaultSetCurrent_clicked()
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QStringLiteral( "project_default.qgs" );
if ( QgsProject::instance()->write( QFileInfo( fileName ) ) )
if ( QgsProject::instance()->write( fileName ) )
{
QMessageBox::information( nullptr, tr( "Save default project" ), tr( "Current project saved as default" ) );
}
Expand Down
13 changes: 3 additions & 10 deletions src/core/qgsproject.cpp
Expand Up @@ -757,9 +757,9 @@ bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &broken
}
}

bool QgsProject::read( const QFileInfo& file )
bool QgsProject::read( const QString& filename )
{
mFile.setFileName( file.filePath() );
mFile.setFileName( filename );

return read();
}
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void QgsProject::cleanTransactionGroups( bool force )
emit transactionGroupsChanged();
}

bool QgsProject::read( QDomNode &layerNode )
bool QgsProject::readLayer( const QDomNode& layerNode )
{
QList<QDomNode> brokenNodes;
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
Expand Down Expand Up @@ -1154,13 +1154,6 @@ bool QgsProject::write( const QString& filename )
return write();
}

bool QgsProject::write( QFileInfo const &file )
{
mFile.setFileName( file.filePath() );

return write();
}

bool QgsProject::write()
{
clearError();
Expand Down
46 changes: 10 additions & 36 deletions src/core/qgsproject.h
Expand Up @@ -166,44 +166,26 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void clear();

/** Reads a project file.
/** Reads given project file from the given file.
* @param file name of project file to read
* @note Any current plug-in state is erased
* @note Calling read() performs the following operations:
*
* - Gets the extents
* - Creates maplayers
* - Registers maplayers
*
* @note it's presumed that the caller has already reset the map canvas, map registry, and legend
* @returns true if project file has been read successfully
*/
bool read( const QFileInfo& file );
bool read( const QString& filename );

/** Reads the current project file.
* @note Any current plug-in state is erased
* @note Calling read() performs the following operations:
*
* - Gets the extents
* - Creates maplayers
* - Registers maplayers
*
* @note it's presumed that the caller has already reset the map canvas, map registry, and legend
/** Reads the project from its currently associated file (see fileName() ).
* @returns true if project file has been read successfully
*/
bool read();

/** Reads the layer described in the associated DOM node.
*
* @param layerNode represents a QgsProject DOM node that encodes a specific layer.
*
* QgsProject raises an exception when one of the QgsProject::read()
* implementations fails. Since the read()s are invoked from qgisapp,
* then qgisapp handles the exception. It prompts the user for the new
* location of the data, if any. If there is a new location, the DOM
* node associated with the layer has its datasource tag corrected.
* Then that node is passed to this member function to be re-opened.
* @note This method is mainly for use by QgsProjectBadLayerHandler subclasses
* that may fix definition of bad layers with the user's help in GUI. Calling
* this method with corrected DOM node adds the layer back to the project.
*
* @param layerNode represents a QgsProject DOM node that encodes a specific layer.
*/
bool read( QDomNode& layerNode );
bool readLayer( const QDomNode& layerNode );

/**
* Writes the project to a file.
Expand All @@ -216,14 +198,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
bool write( const QString& filename );

/** Writes the project to a file.
* @param file destination file
* @note calling this implicitly sets the project's filename (see setFileName() )
* @note isDirty() will be set to false if project is successfully written
* @returns true if project was written successfully
*/
bool write( const QFileInfo& file );

/** Writes the project to its current associated file (see fileName() ).
* @note isDirty() will be set to false if project is successfully written
* @returns true if project was written successfully
Expand Down
1 change: 0 additions & 1 deletion src/core/qgsprojectbadlayerhandler.h
Expand Up @@ -35,7 +35,6 @@ class CORE_EXPORT QgsProjectBadLayerHandler
* log.
*
* @note Added in QGIS 3.0
* @see QgsProjectBadLayerGuiHandler
*/
virtual void handleBadLayers( const QList<QDomNode>& layers );
virtual ~QgsProjectBadLayerHandler() = default;
Expand Down
2 changes: 0 additions & 2 deletions src/gui/CMakeLists.txt
Expand Up @@ -287,7 +287,6 @@ SET(QGIS_GUI_SRCS
qgspluginmanagerinterface.cpp
qgspresetcolorrampdialog.cpp
qgsprevieweffect.cpp
qgsprojectbadlayerguihandler.cpp
qgsprojectionselectionwidget.cpp
qgsprojectionselector.cpp
qgsquerybuilder.cpp
Expand Down Expand Up @@ -450,7 +449,6 @@ SET(QGIS_GUI_MOC_HDRS
qgspluginmanagerinterface.h
qgspresetcolorrampdialog.h
qgsprevieweffect.h
qgsprojectbadlayerguihandler.h
qgsprojectionselectionwidget.h
qgsprojectionselector.h
qgsquerybuilder.h
Expand Down

0 comments on commit 6c5956b

Please sign in to comment.