@@ -205,7 +205,8 @@ QString QgsSearchTreeNode::makeSearchString()
205
205
mOp == opASIN || mOp == opACOS || mOp == opATAN ||
206
206
mOp == opTOINT || mOp == opTOREAL || mOp == opTOSTRING ||
207
207
mOp == opLOWER || mOp == opUPPER || mOp == opSTRLEN ||
208
- mOp == opATAN2 || mOp == opREPLACE || mOp == opSUBSTR )
208
+ mOp == opATAN2 || mOp == opREPLACE || mOp == opSUBSTR ||
209
+ mOp == opXAT || mOp == opYAT )
209
210
{
210
211
// functions
211
212
switch ( mOp )
@@ -226,6 +227,8 @@ QString QgsSearchTreeNode::makeSearchString()
226
227
case opSTRLEN: str += " length" ; break ;
227
228
case opREPLACE: str += " replace" ; break ;
228
229
case opSUBSTR: str += " substr" ; break ;
230
+ case opXAT: str += " xat" ; break ;
231
+ case opYAT: str += " yat" ; break ;
229
232
default : str += " ?" ;
230
233
}
231
234
// currently all functions take one parameter
@@ -364,13 +367,15 @@ bool QgsSearchTreeNode::needsGeometry()
364
367
{
365
368
if ( mType == tOperator )
366
369
{
367
- if ( mOp == opLENGTH || mOp == opAREA || mOp == opPERIMETER || mOp == opX || mOp == opY )
370
+ if ( mOp == opLENGTH || mOp == opAREA || mOp == opPERIMETER || mOp == opX || mOp == opY || mOp == opXAT || mOp == opYAT )
368
371
return true ;
369
372
370
373
if ( mLeft && mLeft ->needsGeometry () )
371
374
return true ;
375
+
372
376
if ( mRight && mRight ->needsGeometry () )
373
377
return true ;
378
+
374
379
return false ;
375
380
}
376
381
else
@@ -664,11 +669,11 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
664
669
return value2;
665
670
}
666
671
667
- if ( mOp == opLENGTH || mOp == opAREA || mOp == opPERIMETER || mOp == opX || mOp == opY )
672
+ if ( mOp == opLENGTH || mOp == opAREA || mOp == opPERIMETER || mOp == opX || mOp == opY || mOp == opXAT || mOp == opYAT )
668
673
{
669
674
if ( !f.geometry () )
670
675
{
671
- return QgsSearchTreeValue ( 2 , " Geometry is 0" );
676
+ return QgsSearchTreeValue ( 2 , QObject::tr ( " Geometry is 0" ) );
672
677
}
673
678
674
679
// check that we don't use area for lines or length for polygons
@@ -692,6 +697,24 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
692
697
{
693
698
return QgsSearchTreeValue ( f.geometry ()->asPoint ().y () );
694
699
}
700
+ if (( mOp == opXAT || mOp == opYAT ) && f.geometry ()->type () == QGis::Line && value1.isNumeric () )
701
+ {
702
+ QgsPolyline p = f.geometry ()->asPolyline ();
703
+
704
+ int idx = value1.number ();
705
+ if ( idx < 0 )
706
+ {
707
+ idx += p.size ();
708
+ }
709
+
710
+ if ( idx < 0 || idx >= p.size () )
711
+ {
712
+ return QgsSearchTreeValue ( 2 , QObject::tr ( " Index %1 out of range [0;%2[" ).arg ( idx ).arg ( p.size () ) );
713
+ }
714
+
715
+ return QgsSearchTreeValue ( mOp == opXAT ? p[idx].x () : p[idx].y () );
716
+ }
717
+
695
718
return QgsSearchTreeValue ( 0 );
696
719
}
697
720
@@ -735,7 +758,7 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
735
758
{
736
759
if ( value1.isNumeric () && value2.isNumeric () )
737
760
{
738
- return QgsSearchTreeValue ( 5 , " Operator doesn't match the argument types." );
761
+ return QgsSearchTreeValue ( 5 , QObject::tr ( " Operator doesn't match the argument types." ) );
739
762
}
740
763
else
741
764
{
@@ -784,7 +807,7 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
784
807
case opMOD:
785
808
// NOTE: we _might_ support float operators, like postgresql does
786
809
// see 83c94a886c059 commit in postgresql git repo for more info
787
- return QgsSearchTreeValue ( int (val1) % int (val2) );
810
+ return QgsSearchTreeValue ( int ( val1 ) % int ( val2 ) );
788
811
case opDIV:
789
812
if ( val2 == 0 )
790
813
return QgsSearchTreeValue ( 2 , " " ); // division by zero
@@ -793,7 +816,7 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
793
816
case opPOW:
794
817
if (( val1 == 0 && val2 < 0 ) || ( val2 < 0 && ( val2 - floor ( val2 ) ) > 0 ) )
795
818
{
796
- return QgsSearchTreeValue ( 4 , " Error in power function" );
819
+ return QgsSearchTreeValue ( 4 , QObject::tr ( " Error in power function" ) );
797
820
}
798
821
return QgsSearchTreeValue ( pow ( val1, val2 ) );
799
822
case opSQRT:
0 commit comments