Skip to content

Commit 442c732

Browse files
committedAug 7, 2018
sip files and some improvements
like make a list copy before go through for loop and log messages
1 parent e8e48ab commit 442c732

10 files changed

+213
-22
lines changed
 

‎python/core/auto_generated/qgsapplication.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,13 @@ The maximum number of concurrent connections per connections pool.
808808
QGIS may in some situations allocate more than this amount
809809
of connections to avoid deadlocks.
810810

811+
.. versionadded:: 3.4
812+
%End
813+
814+
void collectTranslatableObjects( QgsTranslationContext *translationContext );
815+
%Docstring
816+
Emits the signal to collect all the strings of .qgs to be included in ts file
817+
811818
.. versionadded:: 3.4
812819
%End
813820

‎python/core/auto_generated/qgsproject.sip.in

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515

16-
class QgsProject : QObject, QgsExpressionContextGenerator
16+
class QgsProject : QObject, QgsExpressionContextGenerator, QgsProjectTranslator
1717
{
1818
%Docstring
1919
Reads and writes project states.
@@ -135,6 +135,14 @@ Returns last modified time of the project file as returned by the file system (o
135135
Returns full absolute path to the project file if the project is stored in a file system - derived from fileName().
136136
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).
137137

138+
.. versionadded:: 3.2
139+
%End
140+
141+
QString absolutePath() const;
142+
%Docstring
143+
Returns full absolute path to the project folder if the project is stored in a file system - derived from fileName().
144+
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).
145+
138146
.. versionadded:: 3.2
139147
%End
140148

@@ -983,6 +991,28 @@ and it is mainly a hint for the user interface to protect users from removing la
983991
in the project. The removeMapLayer(), removeMapLayers() calls do not block removal of layers listed here.
984992

985993
.. versionadded:: 3.2
994+
%End
995+
996+
void generateTsFile( const QString &locale );
997+
%Docstring
998+
Triggers the collection strings of .qgs to be included in ts file and calls writeTsFile()
999+
1000+
.. versionadded:: 3.4
1001+
%End
1002+
1003+
virtual QString translate( const QString &context, const QString &sourceText, const char *disambiguation = 0, int n = -1 ) const;
1004+
1005+
%Docstring
1006+
Translates the project with QTranslator and qm file
1007+
1008+
:return: the result string (in case there is no QTranslator loaded the sourceText)
1009+
1010+
:param context: describing layer etc.
1011+
:param sourceText: is the identifier of this text
1012+
:param disambiguation: it's the disambiguation
1013+
:param n: if -1 uses the appropriate form
1014+
1015+
.. versionadded:: 3.4
9861016
%End
9871017

9881018
signals:
@@ -997,7 +1027,7 @@ just before a new project is read).
9971027
.. versionadded:: 3.2
9981028
%End
9991029

1000-
void readProject( const QDomDocument & );
1030+
void readProject( const QDomDocument &, QgsReadWriteContext &context );
10011031
%Docstring
10021032
Emitted when a project is being read.
10031033
%End
@@ -1335,6 +1365,27 @@ home path will be automatically determined from the project's file path.
13351365
.. seealso:: :py:func:`homePathChanged`
13361366

13371367
.. versionadded:: 3.2
1368+
%End
1369+
1370+
void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1371+
%Docstring
1372+
Registers the translatable containers into the tranlation context
1373+
this is a rekursive function to get all the child containers
1374+
1375+
:param translationContext: where the objects will be registered
1376+
:param parent: parent-container containing list of children
1377+
1378+
.. versionadded:: 3.4
1379+
%End
1380+
1381+
void registerTranslatableObjects( QgsTranslationContext *translationContext );
1382+
%Docstring
1383+
Registers the translatable objects into the tranlation context
1384+
so there can be created a ts file these values
1385+
1386+
:param translationContext: where the objects will be registered
1387+
1388+
.. versionadded:: 3.4
13381389
%End
13391390

13401391
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsprojecttranslator.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsProjectTranslator
12+
{
13+
%Docstring
14+
This abstract class is to call translate() for project data from wherever QgsReadWriteContext is available.
15+
16+
.. versionadded:: 3.4
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgsprojecttranslator.h"
21+
%End
22+
public:
23+
24+
25+
virtual QString translate( const QString &context, const QString &sourceText, const char *disambiguation = 0, int n = -1 ) const = 0;
26+
%Docstring
27+
This method needs to be reimplemented in all classes which implement this interface
28+
29+
.. versionadded:: 3.4
30+
%End
31+
32+
virtual ~QgsProjectTranslator();
33+
};
34+
35+
/************************************************************************
36+
* This file has been generated automatically from *
37+
* *
38+
* src/core/qgsprojecttranslator.h *
39+
* *
40+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
41+
************************************************************************/

