Skip to content
Permalink
Browse files

Fix indentation

  • Loading branch information
wonder-sk committed Oct 20, 2011
1 parent 847204e commit 188d73359289eed0bfd24124cf9d3e1b554bfc42
@@ -47,7 +47,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
connect( btnBufferColor, SIGNAL( clicked() ), this, SLOT( changeBufferColor() ) );
connect( spinBufferSize, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ) );
connect( btnEngineSettings, SIGNAL( clicked() ), this, SLOT( showEngineConfigDialog() ) );
connect( btnExpression, SIGNAL(clicked()), this, SLOT( showExpressionDialog()));
connect( btnExpression, SIGNAL( clicked() ), this, SLOT( showExpressionDialog() ) );

// set placement methods page based on geometry type
switch ( layer->geometryType() )
@@ -83,8 +83,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
btnExpression->setEnabled( lyr.enabled );

//Add the current expression to the bottom of the list.
if (lyr.isExpression && !lyr.fieldName.isEmpty())
cboFieldName->addItem(lyr.fieldName);
if ( lyr.isExpression && !lyr.fieldName.isEmpty() )
cboFieldName->addItem( lyr.fieldName );

// placement
int distUnitIndex = lyr.distInMapUnits ? 1 : 0;
@@ -212,13 +212,13 @@ QgsLabelingGui::~QgsLabelingGui()

void QgsLabelingGui::apply()
{
QgsPalLayerSettings settings = layerSettings();
settings.writeToLayer( mLayer );
// trigger refresh
if ( mMapCanvas )
{
mMapCanvas->refresh();
}
QgsPalLayerSettings settings = layerSettings();
settings.writeToLayer( mLayer );
// trigger refresh
if ( mMapCanvas )
{
mMapCanvas->refresh();
}
}

QgsPalLayerSettings QgsLabelingGui::layerSettings()
@@ -494,20 +494,20 @@ void QgsLabelingGui::showEngineConfigDialog()

void QgsLabelingGui::showExpressionDialog()
{
//TODO extract this out to a dialog.
QgsExpressionBuilderDialog dlg( mLayer, cboFieldName->currentText() , this );
dlg.setWindowTitle( tr("Expression based label") );
if ( dlg.exec() == QDialog::Accepted )
//TODO extract this out to a dialog.
QgsExpressionBuilderDialog dlg( mLayer, cboFieldName->currentText() , this );
dlg.setWindowTitle( tr( "Expression based label" ) );
if ( dlg.exec() == QDialog::Accepted )
{
QString expression = dlg.expressionBuilder()->getExpressionString();
//Only add the expression if the user has entered some text.
if ( !expression.isEmpty() )
{
QString expression = dlg.expressionBuilder()->getExpressionString();
//Only add the expression if the user has entered some text.
if (!expression.isEmpty())
{
cboFieldName->addItem(expression);
cboFieldName->setCurrentIndex(cboFieldName->count() - 1);
}
cboFieldName->addItem( expression );
cboFieldName->setCurrentIndex( cboFieldName->count() - 1 );
}
}
}
}

void QgsLabelingGui::updateUi()
{
@@ -375,9 +375,9 @@ typedef QgsExpression::FunctionDef FnDef;
FnDef QgsExpression::BuiltinFunctions[] =
{
// math
FnDef( "sqrt", 1, fcnSqrt, "Math"),
FnDef( "sqrt", 1, fcnSqrt, "Math" ),
FnDef( "sin", 1, fcnSin, "Math" ),
FnDef( "cos", 1, fcnCos, "Math"),
FnDef( "cos", 1, fcnCos, "Math" ),
FnDef( "tan", 1, fcnTan, "Math" ),
FnDef( "asin", 1, fcnAsin, "Math" ),
FnDef( "acos", 1, fcnAcos, "Math" ),
@@ -393,15 +393,15 @@ FnDef QgsExpression::BuiltinFunctions[] =
FnDef( "tostring", 1, fcnToString, "Conversions" ),
// string manipulation
FnDef( "lower", 1, fcnLower, "String", "<b>Convert to lower case</b> "\
"<br> Converts a string to lower case letters. " \
"<br> <i>Usage:</i><br>lower('HELLO WORLD') will return 'hello world'"),
"<br> Converts a string to lower case letters. " \
"<br> <i>Usage:</i><br>lower('HELLO WORLD') will return 'hello world'" ),
FnDef( "upper", 1, fcnUpper, "String" , "<b>Convert to upper case</b> "\
"<br> Converts a string to upper case letters. " \
"<br> <i>Usage:</i><br>upper('hello world') will return 'HELLO WORLD'"),
"<br> Converts a string to upper case letters. " \
"<br> <i>Usage:</i><br>upper('hello world') will return 'HELLO WORLD'" ),
FnDef( "length", 1, fcnLength, "String", "<b>Length of string</b> "\
"<br> Returns the legnth of a string. " \
"<br> <i>Usage:</i><br>length('hello') will return 5"),
FnDef( "replace", 3, fcnReplace, "String", "<b>Replace a section of a string.</b> "),
"<br> Returns the legnth of a string. " \
"<br> <i>Usage:</i><br>length('hello') will return 5" ),
FnDef( "replace", 3, fcnReplace, "String", "<b>Replace a section of a string.</b> " ),
FnDef( "regexp_replace", 3, fcnRegexpReplace, "String" ),
FnDef( "substr", 3, fcnSubstr, "String" ),
// geometry accessors
@@ -414,7 +414,7 @@ FnDef QgsExpression::BuiltinFunctions[] =
FnDef( "$y", 0, fcnY, "Geometry", "" , true ),
// special columns
FnDef( "$rownum", 0, fcnRowNumber, "Record" ),
FnDef( "$id", 0, fcnFeatureId, "Record")
FnDef( "$id", 0, fcnFeatureId, "Record" )
};


