Skip to content
Permalink
Browse files

remove protected slots in sip

fix signal emitted twice
handle null expression (fix empty row)
coherent color (colored text, not background)
fix wrong slot
  • Loading branch information
3nids committed May 2, 2014
1 parent 86700d2 commit fe20f7bbfaaf3c215a306cc5a1e61d952e27d83e
@@ -35,7 +35,4 @@ class QgsFieldComboBox : QComboBox

//! setField sets the currently selected field
void setField( QString fieldName );

protected slots:
void indexChanged( int i );
};
@@ -36,13 +36,4 @@ class QgsFieldExpressionWidget : QWidget

//! sets the current field or expression in the widget
void setField( QString fieldName );

protected slots:
//! open the expression dialog to edit the current or add a new expression
void editExpression();

//! when expression is edited by the user in the line edit
void expressionEdited( QString expression );

void indexChanged( int i );
};
@@ -98,37 +98,16 @@ void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )

void QgsFieldExpressionWidget::setField( QString fieldName )
{
if ( fieldName.isEmpty() )
return;

QModelIndex idx = mFieldModel->indexFromName( fieldName );
bool isExpression ;
if ( idx.isValid() )
{
isExpression = mFieldModel->data( idx, QgsFieldModel::IsExpressionRole ).toBool();
}
else
if ( !idx.isValid() )
{
// new expression
idx = mFieldModel->setExpression( fieldName );
isExpression = true;
}
mCombo->setCurrentIndex( idx.row() );

QFont font;
font.setItalic( isExpression );
mCombo->lineEdit()->setFont( font );

QPalette palette;
palette.setColor( QPalette::Text, Qt::black );
if ( isExpression )
{
bool isValid = mFieldModel->data( idx, QgsFieldModel::ExpressionValidityRole ).toBool();
if ( !isValid )
{
palette.setColor( QPalette::Text, Qt::red );
}
}
mCombo->lineEdit()->setPalette( palette );

emit fieldChanged( currentField() );
}

void QgsFieldExpressionWidget::editExpression()
@@ -162,6 +141,28 @@ void QgsFieldExpressionWidget::expressionEdited( QString expression )
void QgsFieldExpressionWidget::indexChanged( int i )
{
Q_UNUSED( i );
QString name = currentField();
emit fieldChanged( name );
bool isExpression;
QString fieldName = currentField( &isExpression );

QFont font = mCombo->lineEdit()->font();
font.setItalic( isExpression );
mCombo->lineEdit()->setFont( font );

QPalette palette;
palette.setColor( QPalette::Text, Qt::black );
if ( isExpression )
{
QModelIndex idx = mFieldModel->indexFromName( fieldName );
if ( idx.isValid() )
{
bool isValid = mFieldModel->data( idx, QgsFieldModel::ExpressionValidityRole ).toBool();
if ( !isValid )
{
palette.setColor( QPalette::Text, Qt::red );
}
}
}
mCombo->lineEdit()->setPalette( palette );

emit fieldChanged( fieldName );
}
@@ -13,6 +13,8 @@
* *
***************************************************************************/

#include <QFont>

#include "qgsfieldmodel.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayerproxymodel.h"
@@ -51,7 +53,7 @@ void QgsFieldModel::setLayer( QgsMapLayer *layer )
{
if ( mLayer )
{
disconnect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateFields() ) );
disconnect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateModel() ) );
disconnect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( layerDeleted() ) );
}

@@ -70,7 +72,7 @@ void QgsFieldModel::setLayer( QgsMapLayer *layer )
}

mLayer = vl;
connect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateFields() ) );
connect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateModel() ) );
connect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( layerDeleted() ) );
updateModel();
}
@@ -241,7 +243,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
return alias;
}

case Qt::BackgroundRole:
case Qt::ForegroundRole:
{
if ( exprIdx >= 0 )
{
@@ -253,7 +255,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
exp.evaluate( &mFeature, mLayer->pendingFields() );
if ( exp.hasEvalError() )
{
return QBrush( QColor( 240, 60, 60, 180 ) );
return QBrush( QColor( Qt::red ) );
}
}
}
@@ -265,7 +267,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
if ( exprIdx >= 0 )
{
// if the line is an expression, set it as italic
QFont font;
QFont font = QFont();
font.setItalic( true );
return font;
}

0 comments on commit fe20f7b

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