Skip to content

Commit

Permalink
layermaptest and fixes
Browse files Browse the repository at this point in the history
after feedback - mostly doc stuff or code style
  • Loading branch information
signedav committed Aug 7, 2018
1 parent 519e91e commit ad086dc
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 80 deletions.
20 changes: 8 additions & 12 deletions python/core/auto_generated/qgsapplication.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -797,18 +797,6 @@ Do not include generated variables (like system name, user name etc.)
Set a single custom expression variable.

.. versionadded:: 3.0
%End

int maxConcurrentConnectionsPerPool() const;
%Docstring
The maximum number of concurrent connections per connections pool.

.. note::

QGIS may in some situations allocate more than this amount
of connections to avoid deadlocks.

.. versionadded:: 3.4
%End

void collectTranslatableObjects( QgsTranslationContext *translationContext );
Expand Down Expand Up @@ -836,6 +824,14 @@ Emitted whenever a custom global variable changes.
void nullRepresentationChanged();
%Docstring
\copydoc nullRepresentation()
%End

void requestForTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Emitted when project strings which require translation are being collected for inclusion in a .ts file.
In order to register translatable strings, connect to this signal and register the strings within the specified ``translationContext``.

.. versionadded:: 3.4
%End

};
Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgseditformconfig.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Sets type of feature form pop-up suppression after feature creation (overrides a
%End


void readXml( const QDomNode &node, QgsReadWriteContext &context );
void readXml( const QDomNode &node, QgsReadWriteContext &context );
%Docstring
Read XML information
Deserialize on project load
Expand All @@ -264,7 +264,7 @@ Write XML information
Serialize on project save
%End

QgsAttributeEditorElement *attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId = QString() );
QgsAttributeEditorElement *attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId = QString(), const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Deserialize drag and drop designer elements.
%End
Expand Down
17 changes: 10 additions & 7 deletions python/core/auto_generated/qgsproject.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1027,9 +1027,14 @@ just before a new project is read).
.. versionadded:: 3.2
%End

void readProject( const QDomDocument &, QgsReadWriteContext &context );
void readProject( const QDomDocument & );
%Docstring
Emitted when a project is being read.
%End

void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
%Docstring
Emitted when a project is being read. And passing the /a context
%End

void writeProject( QDomDocument & );
Expand Down Expand Up @@ -1369,8 +1374,8 @@ home path will be automatically determined from the project's file path.

void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
%Docstring
Registers the translatable containers into the translation context
this is a rekursive function to get all the child containers
Registers the containers that require translation into the translationContext.
This is a recursive function to get all the child containers.

:param translationContext: where the objects will be registered
:param parent: parent-container containing list of children
Expand All @@ -1381,10 +1386,8 @@ this is a rekursive function to get all the child containers

void registerTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Registers the translatable objects into the translation context
so there can be created a ts file these values

:param translationContext: where the objects will be registered
Registers the objects that require translation into the ``translationContext``.
So there can be created a ts file with these values.

