void FilterExpressionsPreferencesFrame::keyPressEvent(QKeyEvent *evt) { if (cur_line_edit_ && cur_line_edit_->hasFocus()) { switch (evt->key()) { case Qt::Key_Escape: cur_line_edit_->setText(saved_col_string_); /* Fall Through */ case Qt::Key_Enter: case Qt::Key_Return: switch (cur_column_) { case label_col_: labelEditingFinished(); break; case expression_col_: expressionEditingFinished(); break; default: break; } delete cur_line_edit_; return; default: break; } } QFrame::keyPressEvent(evt); }
QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent ) : QWidget( parent ) , mExpressionDialogTitle( tr( "Expression dialog" ) ) , mDa( 0 ) { QHBoxLayout* layout = new QHBoxLayout( this ); layout->setContentsMargins( 0, 0, 0, 0 ); mCombo = new QComboBox( this ); mCombo->setEditable( true ); mCombo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum ); mFieldProxyModel = new QgsFieldProxyModel( mCombo ); mFieldProxyModel->sourceFieldModel()->setAllowExpression( true ); mCombo->setModel( mFieldProxyModel ); mButton = new QToolButton( this ); mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); mButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpression.svg" ) ); layout->addWidget( mCombo ); layout->addWidget( mButton ); // give focus to the combo // hence if the widget is used as a delegate // it will allow pressing on the expression dialog button setFocusProxy( mCombo ); connect( mCombo->lineEdit(), SIGNAL( textEdited( QString ) ), this, SLOT( expressionEdited( QString ) ) ); connect( mCombo->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( expressionEditingFinished() ) ); connect( mCombo, SIGNAL( activated( int ) ), this, SLOT( currentFieldChanged() ) ); connect( mButton, SIGNAL( clicked() ), this, SLOT( editExpression() ) ); connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) ); }
void FilterExpressionsPreferencesFrame::on_expressionTreeWidget_itemActivated(QTreeWidgetItem *item, int column) { if (!item || cur_line_edit_) return; QWidget *editor = NULL; cur_column_ = column; switch (column) { case label_col_: { cur_line_edit_ = new QLineEdit(); cur_column_ = column; saved_col_string_ = item->text(label_col_); connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(labelEditingFinished())); editor = cur_line_edit_; break; } case expression_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(expression_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), this, SLOT(expressionTextChanged(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(expressionEditingFinished())); editor = cur_line_edit_ = syntax_edit; break; } default: return; } if (cur_line_edit_) { cur_line_edit_->setText(saved_col_string_); cur_line_edit_->selectAll(); connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); } if (editor) { QFrame *edit_frame = new QFrame(); QHBoxLayout *hb = new QHBoxLayout(); QSpacerItem *spacer = new QSpacerItem(5, 10); hb->addWidget(editor, 0); hb->addSpacerItem(spacer); hb->setStretch(1, 1); hb->setContentsMargins(0, 0, 0, 0); edit_frame->setLineWidth(0); edit_frame->setFrameStyle(QFrame::NoFrame); // The documentation suggests setting autoFillbackground. That looks silly // so we clear the item text instead. item->setText(cur_column_, ""); edit_frame->setLayout(hb); ui->expressionTreeWidget->setItemWidget(item, cur_column_, edit_frame); editor->setFocus(); } }
QgsFieldExpressionWidget::QgsFieldExpressionWidget( QWidget *parent ) : QWidget( parent ) , mExpressionDialogTitle( tr( "Expression dialog" ) ) , mDa( nullptr ) , mExpressionContextCallback( nullptr ) , mExpressionContextCallbackContext( nullptr ) { QHBoxLayout* layout = new QHBoxLayout( this ); layout->setContentsMargins( 0, 0, 0, 0 ); mCombo = new QComboBox( this ); mCombo->setEditable( true ); mCombo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum ); int width = mCombo->minimumSizeHint().width(); mCombo->setMinimumWidth( width ); mFieldProxyModel = new QgsFieldProxyModel( mCombo ); mFieldProxyModel->sourceFieldModel()->setAllowExpression( true ); mCombo->setModel( mFieldProxyModel ); mButton = new QToolButton( this ); mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); mButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpression.svg" ) ); layout->addWidget( mCombo ); layout->addWidget( mButton ); // give focus to the combo // hence if the widget is used as a delegate // it will allow pressing on the expression dialog button setFocusProxy( mCombo ); connect( mCombo->lineEdit(), SIGNAL( textEdited( QString ) ), this, SLOT( expressionEdited( QString ) ) ); connect( mCombo->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( expressionEditingFinished() ) ); connect( mCombo, SIGNAL( activated( int ) ), this, SLOT( currentFieldChanged() ) ); connect( mButton, SIGNAL( clicked() ), this, SLOT( editExpression() ) ); connect( mFieldProxyModel, SIGNAL( modelAboutToBeReset() ), this, SLOT( beforeResetModel() ) ); connect( mFieldProxyModel, SIGNAL( modelReset() ), this, SLOT( afterResetModel() ) ); // NW TODO - Fix in 2.6 // connect( mCombo->lineEdit(), SIGNAL( returnPressed() ), this, SIGNAL( returnPressed() ) ); mExpressionContext.reset( new QgsExpressionContext() ); mExpressionContext->appendScope( QgsExpressionContextUtils::globalScope() ); mExpressionContext->appendScope( QgsExpressionContextUtils::projectScope() ); }