Skip to content
Permalink
Browse files

Fill value list from selected field.

  • Loading branch information
NathanW2 committed Jul 12, 2011
1 parent 983a3ad commit 439a7119d5ade498d8e24f679edd8558744e49cc
Showing with 46 additions and 6 deletions.
  1. +44 −5 src/gui/qgsexpressionbuilder.cpp
  2. +1 −0 src/gui/qgsexpressionbuilder.h
  3. +1 −1 src/ui/qgsexpressionbuilder.ui
@@ -32,6 +32,14 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QgsVectorLayer *layer)
this->registerItem("Operators","-"," -");
this->registerItem("Operators","*"," * ");
this->registerItem("Operators","/"," / ");

this->registerItem("Geometry","Area"," $area ");
this->registerItem("Geometry","Length"," $length ");
this->registerItem("Geometry","Perimeter"," $perimeter ");
this->registerItem("Geometry","X"," $x ");
this->registerItem("Geometry","Y"," $y ");
this->registerItem("Geometry","XAt"," xat() ");
this->registerItem("Geometry","YAt"," yat() ");
}

QgsExpressionBuilderWidget::~QgsExpressionBuilderWidget()
@@ -45,9 +53,36 @@ void QgsExpressionBuilderWidget::on_mAllPushButton_clicked()

}

void QgsExpressionBuilderWidget::on_expressionTree_clicked(const QModelIndex &index)
{
// Get the item
QgsExpressionItem* item = dynamic_cast<QgsExpressionItem*>(mModel->itemFromIndex(index));
if ( item == 0 )
return;
// Handle the special case for fields
// This is a bit hacky. Should be done better.
QStandardItem* parent = mModel->itemFromIndex(index.parent());
if ( parent == 0 )
return;

if (parent->text() == "Fields")
{
int fieldIndex = mLayer->fieldNameIndex(item->text());
fillFieldValues(fieldIndex,10);
}
else
{
// We might be able to show help for the current selected item here.
mValueListWidget->clear();
}
}

void QgsExpressionBuilderWidget::on_expressionTree_doubleClicked(const QModelIndex &index)
{
QgsExpressionItem* item = static_cast<QgsExpressionItem*>(mModel->itemFromIndex(index));
QgsExpressionItem* item = dynamic_cast<QgsExpressionItem*>(mModel->itemFromIndex(index));
if (item == 0)
return;

txtExpressionString->insertPlainText(item->getExpressionText());
}

@@ -67,20 +102,24 @@ void QgsExpressionBuilderWidget::loadFieldNames()
//insert into field list and field combo box
//mFieldMap.insert( fieldName, fieldIt.key() );
this->registerItem("Fields", fieldName, " " + fieldName + " ");
//mFieldsListWidget->addItem( fieldName );
}
}

void QgsExpressionBuilderWidget::fillFieldValues(int fieldIndex, int countLimit)
{
// determine the field type
mValueListWidget->clear();
mValueListWidget->setUpdatesEnabled( false );
mValueListWidget->blockSignals( true );

QList<QVariant> values;
mLayer->uniqueValues( fieldIndex, values, countLimit );

foreach(QVariant value, values)
{
//mValueListWidget->addItem(value.toString());
mValueListWidget->addItem(value.toString());
}

mValueListWidget->setUpdatesEnabled( true );
mValueListWidget->blockSignals( false );
}

void QgsExpressionBuilderWidget::registerItem(QString group, QString label, QString expressionText)
@@ -65,6 +65,7 @@ class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuil

public slots:
void on_mAllPushButton_clicked();
void on_expressionTree_clicked(const QModelIndex &index);
void on_expressionTree_doubleClicked(const QModelIndex &index);

private:
@@ -55,7 +55,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QListView" name="listView"/>
<widget class="QListWidget" name="mValueListWidget"/>
</item>
</layout>
</widget>

0 comments on commit 439a711

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