25 #include <QTextStream>
32 mValueGroupBox->hide();
34 btnLoadSample->hide();
37 mModel =
new QStandardItemModel( );
42 expressionTree->setContextMenuPolicy( Qt::CustomContextMenu );
44 connect( expressionTree, SIGNAL( customContextMenuRequested(
const QPoint & ) ),
this, SLOT(
showContextMenu(
const QPoint & ) ) );
45 connect( expressionTree->selectionModel(), SIGNAL(
currentChanged(
const QModelIndex &,
const QModelIndex & ) ),
46 this, SLOT(
currentChanged(
const QModelIndex &,
const QModelIndex & ) ) );
48 connect( btnLoadAll, SIGNAL( pressed() ),
this, SLOT(
loadAllValues() ) );
49 connect( btnLoadSample, SIGNAL( pressed() ),
this, SLOT(
loadSampleValues() ) );
51 foreach ( QPushButton* button, mOperatorsGroupBox->findChildren<QPushButton *>() )
57 registerItem(
"Operators",
"+",
" + ",
tr(
"Addition operator" ) );
58 registerItem(
"Operators",
"-",
" -" ,
tr(
"Subtraction operator" ) );
59 registerItem(
"Operators",
"*",
" * ",
tr(
"Multiplication operator" ) );
60 registerItem(
"Operators",
"/",
" / ",
tr(
"Division operator" ) );
64 registerItem(
"Operators",
">",
" > ",
tr(
"Greater as operator" ) );
65 registerItem(
"Operators",
"<",
" < ",
tr(
"Less than operator" ) );
66 registerItem(
"Operators",
"<>",
" <> ",
tr(
"Unequal operator" ) );
67 registerItem(
"Operators",
"<=",
" <= ",
tr(
"Less or equal operator" ) );
68 registerItem(
"Operators",
">=",
" >= ",
tr(
"Greater or equal operator" ) );
70 QString(
"<b>|| %1</b><br><i>%2</i><br><i>%3:</i>%4" )
71 .arg(
tr(
"(String Concatenation)" ) )
72 .arg(
tr(
"Joins two values together into a string" ) )
74 .arg(
tr(
"'Dia' || Diameter" ) ) );
82 QString casestring =
"CASE WHEN condition THEN result END";
83 QString caseelsestring =
"CASE WHEN condition THEN result ELSE result END";
85 registerItem(
"Conditionals",
"CASE ELSE", caseelsestring );
89 for (
int i = 0; i < count; i++ )
92 QString name = func->
name();
93 if ( name.startsWith(
"_" ) )
101 for (
int i = 0; i < specials.size(); ++i )
103 QString name = specials[i]->name();
104 registerItem( specials[i]->group(), name,
" " + name +
" " );
107 #if QT_VERSION >= 0x040700
108 txtSearchEdit->setPlaceholderText(
tr(
"Search" ) );
126 QModelIndex idx =
mProxyModel->mapToSource( index );
133 mValueListWidget->clear();
142 txtHelpText->setText( help );
143 txtHelpText->setToolTip( txtHelpText->toPlainText() );
148 QModelIndex idx =
mProxyModel->mapToSource( index );
159 txtExpressionString->setFocus();
177 QStringList fieldNames;
179 for (
int i = 0; i < fields.
count(); ++i )
181 QString fieldName = fields[i].name();
182 fieldNames << fieldName;
196 mValueListWidget->clear();
197 mValueListWidget->setUpdatesEnabled(
false );
198 mValueListWidget->blockSignals(
true );
200 QList<QVariant> values;
202 foreach ( QVariant value, values )
204 if ( value.isNull() )
205 mValueListWidget->addItem(
"NULL" );
206 else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
207 mValueListWidget->addItem( value.toString() );
209 mValueListWidget->addItem(
"'" + value.toString().replace(
"'",
"''" ) +
"'" );
212 mValueListWidget->setUpdatesEnabled(
true );
213 mValueListWidget->blockSignals(
false );
218 QString expressionText,
223 item->setData( label, Qt::UserRole );
228 groupNode->appendRow( item );
234 newgroupNode->setData( group, Qt::UserRole );
235 newgroupNode->appendRow( item );
236 mModel->appendRow( newgroupNode );
253 return txtExpressionString->toPlainText();
258 txtExpressionString->setPlainText( expression );
263 QString text = txtExpressionString->toPlainText();
267 if ( text.isEmpty() )
269 lblPreview->setText(
"" );
270 lblPreview->setStyleSheet(
"" );
271 txtExpressionString->setToolTip(
"" );
272 lblPreview->setToolTip(
"" );
295 lblPreview->setText( value.toString() );
301 lblPreview->setText(
"" );
310 lblPreview->setText( value.toString() );
316 QString tooltip = QString(
"<b>%1:</b><br>%2" ).arg(
tr(
"Parser Error" ) ).arg( exp.
parserErrorString() );
318 tooltip += QString(
"<br><br><b>%1:</b><br>%2" ).arg(
tr(
"Eval Error" ) ).arg( exp.
evalErrorString() );
320 lblPreview->setText(
tr(
"Expression is invalid <a href=""more"">(more info)</a>" ) );
321 lblPreview->setStyleSheet(
"color: rgba(255, 6, 10, 255);" );
322 txtExpressionString->setToolTip( tooltip );
323 lblPreview->setToolTip( tooltip );
329 lblPreview->setStyleSheet(
"" );
330 txtExpressionString->setToolTip(
"" );
331 lblPreview->setToolTip(
"" );
338 mProxyModel->setFilterWildcard( txtSearchEdit->text() );
339 if ( txtSearchEdit->text().isEmpty() )
340 expressionTree->collapseAll();
342 expressionTree->expandAll();
349 mv->setWindowTitle(
tr(
"More info on expression error" ) );
356 txtExpressionString->insertPlainText(
" " + item->text() +
" " );
357 txtExpressionString->setFocus();
362 QPushButton* button =
dynamic_cast<QPushButton*
>( sender() );
363 txtExpressionString->insertPlainText(
" " + button->text() +
" " );
364 txtExpressionString->setFocus();
369 QModelIndex idx = expressionTree->indexAt( pt );
377 QMenu* menu =
new QMenu(
this );
378 menu->addAction(
tr(
"Load top 10 unique values" ),
this, SLOT(
loadSampleValues() ) );
379 menu->addAction(
tr(
"Load all unique values" ),
this, SLOT(
loadAllValues() ) );
380 menu->popup( expressionTree->mapToGlobal( pt ) );
386 QModelIndex idx =
mProxyModel->mapToSource( expressionTree->currentIndex() );
393 mValueGroupBox->show();
400 QModelIndex idx =
mProxyModel->mapToSource( expressionTree->currentIndex() );
407 mValueGroupBox->show();
419 if ( !expressionItem )
422 QString helpContents = expressionItem->
getHelpText();
425 if ( helpContents.isEmpty() )
427 QString name = expressionItem->data( Qt::UserRole ).toString();
436 return "<head><style>" + myStyle +
"</style></head><body>" + helpContents +
"</body>";
Class for parsing and evaluation of expressions (formerly called "search strings").
void setGeomCalculator(QgsDistanceArea &calc)
Sets the geometry calculator used in evaluation of expressions,.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
bool isValid() const
Return the validity of this feature.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
A abstract base class for defining QgsExpression functions.
void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Returns unique values for column.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
static QString helptext(QString name)
Container of fields for a vector layer.
static QString group(QString group)
QString getExpressionText()
static QString reportStyleSheet()
get a standard css style sheet for reports.
static const QList< Function * > & Functions()
void setMessageAsHtml(const QString &msg)
void addFields(QStringList fieldList)
static int functionCount()
Returns the number of functions defined in the parser.
Search proxy used to filter the QgsExpressionBuilderWidget tree.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
int count() const
Return number of items.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QString helptext()
The help text for the function.
QString name()
The name of the function.
QgsExpressionItem::ItemType getItemType()
Get the type of expression item eg header, field, ExpressionNode.
bool needsGeometry()
Returns true if the expression uses feature geometry for some computation.
General purpose distance and area calculator.
An expression item that can be used in the QgsExpressionBuilderWidget tree.
QString group()
The group the function belongs to.
static QList< Function * > specialColumns()
Returns a list of special Column definitions.
int params()
The number of parameters this function takes.
A generic message view for displaying QGIS messages.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
bool isEmpty() const
Check whether the container is empty.
QString parserErrorString() const
Returns parser error.
QString getHelpText()
Get the help text that is associated with this expression item.
QString evalErrorString() const
Returns evaluation error.