‎python/core/auto_generated/qgsreadwritecontext.sip.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,21 @@ Returns the stored messages and remove them
9898
.. versionadded:: 3.2
9999
%End
100100

101+
const QgsProjectTranslator *projectTranslator( ) const;
102+
%Docstring
103+
Returns the project translator
104+
105+
.. versionadded:: 3.4
106+
%End
107+
108+
void setProjectTranslator( QgsProjectTranslator *projectTranslator );
109+
%Docstring
110+
Sets the project translator
111+
112+
.. versionadded:: 3.4
113+
%End
101114

115+
public:
102116
};
103117

104118

‎python/core/auto_generated/qgsrelation.sip.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ class QgsRelation
3535
Default constructor. Creates an invalid relation.
3636
%End
3737

38-
static QgsRelation createFromXml( const QDomNode &node );
38+
static QgsRelation createFromXml( const QDomNode &node, QgsReadWriteContext &context );
3939
%Docstring
4040
Creates a relation from an XML structure. Used for reading .qgs projects.
4141

4242
:param node: The dom node containing the relation information
43+
:param context: to pass project translator
4344

4445
:return: A relation
4546
%End
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgstranslationcontext.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsTranslationContext
13+
{
14+
%Docstring
15+
used for the collecting of strings of .qgs to be translated and writing of ts file
16+
17+
.. versionadded:: 3.4
18+
%End
19+
20+
%TypeHeaderCode
21+
#include "qgstranslationcontext.h"
22+
%End
23+
public:
24+
25+
QgsTranslationContext( );
26+
%Docstring
27+
Constructor
28+
%End
29+
30+
QgsProject *project() const;
31+
%Docstring
32+
Returns the project
33+
34+
.. seealso:: :py:func:`setProject`
35+
%End
36+
37+
void setProject( QgsProject *project );
38+
%Docstring
39+
Sets the ``project`` where the translation need to be done for
40+
41+
.. seealso:: :py:func:`project`
42+
%End
43+
44+
QString fileName() const;
45+
%Docstring
46+
Returns the TS fileName
47+
48+
.. seealso:: :py:func:`setFileName`
49+
%End
50+
51+
void setFileName( const QString &fileName );
52+
%Docstring
53+
Sets the ``name`` of the TS file
54+
55+
.. seealso:: :py:func:`fileName`
56+
%End
57+
58+
void registerTranslation( const QString &context, const QString &source );
59+
%Docstring
60+
Registers the ``string`` to be translated
61+
62+
:param translationString: name and path of the object need to be translated
63+
:param layerName: the name of the layer
64+
%End
65+
66+
void writeTsFile( const QString &locale );
67+
%Docstring
68+
Writes the Ts-file
69+
%End
70+
71+
};
72+
73+
/************************************************************************
74+
* This file has been generated automatically from *
75+
* *
76+
* src/core/qgstranslationcontext.h *
77+
* *
78+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
79+
************************************************************************/

‎src/app/qgsprojectproperties.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
830830
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
831831
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );
832832

833-
//fill ts language checkbox
834833
//fill ts language checkbox
835834
QString i18nPath = QgsApplication::i18nPath();
836835
QDir i18Dir( i18nPath, QStringLiteral( "qgis*.qm" ) );
@@ -845,10 +844,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
845844

846845
// QTBUG-57802: eo locale is improperly handled
847846
QString displayName = l.startsWith( QLatin1String( "eo" ) ) ? QLocale::languageToString( QLocale::Esperanto ) : QLocale( l ).nativeLanguageName();
848-
cbtsLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
847+
cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( l ) ), displayName, l );
849848
}
850849

851-
cbtsLocale->addItem( QIcon( QString( ":/images/flags/%1.svg" ).arg( QStringLiteral( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) );
850+
cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QStringLiteral( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) );
852851
cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) );
853852

854853
connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton );
@@ -2214,7 +2213,7 @@ void QgsProjectProperties::setCurrentPage( const QString &pageWidgetName )
22142213
}
22152214
}
22162215

