Skip to content

Commit

Permalink
remove protected slots in sip
Browse files Browse the repository at this point in the history
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 fe20f7b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
3 changes: 0 additions & 3 deletions python/gui/qgsfieldcombobox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,4 @@ class QgsFieldComboBox : QComboBox

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

protected slots:
void indexChanged( int i );
};
9 changes: 0 additions & 9 deletions python/gui/qgsfieldexpressionwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
55 changes: 28 additions & 27 deletions src/gui/qgsfieldexpressionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
}
12 changes: 7 additions & 5 deletions src/gui/qgsfieldmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* *
***************************************************************************/

#include <QFont>

#include "qgsfieldmodel.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayerproxymodel.h"
Expand Down Expand Up @@ -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() ) );
}

Expand All @@ -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();
}
Expand Down Expand Up @@ -241,7 +243,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
return alias;
}

case Qt::BackgroundRole:
case Qt::ForegroundRole:
{
if ( exprIdx >= 0 )
{
Expand All @@ -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 ) );
}
}
}
Expand All @@ -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;
}
Expand Down

0 comments on commit fe20f7b

Please sign in to comment.