17 #include <QHBoxLayout>
27 , mExpressionDialogTitle(
tr(
"Expression dialog" ) )
30 QHBoxLayout* layout =
new QHBoxLayout(
this );
31 layout->setContentsMargins( 0, 0, 0, 0 );
32 mCombo =
new QComboBox(
this );
33 mCombo->setEditable(
true );
34 mCombo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );
35 int width = mCombo->minimumSizeHint().width();
36 mCombo->setMinimumWidth( width );
39 mCombo->setModel( mFieldProxyModel );
41 mButton =
new QToolButton(
this );
42 mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
45 layout->addWidget( mCombo );
46 layout->addWidget( mButton );
51 setFocusProxy( mCombo );
53 connect( mCombo->lineEdit(), SIGNAL( textEdited( QString ) ),
this, SLOT(
expressionEdited( QString ) ) );
56 connect( mButton, SIGNAL( clicked() ),
this, SLOT(
editExpression() ) );
63 mExpressionDialogTitle = title;
73 QHBoxLayout* layout =
dynamic_cast<QHBoxLayout*
>( this->layout() );
79 QLayoutItem* item = layout->takeAt( 1 );
80 layout->insertWidget( 0, item->widget() );
83 layout->addWidget( mCombo );
88 mDa = QSharedPointer<const QgsDistanceArea>(
new QgsDistanceArea( da ) );
93 return mCombo->currentText();
143 if ( fieldName.isEmpty() )
147 if ( !idx.isValid() )
150 QString simpleFieldName = fieldName.trimmed();
151 if ( simpleFieldName.startsWith(
'"' ) && simpleFieldName.endsWith(
'"' ) )
153 simpleFieldName.remove( 0, 1 ).chop( 1 );
157 if ( !idx.isValid() )
164 QModelIndex proxyIndex = mFieldProxyModel->mapFromSource( idx );
165 mCombo->setCurrentIndex( proxyIndex.row() );
179 dlg.setWindowTitle( mExpressionDialogTitle );
197 const QString expression = mCombo->lineEdit()->text();
200 QModelIndex proxyIndex = mFieldProxyModel->mapFromSource( idx );
201 mCombo->setCurrentIndex( proxyIndex.row() );
207 if ( event->type() == QEvent::EnabledChange )
218 QString fieldName =
currentField( &isExpression, &isValid );
221 QFontMetrics metrics( mCombo->lineEdit()->font() );
222 if ( metrics.width( fieldName ) > mCombo->lineEdit()->width() )
224 mCombo->setToolTip( fieldName );
228 mCombo->setToolTip(
"" );
240 palette.setColor( QPalette::Text, Qt::gray );
245 if ( !expression.isEmpty() )
254 QFont font = mCombo->lineEdit()->font();
255 font.setItalic( isExpression );
256 mCombo->lineEdit()->setFont( font );
258 if ( isExpression && !isValid )
260 palette.setColor( QPalette::Text, Qt::red );
264 palette.setColor( QPalette::Text, Qt::black );
267 mCombo->lineEdit()->setPalette( palette );