@@ -436,7 +436,7 @@ int QgsExpression::functionIndex( QString name )

int QgsExpression::functionCount()
{
return ( sizeof( BuiltinFunctions ) / sizeof( FunctionDef) );
return ( sizeof( BuiltinFunctions ) / sizeof( FunctionDef ) );
}


@@ -211,11 +211,11 @@ QgsPalLayerSettings::~QgsPalLayerSettings()

QgsExpression* QgsPalLayerSettings::getLabelExpression()
{
if (expression == NULL)
{
expression = new QgsExpression( fieldName );
}
return expression;
if ( expression == NULL )
{
expression = new QgsExpression( fieldName );
}
return expression;
}

static QColor _readColor( QgsVectorLayer* layer, QString property )
@@ -303,7 +303,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
return; // there's no information available

fieldName = layer->customProperty( "labeling/fieldName" ).toString();
isExpression = layer->customProperty( "labeling/isExpression").toBool();
isExpression = layer->customProperty( "labeling/isExpression" ).toBool();
placement = ( Placement ) layer->customProperty( "labeling/placement" ).toInt();
placementFlags = layer->customProperty( "labeling/placementFlags" ).toUInt();
QString fontFamily = layer->customProperty( "labeling/fontFamily" ).toString();
@@ -462,42 +462,42 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
labelY = qAbs( ptSize.y() - ptZero.y() );
}

void QgsPalLayerSettings::registerFeature(QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context )
void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context )
{
QString labelText;
// Check to see if we are a expression string.
if (isExpression)
if ( isExpression )
{
QgsExpression* exp = getLabelExpression();
if ( exp->hasParserError() )
{
QgsDebugMsg("PASER HAS ERROR:" + exp->parserErrorString());
QgsDebugMsg( "PASER HAS ERROR:" + exp->parserErrorString() );
return;
}
QVariant result = exp->evaluate(&f,layer->dataProvider()->fields());
QgsDebugMsg("VALUE = " + result.toString());
if (exp->hasEvalError())
QVariant result = exp->evaluate( &f, layer->dataProvider()->fields() );
QgsDebugMsg( "VALUE = " + result.toString() );
if ( exp->hasEvalError() )
{
QgsDebugMsg("Expression Label Error = " + exp->evalErrorString());
return;
QgsDebugMsg( "Expression Label Error = " + exp->evalErrorString() );
return;
}
labelText = result.toString();
}
else if ( formatNumbers == true && ( f.attributeMap()[fieldIndex].type() == QVariant::Int ||
f.attributeMap()[fieldIndex].type() == QVariant::Double ) )
{
QString numberFormat;
double d = f.attributeMap()[fieldIndex].toDouble();
if ( d > 0 && plusSign == true )
{
numberFormat.append( "+" );
}
numberFormat.append( "%1" );
labelText = numberFormat.arg( d, 0, 'f', decimals );
QString numberFormat;
double d = f.attributeMap()[fieldIndex].toDouble();
if ( d > 0 && plusSign == true )
{
numberFormat.append( "+" );
}
numberFormat.append( "%1" );
labelText = numberFormat.arg( d, 0, 'f', decimals );
}
else
{
labelText = f.attributeMap()[fieldIndex].toString();
labelText = f.attributeMap()[fieldIndex].toString();
}

double labelX, labelY; // will receive label size
@@ -774,7 +774,7 @@ bool QgsPalLabeling::willUseLayer( QgsVectorLayer* layer )

int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx )
{
QgsDebugMsg("PREPARE LAYER");
QgsDebugMsg( "PREPARE LAYER" );
Q_ASSERT( mMapRenderer != NULL );

// start with a temporary settings class, find out labeling info
@@ -786,25 +786,25 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,


int fldIndex ;
if(lyrTmp.isExpression)
if ( lyrTmp.isExpression )
{
if (lyrTmp.fieldName.isEmpty())
return 0;
QgsExpression exp( lyrTmp.fieldName );
foreach(QString name, exp.referencedColumns() )
{
QgsDebugMsg("REFERENCED COLUMN = " + name );
fldIndex = layer->fieldNameIndex( name );
attrIndices.insert(fldIndex);
}
if ( lyrTmp.fieldName.isEmpty() )
return 0;
QgsExpression exp( lyrTmp.fieldName );
foreach( QString name, exp.referencedColumns() )
{
QgsDebugMsg( "REFERENCED COLUMN = " + name );
fldIndex = layer->fieldNameIndex( name );
attrIndices.insert( fldIndex );
}
}
else
{
// If we aren't an expression, we check to see if we can find the column.
fldIndex = layer->fieldNameIndex( lyrTmp.fieldName );
if ( fldIndex == -1)
return 0;
attrIndices.insert( fldIndex );
// If we aren't an expression, we check to see if we can find the column.
fldIndex = layer->fieldNameIndex( lyrTmp.fieldName );
if ( fldIndex == -1 )
return 0;
attrIndices.insert( fldIndex );
}

//add indices of data defined fields
@@ -897,7 +897,7 @@ int QgsPalLabeling::addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSetti
void QgsPalLabeling::registerFeature( QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context )
{
QgsPalLayerSettings& lyr = mActiveLayers[layer];
lyr.registerFeature(layer, f, context );
lyr.registerFeature( layer, f, context );
}

void QgsPalLabeling::registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context )
@@ -138,7 +138,7 @@ class CORE_EXPORT QgsPalLayerSettings
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY );

