Skip to content

Commit fe20f7b

Browse files
committedMay 2, 2014
remove protected slots in sip
fix signal emitted twice handle null expression (fix empty row) coherent color (colored text, not background) fix wrong slot
1 parent 86700d2 commit fe20f7b

File tree

4 files changed

+35
-44
lines changed

4 files changed

+35
-44
lines changed
 

‎python/gui/qgsfieldcombobox.sip

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,4 @@ class QgsFieldComboBox : QComboBox
3535

3636
//! setField sets the currently selected field
3737
void setField( QString fieldName );
38-
39-
protected slots:
40-
void indexChanged( int i );
4138
};

‎python/gui/qgsfieldexpressionwidget.sip

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,4 @@ class QgsFieldExpressionWidget : QWidget
3636

3737
//! sets the current field or expression in the widget
3838
void setField( QString fieldName );
39-
40-
protected slots:
41-
//! open the expression dialog to edit the current or add a new expression
42-
void editExpression();
43-
44-
//! when expression is edited by the user in the line edit
45-
void expressionEdited( QString expression );
46-
47-
void indexChanged( int i );
4839
};

‎src/gui/qgsfieldexpressionwidget.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,16 @@ void QgsFieldExpressionWidget::setLayer( QgsVectorLayer *layer )
9898

9999
void QgsFieldExpressionWidget::setField( QString fieldName )
100100
{
101+
if ( fieldName.isEmpty() )
102+
return;
103+
101104
QModelIndex idx = mFieldModel->indexFromName( fieldName );
102-
bool isExpression ;
103-
if ( idx.isValid() )
104-
{
105-
isExpression = mFieldModel->data( idx, QgsFieldModel::IsExpressionRole ).toBool();
106-
}
107-
else
105+
if ( !idx.isValid() )
108106
{
109107
// new expression
110108
idx = mFieldModel->setExpression( fieldName );
111-
isExpression = true;
112109
}
113110
mCombo->setCurrentIndex( idx.row() );
114-
115-
QFont font;
116-
font.setItalic( isExpression );
117-
mCombo->lineEdit()->setFont( font );
118-
119-
QPalette palette;
120-
palette.setColor( QPalette::Text, Qt::black );
121-
if ( isExpression )
122-
{
123-
bool isValid = mFieldModel->data( idx, QgsFieldModel::ExpressionValidityRole ).toBool();
124-
if ( !isValid )
125-
{
126-
palette.setColor( QPalette::Text, Qt::red );
127-
}
128-
}
129-
mCombo->lineEdit()->setPalette( palette );
130-
131-
emit fieldChanged( currentField() );
132111
}
133112

134113
void QgsFieldExpressionWidget::editExpression()
@@ -162,6 +141,28 @@ void QgsFieldExpressionWidget::expressionEdited( QString expression )
162141
void QgsFieldExpressionWidget::indexChanged( int i )
163142
{
164143
Q_UNUSED( i );
165-
QString name = currentField();
166-
emit fieldChanged( name );
144+
bool isExpression;
145+
QString fieldName = currentField( &isExpression );
146+
147+
QFont font = mCombo->lineEdit()->font();
148+
font.setItalic( isExpression );
149+
mCombo->lineEdit()->setFont( font );
150+
151+
QPalette palette;
152+
palette.setColor( QPalette::Text, Qt::black );
153+
if ( isExpression )
154+
{
155+
QModelIndex idx = mFieldModel->indexFromName( fieldName );
156+
if ( idx.isValid() )
157+
{
158+
bool isValid = mFieldModel->data( idx, QgsFieldModel::ExpressionValidityRole ).toBool();
159+
if ( !isValid )
160+
{
161+
palette.setColor( QPalette::Text, Qt::red );
162+
}
163+
}
164+
}
165+
mCombo->lineEdit()->setPalette( palette );
166+
167+
emit fieldChanged( fieldName );
167168
}

‎src/gui/qgsfieldmodel.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* *
1414
***************************************************************************/
1515

16+
#include <QFont>
17+
1618
#include "qgsfieldmodel.h"
1719
#include "qgsmaplayermodel.h"
1820
#include "qgsmaplayerproxymodel.h"
@@ -51,7 +53,7 @@ void QgsFieldModel::setLayer( QgsMapLayer *layer )
5153
{
5254
if ( mLayer )
5355
{
54-
disconnect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateFields() ) );
56+
disconnect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateModel() ) );
5557
disconnect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( layerDeleted() ) );
5658
}
5759

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

7274
mLayer = vl;
73-
connect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateFields() ) );
75+
connect( mLayer, SIGNAL( updatedFields() ), this, SLOT( updateModel() ) );
7476
connect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( layerDeleted() ) );
7577
updateModel();
7678
}
@@ -241,7 +243,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
241243
return alias;
242244
}
243245

244-
case Qt::BackgroundRole:
246+
case Qt::ForegroundRole:
245247
{
246248
if ( exprIdx >= 0 )
247249
{
@@ -253,7 +255,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
253255
exp.evaluate( &mFeature, mLayer->pendingFields() );
254256
if ( exp.hasEvalError() )
255257
{
256-
return QBrush( QColor( 240, 60, 60, 180 ) );
258+
return QBrush( QColor( Qt::red ) );
257259
}
258260
}
259261
}
@@ -265,7 +267,7 @@ QVariant QgsFieldModel::data( const QModelIndex &index, int role ) const
265267
if ( exprIdx >= 0 )
266268
{
267269
// if the line is an expression, set it as italic
268-
QFont font;
270+
QFont font = QFont();
269271
font.setItalic( true );
270272
return font;
271273
}

0 commit comments

Comments
 (0)
Please sign in to comment.