Skip to content

Commit 9bd4cc9

Browse files
authored
Add missing translations for new project page elements (#4489)
1 parent 6a39af7 commit 9bd4cc9

6 files changed

Lines changed: 111 additions & 104 deletions

File tree

app/fieldsmodel.cpp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
/***************************************************************************
2+
* *
3+
* This program is free software; you can redistribute it and/or modify *
4+
* it under the terms of the GNU General Public License as published by *
5+
* the Free Software Foundation; either version 2 of the License, or *
6+
* (at your option) any later version. *
7+
* *
8+
***************************************************************************/
9+
110
#include "fieldsmodel.h"
2-
#include <QtDebug>
311

412
FieldsModel::FieldsModel( QObject *parent )
513
: QAbstractListModel( parent )
614
{
715
// fill the model with initial data
8-
addField( "Date", "DateTime" );
9-
addField( "Notes", "TextEdit" );
10-
addField( "Photo", "ExternalResource" );
16+
addField( tr( "Date" ), "DateTime" );
17+
addField( tr( "Notes" ), "TextEdit" );
18+
addField( tr( "Photo" ), "ExternalResource" );
1119
}
1220

1321
bool FieldsModel::addField( const QString &name, const QString &widgetType )
@@ -36,13 +44,13 @@ bool FieldsModel::addField( const QString &name, const QString &widgetType )
3644
return true;
3745
}
3846

39-
bool FieldsModel::removeField( int row )
47+
bool FieldsModel::removeField( const int rowIndex )
4048
{
41-
if ( row < 0 || row >= mFields.count() )
49+
if ( rowIndex < 0 || rowIndex >= mFields.count() )
4250
return false;
4351

4452
beginResetModel();
45-
mFields.removeAt( row );
53+
mFields.removeAt( rowIndex );
4654
endResetModel();
4755
return true;
4856
}
@@ -55,8 +63,8 @@ QList<FieldConfiguration> FieldsModel::fields() const
5563
QHash<int, QByteArray> FieldsModel::roleNames() const
5664
{
5765
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
58-
roles[AttributeName] = QByteArrayLiteral( "AttributeName" );
59-
roles[WidgetType] = QByteArrayLiteral( "WidgetType" );
66+
roles[AttributeName] = QByteArrayLiteral( "attributeName" );
67+
roles[WidgetType] = QByteArrayLiteral( "widgetType" );
6068

6169
return roles;
6270
}
@@ -65,12 +73,12 @@ QHash<int, QByteArray> FieldsModel::roleNames() const
6573
int FieldsModel::rowCount( const QModelIndex &parent ) const
6674
{
6775
Q_UNUSED( parent );
68-
return mFields.count();
76+
return static_cast<int>( mFields.count() );
6977
}
7078

71-
QVariant FieldsModel::data( const QModelIndex &index, int role ) const
79+
QVariant FieldsModel::data( const QModelIndex &index, const int role ) const
7280
{
73-
int row = index.row();
81+
const int row = index.row();
7482
if ( row < 0 || row >= mFields.count() )
7583
return QVariant();
7684

@@ -80,22 +88,21 @@ QVariant FieldsModel::data( const QModelIndex &index, int role ) const
8088
{
8189
case AttributeName:
8290
return field.attributeName;
83-
break;
8491

8592
case WidgetType:
8693
return field.widgetType;
87-
break;
88-
}
8994

90-
return QVariant();
95+
default:
96+
return QVariant();
97+
}
9198
}
9299

93-
bool FieldsModel::setData( const QModelIndex &index, const QVariant &value, int role )
100+
bool FieldsModel::setData( const QModelIndex &index, const QVariant &value, const int role )
94101
{
95102
if ( data( index, role ) == value )
96103
return true;
97104

98-
int row = index.row();
105+
const int row = index.row();
99106
if ( row < 0 || row >= mFields.count() )
100107
return false;
101108

@@ -111,18 +118,20 @@ bool FieldsModel::setData( const QModelIndex &index, const QVariant &value, int
111118
emit dataChanged( index, index, {AttributeName} );
112119
return true;
113120
}
121+
114122
case WidgetType:
115123
{
116124
mFields[row].widgetType = value.toString();
117125
emit dataChanged( index, index, {WidgetType} );
118126
return true;
119127
}
120-
}
121128

122-
return false;
129+
default:
130+
return false;
131+
}
123132
}
124133

