Fix single/multi select DateTime filter#4495
Conversation
Coverage Report for CI Build 27557989684Warning No base build found for commit Coverage: 59.068%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
📦 Build Artifacts Ready
|
|
I have a bad feeling though that, if the user will use |
📦 Build Artifacts Ready
|
Modified logic to convert convert utc date time
Added constant for timestamp with no milliseconds
bed2d9c to
429d49c
Compare
📦 Build Artifacts Ready
|
tomasMizera
left a comment
There was a problem hiding this comment.
Can we add unit tests here?
Added helper methods to testUtils Changed single/ multi select filter to support IS NULL
📦 Build Artifacts Ready
|
Withalion
left a comment
There was a problem hiding this comment.
The tests look okay in general, let's just improve the approach.
| QStringList expressions; | ||
| QString expressionTemplate( expressionCopy ); | ||
| expressionTemplate.replace( QStringLiteral( "@@value@@" ), QStringLiteral( "NULL" ) ); | ||
| expressionTemplate.replace( QStringLiteral( "= NULL" ), QStringLiteral( "IS NULL" ) ); |
There was a problem hiding this comment.
if there was no change in plugin then the sql query should be column IS value. Did something change in the meantime?
| if ( QgsVariantUtils::isNull( value ) ) | ||
| { | ||
| expressionTemplate.replace( QStringLiteral( "@@value@@" ), QStringLiteral( "NULL" ) ); | ||
| expressionTemplate.replace( QStringLiteral( "= NULL" ), QStringLiteral( "IS NULL" ) ); |
| void testDateRange_dateTime(); | ||
| void testDateRange_date(); | ||
| void testDateRange_dateTime_null(); // invalid bounds fall back to min/max sentinels | ||
| void testDateRange_date_null(); // invalid bounds fall back to min/max sentinels | ||
| void testDateRange_dateTime_featureAtLowerBound(); // >= is inclusive: feature exactly at from-bound is counted | ||
| void testDateRange_dateTime_midnightLowerBound(); // from=midnight; midnight feature is at the inclusive lower bound | ||
| void testDateRange_dateTime_zeroMsInsideRange(); // 0 ms feature inside range: range uses >= / <=, no double-expr needed | ||
|
|
||
| // Single select | ||
| void testSingleSelect_dateTime_nonZeroMs(); | ||
| void testSingleSelect_dateTime_zeroMs(); // edge case: 0 ms | ||
| void testSingleSelect_dateTime_null(); // null -> NULL OR '' | ||
| void testSingleSelect_date(); | ||
|
|
||
| // Multi select | ||
| void testMultiSelect_dateTime_nonZeroMs(); | ||
| void testMultiSelect_dateTime_zeroMs(); // edge case: 0 ms | ||
| void testMultiSelect_dateTime_mixed(); // mix of 0 ms and non-zero ms values | ||
| void testMultiSelect_dateTime_null(); // null -> NULL OR '' | ||
| void testMultiSelect_dateTime_empty(); // empty list -> no subset string | ||
| void testMultiSelect_date(); |
There was a problem hiding this comment.
use camelCase or PascalCase, which is used in the rest of repo
|
|
||
| //! Creates an in-memory layer with a single field of the given type and registers it in QgsProject::instance() | ||
| //! fieldType is the QGIS memory-provider type string: "datetime", "date", "string", "integer", "double", "bool", etc. | ||
| QgsVectorLayer *createFilterTestLayer( const QString &fieldName, | ||
| const QString &fieldType, | ||
| const QString &layerName = QStringLiteral( "FilterTestLayer" ) ); | ||
|
|
||
| //! Appends a single feature to layer via the data provider; value is stored in the named field. Returns false if addFeatures() fails. | ||
| bool addFeatureToLayer( QgsVectorLayer *layer, const QString &fieldName, const QVariant &value ); | ||
|
|
||
| //! Writes a single-filter config into the project and loads it; returns the assigned filterId | ||
| QString setupControllerWithFilter( FilterController *controller, | ||
| FieldFilter::FilterType filterType, | ||
| const QString &layerId, | ||
| const QString &fieldName, | ||
| const QString &sqlExpression ); |
There was a problem hiding this comment.
Instead of doing this in the code create a QGIS project, which will have filters, layers, features already setup. That should also mitigate the filter definition duplication in testfiltercontroller.cpp. Place the project in test/test_data/ and load it before running the tests
GeoPackage can store DateTime as UTC with or without milliseconds.
The original code assumed that the DateTime entry for Single/Multi select contained milliseconds, which is not always the case if a point is added in QGIS compared to one saved with the mobile app.
Fix: check if the value contains milliseconds and change the format when creating the filter