Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
574 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*************************************************************************** | ||
qgsexpressionfieldbuffer.cpp | ||
--------------------------- | ||
begin : May 27, 2014 | ||
copyright : (C) 2014 by Matthias Kuhn | ||
email : matthias dot kuhn at gmx dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsexpressionfieldbuffer.h" | ||
|
||
#include "qgsvectorlayer.h" | ||
|
||
QgsExpressionFieldBuffer::QgsExpressionFieldBuffer() | ||
{ | ||
} | ||
|
||
void QgsExpressionFieldBuffer::addExpression( const QString& exp, const QgsField& fld ) | ||
{ | ||
mExpressions << ExpressionField( exp, fld ); | ||
} | ||
|
||
void QgsExpressionFieldBuffer::removeExpression( int index ) | ||
{ | ||
mExpressions.removeAt( index ); | ||
} | ||
|
||
void QgsExpressionFieldBuffer::writeXml( QDomNode& layerNode, QDomDocument& document ) const | ||
{ | ||
QDomElement expressionFieldsElem = document.createElement( "expressionfields" ); | ||
layerNode.appendChild( expressionFieldsElem ); | ||
|
||
Q_FOREACH( const ExpressionField& fld, mExpressions ) | ||
{ | ||
QDomElement fldElem = document.createElement( "field" ); | ||
|
||
fldElem.setAttribute( "expression", fld.expression ); | ||
fldElem.setAttribute( "name", fld.field.name() ); | ||
fldElem.setAttribute( "precision", fld.field.precision() ); | ||
fldElem.setAttribute( "comment", fld.field.comment() ); | ||
fldElem.setAttribute( "length", fld.field.length() ); | ||
fldElem.setAttribute( "type", fld.field.type() ); | ||
fldElem.setAttribute( "typeName", fld.field.typeName() ); | ||
|
||
expressionFieldsElem.appendChild( fldElem ); | ||
} | ||
} | ||
|
||
void QgsExpressionFieldBuffer::readXml( const QDomNode& layerNode ) | ||
{ | ||
mExpressions.clear(); | ||
|
||
const QDomElement expressionFieldsElem = layerNode.firstChildElement( "expressionfields" ); | ||
|
||
if ( !expressionFieldsElem.isNull() ) | ||
{ | ||
QDomNodeList fields = expressionFieldsElem.elementsByTagName( "field" ); | ||
|
||
for ( unsigned int i = 0; i < fields.length(); ++i ) | ||
{ | ||
QDomElement field = fields.at( i ).toElement(); | ||
QString exp = field.attribute( "expression" ); | ||
QString name = field.attribute( "name" ); | ||
QString comment = field.attribute( "comment" ); | ||
int precision = field.attribute( "precision" ).toInt(); | ||
int length = field.attribute( "length" ).toInt(); | ||
QVariant::Type type = ( QVariant::Type )( field.attribute( "type" ).toInt() ); | ||
QString typeName = field.attribute( "typeName" ); | ||
|
||
mExpressions.append( ExpressionField( exp, QgsField( name, type, typeName, length, precision, comment ) ) ); | ||
} | ||
} | ||
} | ||
|
||
void QgsExpressionFieldBuffer::updateFields( QgsFields& flds ) | ||
{ | ||
int index = 0; | ||
Q_FOREACH( const ExpressionField& fld, mExpressions ) | ||
{ | ||
flds.appendExpressionField( fld.field, index ); | ||
++index; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*************************************************************************** | ||
qgsexpressionfieldbuffer.h | ||
--------------------------- | ||
begin : May 27, 2014 | ||
copyright : (C) 2014 by Matthias Kuhn | ||
email : matthias dot kuhn at gmx dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSEXPRESSIONFIELDBUFFER_H | ||
#define QGSEXPRESSIONFIELDBUFFER_H | ||
|
||
#include <QString> | ||
#include <QList> | ||
#include <QDomNode> | ||
|
||
#include "qgsfield.h" | ||
|
||
/** | ||
* Buffers information about expression fields for a vector layer. | ||
* | ||
* @note added in 2.6 | ||
*/ | ||
class CORE_EXPORT QgsExpressionFieldBuffer | ||
{ | ||
public: | ||
typedef struct ExpressionField | ||
{ | ||
ExpressionField() {} | ||
ExpressionField( QString exp, QgsField fld ) : expression( exp ), field( fld ) {} | ||
|
||
QString expression; | ||
QgsField field; | ||
} ExpressionField; | ||
|
||
QgsExpressionFieldBuffer(); | ||
|
||
/** | ||
* Add an expression to the buffer | ||
* | ||
* @param exp Expression to add | ||
*/ | ||
void addExpression( const QString& exp, const QgsField& fld ); | ||
|
||
/** | ||
* Remove an expression from the buffer | ||
* | ||
* @param exp Expression to remove | ||
*/ | ||
void removeExpression( int index ); | ||
|
||
/** | ||
* Saves expressions to xml under the layer node | ||
*/ | ||
void writeXml( QDomNode& layer_node, QDomDocument& document ) const; | ||
|
||
/** | ||
* Reads expressions from project file | ||
*/ | ||
void readXml( const QDomNode& layer_node ); | ||
|
||
/** | ||
* Adds fields with the expressions buffered in this object to a QgsFields object | ||
* | ||
* @param flds The fields to be updated | ||
*/ | ||
void updateFields( QgsFields& flds ); | ||
|
||
const QList<ExpressionField> expressions() const { return mExpressions; } | ||
|
||
private: | ||
QList<ExpressionField> mExpressions; | ||
}; | ||
|
||
#endif // QGSEXPRESSIONFIELDBUFFER_H |
Oops, something went wrong.