Skip to content

Commit

Permalink
renamed QgsArrayUtils to QgsPostgresStringUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav authored and m-kuhn committed Aug 10, 2019
1 parent 6527f22 commit b537aa2
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 39 deletions.
6 changes: 4 additions & 2 deletions python/core/auto_generated/qgsarrayutils.sip.in
Expand Up @@ -26,13 +26,15 @@ Returns a QVariantList created out of a string containing an array in postgres a

QString build( const QVariantList &list );
%Docstring
Build a hstore-formatted string from a QVariantMap.
Build a postgres array like formatted list in a string from a QVariantList

:param map: The map to format as a string
:param list: The list that needs to be stored to the string

.. versionadded:: 3.8
%End

QString getNextString( const QString &txt, int &i, const QString &sep );

};

/************************************************************************
Expand Down
55 changes: 55 additions & 0 deletions python/core/auto_generated/qgspostgresstringutils.sip.in
@@ -0,0 +1,55 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgspostgresstringutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



%ModuleHeaderCode
#include "qgspostgresstringutils.h"
%End

namespace QgsPostgresStringUtils
{

QVariantList parse( const QString &string );
%Docstring
Returns a QVariantList created out of a string containing an array in postgres array format {1,2,3} or {"a","b","c"}

:param string: The formatted list in a string

.. versionadded:: 3.8
%End

QString build( const QVariantList &list );
%Docstring
Build a postgres array like formatted list in a string from a QVariantList

:param list: The list that needs to be stored to the string

.. versionadded:: 3.8
%End

QString getNextString( const QString &txt, int &i, const QString &sep );
%Docstring
get the string until the separator

:param txt: the input text
:param i: the current position
:param sep: the separator

.. versionadded:: 3.8
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgspostgresstringutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 1 addition & 1 deletion python/core/core_auto.sip
Expand Up @@ -10,7 +10,7 @@
%Include auto_generated/qgsactionscope.sip
%Include auto_generated/qgsactionmanager.sip
%Include auto_generated/qgsaggregatecalculator.sip
%Include auto_generated/qgsarrayutils.sip
%Include auto_generated/qgspostgresstringutils.sip
%Include auto_generated/qgsattributes.sip
%Include auto_generated/qgsattributetableconfig.sip
%Include auto_generated/qgsattributeeditorelement.sip
Expand Down
4 changes: 2 additions & 2 deletions src/core/CMakeLists.txt
Expand Up @@ -148,7 +148,7 @@ SET(QGIS_CORE_SRCS
qgsactionmanager.cpp
qgsaggregatecalculator.cpp
qgsanimatedicon.cpp
qgsarrayutils.cpp
qgspostgresstringutils.cpp
qgsattributes.cpp
qgsattributetableconfig.cpp
qgsattributeeditorelement.cpp
Expand Down Expand Up @@ -846,7 +846,7 @@ SET(QGIS_CORE_HDRS
qgsactionscope.h
qgsactionmanager.h
qgsaggregatecalculator.h
qgsarrayutils.h
qgspostgresstringutils.h
qgsattributes.h
qgsattributetableconfig.h
qgsattributeeditorelement.h
Expand Down
4 changes: 2 additions & 2 deletions src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp
Expand Up @@ -22,7 +22,7 @@
#include "qgsapplication.h"
#include "qgsexpressioncontextutils.h"
#include "qgsvectorlayerref.h"
#include "qgsarrayutils.h"
#include "qgspostgresstringutils.h"

#include <nlohmann/json.hpp>
using json = nlohmann::json;
Expand Down Expand Up @@ -180,7 +180,7 @@ QStringList QgsValueRelationFieldFormatter::valueToStringList( const QVariant &v
if ( value.type() == QVariant::String )
{
// This must be an array representation
valuesList = QgsArrayUtils::parse( value.toString() );
valuesList = QgsPostgresStringUtils::parse( value.toString() );
}
else if ( value.type() == QVariant::List )
{
Expand Down
@@ -1,5 +1,5 @@
/***************************************************************************
qgsarrayutils.h
qgspostgresstringutils.cpp
---------------------
begin : July 2019
copyright : (C) 2019 by David Signer
Expand All @@ -13,7 +13,7 @@
* *
***************************************************************************/

