QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsexpressionbuilderwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgisexpressionbuilderwidget.h - A genric expression string builder widget.
3  --------------------------------------
4  Date : 29-May-2011
5  Copyright : (C) 2011 by Nathan Woodrow
6  Email : woodrow.nathan at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSEXPRESSIONBUILDER_H
17 #define QGSEXPRESSIONBUILDER_H
18 
19 #include <QWidget>
20 #include "ui_qgsexpressionbuilder.h"
21 #include "qgsvectorlayer.h"
23 #include "qgsdistancearea.h"
24 
25 #include "QStandardItemModel"
26 #include "QStandardItem"
27 #include "QSortFilterProxyModel"
28 
33 class QgsExpressionItemSearchProxy : public QSortFilterProxyModel
34 {
35  public:
37 
38  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
39  {
40  if ( source_parent == qobject_cast<QStandardItemModel*>( sourceModel() )->invisibleRootItem()->index() )
41  return true;
42 
43  return QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent );
44  }
45 };
46 
49 class QgsExpressionItem : public QStandardItem
50 {
51  public:
52  enum ItemType
53  {
57  };
58 
59  QgsExpressionItem( QString label,
60  QString expressionText,
61  QString helpText,
63  : QStandardItem( label )
64  {
65  mExpressionText = expressionText;
66  mHelpText = helpText;
67  mType = itemType;
68  }
69 
70  QgsExpressionItem( QString label,
71  QString expressionText,
73  : QStandardItem( label )
74  {
75  mExpressionText = expressionText;
76  mType = itemType;
77  }
78 
79  QString getExpressionText() { return mExpressionText; }
80 
85  QString getHelpText() { return mHelpText; }
90  void setHelpText( QString helpText ) { mHelpText = helpText; }
91 
97 
98  private:
99  QString mExpressionText;
100  QString mHelpText;
102 };
103 
107 class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExpressionBuilderWidgetBase
108 {
109  Q_OBJECT
110  public:
111  QgsExpressionBuilderWidget( QWidget *parent );
113 
117  void setLayer( QgsVectorLayer* layer );
118 
122  void loadFieldNames();
123 
124  void loadFieldNames( const QgsFields& fields );
125 
129  void setGeomCalculator( const QgsDistanceArea & da );
130 
133  QString expressionText();
134 
136  void setExpressionText( const QString& expression );
137 
145  void registerItem( QString group, QString label, QString expressionText,
146  QString helpText = "",
148 
149  bool isExpressionValid();
150 
151  void saveToRecent( QString key );
152 
153  void loadRecent( QString key );
154 
155  public slots:
156  void currentChanged( const QModelIndex &index, const QModelIndex & );
157  void on_expressionTree_doubleClicked( const QModelIndex &index );
158  void on_txtExpressionString_textChanged();
159  void on_txtSearchEdit_textChanged();
160  void on_lblPreview_linkActivated( QString link );
161  void on_mValueListWidget_itemDoubleClicked( QListWidgetItem* item );
162  void operatorButtonClicked();
163  void showContextMenu( const QPoint & );
164  void loadSampleValues();
165  void loadAllValues();
166 
167  private slots:
168  void setExpressionState( bool state );
169 
170  signals:
176  void expressionParsed( bool isValid );
177 
178  private:
179  void fillFieldValues( int fieldIndex, int countLimit );
180  QString loadFunctionHelp( QgsExpressionItem* functionName );
181 
183  QStandardItemModel *mModel;
185  QMap<QString, QgsExpressionItem*> mExpressionGroups;
190 };
191 
192 #endif // QGSEXPRESSIONBUILDER_H
static unsigned index
void setHelpText(QString helpText)
Set the help text for the current item.
QgsExpressionItemSearchProxy * mProxyModel
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Container of fields for a vector layer.
Definition: qgsfield.h:163
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QgsExpressionItem::ItemType mType
Search proxy used to filter the QgsExpressionBuilderWidget tree.
QMap< QString, QgsExpressionItem * > mExpressionGroups
QgsExpressionItem(QString label, QString expressionText, QString helpText, QgsExpressionItem::ItemType itemType=ExpressionNode)
QgsExpressionItem::ItemType getItemType()
Get the type of expression item eg header, field, ExpressionNode.
General purpose distance and area calculator.
A reusable widget that can be used to build a expression string.
An expression item that can be used in the QgsExpressionBuilderWidget tree.
QgsExpressionItem(QString label, QString expressionText, QgsExpressionItem::ItemType itemType=ExpressionNode)
Represents a vector layer which manages a vector based data sets.
QgsExpressionHighlighter * highlighter
QString getHelpText()
Get the help text that is associated with this expression item.