2217-
void QgsProjectProperties::onGenerateTsFileButton()
2216+
void QgsProjectProperties::onGenerateTsFileButton() const
22182217
{
22192218
QString l = cbtsLocale->currentData().toString();
22202219
QgsProject::instance()->generateTsFile( l );

‎src/app/qgsprojectproperties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
9393
void scaleItemChanged( QListWidgetItem *changedScaleItem );
9494

9595
//! generate the ts file with the locale selected in the checkbox
96-
void onGenerateTsFileButton();
96+
void onGenerateTsFileButton() const;
9797

9898
/**
9999
* Set WMS default extent to current canvas extent

‎src/core/qgsapplication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ class CORE_EXPORT QgsApplication : public QApplication
746746
/**
747747
* Emits the signal to collect all the strings of .qgs to be included in ts file
748748
*
749-
* \since QGIS 3.2
749+
* \since QGIS 3.4
750750
*/
751751
void collectTranslatableObjects( QgsTranslationContext *translationContext );
752752

‎src/core/qgsproject.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ void QgsProject::setPresetHomePath( const QString &path )
444444

445445
void QgsProject::registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId )
446446
{
447-
QList<QgsAttributeEditorElement *> elements = parent->children();
447+
const QList<QgsAttributeEditorElement *> elements = parent->children();
448448

449449
for ( QgsAttributeEditorElement *element : elements )
450450
{
@@ -463,7 +463,9 @@ void QgsProject::registerTranslatableContainers( QgsTranslationContext *translat
463463
void QgsProject::registerTranslatableObjects( QgsTranslationContext *translationContext )
464464
{
465465
//register layers
466-
for ( QgsLayerTreeLayer *layer : mRootGroup->findLayers() )
466+
const QList<QgsLayerTreeLayer *> layers = mRootGroup->findLayers();
467+
468+
for ( const QgsLayerTreeLayer *layer : layers )
467469
{
468470
translationContext->registerTranslation( QStringLiteral( "project:layers:%1" ).arg( layer->layerId() ), layer->name() );
469471

@@ -489,7 +491,8 @@ void QgsProject::registerTranslatableObjects( QgsTranslationContext *translation
489491
}
490492

491493
//register layergroups
492-
for ( const QgsLayerTreeGroup *groupLayer : mRootGroup->findGroups() )
494+
const QList<QgsLayerTreeGroup *> groupLayers = mRootGroup->findGroups();
495+
for ( const QgsLayerTreeGroup *groupLayer : groupLayers )
493496
{
494497
translationContext->registerTranslation( QStringLiteral( "project:layergroups" ), groupLayer->name() );
495498
}
@@ -1012,10 +1015,7 @@ bool QgsProject::readProjectFile( const QString &filename )
10121015
if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() )
10131016
{
10141017
mTranslator.reset( new QTranslator() );
1015-
if ( mTranslator->load( localeFileName, QFileInfo( projectFile.fileName() ).absolutePath() ) )
1016-
{
1017-
QgsDebugMsg( "Translation loaded" );
1018-
}
1018+
mTranslator->load( localeFileName, QFileInfo( projectFile.fileName() ).absolutePath() );
10191019
}
10201020

10211021
std::unique_ptr<QDomDocument> doc( new QDomDocument( QStringLiteral( "qgis" ) ) );
@@ -1319,17 +1319,16 @@ bool QgsProject::readProjectFile( const QString &filename )
13191319
{
13201320
//project possibly translated -> rename it with locale postfix
13211321
QString newFileName( QStringLiteral( "%1/%2.qgs" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) );
1322-
QgsProject::instance()->setFileName( newFileName );
1322+
setFileName( newFileName );
13231323

1324-
if ( QgsProject::instance()->write() )
1324+
if ( write() )
13251325
{
1326-
QgsProject::instance()->setTitle( localeFileName );
1327-
1328-
QgsDebugMsg( "Translated project saved with locale prefix " + newFileName );
1326+
setTitle( localeFileName );
1327+
QgsMessageLog::logMessage( tr( "Translated project saved with locale prefix %1" ).arg( newFileName ), QObject::tr( "Project translation" ), Qgis::Success );
13291328
}
13301329
else
13311330
{
1332-
QgsDebugMsg( "Error saving translated project with locale prefix " + newFileName );
1331+
QgsMessageLog::logMessage( tr( "Error saving translated project with locale prefix %1" ).arg( newFileName ), QObject::tr( "Project translation" ), Qgis::Critical );
13331332
}
13341333
}
13351334
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.