layermaptest and fixes

after feedback - mostly doc stuff or code style
This commit is contained in:
signedav 2018-08-07 14:18:45 +02:00
parent 519e91e626
commit ad086dc474
20 changed files with 115 additions and 80 deletions

View File

@ -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 );
@ -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
};

View File

@ -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
@ -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

View File

@ -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 & );
@ -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
@ -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

View File

@ -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
@ -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

View File

@ -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

View File

@ -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
@ -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
@ -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
@ -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 );

View File

@ -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 )

View File

@ -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" ) );

View File

@ -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
@ -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 );

View File

@ -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 );
}
@ -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 )
@ -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 );
}

View File

@ -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
@ -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

View File

@ -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 );
}

View File

@ -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 );
}
}
@ -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() )
{
@ -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

View File

@ -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.
@ -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
@ -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 );

View File

@ -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
*/
@ -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
*/

View File

@ -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 );
@ -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;
};

View File

@ -27,7 +27,7 @@ QgsRelationManager::QgsRelationManager( QgsProject *project )
{
if ( mProject )
{
connect( project, &QgsProject::readProject, this, &QgsRelationManager::readProject );
connect( project, &QgsProject::readProjectWithContext, this, &QgsRelationManager::readProject );
connect( project, &QgsProject::writeProject, this, &QgsRelationManager::writeProject );
connect( project, &QgsProject::layersRemoved, this, &QgsRelationManager::layersRemoved );
}

View File

@ -22,9 +22,6 @@
#include "qgssettings.h"
QgsTranslationContext::QgsTranslationContext()
{}
QgsProject *QgsTranslationContext::project() const
{
return mProject;

View File

@ -25,17 +25,21 @@ class QgsProject;
/**
* \ingroup core
* \class QgsTranslationContext
* \brief used for the collecting of strings of .qgs to be translated and writing of ts file
* \brief Used for the collecting of strings from projects for translation and creation of ts files.
*
* \since QGIS 3.4
*/
class CORE_EXPORT QgsTranslationContext
{
/**
* Object that could be translated by the QTranslator with the qm file.
*/
struct TranslatableObject
{
QString context;
QString source;
QString context; //!< In what context the object is used
QString source; //!< The original text of the object
};
public:
@ -43,7 +47,7 @@ class CORE_EXPORT QgsTranslationContext
/**
* Constructor
*/
QgsTranslationContext( );
QgsTranslationContext() = default;
/**
* Returns the project
@ -52,7 +56,7 @@ class CORE_EXPORT QgsTranslationContext
QgsProject *project() const;
/**
* Sets the \a project where the translation need to be done for
* Sets the \a project being translated.
*
* \see project()
*/
@ -65,17 +69,15 @@ class CORE_EXPORT QgsTranslationContext
QString fileName() const;
/**
* Sets the \a name of the TS file
* Sets the \a fileName of the TS file
*
* \see fileName()
*/
void setFileName( const QString &fileName );
/**
* Registers the \a 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 \a source to be translated. It's the text of the object needed to be translated.
* The \a context defines in what context the object is used. Means layer name and sub category of object needed to be translated.
*/
void registerTranslation( const QString &context, const QString &source );

View File

@ -49,6 +49,7 @@ class TestQgsLayerTree : public QObject
void testEmbeddedGroup();
void testFindLayer();
void testLayerDeleted();
void testFindGroups();
private:
@ -636,6 +637,30 @@ void TestQgsLayerTree::testLayerDeleted()
QCOMPARE( model.layerLegendNodes( tl ).count(), 0 );
}
void TestQgsLayerTree::testFindGroups()
{
QgsProject project;
QgsLayerTreeGroup *group1 = project.layerTreeRoot()->addGroup( QStringLiteral( "Group_One" ) );
QVERIFY( group1 );
QgsLayerTreeGroup *group2 = project.layerTreeRoot()->addGroup( QStringLiteral( "Group_Two" ) );
QVERIFY( group2 );
QgsLayerTreeGroup *group3 = project.layerTreeRoot()->addGroup( QStringLiteral( "Group_Three" ) );
QVERIFY( group3 );
QgsLayerTreeGroup *group = project.layerTreeRoot()->findGroup( QStringLiteral( "Group_One" ) );
QVERIFY( group );
group = project.layerTreeRoot()->findGroup( QStringLiteral( "Group_Two" ) );
QVERIFY( group );
group = project.layerTreeRoot()->findGroup( QStringLiteral( "Group_Three" ) );
QVERIFY( group );
QList<QgsLayerTreeGroup *> groups = project.layerTreeRoot()->findGroups();
QVERIFY( groups.contains( group1 ) );
QVERIFY( groups.contains( group2 ) );
QVERIFY( groups.contains( group3 ) );
}
QGSTEST_MAIN( TestQgsLayerTree )
#include "testqgslayertree.moc"