// implementation of register feature hook
void registerFeature(QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context );
void registerFeature( QgsVectorLayer* layer, QgsFeature& f, const QgsRenderContext& context );

void readFromLayer( QgsVectorLayer* layer );
void writeToLayer( QgsVectorLayer* layer );
@@ -16,37 +16,37 @@
#include "qgsexpressionbuilderdialog.h"
#include <QSettings>

QgsExpressionBuilderDialog::QgsExpressionBuilderDialog( QgsVectorLayer* layer, QString startText, QWidget* parent)
:QDialog( parent )
QgsExpressionBuilderDialog::QgsExpressionBuilderDialog( QgsVectorLayer* layer, QString startText, QWidget* parent )
: QDialog( parent )
{
setupUi( this );
setupUi( this );

QPushButton* okButuon = buttonBox->button(QDialogButtonBox::Ok);
connect(builder, SIGNAL(expressionParsed(bool)), okButuon, SLOT(setEnabled(bool)));
QPushButton* okButuon = buttonBox->button( QDialogButtonBox::Ok );
connect( builder, SIGNAL( expressionParsed( bool ) ), okButuon, SLOT( setEnabled( bool ) ) );

builder->setLayer( layer );
builder->setExpressionString(startText);
builder->loadFieldNames();
builder->setLayer( layer );
builder->setExpressionString( startText );
builder->loadFieldNames();

QSettings settings;
restoreGeometry( settings.value( "/Windows/ExpressionBuilderDialog/geometry" ).toByteArray() );
QSettings settings;
restoreGeometry( settings.value( "/Windows/ExpressionBuilderDialog/geometry" ).toByteArray() );
}

QgsExpressionBuilderWidget* QgsExpressionBuilderDialog::expressionBuilder()
{
return builder;
return builder;
}

void QgsExpressionBuilderDialog::setExpressionText( QString text )
{
builder->setExpressionString( text );
builder->setExpressionString( text );
}

void QgsExpressionBuilderDialog::closeEvent( QCloseEvent *event )
{
QDialog::closeEvent( event );
QDialog::closeEvent( event );

// TODO Work out why this is not working yet.
QSettings settings;
settings.setValue( "/Windows/ExpressionBuilderDialog/geometry", saveGeometry() );
// TODO Work out why this is not working yet.
QSettings settings;
settings.setValue( "/Windows/ExpressionBuilderDialog/geometry", saveGeometry() );
}
@@ -21,20 +21,20 @@

class QgsExpressionBuilderDialog : public QDialog, private Ui::QgsExpressionBuilderDialogBase
{
public:
QgsExpressionBuilderDialog( QgsVectorLayer* layer, QString startText = "", QWidget* parent = NULL);
public:
QgsExpressionBuilderDialog( QgsVectorLayer* layer, QString startText = "", QWidget* parent = NULL );

/** The builder widget that is used by the dialog */
QgsExpressionBuilderWidget* expressionBuilder();
/** The builder widget that is used by the dialog */
QgsExpressionBuilderWidget* expressionBuilder();

void setExpressionText( QString text );
void setExpressionText( QString text );

protected:
/**
* Handle closing of the window
* @param event unused
*/
void closeEvent( QCloseEvent * event );
protected:
/**
* Handle closing of the window
* @param event unused
*/
void closeEvent( QCloseEvent * event );
};

#endif

0 comments on commit 188d733

Please sign in to comment.
You can’t perform that action at this time.