16
16
import tempfile
17
17
import shutil
18
18
19
- from qgis .PyQt .QtCore import QDate , QDateTime , QVariant , Qt
19
+ from qgis .PyQt .QtCore import QDate , QDateTime , QVariant , Qt , QDateTime , QDate , QTime
20
20
from qgis .PyQt .QtGui import QPainter , QColor
21
21
from qgis .PyQt .QtXml import QDomDocument
22
22
@@ -211,27 +211,27 @@ class TestQgsVectorLayer(unittest.TestCase, FeatureSourceTestCase):
211
211
@classmethod
212
212
def getSource (cls ):
213
213
vl = QgsVectorLayer (
214
- 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk' ,
214
+ 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time& key=pk' ,
215
215
'test' , 'memory' )
216
216
assert (vl .isValid ())
217
217
218
218
f1 = QgsFeature ()
219
- f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' ])
219
+ f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 2 ), QTime ( 12 , 13 , 1 ) ])
220
220
f1 .setGeometry (QgsGeometry .fromWkt ('Point (-71.123 78.23)' ))
221
221
222
222
f2 = QgsFeature ()
223
- f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' ])
223
+ f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' , NULL , NULL , NULL ])
224
224
225
225
f3 = QgsFeature ()
226
- f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' ])
226
+ f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' , QDateTime ( QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 ) ])
227
227
f3 .setGeometry (QgsGeometry .fromWkt ('Point (-70.332 66.33)' ))
228
228
229
229
f4 = QgsFeature ()
230
- f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' ])
230
+ f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 )), QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 ) ])
231
231
f4 .setGeometry (QgsGeometry .fromWkt ('Point (-68.2 70.8)' ))
232
232
233
233
f5 = QgsFeature ()
234
- f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' ])
234
+ f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' , QDateTime ( QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 )), QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 ) ])
235
235
f5 .setGeometry (QgsGeometry .fromWkt ('Point (-65.32 78.3)' ))
236
236
237
237
vl .dataProvider ().addFeatures ([f1 , f2 , f3 , f4 , f5 ])
@@ -3058,27 +3058,27 @@ class TestQgsVectorLayerSourceAddedFeaturesInBuffer(unittest.TestCase, FeatureSo
3058
3058
@classmethod
3059
3059
def getSource (cls ):
3060
3060
vl = QgsVectorLayer (
3061
- 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk' ,
3061
+ 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time& key=pk' ,
3062
3062
'test' , 'memory' )
3063
3063
assert (vl .isValid ())
3064
3064
3065
3065
f1 = QgsFeature ()
3066
- f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' ])
3066
+ f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 2 ), QTime ( 12 , 13 , 1 ) ])
3067
3067
f1 .setGeometry (QgsGeometry .fromWkt ('Point (-71.123 78.23)' ))
3068
3068
3069
3069
f2 = QgsFeature ()
3070
- f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' ])
3070
+ f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' , NULL , NULL , NULL ])
3071
3071
3072
3072
f3 = QgsFeature ()
3073
- f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' ])
3073
+ f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' , QDateTime ( QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 ) ])
3074
3074
f3 .setGeometry (QgsGeometry .fromWkt ('Point (-70.332 66.33)' ))
3075
3075
3076
3076
f4 = QgsFeature ()
3077
- f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' ])
3077
+ f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 )), QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 ) ])
3078
3078
f4 .setGeometry (QgsGeometry .fromWkt ('Point (-68.2 70.8)' ))
3079
3079
3080
3080
f5 = QgsFeature ()
3081
- f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' ])
3081
+ f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' , QDateTime ( QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 )), QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 ) ])
3082
3082
f5 .setGeometry (QgsGeometry .fromWkt ('Point (-65.32 78.3)' ))
3083
3083
3084
3084
# create a layer with features only in the added features buffer - not the provider
@@ -3122,25 +3122,25 @@ class TestQgsVectorLayerSourceChangedGeometriesInBuffer(unittest.TestCase, Featu
3122
3122
@classmethod
3123
3123
def getSource (cls ):
3124
3124
vl = QgsVectorLayer (
3125
- 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk' ,
3125
+ 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time& key=pk' ,
3126
3126
'test' , 'memory' )
3127
3127
assert (vl .isValid ())
3128
3128
3129
3129
f1 = QgsFeature ()
3130
- f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' ])
3130
+ f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 2 ), QTime ( 12 , 13 , 1 ) ])
3131
3131
3132
3132
f2 = QgsFeature ()
3133
- f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' ])
3133
+ f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' , NULL , NULL , NULL ])
3134
3134
f2 .setGeometry (QgsGeometry .fromWkt ('Point (-70.5 65.2)' ))
3135
3135
3136
3136
f3 = QgsFeature ()
3137
- f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' ])
3137
+ f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' , QDateTime ( QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 ) ])
3138
3138
3139
3139
f4 = QgsFeature ()
3140
- f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' ])
3140
+ f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 )), QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 ) ])
3141
3141
3142
3142
f5 = QgsFeature ()
3143
- f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' ])
3143
+ f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' , QDateTime ( QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 )), QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 ) ])
3144
3144
3145
3145
vl .dataProvider ().addFeatures ([f1 , f2 , f3 , f4 , f5 ])
3146
3146
@@ -3186,27 +3186,27 @@ class TestQgsVectorLayerSourceChangedAttributesInBuffer(unittest.TestCase, Featu
3186
3186
@classmethod
3187
3187
def getSource (cls ):
3188
3188
vl = QgsVectorLayer (
3189
- 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk' ,
3189
+ 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time& key=pk' ,
3190
3190
'test' , 'memory' )
3191
3191
assert (vl .isValid ())
3192
3192
3193
3193
f1 = QgsFeature ()
3194
- f1 .setAttributes ([5 , 200 , 'a' , 'b' , 'c' ])
3194
+ f1 .setAttributes ([5 , 200 , 'a' , 'b' , 'c' , QDateTime ( 2020 , 4 , 5 , 1 , 2 , 3 ), QDate ( 2020 , 4 , 5 ), QTime ( 1 , 2 , 3 ) ])
3195
3195
f1 .setGeometry (QgsGeometry .fromWkt ('Point (-71.123 78.23)' ))
3196
3196
3197
3197
f2 = QgsFeature ()
3198
- f2 .setAttributes ([3 , - 200 , 'd' , 'e' , 'f' ])
3198
+ f2 .setAttributes ([3 , - 200 , 'd' , 'e' , 'f' , QDateTime ( 2020 , 4 , 5 , 1 , 2 , 3 ), QDate ( 2020 , 4 , 5 ), QTime ( 1 , 2 , 3 ) ])
3199
3199
3200
3200
f3 = QgsFeature ()
3201
- f3 .setAttributes ([1 , - 100 , 'g' , 'h' , 'i' ])
3201
+ f3 .setAttributes ([1 , - 100 , 'g' , 'h' , 'i' , QDateTime ( 2020 , 4 , 5 , 1 , 2 , 3 ), QDate ( 2020 , 4 , 5 ), QTime ( 1 , 2 , 3 ) ])
3202
3202
f3 .setGeometry (QgsGeometry .fromWkt ('Point (-70.332 66.33)' ))
3203
3203
3204
3204
f4 = QgsFeature ()
3205
- f4 .setAttributes ([2 , - 200 , 'j' , 'k' , 'l' ])
3205
+ f4 .setAttributes ([2 , - 200 , 'j' , 'k' , 'l' , QDateTime ( 2020 , 4 , 5 , 1 , 2 , 3 ), QDate ( 2020 , 4 , 5 ), QTime ( 1 , 2 , 3 ) ])
3206
3206
f4 .setGeometry (QgsGeometry .fromWkt ('Point (-68.2 70.8)' ))
3207
3207
3208
3208
f5 = QgsFeature ()
3209
- f5 .setAttributes ([4 , 400 , 'm' , 'n' , 'o' ])
3209
+ f5 .setAttributes ([4 , 400 , 'm' , 'n' , 'o' , QDateTime ( 2020 , 4 , 5 , 1 , 2 , 3 ), QDate ( 2020 , 4 , 5 ), QTime ( 1 , 2 , 3 ) ])
3210
3210
f5 .setGeometry (QgsGeometry .fromWkt ('Point (-65.32 78.3)' ))
3211
3211
3212
3212
vl .dataProvider ().addFeatures ([f1 , f2 , f3 , f4 , f5 ])
@@ -3219,26 +3219,41 @@ def getSource(cls):
3219
3219
vl .changeAttributeValue (ids [5 ], 2 , NULL )
3220
3220
vl .changeAttributeValue (ids [5 ], 3 , 'NuLl' )
3221
3221
vl .changeAttributeValue (ids [5 ], 4 , '5' )
3222
+ vl .changeAttributeValue (ids [5 ], 5 , QDateTime (QDate (2020 , 5 , 4 ), QTime (12 , 13 , 14 )))
3223
+ vl .changeAttributeValue (ids [5 ], 6 , QDate (2020 , 5 , 2 ))
3224
+ vl .changeAttributeValue (ids [5 ], 7 , QTime (12 , 13 , 1 ))
3222
3225
3223
3226
vl .changeAttributeValue (ids [3 ], 1 , 300 )
3224
3227
vl .changeAttributeValue (ids [3 ], 2 , 'Pear' )
3225
3228
vl .changeAttributeValue (ids [3 ], 3 , 'PEaR' )
3226
3229
vl .changeAttributeValue (ids [3 ], 4 , '3' )
3230
+ vl .changeAttributeValue (ids [3 ], 5 , NULL )
3231
+ vl .changeAttributeValue (ids [3 ], 6 , NULL )
3232
+ vl .changeAttributeValue (ids [3 ], 7 , NULL )
3227
3233
3228
3234
vl .changeAttributeValue (ids [1 ], 1 , 100 )
3229
3235
vl .changeAttributeValue (ids [1 ], 2 , 'Orange' )
3230
3236
vl .changeAttributeValue (ids [1 ], 3 , 'oranGe' )
3231
3237
vl .changeAttributeValue (ids [1 ], 4 , '1' )
3238
+ vl .changeAttributeValue (ids [1 ], 5 , QDateTime (QDate (2020 , 5 , 3 ), QTime (12 , 13 , 14 )))
3239
+ vl .changeAttributeValue (ids [1 ], 6 , QDate (2020 , 5 , 3 ))
3240
+ vl .changeAttributeValue (ids [1 ], 7 , QTime (12 , 13 , 14 ))
3232
3241
3233
3242
vl .changeAttributeValue (ids [2 ], 1 , 200 )
3234
3243
vl .changeAttributeValue (ids [2 ], 2 , 'Apple' )
3235
3244
vl .changeAttributeValue (ids [2 ], 3 , 'Apple' )
3236
3245
vl .changeAttributeValue (ids [2 ], 4 , '2' )
3246
+ vl .changeAttributeValue (ids [2 ], 5 , QDateTime (QDate (2020 , 5 , 4 ), QTime (12 , 14 , 14 )))
3247
+ vl .changeAttributeValue (ids [2 ], 6 , QDate (2020 , 5 , 4 ))
3248
+ vl .changeAttributeValue (ids [2 ], 7 , QTime (12 , 14 , 14 ))
3237
3249
3238
3250
vl .changeAttributeValue (ids [4 ], 1 , 400 )
3239
3251
vl .changeAttributeValue (ids [4 ], 2 , 'Honey' )
3240
3252
vl .changeAttributeValue (ids [4 ], 3 , 'Honey' )
3241
3253
vl .changeAttributeValue (ids [4 ], 4 , '4' )
3254
+ vl .changeAttributeValue (ids [4 ], 5 , QDateTime (QDate (2021 , 5 , 4 ), QTime (13 , 13 , 14 )))
3255
+ vl .changeAttributeValue (ids [4 ], 6 , QDate (2021 , 5 , 4 ))
3256
+ vl .changeAttributeValue (ids [4 ], 7 , QTime (13 , 13 , 14 ))
3242
3257
3243
3258
return vl
3244
3259
@@ -3287,28 +3302,28 @@ class TestQgsVectorLayerSourceDeletedFeaturesInBuffer(unittest.TestCase, Feature
3287
3302
@classmethod
3288
3303
def getSource (cls ):
3289
3304
vl = QgsVectorLayer (
3290
- 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&key=pk' ,
3305
+ 'Point?crs=epsg:4326&field=pk:integer&field=cnt:integer&field=name:string(0)&field=name2:string(0)&field=num_char:string&field=dt:datetime&field=date:date&field=time:time&& key=pk' ,
3291
3306
'test' , 'memory' )
3292
3307
assert (vl .isValid ())
3293
3308
3294
3309
# add a bunch of similar features to the provider
3295
3310
b1 = QgsFeature ()
3296
- b1 .setAttributes ([5 , - 300 , 'Apple' , 'PEaR' , '1' ])
3311
+ b1 .setAttributes ([5 , - 300 , 'Apple' , 'PEaR' , '1' , QDateTime ( QDate ( 2020 , 5 , 5 ), QTime ( 12 , 11 , 14 )), QDate ( 2020 , 5 , 1 ), QTime ( 10 , 13 , 1 ) ])
3297
3312
b1 .setGeometry (QgsGeometry .fromWkt ('Point (-70.332 66.33)' ))
3298
3313
3299
3314
b2 = QgsFeature ()
3300
- b2 .setAttributes ([3 , 100 , 'Orange' , 'NuLl' , '2' ])
3315
+ b2 .setAttributes ([3 , 100 , 'Orange' , 'NuLl' , '2' , QDateTime ( QDate ( 2020 , 5 , 1 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 9 ), QTime ( 9 , 13 , 1 ) ])
3301
3316
b2 .setGeometry (QgsGeometry .fromWkt ('Point (-71.123 78.23)' ))
3302
3317
3303
3318
b3 = QgsFeature ()
3304
- b3 .setAttributes ([1 , - 200 , 'Honey' , 'oranGe' , '5' ])
3319
+ b3 .setAttributes ([1 , - 200 , 'Honey' , 'oranGe' , '5' , QDateTime ( QDate ( 2020 , 5 , 1 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 19 ), QTime ( 2 , 13 , 1 ) ])
3305
3320
3306
3321
b4 = QgsFeature ()
3307
- b4 .setAttributes ([2 , 400 , 'Pear' , 'Honey' , '3' ])
3322
+ b4 .setAttributes ([2 , 400 , 'Pear' , 'Honey' , '3' , QDateTime ( QDate ( 2020 , 4 , 4 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 4 , 2 ), QTime ( 4 , 13 , 1 ) ])
3308
3323
b4 .setGeometry (QgsGeometry .fromWkt ('Point (-65.32 78.3)' ))
3309
3324
3310
3325
b5 = QgsFeature ()
3311
- b5 .setAttributes ([4 , 200 , NULL , 'oranGe' , '3' ])
3326
+ b5 .setAttributes ([4 , 200 , NULL , 'oranGe' , '3' , QDateTime ( QDate ( 2019 , 5 , 4 ), QTime ( 12 , 13 , 14 )), QDate ( 2019 , 5 , 2 ), QTime ( 1 , 13 , 1 ) ])
3312
3327
b5 .setGeometry (QgsGeometry .fromWkt ('Point (-68.2 70.8)' ))
3313
3328
3314
3329
vl .dataProvider ().addFeatures ([b1 , b2 , b3 , b4 , b5 ])
@@ -3317,22 +3332,22 @@ def getSource(cls):
3317
3332
3318
3333
# here's our good features
3319
3334
f1 = QgsFeature ()
3320
- f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' ])
3335
+ f1 .setAttributes ([5 , - 200 , NULL , 'NuLl' , '5' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 2 ), QTime ( 12 , 13 , 1 ) ])
3321
3336
f1 .setGeometry (QgsGeometry .fromWkt ('Point (-71.123 78.23)' ))
3322
3337
3323
3338
f2 = QgsFeature ()
3324
- f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' ])
3339
+ f2 .setAttributes ([3 , 300 , 'Pear' , 'PEaR' , '3' , NULL , NULL , NULL ])
3325
3340
3326
3341
f3 = QgsFeature ()
3327
- f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' ])
3342
+ f3 .setAttributes ([1 , 100 , 'Orange' , 'oranGe' , '1' , QDateTime ( QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 )), QDate ( 2020 , 5 , 3 ), QTime ( 12 , 13 , 14 ) ])
3328
3343
f3 .setGeometry (QgsGeometry .fromWkt ('Point (-70.332 66.33)' ))
3329
3344
3330
3345
f4 = QgsFeature ()
3331
- f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' ])
3346
+ f4 .setAttributes ([2 , 200 , 'Apple' , 'Apple' , '2' , QDateTime ( QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 )), QDate ( 2020 , 5 , 4 ), QTime ( 12 , 14 , 14 ) ])
3332
3347
f4 .setGeometry (QgsGeometry .fromWkt ('Point (-68.2 70.8)' ))
3333
3348
3334
3349
f5 = QgsFeature ()
3335
- f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' ])
3350
+ f5 .setAttributes ([4 , 400 , 'Honey' , 'Honey' , '4' , QDateTime ( QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 )), QDate ( 2021 , 5 , 4 ), QTime ( 13 , 13 , 14 ) ])
3336
3351
f5 .setGeometry (QgsGeometry .fromWkt ('Point (-65.32 78.3)' ))
3337
3352
3338
3353
vl .dataProvider ().addFeatures ([f1 , f2 , f3 , f4 , f5 ])
0 commit comments