QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgsogrproxytextcodec.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsogrproxytextcodec.cpp
3 -------------
4 begin : June 2020
5 copyright : (C) 2020 Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include <cpl_string.h>
19#include <mutex>
20
21#include "qgslogger.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28 : mName( name )
29{}
30
31QString QgsOgrProxyTextCodec::convertToUnicode( const char *chars, int, ConverterState * ) const
32{
33 if ( !chars )
34 return QString();
35
36 char *res = CPLRecode( chars, mName.constData(), CPL_ENC_UTF8 );
37 if ( !res )
38 {
39 QgsDebugError( "convertToUnicode failed" );
40 return QString();
41 }
42
43 const QString result = QString::fromUtf8( res );
44 CPLFree( res );
45 return result;
46}
47
48QByteArray QgsOgrProxyTextCodec::convertFromUnicode( const QChar *unicode, int length, ConverterState * ) const
49{
50 if ( !unicode )
51 return QByteArray();
52
53 const QString src = QString( unicode, length );
54 char *res = CPLRecode( src.toUtf8().constData(), CPL_ENC_UTF8, mName.constData() );
55 if ( !res )
56 {
57 QgsDebugError( "convertFromUnicode failed" );
58 return QByteArray();
59 }
60
61 const QByteArray result = QByteArray( res );
62 CPLFree( res );
63 return result;
64}
65
66// MY 5 YEAR OLD DAUGHTER WROTE THIS LINE, REMOVE AT YOUR OWN RISK!!!
67// i don't want this to be here
68
70{
71 return mName;
72}
73
74QList<QByteArray> QgsOgrProxyTextCodec::aliases() const
75{
76 return QList<QByteArray>();
77}
78
80{
81 // doesn't seem required in this case
82 return 0;
83}
84
86{
87 static QStringList codecs;
88 static std::once_flag initialized;
89 std::call_once( initialized, [&]() {
90 // there's likely others that are supported by GDAL, but we're primarily concerned here
91 // with codecs used by the shapefile driver, and which are no longer supported on the
92 // windows Qt builds (due to removal of ICU support in windows Qt builds)
93 // see https://github.com/qgis/QGIS/issues/36871
94 for ( int i = 437; i <= 950; ++i )
95 codecs << u"CP%1"_s.arg( i );
96 for ( int i = 1250; i <= 1258; ++i )
97 codecs << u"CP%1"_s.arg( i );
98 codecs << u"CP1251"_s;
99 } );
100 return codecs;
101}
QByteArray name() const override
QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const override
QgsOgrProxyTextCodec(const QByteArray &name)
Constructor for QgsOgrProxyTextCodec, for the specified encoding name.
QString convertToUnicode(const char *in, int length, ConverterState *state) const override
int mibEnum() const override
QList< QByteArray > aliases() const override
static QStringList supportedCodecs()
Returns a list of supported text codecs.
#define QgsDebugError(str)
Definition qgslogger.h:59