[QGIS Commit] r13941 - in trunk/qgis: python/core src/app src/core
src/ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jul 20 06:39:25 EDT 2010
Author: wonder
Date: 2010-07-20 10:39:25 +0000 (Tue, 20 Jul 2010)
New Revision: 13941
Modified:
trunk/qgis/python/core/qgssearchtreenode.sip
trunk/qgis/src/app/qgsfieldcalculator.cpp
trunk/qgis/src/app/qgsfieldcalculator.h
trunk/qgis/src/core/qgssearchstringlexer.ll
trunk/qgis/src/core/qgssearchstringparser.yy
trunk/qgis/src/core/qgssearchtreenode.cpp
trunk/qgis/src/core/qgssearchtreenode.h
trunk/qgis/src/ui/qgsfieldcalculatorbase.ui
Log:
Added "$rownum" token to syntax of expressions. In field calculator it can be used for counting rows. The counter starts from 1. Outside field calculator it returns always zero.
Developed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana - Sistema Informativo per la Gestione del Territorio e dell' Ambiente [RT-SIGTA].
For the project: "Sviluppo di prodotti software GIS open-source basati sui prodotti QuantumGIS e Postgis (CIG 037728516E)"
Modified: trunk/qgis/python/core/qgssearchtreenode.sip
===================================================================
--- trunk/qgis/python/core/qgssearchtreenode.sip 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/python/core/qgssearchtreenode.sip 2010-07-20 10:39:25 UTC (rev 13941)
@@ -57,7 +57,9 @@
opLike, // LIKE
// string handling
- opCONCAT
+ opCONCAT,
+
+ opROWNUM
};
//! constructors
@@ -126,6 +128,11 @@
//! @note added in 1.5
static QString quotedColumnRef( QString name );
+ //! Set current row number within this tree.
+ //! This value is stored only in the nodes being $rownum operator - in mNumber
+ //! @note added in 1.6
+ void setCurrentRowNumber( int rownum );
+
protected:
Modified: trunk/qgis/src/app/qgsfieldcalculator.cpp
===================================================================
--- trunk/qgis/src/app/qgsfieldcalculator.cpp 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/app/qgsfieldcalculator.cpp 2010-07-20 10:39:25 UTC (rev 13941)
@@ -154,6 +154,7 @@
mVectorLayer->blockSignals( true );
bool useGeometry = calcString.contains( "$area" ) || calcString.contains( "$length" );
+ int rownum = 1;
mVectorLayer->select( mVectorLayer->pendingAllAttributesList(), QgsRectangle(), useGeometry, false );
while ( mVectorLayer->nextFeature( feature ) )
@@ -166,6 +167,8 @@
}
}
+ searchTree->setCurrentRowNumber( rownum );
+
QgsSearchTreeValue value;
if ( useGeometry )
{
@@ -188,6 +191,8 @@
{
mVectorLayer->changeAttributeValue( feature.id(), attributeId, value.string(), false );
}
+
+ rownum++;
}
// stop blocking layerModified signals and make sure that one layerModified signal is emitted
@@ -387,6 +392,11 @@
mExpressionTextEdit->insertPlainText( "$area" );
}
+void QgsFieldCalculator::on_mRowNumButton_clicked()
+{
+ mExpressionTextEdit->insertPlainText( "$rownum" );
+}
+
void QgsFieldCalculator::on_mSamplePushButton_clicked()
{
getFieldValues( 25 );
Modified: trunk/qgis/src/app/qgsfieldcalculator.h
===================================================================
--- trunk/qgis/src/app/qgsfieldcalculator.h 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/app/qgsfieldcalculator.h 2010-07-20 10:39:25 UTC (rev 13941)
@@ -53,6 +53,7 @@
void on_mToStringButton_clicked();
void on_mLengthButton_clicked();
void on_mAreaButton_clicked();
+ void on_mRowNumButton_clicked();
void on_mSamplePushButton_clicked();
void on_mAllPushButton_clicked();
void on_mOutputFieldNameLineEdit_textChanged( const QString& text );
Modified: trunk/qgis/src/core/qgssearchstringlexer.ll
===================================================================
--- trunk/qgis/src/core/qgssearchstringlexer.ll 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/core/qgssearchstringlexer.ll 2010-07-20 10:39:25 UTC (rev 13941)
@@ -102,6 +102,8 @@
{string} { return STRING; }
+"$rownum" { return ROWNUM; }
+
"$area" { return AREA; }
"$length" { return LENGTH; }
Modified: trunk/qgis/src/core/qgssearchstringparser.yy
===================================================================
--- trunk/qgis/src/core/qgssearchstringparser.yy 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/core/qgssearchstringparser.yy 2010-07-20 10:39:25 UTC (rev 13941)
@@ -64,6 +64,7 @@
%token <op> FUNCTION
%token CONCAT
%token IS
+%token ROWNUM
%token AREA
%token LENGTH
%token NULLVALUE
@@ -140,6 +141,7 @@
| '+' scalar_exp %prec UMINUS { $$ = $2; }
| '-' scalar_exp %prec UMINUS { $$ = $2; if ($$->type() == QgsSearchTreeNode::tNumber) $$->setNumber(- $$->number()); }
| scalar_exp CONCAT scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opCONCAT, $1, $3); joinTmpNodes($$, $1, $3); }
+ | ROWNUM { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opROWNUM, 0, 0); addToTmpNodes($$); }
| AREA { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opAREA, 0, 0); addToTmpNodes($$); }
| LENGTH { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opLENGTH, 0, 0); addToTmpNodes($$); }
| NUMBER { $$ = new QgsSearchTreeNode($1); addToTmpNodes($$); }
Modified: trunk/qgis/src/core/qgssearchtreenode.cpp
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.cpp 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/core/qgssearchtreenode.cpp 2010-07-20 10:39:25 UTC (rev 13941)
@@ -125,6 +125,8 @@
void QgsSearchTreeNode::init()
{
+ mCalc = NULL;
+
if ( mType == tOperator && ( mOp == opLENGTH || mOp == opAREA ) )
{
//initialize QgsDistanceArea
@@ -134,9 +136,10 @@
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
mCalc->setEllipsoid( ellipsoid );
}
- else
+ else if ( mType == tOperator && mOp == opROWNUM )
{
- mCalc = NULL;
+ // initialize row number to a sane value
+ mNumber = 0;
}
}
@@ -535,6 +538,12 @@
return QgsSearchTreeValue( mCalc->measure( geom ) );
}
+ if ( mOp == opROWNUM )
+ {
+ // the row number has to be previously set by the caller using setCurrentRowNumber
+ return QgsSearchTreeValue( mNumber );
+ }
+
//string operations with one argument
if ( !mRight && !value1.isNumeric() )
{
@@ -635,6 +644,25 @@
}
+void QgsSearchTreeNode::setCurrentRowNumber( int rownum )
+{
+ if ( mType == tOperator )
+ {
+ if ( mOp == opROWNUM )
+ mNumber = rownum;
+ else
+ {
+ // propagate the new row number to children
+ if ( mLeft )
+ mLeft->setCurrentRowNumber( rownum );
+ if ( mRight )
+ mRight->setCurrentRowNumber( rownum );
+ }
+ }
+}
+
+
+
int QgsSearchTreeValue::compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2, Qt::CaseSensitivity cs )
{
if ( value1.isNumeric() || value2.isNumeric() )
Modified: trunk/qgis/src/core/qgssearchtreenode.h
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.h 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/core/qgssearchtreenode.h 2010-07-20 10:39:25 UTC (rev 13941)
@@ -95,7 +95,9 @@
opLike, // LIKE
// string handling
- opCONCAT
+ opCONCAT,
+
+ opROWNUM
};
//! constructors
@@ -164,6 +166,11 @@
//! @note added in 1.5
static QString quotedColumnRef( QString name );
+ //! Set current row number within this tree.
+ //! This value is stored only in the nodes being $rownum operator - in mNumber
+ //! @note added in 1.6
+ void setCurrentRowNumber( int rownum );
+
protected:
Modified: trunk/qgis/src/ui/qgsfieldcalculatorbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsfieldcalculatorbase.ui 2010-07-20 09:50:41 UTC (rev 13940)
+++ trunk/qgis/src/ui/qgsfieldcalculatorbase.ui 2010-07-20 10:39:25 UTC (rev 13941)
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>615</width>
+ <width>624</width>
<height>686</height>
</rect>
</property>
@@ -269,6 +269,13 @@
</property>
</widget>
</item>
+ <item row="2" column="5">
+ <widget class="QPushButton" name="mRowNumButton">
+ <property name="text">
+ <string>rownum</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -328,6 +335,7 @@
<tabstop>mToStringButton</tabstop>
<tabstop>mLengthButton</tabstop>
<tabstop>mAreaButton</tabstop>
+ <tabstop>mRowNumButton</tabstop>
<tabstop>mExpressionTextEdit</tabstop>
<tabstop>mButtonBox</tabstop>
</tabstops>
More information about the QGIS-commit
mailing list