sip files and some improvements

like make a list copy before go through for loop and log messages
This commit is contained in:
signedav 2018-07-31 20:32:54 +02:00
parent e8e48abae2
commit 442c7323f7
10 changed files with 213 additions and 22 deletions

View File

@ -808,6 +808,13 @@ The maximum number of concurrent connections per connections pool.
QGIS may in some situations allocate more than this amount QGIS may in some situations allocate more than this amount
of connections to avoid deadlocks. of connections to avoid deadlocks.
.. versionadded:: 3.4
%End
void collectTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Emits the signal to collect all the strings of .qgs to be included in ts file
.. versionadded:: 3.4 .. versionadded:: 3.4
%End %End

View File

@ -13,7 +13,7 @@
class QgsProject : QObject, QgsExpressionContextGenerator class QgsProject : QObject, QgsExpressionContextGenerator, QgsProjectTranslator
{ {
%Docstring %Docstring
Reads and writes project states. Reads and writes project states.
@ -135,6 +135,14 @@ Returns last modified time of the project file as returned by the file system (o
Returns full absolute path to the project file if the project is stored in a file system - derived from fileName(). Returns full absolute path to the project file if the project is stored in a file system - derived from fileName().
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages). Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).
.. versionadded:: 3.2
%End
QString absolutePath() const;
%Docstring
Returns full absolute path to the project folder if the project is stored in a file system - derived from fileName().
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).
.. versionadded:: 3.2 .. versionadded:: 3.2
%End %End
@ -983,6 +991,28 @@ and it is mainly a hint for the user interface to protect users from removing la
in the project. The removeMapLayer(), removeMapLayers() calls do not block removal of layers listed here. in the project. The removeMapLayer(), removeMapLayers() calls do not block removal of layers listed here.
.. versionadded:: 3.2 .. versionadded:: 3.2
%End
void generateTsFile( const QString &locale );
%Docstring
Triggers the collection strings of .qgs to be included in ts file and calls writeTsFile()
.. versionadded:: 3.4
%End
virtual QString translate( const QString &context, const QString &sourceText, const char *disambiguation = 0, int n = -1 ) const;
%Docstring
Translates the project with QTranslator and qm file
:return: the result string (in case there is no QTranslator loaded the sourceText)
: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 %End
signals: signals:
@ -997,7 +1027,7 @@ just before a new project is read).
.. versionadded:: 3.2 .. versionadded:: 3.2
%End %End
void readProject( const QDomDocument & ); void readProject( const QDomDocument &, QgsReadWriteContext &context );
%Docstring %Docstring
Emitted when a project is being read. Emitted when a project is being read.
%End %End
@ -1335,6 +1365,27 @@ home path will be automatically determined from the project's file path.
.. seealso:: :py:func:`homePathChanged` .. seealso:: :py:func:`homePathChanged`
.. versionadded:: 3.2 .. versionadded:: 3.2
%End
void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
%Docstring
Registers the translatable containers into the tranlation context
this is a rekursive function to get all the child containers
:param translationContext: where the objects will be registered
:param parent: parent-container containing list of children
.. versionadded:: 3.4
%End
void registerTranslatableObjects( QgsTranslationContext *translationContext );
%Docstring
Registers the translatable objects into the tranlation context
so there can be created a ts file these values
:param translationContext: where the objects will be registered
.. versionadded:: 3.4
%End %End
}; };

View File

@ -0,0 +1,41 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsprojecttranslator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsProjectTranslator
{
%Docstring
This abstract class is to call translate() for project data from wherever QgsReadWriteContext is available.
.. versionadded:: 3.4
%End
%TypeHeaderCode
#include "qgsprojecttranslator.h"
%End
public:
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
.. versionadded:: 3.4
%End
virtual ~QgsProjectTranslator();
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsprojecttranslator.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -98,7 +98,21 @@ Returns the stored messages and remove them
.. versionadded:: 3.2 .. versionadded:: 3.2
%End %End
const QgsProjectTranslator *projectTranslator( ) const;
%Docstring
Returns the project translator
.. versionadded:: 3.4
%End
void setProjectTranslator( QgsProjectTranslator *projectTranslator );
%Docstring
Sets the project translator
.. versionadded:: 3.4
%End
public:
}; };

