mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
parent
cb63fe9a77
commit
ebc23263ba
@ -2860,9 +2860,9 @@ QString QgsOgrUtils::loadStoredStyle( GDALDatasetH hDS, const QString &layerName
|
||||
" AND f_table_name=%1"
|
||||
" AND f_geometry_column=%2"
|
||||
" ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
|
||||
",update_time DESC LIMIT 1" )
|
||||
.arg( QgsOgrProviderUtils::quotedValue( layerName ) )
|
||||
.arg( QgsOgrProviderUtils::quotedValue( geomColumn ) );
|
||||
",update_time DESC" )
|
||||
.arg( QgsOgrProviderUtils::quotedValue( layerName ),
|
||||
QgsOgrProviderUtils::quotedValue( geomColumn ) );
|
||||
OGR_L_SetAttributeFilter( hLayer, selectQmlQuery.toUtf8().constData() );
|
||||
OGR_L_ResetReading( hLayer );
|
||||
OGRFeatureDefnH hLayerDefn = OGR_L_GetLayerDefn( hLayer );
|
||||
|
@ -38,6 +38,8 @@
|
||||
#include "qgssymbol.h"
|
||||
#include "qgsfielddomain.h"
|
||||
#include "qgsweakrelation.h"
|
||||
#include "qgsogrproviderutils.h"
|
||||
#include "qgssinglesymbolrenderer.h"
|
||||
|
||||
class TestQgsOgrUtils: public QObject
|
||||
{
|
||||
@ -71,6 +73,7 @@ class TestQgsOgrUtils: public QObject
|
||||
void testVariantTypeToOgrFieldType();
|
||||
void testOgrStringToVariant_data();
|
||||
void testOgrStringToVariant();
|
||||
void testOgrUtilsStoredStyle();
|
||||
|
||||
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
|
||||
void testConvertFieldDomain();
|
||||
@ -1045,6 +1048,66 @@ void TestQgsOgrUtils::testOgrStringToVariant()
|
||||
QCOMPARE( res, expected );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for issue GH #57251
|
||||
*/
|
||||
void TestQgsOgrUtils::testOgrUtilsStoredStyle()
|
||||
{
|
||||
// Create a test GPKG file with layer in a temporary directory
|
||||
QTemporaryDir tempDir;
|
||||
QVERIFY( tempDir.isValid() );
|
||||
QString tempDirPath = tempDir.path();
|
||||
QString testFile = tempDirPath + "/test.gpkg";
|
||||
// Create datasource
|
||||
QString error;
|
||||
QVERIFY( QgsOgrProviderUtils::createEmptyDataSource( testFile, QStringLiteral( "GPKG" ),
|
||||
QStringLiteral( "UTF-8" ), Qgis::WkbType::Point, QList< QPair<QString, QString> >(),
|
||||
QgsCoordinateReferenceSystem::fromEpsgId( 4326 ), error ) );
|
||||
|
||||
{
|
||||
// Open the datasource
|
||||
QgsVectorLayer vl = QgsVectorLayer( testFile, QStringLiteral( "test" ), QStringLiteral( "ogr" ) );
|
||||
QVERIFY( vl.isValid() );
|
||||
|
||||
QgsSingleSymbolRenderer *renderer { static_cast<QgsSingleSymbolRenderer *>( vl.renderer() ) };
|
||||
QVERIFY( renderer );
|
||||
QgsSymbol *symbol = renderer->symbol()->clone();
|
||||
|
||||
// Store styles in the DB
|
||||
|
||||
symbol->setColor( QColor( 255, 0, 0 ) );
|
||||
renderer->setSymbol( symbol );
|
||||
vl.saveStyleToDatabase( "style1", "style1", false, QString(), error );
|
||||
|
||||
// Default
|
||||
symbol = renderer->symbol()->clone();
|
||||
symbol->setColor( QColor( 0, 255, 0 ) );
|
||||
renderer->setSymbol( symbol );
|
||||
vl.saveStyleToDatabase( "style2", "style2", true, QString(), error );
|
||||
|
||||
symbol = renderer->symbol()->clone();
|
||||
symbol->setColor( QColor( 0, 0, 255 ) );
|
||||
renderer->setSymbol( symbol );
|
||||
vl.saveStyleToDatabase( "style3", "style3", false, QString(), error );
|
||||
}
|
||||
|
||||
gdal::ogr_datasource_unique_ptr hDS( OGROpen( testFile.toUtf8().constData(), false, nullptr ) );
|
||||
|
||||
QString styleName;
|
||||
QgsOgrUtils::loadStoredStyle( hDS.get(), QStringLiteral( "test" ), QStringLiteral( "geom" ), styleName, error );
|
||||
QCOMPARE( styleName, QStringLiteral( "style2" ) );
|
||||
|
||||
QStringList ids;
|
||||
QStringList names;
|
||||
QStringList descriptions;
|
||||
QgsOgrUtils::listStyles( hDS.get(), QStringLiteral( "test" ), QStringLiteral( "geom" ), ids, names, descriptions, error );
|
||||
QCOMPARE( ids.size(), 3 );
|
||||
QCOMPARE( names.size(), 3 );
|
||||
QCOMPARE( descriptions.size(), 3 );
|
||||
QCOMPARE( names.toSet(), QSet<QString>() << QStringLiteral( "style1" ) << QStringLiteral( "style2" ) << QStringLiteral( "style3" ) );
|
||||
|
||||
}
|
||||
|
||||
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,3,0)
|
||||
void TestQgsOgrUtils::testConvertFieldDomain()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user