Skip to content
Permalink
Browse files

UI clean up; Hide and show value list when needed; handle field items…

… better; code clean up.
  • Loading branch information
NathanW2 committed Sep 3, 2011
1 parent 27d3e51 commit 8f9fa6d5d22626f1cbd517c80c524cd74ae1a6f6
Showing with 141 additions and 79 deletions.
  1. +29 −21 src/gui/qgsexpressionbuilder.cpp
  2. +18 −5 src/gui/qgsexpressionbuilder.h
  3. +94 −53 src/ui/qgsexpressionbuilder.ui
@@ -20,9 +20,13 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget(QgsVectorLayer *layer)
: QWidget(),
mLayer( layer )
{
setupUi(this);
if (!layer) return;

setupUi(this);

mValueListWidget->hide();
mValueListLabel->hide();

mModel = new QStandardItemModel( );
expressionTree->setModel( mModel );

@@ -65,23 +69,25 @@ void QgsExpressionBuilderWidget::on_expressionTree_clicked(const QModelIndex &in
if ( item == 0 )
return;


// Handle the special case for fields
// This is a bit hacky. Should be done better. Handle it with a enum on QgsExpressionItem.
QStandardItem* parent = mModel->itemFromIndex(index.parent());
if ( parent == 0 )
return;

if (parent->text() == "Fields")
// If field item then we load a sample set of values from the field.
if (item->getItemType() == QgsExpressionItem::Field)
{
mValueListWidget->show();
mValueListLabel->show();
int fieldIndex = mLayer->fieldNameIndex(item->text());
fillFieldValues(fieldIndex,10);
txtHelpText->setText("Double click to add field name to expression string. <br> " \
"Or double click an item in the value list to add it to the expression string.");
txtHelpText->setToolTip(txtHelpText->text());
}
else
{
// Show the help for the current item.
mValueListWidget->hide();
mValueListLabel->hide();
mValueListWidget->clear();
txtHelpText->setText(item->getHelpText());
txtHelpText->setToolTip(txtHelpText->text());
}
}

@@ -91,6 +97,11 @@ void QgsExpressionBuilderWidget::on_expressionTree_doubleClicked(const QModelInd
if (item == 0)
return;

// Don't handle the double click it we are on a header node.
if (item->getItemType() == QgsExpressionItem::Header)
return;

// Insert the expression text.
txtExpressionString->insertPlainText(item->getExpressionText());
}

@@ -106,10 +117,7 @@ void QgsExpressionBuilderWidget::loadFieldNames()
for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
{
QString fieldName = fieldIt.value().name();

//insert into field list and field combo box
//mFieldMap.insert( fieldName, fieldIt.key() );
this->registerItem("Fields", fieldName, " " + fieldName + " ");
this->registerItem("Fields", fieldName, " " + fieldName + " ","", QgsExpressionItem::Field);
}
}

@@ -130,14 +138,13 @@ void QgsExpressionBuilderWidget::fillFieldValues(int fieldIndex, int countLimit)
mValueListWidget->blockSignals( false );
}

void QgsExpressionBuilderWidget::registerItem(QString group, QString label, QString expressionText)
{
this->registerItem(group,label,expressionText,"");
}

void QgsExpressionBuilderWidget::registerItem(QString group, QString label, QString expressionText, QString helpText)
void QgsExpressionBuilderWidget::registerItem(QString group,
QString label,
QString expressionText,
QString helpText,
QgsExpressionItem::ItemType type)
{
QgsExpressionItem* item = new QgsExpressionItem(label,expressionText, helpText);
QgsExpressionItem* item = new QgsExpressionItem(label,expressionText, helpText, type);
// Look up the group and insert the new function.
if (mExpressionGroups.contains(group))
{
@@ -146,7 +153,8 @@ void QgsExpressionBuilderWidget::registerItem(QString group, QString label, QStr
}
else
{
QgsExpressionItem* newgroupNode = new QgsExpressionItem(group,"");
// If the group doesn't exsit yet we make it first.
QgsExpressionItem* newgroupNode = new QgsExpressionItem(group,"", QgsExpressionItem::Header);
newgroupNode->appendRow(item);
mModel->appendRow(newgroupNode);
mExpressionGroups.insert(group , newgroupNode );
@@ -23,30 +23,43 @@
#include "QStandardItemModel"
#include "QStandardItem"


class QgsExpressionItem : public QStandardItem
{
public:
QgsExpressionItem(QString label, QString expressionText, QString helpText)
enum ItemType
{
Header,
Field,
ExpressionNode
};

QgsExpressionItem(QString label, QString expressionText, QString helpText, QgsExpressionItem::ItemType itemType = ExpressionNode)
: QStandardItem(label)
{
mExpressionText = expressionText;
mHelpText = helpText;
mType = itemType;
}

QgsExpressionItem(QString label, QString expressionText)
QgsExpressionItem(QString label, QString expressionText, QgsExpressionItem::ItemType itemType = ExpressionNode)
: QStandardItem(label)
{
mExpressionText = expressionText;
mType = itemType;
}

QString getExpressionText() { return mExpressionText; }

QString getHelpText() { return mHelpText; }

void setHelpText(QString helpText) { mHelpText = helpText; }

QgsExpressionItem::ItemType getItemType() { return mType ; }

private:
QString mExpressionText;
QString mHelpText;
QgsExpressionItem::ItemType mType;
};

class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuilder {
@@ -59,8 +72,8 @@ class QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuil
void fillFieldValues(int fieldIndex, int countLimit);
QString getExpressionString();
void setExpressionString(const QString expressionString);
void registerItem(QString group, QString label, QString expressionText);
void registerItem(QString group, QString label, QString expressionText, QString helpText);
void registerItem(QString group, QString label,QString expressionText,
QString helpText = "",QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode);

public slots:
void on_mAllPushButton_clicked();
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>538</width>
<height>615</height>
<width>589</width>
<height>604</height>
</rect>
</property>
<property name="windowTitle">
@@ -18,7 +18,7 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="moperationListGroup">
<property name="title">
<string>Operation List</string>
</property>
@@ -35,7 +35,10 @@
<property name="bottomMargin">
<number>2</number>
</property>
<property name="spacing">
<property name="horizontalSpacing">
<number>3</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
@@ -74,12 +77,25 @@
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="mValueListLabel">
<property name="text">
<string>Field Values</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="mValueListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>0</height>
<height>16777215</height>
</size>
</property>
<property name="autoFillBackground">
@@ -88,66 +104,91 @@
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="viewMode">
<enum>QListView::ListMode</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<widget class="QGroupBox" name="mFunctionHelGroup">
<property name="title">
<string>Function Help</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
<property name="flat">
<bool>false</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>261</width>
<height>362</height>
</rect>
<layout class="QGridLayout" name="gridLayout_5">
<property name="margin">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="txtHelpText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>fsbn</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>277</width>
<height>140</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<property name="margin">
<number>3</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="txtHelpText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
<zorder>txtHelpText</zorder>
<zorder>scrollArea</zorder>
</widget>
</item>
</layout>

0 comments on commit 8f9fa6d

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