View File

@ -35,11 +35,12 @@ class QgsRelation
Default constructor. Creates an invalid relation. Default constructor. Creates an invalid relation.
%End %End
static QgsRelation createFromXml( const QDomNode &node ); static QgsRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context );
%Docstring %Docstring
Creates a relation from an XML structure. Used for reading .qgs projects. Creates a relation from an XML structure. Used for reading .qgs projects.
:param node: The dom node containing the relation information :param node: The dom node containing the relation information
:param context: to pass project translator
:return: A relation :return: A relation
%End %End

View File

@ -0,0 +1,79 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstranslationcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsTranslationContext
{
%Docstring
used for the collecting of strings of .qgs to be translated and writing of ts file
.. versionadded:: 3.4
%End
%TypeHeaderCode
#include "qgstranslationcontext.h"
%End
public:
QgsTranslationContext( );
%Docstring
Constructor
%End
QgsProject *project() const;
%Docstring
Returns the project
.. seealso:: :py:func:`setProject`
%End
void setProject( QgsProject *project );
%Docstring
Sets the ``project`` where the translation need to be done for
.. seealso:: :py:func:`project`
%End
QString fileName() const;
%Docstring
Returns the TS fileName
.. seealso:: :py:func:`setFileName`
%End
void setFileName( const QString &fileName );
%Docstring
Sets the ``name`` 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 translationString: name and path of the object need to be translated
:param layerName: the name of the layer
%End
void writeTsFile( const QString &locale );
%Docstring
Writes the Ts-file
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgstranslationcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -830,7 +830,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText ); connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle ); connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );
//fill ts language checkbox
//fill ts language checkbox //fill ts language checkbox
QString i18nPath = QgsApplication::i18nPath(); QString i18nPath = QgsApplication::i18nPath();
QDir i18Dir( i18nPath, QStringLiteral( "qgis*.qm" ) ); QDir i18Dir( i18nPath, QStringLiteral( "qgis*.qm" ) );
@ -845,10 +844,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
// QTBUG-57802: eo locale is improperly handled // QTBUG-57802: eo locale is improperly handled
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName(); QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
cbtsLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l ); cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
} }
cbtsLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( QStringLiteral( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) ); cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QStringLiteral( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) );
cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) ); cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) );
connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton ); connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton );
@ -2214,7 +2213,7 @@ void QgsProjectProperties::setCurrentPage( const QString &pageWidgetName )
} }
} }
void QgsProjectProperties::onGenerateTsFileButton() void QgsProjectProperties::onGenerateTsFileButton() const
{ {
QString l = cbtsLocale->currentData().toString(); QString l = cbtsLocale->currentData().toString();
QgsProject::instance()->generateTsFile( l ); QgsProject::instance()->generateTsFile( l );

View File

@ -93,7 +93,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
void scaleItemChanged( QListWidgetItem *changedScaleItem ); void scaleItemChanged( QListWidgetItem *changedScaleItem );
//! generate the ts file with the locale selected in the checkbox //! generate the ts file with the locale selected in the checkbox
void onGenerateTsFileButton(); void onGenerateTsFileButton() const;
/** /**
* Set WMS default extent to current canvas extent * Set WMS default extent to current canvas extent

View File

@ -746,7 +746,7 @@ class CORE_EXPORT QgsApplication : public QApplication
/** /**
* Emits the signal to collect all the strings of .qgs to be included in ts file * Emits the signal to collect all the strings of .qgs to be included in ts file
* *
* \since QGIS 3.2 * \since QGIS 3.4
*/ */
void collectTranslatableObjects( QgsTranslationContext *translationContext ); void collectTranslatableObjects( QgsTranslationContext *translationContext );

View File

@ -444,7 +444,7 @@ void QgsProject::setPresetHomePath( const QString &path )
void QgsProject::registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId ) void QgsProject::registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId )
{ {
QList<QgsAttributeEditorElement *> elements = parent->children(); const QList<QgsAttributeEditorElement *> elements = parent->children();
for ( QgsAttributeEditorElement *element : elements ) for ( QgsAttributeEditorElement *element : elements )
{ {
@ -463,7 +463,9 @@ void QgsProject::registerTranslatableContainers( QgsTranslationContext *translat
void QgsProject::registerTranslatableObjects( QgsTranslationContext *translationContext ) void QgsProject::registerTranslatableObjects( QgsTranslationContext *translationContext )
{ {
//register layers //register layers
for ( QgsLayerTreeLayer *layer : mRootGroup->findLayers() ) const QList<QgsLayerTreeLayer *> layers = mRootGroup->findLayers();
for ( const QgsLayerTreeLayer *layer : layers )
{ {
translationContext->registerTranslation( QStringLiteral( "project:layers:%1" ).arg( layer->layerId() ), layer->name() ); translationContext->registerTranslation( QStringLiteral( "project:layers:%1" ).arg( layer->layerId() ), layer->name() );
@ -489,7 +491,8 @@ void QgsProject::registerTranslatableObjects( QgsTranslationContext *translation
} }
//register layergroups //register layergroups
for ( const QgsLayerTreeGroup *groupLayer : mRootGroup->findGroups() ) const QList<QgsLayerTreeGroup *> groupLayers = mRootGroup->findGroups();
for ( const QgsLayerTreeGroup *groupLayer : groupLayers )
{ {
translationContext->registerTranslation( QStringLiteral( "project:layergroups" ), groupLayer->name() ); translationContext->registerTranslation( QStringLiteral( "project:layergroups" ), groupLayer->name() );
} }
@ -1012,10 +1015,7 @@ bool QgsProject::readProjectFile( const QString &filename )
if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() ) if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() )
{ {
mTranslator.reset( new QTranslator() ); mTranslator.reset( new QTranslator() );
if ( mTranslator->load( localeFileName, QFileInfo( projectFile.fileName() ).absolutePath() ) ) mTranslator->load( localeFileName, QFileInfo( projectFile.fileName() ).absolutePath() );
{
QgsDebugMsg( "Translation loaded" );
}
} }
std::unique_ptr<QDomDocument> doc( new QDomDocument( QStringLiteral( "qgis" ) ) ); std::unique_ptr<QDomDocument> doc( new QDomDocument( QStringLiteral( "qgis" ) ) );
@ -1319,17 +1319,16 @@ bool QgsProject::readProjectFile( const QString &filename )
{ {
//project possibly translated -> rename it with locale postfix //project possibly translated -> rename it with locale postfix
QString newFileName( QStringLiteral( "%1/%2.qgs" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ); QString newFileName( QStringLiteral( "%1/%2.qgs" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) );
QgsProject::instance()->setFileName( newFileName ); setFileName( newFileName );
if ( QgsProject::instance()->write() ) if ( write() )
{ {
QgsProject::instance()->setTitle( localeFileName ); setTitle( localeFileName );
QgsMessageLog::logMessage( tr( "Translated project saved with locale prefix %1" ).arg( newFileName ), QObject::tr( "Project translation" ), Qgis::Success );
QgsDebugMsg( "Translated project saved with locale prefix " + newFileName );
} }
else else
{ {
QgsDebugMsg( "Error saving translated project with locale prefix " + newFileName ); QgsMessageLog::logMessage( tr( "Error saving translated project with locale prefix %1" ).arg( newFileName ), QObject::tr( "Project translation" ), Qgis::Critical );
} }
} }
return true; return true;