Skip to content
Permalink
Browse files

function to get info about available values to avoid duplicate code

  • Loading branch information
signedav committed Dec 16, 2019
1 parent 83be397 commit fe9a7ee5bde8dd4fa7f17a3be005c328da40acf7
Showing with 21 additions and 21 deletions.
  1. +20 −21 src/gui/qgsexpressionbuilderwidget.cpp
  2. +1 −0 src/gui/qgsexpressionbuilderwidget.h
@@ -243,16 +243,8 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const
{
loadFieldValues( mFieldValues.value( item->text() ) );

const QgsFields fields = mLayer->fields();
int fieldIndex = fields.lookupField( item->text() );
if ( fieldIndex != -1 )
{
const QgsEditorWidgetSetup setup = fields.at( fieldIndex ).editorWidgetSetup();
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );

cbxValuesInUse->setVisible( formatter->flags() & QgsFieldFormatter::CanProvideAvailableValues );
cbxValuesInUse->setChecked( false );
}
cbxValuesInUse->setVisible( formatterCanProvideAvailableValues( item->text() ) );
cbxValuesInUse->setChecked( false );
}
mValueGroupBox->setVisible( isField );

@@ -512,6 +504,20 @@ void QgsExpressionBuilderWidget::fillFieldValues( const QString &fieldName, int
}
}

bool QgsExpressionBuilderWidget::formatterCanProvideAvailableValues( const QString &fieldName )
{
const QgsFields fields = mLayer->fields();
int fieldIndex = fields.lookupField( fieldName );
if ( fieldIndex != -1 )
{
const QgsEditorWidgetSetup setup = fields.at( fieldIndex ).editorWidgetSetup();
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );

return ( formatter->flags() & QgsFieldFormatter::CanProvideAvailableValues );
}
return false;
}

QString QgsExpressionBuilderWidget::getFunctionHelp( QgsExpressionFunction *function )
{
if ( !function )
@@ -1108,18 +1114,11 @@ void QgsExpressionBuilderWidget::showContextMenu( QPoint pt )
QMenu *menu = new QMenu( this );
menu->addAction( tr( "Load First 10 Unique Values" ), this, SLOT( loadSampleValues() ) );
menu->addAction( tr( "Load All Unique Values" ), this, SLOT( loadAllValues() ) );
const QgsFields fields = mLayer->fields();
int fieldIndex = fields.lookupField( item->text() );
if ( fieldIndex != -1 )
{
const QgsEditorWidgetSetup setup = fields.at( fieldIndex ).editorWidgetSetup();
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );

if ( formatter->flags() & QgsFieldFormatter::CanProvideAvailableValues )
{
menu->addAction( tr( "Load First 10 Unique Used Values" ), this, SLOT( loadSampleUsedValues() ) );
menu->addAction( tr( "Load All Unique Used Values" ), this, SLOT( loadAllUsedValues() ) );
}
if ( formatterCanProvideAvailableValues( item->text() ) )
{
menu->addAction( tr( "Load First 10 Unique Used Values" ), this, SLOT( loadSampleUsedValues() ) );
menu->addAction( tr( "Load All Unique Used Values" ), this, SLOT( loadAllUsedValues() ) );
}
menu->popup( expressionTree->mapToGlobal( pt ) );
}
@@ -396,6 +396,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
void runPythonCode( const QString &code );
void updateFunctionTree();
void fillFieldValues( const QString &fieldName, int countLimit, bool forceUsedValues = false );
bool formatterCanProvideAvailableValues( const QString &fieldName );
QString getFunctionHelp( QgsExpressionFunction *function );
QString loadFunctionHelp( QgsExpressionItem *functionName );
QString helpStylesheet() const;

0 comments on commit fe9a7ee

Please sign in to comment.
You can’t perform that action at this time.