Skip to content
Permalink
Browse files

Added fields and operators to tree view

  • Loading branch information
NathanW2 committed Jul 12, 2011
1 parent e13fb8a commit 7d14d0b1ba2162dac131ceb7952b93c4f6798c12
Showing with 54 additions and 15 deletions.
  1. +18 −10 src/gui/qgsexpressionbuilder.cpp
  2. +32 −4 src/gui/qgsexpressionbuilder.h
  3. +4 −1 src/ui/qgsexpressionbuilder.ui
@@ -16,20 +16,20 @@
#include "qgsexpressionbuilder.h"
#include "ui_qgsexpressionbuilder.h"


QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QgsVectorLayer *layer)
: QWidget(),
mLayer( layer )
{
setupUi(this);
if (!layer) return;
mModel = new QStandardItemModel();
expressionTree->setModel(mModel);
QStandardItem* operators = new QStandardItem('Operators');
mModel->appendRow(operators);
//mExpressionGroups.insert("Operators",operators);

//this->registerFunction("Operators","+"," + ");
mModel = new QStandardItemModel( );
expressionTree->setModel( mModel );

this->registerItem("Operators","+"," + ");
this->registerItem("Operators","-"," -");
this->registerItem("Operators","*"," * ");
this->registerItem("Operators","/"," / ");
}

QgsExpressionBuilderWidget::~QgsExpressionBuilderWidget()
@@ -57,6 +57,7 @@ void QgsExpressionBuilderWidget::loadFieldNames()

//insert into field list and field combo box
//mFieldMap.insert( fieldName, fieldIt.key() );
this->registerItem("Fields", fieldName, " " + fieldName + " ");
//mFieldsListWidget->addItem( fieldName );
}
}
@@ -73,15 +74,22 @@ void QgsExpressionBuilderWidget::fillFieldValues(int fieldIndex, int countLimit)
}
}

void QgsExpressionBuilderWidget::registerFunction(QString group, QString label, QString expressionText)
void QgsExpressionBuilderWidget::registerItem(QString group, QString label, QString expressionText)
{
QgsExpressionItem* item = new QgsExpressionItem(label,expressionText);
// Look up the group and insert the new function.
if (mExpressionGroups.contains(group))
{
QStandardItem* groupNode = mExpressionGroups.value(group);
QStandardItem* item = new QStandardItem(label);
QgsExpressionItem* groupNode = mExpressionGroups.value(group);
groupNode->appendRow(item);
}
else
{
QgsExpressionItem* newgroupNode = new QgsExpressionItem(group,"");
newgroupNode->appendRow(item);
mModel->appendRow(newgroupNode);
mExpressionGroups.insert(group , newgroupNode );
}
}

QString QgsExpressionBuilderWidget::getExpressionString()
@@ -23,6 +23,34 @@
#include "QStandardItemModel"
#include "QStandardItem"

//class QgsExpressionItem : public QStandardItem
//{
//public:
// QgsExpressionItem(QString label, QString expressionText);
// ~QgsExpressionItem();

// QString getExpressionText();
//private:
// QString mExpressionText;
//};

class QgsExpressionItem : public QStandardItem
{
public:
QgsExpressionItem(QString label, QString expressionText)
: QStandardItem(label)
{
mExpressionText = expressionText;
}

QString getExpressionText()
{
return mExpressionText;
}
private:
QString mExpressionText;
};

class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuilder {
Q_OBJECT
public:
@@ -33,15 +61,15 @@ class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuil
void fillFieldValues(int fieldIndex, int countLimit);
QString getExpressionString();
void setExpressionString(const QString expressionString);
void registerFunction(QString group, QString label, QString expressionText);
void registerItem(QString group, QString label, QString expressionText);

public slots:
void on_mAllPushButton_clicked();

private:
QgsVectorLayer* mLayer;
QStandardItemModel* mModel;
QMap<QString, QStandardItem*> mExpressionGroups;
QgsVectorLayer *mLayer;
QStandardItemModel *mModel;
QMap<QString, QgsExpressionItem*> mExpressionGroups;
};

#endif // QGSEXPRESSIONBUILDER_H
@@ -14,6 +14,9 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
@@ -47,7 +50,7 @@
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>true</bool>
<bool>false</bool>
</attribute>
</widget>
</item>

0 comments on commit 7d14d0b

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