Skip to content
Permalink
Browse files

menu action to only display the used values if formatter can provide …

…available values
  • Loading branch information
signedav committed Dec 16, 2019
1 parent 8e0b938 commit 83be397f8d96712ffda2fc63ab80fa0a15297c4a
@@ -299,12 +299,30 @@ with the context.

void loadSampleValues();
%Docstring
Load sample values into the sample value area
Load sample values into the sample value area.
Including available values, in case the formatter can
provide them (eg. RelationReference).
%End

void loadAllValues();
%Docstring
Load all unique values from the set layer into the sample area
Load all unique values from the set layer into the sample area.
Including all available values, in case the formatter can
provide them (eg. RelationReference).
%End

void loadSampleUsedValues();
%Docstring
Load used sample values into the sample value area.
Only the used ones. Without available values, even if the
formatter can provide them (eg. RelationReference).
%End

void loadAllUsedValues();
%Docstring
Load all unique values from the set layer into the sample area.
Only the used ones. Without available values, even if the
formatter can provide them (eg. RelationReference).
%End

void autosave();
@@ -462,7 +462,7 @@ void QgsExpressionBuilderWidget::loadFieldsAndValues( const QMap<QString, QVaria
mFieldValues = fieldValues;
}

void QgsExpressionBuilderWidget::fillFieldValues( const QString &fieldName, int countLimit )
void QgsExpressionBuilderWidget::fillFieldValues( const QString &fieldName, int countLimit, bool forceUsedValues )
{
// TODO We should really return a error the user of the widget that
// the there is no layer set.
@@ -481,7 +481,7 @@ void QgsExpressionBuilderWidget::fillFieldValues( const QString &fieldName, int
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );

QList<QVariant> values;
if ( cbxValuesInUse->isVisible() && !cbxValuesInUse->isChecked() )
if ( cbxValuesInUse->isVisible() && !cbxValuesInUse->isChecked() && !forceUsedValues )
{
values = formatter->availableValues( setup.config(), countLimit );
}
@@ -1108,6 +1108,19 @@ 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() ) );
}
}
menu->popup( expressionTree->mapToGlobal( pt ) );
}
}
@@ -1138,6 +1151,32 @@ void QgsExpressionBuilderWidget::loadAllValues()
fillFieldValues( item->text(), -1 );
}

void QgsExpressionBuilderWidget::loadSampleUsedValues()
{
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer || !item )
return;

mValueGroupBox->show();
fillFieldValues( item->text(), 10, true );
}

void QgsExpressionBuilderWidget::loadAllUsedValues()
{
QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
QgsExpressionItem *item = dynamic_cast<QgsExpressionItem *>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer || !item )
return;

mValueGroupBox->show();
fillFieldValues( item->text(), -1, true );
}

void QgsExpressionBuilderWidget::txtPython_textChanged()
{
lblAutoSave->setText( tr( "Saving…" ) );
@@ -302,15 +302,33 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
public slots:

/**
* Load sample values into the sample value area
* Load sample values into the sample value area.
* Including available values, in case the formatter can
* provide them (eg. RelationReference).
*/
void loadSampleValues();

/**
* Load all unique values from the set layer into the sample area
* Load all unique values from the set layer into the sample area.
* Including all available values, in case the formatter can
* provide them (eg. RelationReference).
*/
void loadAllValues();

/**
* Load used sample values into the sample value area.
* Only the used ones. Without available values, even if the
* formatter can provide them (eg. RelationReference).
*/
void loadSampleUsedValues();

/**
* Load all unique values from the set layer into the sample area.
* Only the used ones. Without available values, even if the
* formatter can provide them (eg. RelationReference).
*/
void loadAllUsedValues();

/**
* Auto save the current Python function code.
*/
@@ -377,7 +395,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
void clearErrors();
void runPythonCode( const QString &code );
void updateFunctionTree();
void fillFieldValues( const QString &fieldName, int countLimit );
void fillFieldValues( const QString &fieldName, int countLimit, bool forceUsedValues = false );
QString getFunctionHelp( QgsExpressionFunction *function );
QString loadFunctionHelp( QgsExpressionItem *functionName );
QString helpStylesheet() const;

0 comments on commit 83be397

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