#include "qgsarrayutils.h"
#include "qgspostgresstringutils.h"
#include "qgsmessagelog.h"
#include <QDebug>
#include <nlohmann/json.hpp>
Expand All @@ -25,7 +25,7 @@ static void jumpSpace( const QString &txt, int &i )
++i;
}

QString QgsArrayUtils::getNextString( const QString &txt, int &i, const QString &sep )
QString QgsPostgresStringUtils::getNextString( const QString &txt, int &i, const QString &sep )
{
jumpSpace( txt, i );
QString cur = txt.mid( i );
Expand Down Expand Up @@ -60,7 +60,7 @@ QString QgsArrayUtils::getNextString( const QString &txt, int &i, const QString
}
}

QVariantList QgsArrayUtils::parse( const QString &string )
QVariantList QgsPostgresStringUtils::parse( const QString &string )
{
QVariantList variantList;

Expand Down Expand Up @@ -145,7 +145,7 @@ QVariantList QgsArrayUtils::parse( const QString &string )

}

QString QgsArrayUtils::build( const QVariantList &list )
QString QgsPostgresStringUtils::build( const QVariantList &list )
{
QStringList sl;
for ( const QVariant &v : qgis::as_const( list ) )
Expand Down
23 changes: 15 additions & 8 deletions src/core/qgsarrayutils.h → src/core/qgspostgresstringutils.h
@@ -1,5 +1,5 @@
/***************************************************************************
qgsarrayutils.h
qgspostgresstringutils.h
---------------------
begin : July 2019
copyright : (C) 2019 by David Signer
Expand All @@ -13,25 +13,25 @@
* *
***************************************************************************/

#ifndef QGSARRAYUTILS_H
#define QGSARRAYUTILS_H
#ifndef QGSPOSTGRESSTRINGUTILS_H
#define QGSPOSTGRESSTRINGUTILS_H

#include "qgis_core.h"
#include "qgis.h"
#include "qlist.h"

#ifdef SIP_RUN
% ModuleHeaderCode
#include "qgsarrayutils.h"
#include "qgspostgresstringutils.h"
% End
#endif

/**
* \ingroup core
* The QgsArrayUtils namespace provides functions to handle postgres array like formatted lists in strings.
* The QgsPostgresStringUtils namespace provides functions to handle postgres array like formatted lists in strings.
* \since QGIS 3.4
*/
namespace QgsArrayUtils
namespace QgsPostgresStringUtils
{

/**
Expand All @@ -48,8 +48,15 @@ namespace QgsArrayUtils
*/
CORE_EXPORT QString build( const QVariantList &list );

QString getNextString( const QString &txt, int &i, const QString &sep );
/**
* get the string until the separator
* \param txt the input text
* \param i the current position
* \param sep the separator
* \since QGIS 3.8
*/
CORE_EXPORT QString getNextString( const QString &txt, int &i, const QString &sep );

};

#endif //QGSARRAYUTILS_H
#endif //QGSPOSTGRESSTRINGUTILS_H
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -26,7 +26,7 @@
#include "qgsattributeform.h"
#include "qgsattributes.h"
#include "qgsjsonutils.h"
#include "qgsarrayutils.h"
#include "qgspostgresstringutils.h"

#include <QHeaderView>
#include <QComboBox>
Expand Down Expand Up @@ -103,7 +103,7 @@ QVariant QgsValueRelationWidgetWrapper::value() const
else
{
//make string
v = QgsArrayUtils::build( vl );
v = QgsPostgresStringUtils::build( vl );
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/CMakeLists.txt
Expand Up @@ -221,7 +221,7 @@ SET(TESTS
testqgsofflineediting.cpp
testqgstranslateproject.cpp
testqobjectuniqueptr.cpp
testqgsarrayutils.cpp
testqgspostgresstringutils.cpp
)

IF(WITH_QTWEBKIT)
Expand Down
Expand Up @@ -15,9 +15,9 @@

#include <QString>
#include "qgstest.h"
#include "qgsarrayutils.h"
#include "qgspostgresstringutils.h"

class TestQgsArrayUtils : public QObject
class TestQgsPostgresStringUtils : public QObject
{
Q_OBJECT
private slots:
Expand All @@ -29,7 +29,7 @@ class TestQgsArrayUtils : public QObject
};


void TestQgsArrayUtils::testPgArrayStringToListAndBack()
void TestQgsPostgresStringUtils::testPgArrayStringToListAndBack()
{

QVariantList vl;
Expand All @@ -43,13 +43,13 @@ void TestQgsArrayUtils::testPgArrayStringToListAndBack()
vl.push_back( QStringLiteral( "...all the etceteras" ) );

QString string = QStringLiteral( "{\"one\",\"}two{\",\"thr\\\"ee\",\"fo,ur\",\"fiv'e\",6,\"and 7garcìa][\",\"...all the etceteras\"}" );
QCOMPARE( QgsArrayUtils::parse( string ), vl );
QCOMPARE( QgsPostgresStringUtils::parse( string ), vl );

// and back
QCOMPARE( QgsArrayUtils::build( vl ), string );
QCOMPARE( QgsPostgresStringUtils::build( vl ), string );
}

void TestQgsArrayUtils::testUnquotedPgArrayStringToListAndBack()
void TestQgsPostgresStringUtils::testUnquotedPgArrayStringToListAndBack()
{
//there might have been used
QVariantList vl;
Expand All @@ -61,14 +61,14 @@ void TestQgsArrayUtils::testUnquotedPgArrayStringToListAndBack()
vl.push_back( QStringLiteral( "that genius" ) );

QString fallback_string = QStringLiteral( "{one,two,three,four,five,that genius}" );
QCOMPARE( QgsArrayUtils::parse( fallback_string ), vl );
QCOMPARE( QgsPostgresStringUtils::parse( fallback_string ), vl );

// and back including quotes
QString new_string = QStringLiteral( "{\"one\",\"two\",\"three\",\"four\",\"five\",\"that genius\"}" );
QCOMPARE( QgsArrayUtils::build( vl ), new_string );
QCOMPARE( QgsPostgresStringUtils::build( vl ), new_string );
}

void TestQgsArrayUtils::testNumberArrayStringToListAndBack()
void TestQgsPostgresStringUtils::testNumberArrayStringToListAndBack()
{
//there might have been used
QVariantList vl;
Expand All @@ -78,13 +78,13 @@ void TestQgsArrayUtils::testNumberArrayStringToListAndBack()
vl.push_back( 4 );

QString number_string = QStringLiteral( "{1,2,3,4}" );
QCOMPARE( QgsArrayUtils::parse( number_string ), vl );
QCOMPARE( QgsPostgresStringUtils::parse( number_string ), vl );

// and back without quotes
QCOMPARE( QgsArrayUtils::build( vl ), number_string );
QCOMPARE( QgsPostgresStringUtils::build( vl ), number_string );
}

void TestQgsArrayUtils::testMultidimensionalPgArrayStringToListAndBack()
void TestQgsPostgresStringUtils::testMultidimensionalPgArrayStringToListAndBack()
{
//there might have been used
QVariantList vl;
Expand All @@ -93,11 +93,11 @@ void TestQgsArrayUtils::testMultidimensionalPgArrayStringToListAndBack()
vl.push_back( QStringLiteral( "{three one third,three two third,three three third}" ) );

QString string = QStringLiteral( "{{one one third,one two third,one three third},{\"two one third\",\"two two third\",\"two three third\"},{three one third,three two third,three three third}}" );
QCOMPARE( QgsArrayUtils::parse( string ), vl );
QCOMPARE( QgsPostgresStringUtils::parse( string ), vl );

// and back without quotes
QCOMPARE( QgsArrayUtils::build( vl ), string );
QCOMPARE( QgsPostgresStringUtils::build( vl ), string );
}

QGSTEST_MAIN( TestQgsArrayUtils )
#include "testqgsarrayutils.moc"
QGSTEST_MAIN( TestQgsPostgresStringUtils )
#include "testqgspostgresstringutils.moc"

0 comments on commit b537aa2

Please sign in to comment.