125-
bool FieldsModel::contains( const QString &name )
134+
bool FieldsModel::contains( const QString &name ) const
126135
{
127136
for ( int i = 0; i < mFields.count(); ++i )
128137
{

app/fieldsmodel.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
#ifndef FIELDSMODEL_H
1111
#define FIELDSMODEL_H
1212

13-
#include <QObject>
1413
#include <QAbstractListModel>
15-
#include <QVector>
16-
#include <QMap>
14+
#include <QtQml/qqmlregistration.h>
1715

18-
#include "qgsfield.h"
19-
#include "qgsfields.h"
16+
#include <qgsfield.h>
2017

2118
struct FieldConfiguration
2219
{
@@ -28,18 +25,18 @@ struct FieldConfiguration
2825
class FieldsModel: public QAbstractListModel
2926
{
3027
Q_OBJECT
28+
QML_ELEMENT
29+
3130
public:
3231
/**
3332
* Feature roles enum.
3433
*/
35-
Q_ENUMS( FeatureRoles )
36-
37-
//! Feature roles
3834
enum FeatureRoles
3935
{
4036
AttributeName = Qt::UserRole + 1, //!< Attribute's display name (the original field name)
4137
WidgetType, //!< Widget type name. Should match QT/QML editor widgets names.
4238
};
39+
Q_ENUM( FeatureRoles )
4340

4441
//! Creates a new fields model
4542
explicit FieldsModel( QObject *parent = nullptr );
@@ -62,7 +59,7 @@ class FieldsModel: public QAbstractListModel
6259
QList<FieldConfiguration> mFields;
6360

6461

65-
bool contains( const QString &name );
62+
bool contains( const QString &name ) const;
6663
};
6764

6865
#endif // FIELDSMODEL_H

app/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#include "variablesmanager.h"
5656
#include "inputhelp.h"
5757
#include "inputprojutils.h"
58-
#include "fieldsmodel.h"
5958
#include "projectwizard.h"
6059
#include "qrcodedecoder.h"
6160
#include "inputexpressionfunctions.h"
@@ -270,7 +269,6 @@ void initDeclarative()
270269
qmlRegisterUncreatableType<RegistrationError>( "mm", 1, 0, "RegistrationError", "RegistrationError Enum" );
271270
qmlRegisterType<PositionDirection>( "mm", 1, 0, "PositionDirection" );
272271
qmlRegisterType<Compass>( "mm", 1, 0, "Compass" );
273-
qmlRegisterType<FieldsModel>( "mm", 1, 0, "FieldsModel" );
274272
qmlRegisterType<QrCodeDecoder>( "mm", 1, 0, "QrCodeDecoder" );
275273
qmlRegisterType<ProjectsModel>( "mm", 1, 0, "ProjectsModel" );
276274
qmlRegisterType<ProjectsProxyModel>( "mm", 1, 0, "ProjectsProxyModel" );

app/projectwizard.cpp

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@
1515
#include "qgsvectortilelayer.h"
1616
#include "qgsvectorlayer.h"
1717
#include "qgsvectorfilewriter.h"
18-
#include "qgsdatetimefieldformatter.h"
1918
#include "qgsmarkersymbollayer.h"
20-
#include "qgis.h"
2119
#include "qgslinesymbol.h"
2220
#include "qgssymbollayer.h"
2321
#include "qgssymbollayerutils.h"
2422
#include "qgssymbol.h"
2523
#include "qgsmarkersymbol.h"
2624
#include "qgssinglesymbolrenderer.h"
27-
#include "inpututils.h"
28-
#include "coreutils.h"
2925

3026
const QString TILES_URL = QStringLiteral( "https://tiles.merginmaps.com" );
3127

@@ -39,17 +35,17 @@ ProjectWizard::ProjectWizard( const QString &dataDir, QObject *parent )
3935

4036
QgsVectorLayer *ProjectWizard::createGpkgLayer( QString const &projectDir, QList<FieldConfiguration> const &fieldsConfig )
4137
{
42-
QString gpkgName( QStringLiteral( "data" ) );
43-
QString projectGpkgPath( QString( "%1/%2.%3" ).arg( projectDir ).arg( gpkgName ).arg( "gpkg" ) );
44-
QString layerName( QStringLiteral( "Survey" ) );
45-
QgsCoordinateReferenceSystem layerCrs( LAYER_CRS_ID );
38+
const QString gpkgName( QStringLiteral( "data" ) );
39+
const QString projectGpkgPath( QString( "%1/%2.%3" ).arg( projectDir ).arg( gpkgName ).arg( "gpkg" ) );
40+
const QString layerName( QStringLiteral( "Survey" ) );
41+
const QgsCoordinateReferenceSystem layerCrs( LAYER_CRS_ID );
4642
QgsFields predefinedFields = createFields( fieldsConfig );
4743

4844
// Write layer as gpkg
4945
QgsVectorLayer *layer = new QgsVectorLayer( QStringLiteral( "PointZ?crs=%1" ).arg( LAYER_CRS_ID ), layerName, "memory" );
5046
layer->startEditing();
5147
layer->setCrs( layerCrs );
52-
for ( QgsField f : predefinedFields )
48+
for ( const QgsField &f : predefinedFields )
5349
{
5450
layer->addAttribute( f );
5551
}
@@ -103,19 +99,19 @@ QgsVectorLayer *ProjectWizard::createTrackingLayer( const QString &trackingGpkgP
10399
options.driverName = "GPKG";
104100
options.layerName = "tracking_layer";
105101

106-
QgsVectorFileWriter *writer = QgsVectorFileWriter::create(
107-
trackingGpkgPath,
108-
fields,
109-
Qgis::WkbType::LineStringZM,
110-
QgsCoordinateReferenceSystem( "EPSG:4326" ),
111-
mSettings->transformContext(),
112-
options );
102+
const QgsVectorFileWriter *writer = QgsVectorFileWriter::create(
103+
trackingGpkgPath,
104+
fields,
105+
Qgis::WkbType::LineStringZM,
106+
QgsCoordinateReferenceSystem( "EPSG:4326" ),
107+
mSettings->transformContext(),
108+
options );
113109
delete writer;
114110

115111
QgsVectorLayer *layer = new QgsVectorLayer( trackingGpkgPath, "tracking_layer", "ogr" );
116112

117113
int idx = layer->fields().indexFromName( "fid" );
118-
QgsEditorWidgetSetup cfg( "Hidden", QVariantMap() );
114+
const QgsEditorWidgetSetup cfg( "Hidden", QVariantMap() );
119115
layer->setEditorWidgetSetup( idx, cfg );
120116

121117
idx = layer->fields().indexFromName( "tracking_start_time" );
@@ -154,7 +150,7 @@ QgsVectorLayer *ProjectWizard::createTrackingLayer( const QString &trackingGpkgP
154150
return layer;
155151
}
156152

157-
void ProjectWizard::createProject( QString const &projectNameRaw, FieldsModel *fieldsModel )
153+
void ProjectWizard::createProject( QString const &projectNameRaw, const FieldsModel *fieldsModel )
158154
{
159155
if ( !CoreUtils::isValidName( projectNameRaw ) )
160156
{
@@ -165,10 +161,10 @@ void ProjectWizard::createProject( QString const &projectNameRaw, FieldsModel *f
165161
QString projectName( projectNameRaw );
166162
projectName = InputUtils::sanitizeNode( projectName );
167163

168-
QString projectDir = CoreUtils::createUniqueProjectDirectory( mDataDir, projectName );
169-
QString projectFilepath( QString( "%1/%2.qgz" ).arg( projectDir ).arg( projectName ) );
170-
QString projectGpkgPath( QString( "%1/data.gpkg" ).arg( projectDir ) );
171-
QString trackingGpkgPath( QString( "%1/tracking_layer.gpkg" ).arg( projectDir ) );
164+
const QString projectDir = CoreUtils::createUniqueProjectDirectory( mDataDir, projectName );
165+
const QString projectFilepath( QString( "%1/%2.qgz" ).arg( projectDir ).arg( projectName ) );
166+
const QString projectGpkgPath( QString( "%1/data.gpkg" ).arg( projectDir ) );
167+
const QString trackingGpkgPath( QString( "%1/tracking_layer.gpkg" ).arg( projectDir ) );
172168

173169
QgsProject project;
174170

@@ -197,7 +193,7 @@ void ProjectWizard::createProject( QString const &projectNameRaw, FieldsModel *f
197193
project.addMapLayers( layers );
198194

199195
// Configurate mapSettings
200-
QgsCoordinateReferenceSystem projectCrs( PROJECT_CRS_ID );
196+
const QgsCoordinateReferenceSystem projectCrs( PROJECT_CRS_ID );
201197
mSettings->setExtent( bgLayer->extent() );
202198
mSettings->setEllipsoid( "WGS84" );
203199
mSettings->setDestinationCrs( projectCrs );
@@ -218,7 +214,7 @@ void ProjectWizard::createProject( QString const &projectNameRaw, FieldsModel *f
218214

219215
void ProjectWizard::writeMapCanvasSetting( QDomDocument &doc )
220216
{
221-
QDomNodeList nl = doc.elementsByTagName( QStringLiteral( "qgis" ) );
217+
const QDomNodeList nl = doc.elementsByTagName( QStringLiteral( "qgis" ) );
222218
if ( !nl.count() )
223219
{
224220
QgsDebugError( QStringLiteral( "Unable to find qgis element in project file" ) );
@@ -232,14 +228,14 @@ void ProjectWizard::writeMapCanvasSetting( QDomDocument &doc )
232228
mSettings->writeXml( mapcanvasNode, doc );
233229
}
234230

235-
QgsFields ProjectWizard::createFields( const QList<FieldConfiguration> fieldsConfig ) const
231+
QgsFields ProjectWizard::createFields( const QList<FieldConfiguration> &fieldsConfig ) const
236232
{
237233

238234
QgsFields fields;
239235
for ( const FieldConfiguration &fc : fieldsConfig )
240236
{
241237
QString type = widgetToType( fc.widgetType );
242-
QVariant::Type qtype = parseType( type );
238+
const QMetaType::Type qtype = parseType( type );
243239
QgsField field( fc.attributeName, qtype, type );
244240
fields.append( field );
245241
}
@@ -257,45 +253,53 @@ QgsSingleSymbolRenderer *ProjectWizard::surveyLayerRenderer()
257253
return new QgsSingleSymbolRenderer( symbol );
258254
}
259255

260-
QVariant::Type ProjectWizard::parseType( const QString &type ) const
256+
QMetaType::Type ProjectWizard::parseType( const QString &type ) const
261257
{
262258
if ( type == QLatin1String( "text" ) )
263-
return QVariant::String;
264-
else if ( type == QLatin1String( "integer" ) )
265-
return QVariant::Int;
266-
else if ( type == QLatin1String( "integer64" ) )
267-
return QVariant::Int;
268-
else if ( type == QLatin1String( "real" ) )
269-
return QVariant::Double;
270-
else if ( type == QLatin1String( "date" ) )
271-
return QVariant::Date;
272-
else if ( type == QLatin1String( "datetime" ) )
273-
return QVariant::DateTime;
274-
else if ( type == QLatin1String( "bool" ) )
275-
return QVariant::Bool;
276-
else if ( type == QLatin1String( "binary" ) )
277-
return QVariant::ByteArray;
278-
279-
return QVariant::Invalid;
259+
return QMetaType::QString;
260+
261+
if ( type == QLatin1String( "integer" ) || type == QLatin1String( "integer64" ) )
262+
return QMetaType::Int;
263+
264+
if ( type == QLatin1String( "real" ) )
265+
return QMetaType::Double;
266+
267+
if ( type == QLatin1String( "date" ) )
268+
return QMetaType::QDate;
269+
270+
if ( type == QLatin1String( "datetime" ) )
271+
return QMetaType::QDateTime;
272+
273+
if ( type == QLatin1String( "bool" ) )
274+
return QMetaType::Bool;
275+
276+
if ( type == QLatin1String( "binary" ) )
277+
return QMetaType::QByteArray;
278+
279+
return QMetaType::UnknownType;
280280
}
281281

282282
QString ProjectWizard::widgetToType( const QString &widgetType ) const
283283
{
284284
if ( widgetType == QStringLiteral( "TextEdit" ) )
285285
return QStringLiteral( "text" );
286-
else if ( widgetType == QStringLiteral( "Range" ) )
286+
287+
if ( widgetType == QStringLiteral( "Range" ) )
287288
return QStringLiteral( "integer" );
288-
else if ( widgetType == QStringLiteral( "DateTime" ) )
289+
290+
if ( widgetType == QStringLiteral( "DateTime" ) )
289291
return QStringLiteral( "datetime" );
290-
else if ( widgetType == QStringLiteral( "CheckBox" ) )
292+
293+
if ( widgetType == QStringLiteral( "CheckBox" ) )
291294
return QStringLiteral( "bool" );
292-
else if ( widgetType == QStringLiteral( "ExternalResource" ) )
295+
296+
if ( widgetType == QStringLiteral( "ExternalResource" ) )
293297
return QStringLiteral( "text" );
294298

295299
return QStringLiteral( "text" );
296300
}
297301

298-
QString ProjectWizard::findWidgetTypeByFieldName( const QString name, const QList<FieldConfiguration> fieldsConfig ) const
302+
QString ProjectWizard::findWidgetTypeByFieldName( const QString &name, const QList<FieldConfiguration> &fieldsConfig ) const
299303
{
300304

301305
for ( int i = 0; i < fieldsConfig.count(); ++i )

0 commit comments

Comments
 (0)