Skip to content
Permalink
Browse files

Copy layout and code from field calculator for expression builder widget

  • Loading branch information
NathanW2 committed Jul 3, 2011
1 parent 44fddd1 commit 14a8924709f600e1dd6125c166483757aa962751
Showing with 300 additions and 8 deletions.
  1. +1 −0 src/app/qgslabelinggui.cpp
  2. +40 −3 src/gui/qgsexpressionbuilder.cpp
  3. +8 −1 src/gui/qgsexpressionbuilder.h
  4. +251 −4 src/ui/qgsexpressionbuilder.ui
@@ -471,6 +471,7 @@ void QgsLabelingGui::showExpressionDialog()

// Set the current expression using the selected text in the combo box.
builder->setExpressionString(this->cboFieldName->currentText());
builder->loadFieldNames(mLayer);

if ( dlg->exec() == QDialog::Accepted )
{
@@ -16,18 +16,55 @@
#include "qgsexpressionbuilder.h"
#include "ui_qgsexpressionbuilder.h"

QgsExpressionBuilder::QgsExpressionBuilder(QWidget *parent) :
QWidget(parent)

QgsExpressionBuilder::QgsExpressionBuilder(QWidget *parent, QgsVectorLayer *layer)
: QWidget(parent),
mLayer( layer )
{
setupUi(this);
if (!layer) return;
}

QgsExpressionBuilder::~QgsExpressionBuilder()
{

}

void QgsExpressionBuilder::on_mAllPushButton_clicked()
{

}

void QgsExpressionBuilder::loadFieldNames()
{
if ( !mLayer )
{
return;
}

const QgsFieldMap fieldMap = mLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
{
QString fieldName = fieldIt.value().name();

//insert into field list and field combo box
//mFieldMap.insert( fieldName, fieldIt.key() );
mFieldsListWidget->addItem( fieldName );
}
}

void QgsExpressionBuilder::fillFieldValues(int fieldIndex, int countLimit)
{
// determine the field type
QList<QVariant> values;
mLayer->uniqueValues( fieldIndex, values, countLimit );

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

QString QgsExpressionBuilder::getExpressionString()
{
return this->txtExpressionString->toPlainText();
@@ -18,15 +18,22 @@

#include <QWidget>
#include "ui_qgsexpressionbuilder.h"
#include "qgsvectorlayer.h"

class QgsExpressionBuilder : public QWidget, private Ui::QgsExpressionBuilder {
Q_OBJECT
public:
QgsExpressionBuilder(QWidget *parent = 0);
QgsExpressionBuilder(QWidget *parent = 0, QgsVectorLayer * layer=0);
~QgsExpressionBuilder();

void loadFieldNames();
void fillFieldValues(int fieldIndex, int countLimit);
QString getExpressionString();
void setExpressionString(const QString expressionString);
public slots:
void on_mAllPushButton_clicked();
private:
QgsVectorLayer* mLayer;
};

#endif // QGSEXPRESSIONBUILDER_H
@@ -6,16 +6,263 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>675</width>
<height>627</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QTextEdit" name="txtExpressionString"/>
<item row="0" column="0">
<widget class="QFrame" name="frame">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<widget class="QListWidget" name="mFieldsListWidget">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Fields</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Values</string>
</property>
</widget>
</item>
<item row="1" column="1" rowspan="2" colspan="2">
<widget class="QFrame" name="mValuesFrame">
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="1" rowspan="3">
<widget class="QListWidget" name="mValueListWidget">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="mAllPushButton">
<property name="text">
<string>Show all values ...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="mOperatorsGroupBox">
<property name="title">
<string>Operators</string>
</property>
<layout class="QGridLayout" name="gridLayout_1">
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="4">
<widget class="QPushButton" name="mTanButton">
<property name="text">
<string>tan</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="mACosButton">
<property name="text">
<string>acos</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="mToRealButton">
<property name="text">
<string>to real</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="mToIntButton">
<property name="text">
<string>to int</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="mSinButton">
<property name="text">
<string>sin</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="mSqrtButton">
<property name="text">
<string>sqrt</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="mMultiplyPushButton">
<property name="text">
<string>*</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="mPlusPushButton">
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QPushButton" name="mOpenBracketPushButton">
<property name="text">
<string>(</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QPushButton" name="mCloseBracketPushButton">
<property name="text">
<string>)</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QPushButton" name="mConcatButton">
<property name="text">
<string>||</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QPushButton" name="mRowNumButton">
<property name="text">
<string>rownum</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QPushButton" name="mATanButton">
<property name="text">
<string>atan</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="mASinButton">
<property name="text">
<string>asin</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="mAreaButton">
<property name="text">
<string>area</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="mLengthButton">
<property name="text">
<string>length</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="mToStringButton">
<property name="text">
<string>to string</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="mCosButton">
<property name="text">
<string>cos</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="mExpButton">
<property name="text">
<string>^</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="mDividePushButton">
<property name="text">
<string>/</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="mMinusPushButton">
<property name="text">
<string>-</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QTextEdit" name="txtExpressionString">
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mExpressionLabel">
<property name="text">
<string>Expression</string>
</property>
<property name="buddy">
<cstring>txtExpressionString</cstring>
</property>
</widget>
</item>
</layout>
</widget>

0 comments on commit 14a8924

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