Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1480 from 3nids/fixew
small expression widget changes
  • Loading branch information
wonder-sk committed Jun 23, 2014
2 parents daefe3e + 4c199ff commit a843038
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions python/gui/qgsfieldmodel.sip
Expand Up @@ -36,9 +36,8 @@ class QgsFieldModel : QAbstractItemModel

/**
* @brief setExpression sets a single expression to be added after the fields at the end of the model
* @return the model index of the newly added expression
*/
QModelIndex setExpression( const QString &expression );
void setExpression( const QString &expression );

//! remove expressions from the model
void removeExpression();
Expand Down
6 changes: 4 additions & 2 deletions src/gui/qgsfieldexpressionwidget.cpp
Expand Up @@ -152,7 +152,8 @@ void QgsFieldExpressionWidget::setField( const QString &fieldName )
if ( !idx.isValid() )
{
// new expression
idx = mFieldProxyModel->sourceFieldModel()->setExpression( fieldName );
mFieldProxyModel->sourceFieldModel()->setExpression( fieldName );
idx = mFieldProxyModel->sourceFieldModel()->indexFromName( fieldName );
}
}
QModelIndex proxyIndex = mFieldProxyModel->mapFromSource( idx );
Expand Down Expand Up @@ -189,7 +190,8 @@ void QgsFieldExpressionWidget::expressionEditingFinished()
{
QgsDebugMsg( "Editing finsihed" );
const QString expression = mCombo->lineEdit()->text();
QModelIndex idx = mFieldProxyModel->sourceFieldModel()->setExpression( expression );
mFieldProxyModel->sourceFieldModel()->setExpression( expression );
QModelIndex idx = mFieldProxyModel->sourceFieldModel()->indexFromName( expression );
QModelIndex proxyIndex = mFieldProxyModel->mapFromSource( idx );
mCombo->setCurrentIndex( proxyIndex.row() );
currentFieldChanged();
Expand Down
12 changes: 6 additions & 6 deletions src/gui/qgsfieldmodel.cpp
Expand Up @@ -110,20 +110,20 @@ void QgsFieldModel::setAllowExpression( bool allowExpression )
}
}

QModelIndex QgsFieldModel::setExpression( const QString &expression )
void QgsFieldModel::setExpression( const QString &expression )
{
if ( !mAllowExpression )
return QModelIndex();
return;

QModelIndex idx = indexFromName( expression );
if ( idx.isValid() )
return idx;
return;

beginResetModel();
mExpression = QList<QString>() << expression;
mExpression = QList<QString>();
if ( !expression.isEmpty() )
mExpression << expression;
endResetModel();

return index( mFields.count() , 0 );
}

void QgsFieldModel::removeExpression()
Expand Down
3 changes: 1 addition & 2 deletions src/gui/qgsfieldmodel.h
Expand Up @@ -58,9 +58,8 @@ class GUI_EXPORT QgsFieldModel : public QAbstractItemModel

/**
* @brief setExpression sets a single expression to be added after the fields at the end of the model
* @return the model index of the newly added expression
*/
QModelIndex setExpression( const QString &expression );
void setExpression( const QString &expression );

//! remove expressions from the model
void removeExpression();
Expand Down

0 comments on commit a843038

Please sign in to comment.