.. versionadded:: 3.4
%End
Expand Down
12 changes: 10 additions & 2 deletions python/core/auto_generated/qgsprojecttranslator.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class QgsProjectTranslator
{
%Docstring
This abstract class is to call translate() for project data from wherever QgsReadWriteContext is available.
Wherever an object of this class is available, the derived translate function can be called from.

.. versionadded:: 3.4
%End
Expand All @@ -24,7 +24,15 @@ This abstract class is to call translate() for project data from wherever QgsRea

virtual QString translate( const QString &context, const QString &sourceText, const char *disambiguation = 0, int n = -1 ) const = 0;
%Docstring
This method needs to be reimplemented in all classes which implement this interface
The derived translate() translates with QTranslator and qm file the sourceText.
It
:return: the result string and in case there is no QTranslator loaded, the sourceText.
This function can be called from wherever the QgsReadWriteContext is available.

:param context: describing layer etc.
:param sourceText: is the identifier of this text
:param disambiguation: it's the disambiguation
:param n: if -1 uses the appropriate form

.. versionadded:: 3.4
%End
Expand Down
3 changes: 2 additions & 1 deletion python/core/auto_generated/qgsreadwritecontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ Returns the project translator

void setProjectTranslator( QgsProjectTranslator *projectTranslator );
%Docstring
Sets the project translator
Sets the project translator. Means it shouldn't conform mDefaultTranslator anymore.
It's usually the QgsProject where the function with the context is made and won't be changed anymore.

.. versionadded:: 3.4
%End
Expand Down
14 changes: 6 additions & 8 deletions python/core/auto_generated/qgstranslationcontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class QgsTranslationContext
{
%Docstring
used for the collecting of strings of .qgs to be translated and writing of ts file
Used for the collecting of strings from projects for translation and creation of ts files.

.. versionadded:: 3.4
%End
Expand All @@ -22,7 +22,7 @@ used for the collecting of strings of .qgs to be translated and writing of ts fi
%End
public:

QgsTranslationContext( );
QgsTranslationContext();
%Docstring
Constructor
%End
Expand All @@ -36,7 +36,7 @@ Returns the project

void setProject( QgsProject *project );
%Docstring
Sets the ``project`` where the translation need to be done for
Sets the ``project`` being translated.

.. seealso:: :py:func:`project`
%End
Expand All @@ -50,17 +50,15 @@ Returns the TS fileName

void setFileName( const QString &fileName );
%Docstring
Sets the ``name`` of the TS file
Sets the ``fileName`` of the TS file

.. seealso:: :py:func:`fileName`
%End

void registerTranslation( const QString &context, const QString &source );
%Docstring
Registers the ``string`` to be translated

:param context: layer name and sub category of object needed to be translated
:param source: the name of the object needed to be translated
Registers the ``source`` to be translated. It's the text of the object needed to be translated.
The ``context`` defines in what context the object is used. Means layer name and sub category of object needed to be translated.
%End

void writeTsFile( const QString &locale );
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ QgsLayerTreeNode *QgsLayerTreeNode::readXml( QDomElement &element, const QgsProj
if ( project )
resolver = project->pathResolver();
context.setPathResolver( resolver );
context.setProjectTranslator( ( QgsProject * )project );
context.setProjectTranslator( const_cast<QgsProject *>( project ) );

QgsLayerTreeNode *node = readXml( element, context );
if ( node )
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgscompositionconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ bool QgsCompositionConverter::readLegendXml( QgsLayoutItemLegend *layoutItem, co
pathResolver = project->pathResolver();
QgsReadWriteContext context;
context.setPathResolver( pathResolver );
context.setProjectTranslator( ( QgsProject * )project );
context.setProjectTranslator( const_cast<QgsProject *>( project ) );

//composer map: use uuid
QString mapId = itemElem.attribute( QStringLiteral( "map" ), QStringLiteral( "-1" ) );
Expand Down
15 changes: 3 additions & 12 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,16 +734,6 @@ class CORE_EXPORT QgsApplication : public QApplication
static void setCustomVariable( const QString &name, const QVariant &value );

/**
* The maximum number of concurrent connections per connections pool.
*
* \note QGIS may in some situations allocate more than this amount
* of connections to avoid deadlocks.
*
* \since QGIS 3.4
*/
int maxConcurrentConnectionsPerPool() const;

/**
* Emits the signal to collect all the strings of .qgs to be included in ts file
*
* \since QGIS 3.4
Expand Down Expand Up @@ -774,9 +764,10 @@ class CORE_EXPORT QgsApplication : public QApplication
void nullRepresentationChanged();

/**
* dave : to write
* Emitted when project strings which require translation are being collected for inclusion in a .ts file.
* In order to register translatable strings, connect to this signal and register the strings within the specified \a translationContext.
*
* \since QGIS 3.2
* \since QGIS 3.4
*/
void requestForTranslatableObjects( QgsTranslationContext *translationContext );

Expand Down
8 changes: 4 additions & 4 deletions src/core/qgseditformconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void QgsEditFormConfig::readXml( const QDomNode &node, QgsReadWriteContext &cont
{
QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();

QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, nullptr, node.namedItem( QStringLiteral( "id" ) ).toElement().text() );
QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, nullptr, node.namedItem( QStringLiteral( "id" ) ).toElement().text(), context );
addTab( attributeEditorWidget );
}

Expand Down Expand Up @@ -518,13 +518,13 @@ void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &con
//// END TODO
}

QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId )
QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId, const QgsReadWriteContext &context )
{
QgsAttributeEditorElement *newElement = nullptr;

if ( elem.tagName() == QLatin1String( "attributeEditorContainer" ) )
{
QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( QgsProject::instance()->translate( QStringLiteral( "project:layers:%1:formcontainers" ).arg( layerId ), elem.attribute( QStringLiteral( "name" ) ) ), parent );
QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( context.projectTranslator()->translate( QStringLiteral( "project:layers:%1:formcontainers" ).arg( layerId ), elem.attribute( QStringLiteral( "name" ) ) ), parent );
bool ok;
int cc = elem.attribute( QStringLiteral( "columnCount" ) ).toInt( &ok );
if ( !ok )
Expand All @@ -551,7 +551,7 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme
for ( int i = 0; i < childNodeList.size(); i++ )
{
QDomElement childElem = childNodeList.at( i ).toElement();
QgsAttributeEditorElement *myElem = attributeEditorElementFromDomElement( childElem, container, layerId );
QgsAttributeEditorElement *myElem = attributeEditorElementFromDomElement( childElem, container, layerId, context );
if ( myElem )
container->addChildElement( myElem );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgseditformconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class CORE_EXPORT QgsEditFormConfig
* Read XML information
* Deserialize on project load
*/
void readXml( const QDomNode &node, QgsReadWriteContext &context );
void readXml( const QDomNode &node, QgsReadWriteContext &context );

/**
* Write XML information
Expand All @@ -288,7 +288,7 @@ class CORE_EXPORT QgsEditFormConfig
/**
* Deserialize drag and drop designer elements.
*/
QgsAttributeEditorElement *attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId = QString() );
QgsAttributeEditorElement *attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement *parent, const QString &layerId = QString(), const QgsReadWriteContext &context = QgsReadWriteContext() );

/**
* Create a new edit form config. Normally invoked by QgsVectorLayer
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslayerdefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ QList<QgsMapLayer *> QgsLayerDefinition::loadLayerDefinitionLayers( const QStrin

QgsReadWriteContext context;
context.setPathResolver( QgsPathResolver( qlrfile ) );
//no projecttranslator defined here
//no project translator defined here
return QgsLayerDefinition::loadLayerDefinitionLayers( doc, context );
}

Expand Down
7 changes: 4 additions & 3 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void QgsProject::registerTranslatableContainers( QgsTranslationContext *translat

translationContext->registerTranslation( QStringLiteral( "project:layers:%1:formcontainers" ).arg( layerId ), container->name() );

if ( container->children().size() > 0 )
if ( !container->children().empty() )
registerTranslatableContainers( translationContext, container, layerId );
}
}
Expand Down Expand Up @@ -1010,7 +1010,7 @@ bool QgsProject::readProjectFile( const QString &filename )

QgsSettings settings;

QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString() );
QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() );

if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() )
{
Expand Down Expand Up @@ -1306,7 +1306,8 @@ bool QgsProject::readProjectFile( const QString &filename )
emit ellipsoidChanged( ellipsoid() );

// read the project: used by map canvas and legend
emit readProject( *doc, context );
emit readProject( *doc );
emit readProjectWithContext( *doc, context );
emit snappingConfigChanged( mSnappingConfig );

// if all went well, we're allegedly in pristine state
Expand Down
16 changes: 10 additions & 6 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
/**
* Emitted when a project is being read.
*/
void readProject( const QDomDocument &, QgsReadWriteContext &context );
void readProject( const QDomDocument & );

/**
* Emitted when a project is being read. And passing the /a context
*/
void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );

/**
* Emitted when the project is being written.
Expand Down Expand Up @@ -1299,8 +1304,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
void setPresetHomePath( const QString &path );

/**
* Registers the translatable containers into the translation context
* this is a rekursive function to get all the child containers
* Registers the containers that require translation into the translationContext.
* This is a recursive function to get all the child containers.
*
* \param translationContext where the objects will be registered
* \param parent parent-container containing list of children
Expand All @@ -1310,10 +1315,9 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );

/**
* Registers the translatable objects into the translation context
* so there can be created a ts file these values
* Registers the objects that require translation into the \a translationContext.
* So there can be created a ts file with these values.
*
* \param translationContext where the objects will be registered
* \since QGIS 3.4
*/
void registerTranslatableObjects( QgsTranslationContext *translationContext );
Expand Down
11 changes: 9 additions & 2 deletions src/core/qgsprojecttranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* \ingroup core
* This abstract class is to call translate() for project data from wherever QgsReadWriteContext is available.
* Wherever an object of this class is available, the derived translate function can be called from.
*
* \since QGIS 3.4
*/
Expand All @@ -33,7 +33,14 @@ class CORE_EXPORT QgsProjectTranslator
public:

/**
* This method needs to be reimplemented in all classes which implement this interface
* The derived translate() translates with QTranslator and qm file the sourceText.
* It \returns the result string and in case there is no QTranslator loaded, the sourceText.
* This function can be called from wherever the QgsReadWriteContext is available.
*
* \param context describing layer etc.
* \param sourceText is the identifier of this text
* \param disambiguation it's the disambiguation
* \param n if -1 uses the appropriate form
*
* \since QGIS 3.4
*/
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsreadwritecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class CORE_EXPORT QgsReadWriteContext
const QgsProjectTranslator *projectTranslator( ) const { return mProjectTranslator; }

/**
* Sets the project translator
* Sets the project translator. Means it shouldn't conform mDefaultTranslator anymore.
* It's usually the QgsProject where the function with the context is made and won't be changed anymore.
*
* \since QGIS 3.4
*/
void setProjectTranslator( QgsProjectTranslator *projectTranslator );
Expand All @@ -127,7 +129,7 @@ class CORE_EXPORT QgsReadWriteContext
QgsPathResolver mPathResolver;
QList<ReadWriteMessage> mMessages;
QStringList mCategories = QStringList();
QgsProjectTranslator *mProjectTranslator;
QgsProjectTranslator *mProjectTranslator = nullptr;
friend class QgsReadWriteContextCategoryPopper;
DefaultTranslator mDefaultTranslator;
};
Expand Down
Loading

0 comments on commit ad086dc

Please sign in to comment.