25 #include <QTextStream>
32 mValueGroupBox->hide();
33 mLoadGroupBox->hide();
36 mModel =
new QStandardItemModel( );
41 expressionTree->setContextMenuPolicy( Qt::CustomContextMenu );
43 connect( expressionTree, SIGNAL( customContextMenuRequested(
const QPoint & ) ),
this, SLOT(
showContextMenu(
const QPoint & ) ) );
44 connect( expressionTree->selectionModel(), SIGNAL(
currentChanged(
const QModelIndex &,
const QModelIndex & ) ),
45 this, SLOT(
currentChanged(
const QModelIndex &,
const QModelIndex & ) ) );
47 connect( btnLoadAll, SIGNAL( pressed() ),
this, SLOT(
loadAllValues() ) );
48 connect( btnLoadSample, SIGNAL( pressed() ),
this, SLOT(
loadSampleValues() ) );
50 foreach ( QPushButton* button, mOperatorsGroupBox->findChildren<QPushButton *>() )
56 registerItem(
"Operators",
"+",
" + ",
tr(
"Addition operator" ) );
57 registerItem(
"Operators",
"-",
" -" ,
tr(
"Subtraction operator" ) );
58 registerItem(
"Operators",
"*",
" * ",
tr(
"Multiplication operator" ) );
59 registerItem(
"Operators",
"/",
" / ",
tr(
"Division operator" ) );
63 registerItem(
"Operators",
">",
" > ",
tr(
"Greater as operator" ) );
64 registerItem(
"Operators",
"<",
" < ",
tr(
"Less than operator" ) );
65 registerItem(
"Operators",
"<>",
" <> ",
tr(
"Unequal operator" ) );
66 registerItem(
"Operators",
"<=",
" <= ",
tr(
"Less or equal operator" ) );
67 registerItem(
"Operators",
">=",
" >= ",
tr(
"Greater or equal operator" ) );
69 QString(
"<b>|| %1</b><br><i>%2</i><br><i>%3:</i>%4" )
70 .arg(
tr(
"(String Concatenation)" ) )
71 .arg(
tr(
"Joins two values together into a string" ) )
73 .arg(
tr(
"'Dia' || Diameter" ) ) );
81 QString casestring =
"CASE WHEN condition THEN result END";
82 QString caseelsestring =
"CASE WHEN condition THEN result ELSE result END";
84 registerItem(
"Conditionals",
"CASE ELSE", caseelsestring );
88 for (
int i = 0; i < count; i++ )
91 QString name = func->
name();
92 if ( name.startsWith(
"_" ) )
100 for (
int i = 0; i < specials.size(); ++i )
102 QString name = specials[i]->name();
103 registerItem( specials[i]->group(), name,
" " + name +
" " );
106 txtSearchEdit->setPlaceholderText(
tr(
"Search" ) );
123 QModelIndex idx =
mProxyModel->mapToSource( index );
130 mValueListWidget->clear();
138 txtHelpText->setText( help );
139 txtHelpText->setToolTip( txtHelpText->toPlainText() );
144 QModelIndex idx =
mProxyModel->mapToSource( index );
155 txtExpressionString->setFocus();
173 QStringList fieldNames;
175 for (
int i = 0; i < fields.
count(); ++i )
177 QString fieldName = fields[i].name();
178 fieldNames << fieldName;
192 mValueListWidget->clear();
193 mValueListWidget->setUpdatesEnabled(
false );
194 mValueListWidget->blockSignals(
true );
196 QList<QVariant> values;
198 foreach ( QVariant value, values )
200 if ( value.isNull() )
201 mValueListWidget->addItem(
"NULL" );
202 else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
203 mValueListWidget->addItem( value.toString() );
205 mValueListWidget->addItem(
"'" + value.toString().replace(
"'",
"''" ) +
"'" );
208 mValueListWidget->setUpdatesEnabled(
true );
209 mValueListWidget->blockSignals(
false );
214 QString expressionText,
219 item->setData( label, Qt::UserRole );
224 groupNode->appendRow( item );
230 newgroupNode->setData( group, Qt::UserRole );
231 newgroupNode->appendRow( item );
232 mModel->appendRow( newgroupNode );
245 QString location = QString(
"/expressions/recent/%1" ).arg( key );
246 QStringList expressions = settings.value( location ).toStringList();
251 while ( expressions.count() > 20 )
253 expressions.pop_back();
256 settings.setValue( location, expressions );
262 QString name =
tr(
"Recent (%1)" ).arg( key );
266 node->removeRows( 0, node->rowCount() );
270 QString location = QString(
"/expressions/recent/%1" ).arg( key );
271 QStringList expressions = settings.value( location ).toStringList();
272 foreach ( QString expression, expressions )
274 this->
registerItem( name, expression, expression, expression );
285 return txtExpressionString->toPlainText();
290 txtExpressionString->setPlainText( expression );
295 QString text = txtExpressionString->toPlainText();
299 if ( text.isEmpty() )
301 lblPreview->setText(
"" );
302 lblPreview->setStyleSheet(
"" );
303 txtExpressionString->setToolTip(
"" );
304 lblPreview->setToolTip(
"" );
327 lblPreview->setText( value.toString() );
333 lblPreview->setText(
"" );
342 lblPreview->setText( value.toString() );
348 QString tooltip = QString(
"<b>%1:</b><br>%2" ).arg(
tr(
"Parser Error" ) ).arg( exp.
parserErrorString() );
350 tooltip += QString(
"<br><br><b>%1:</b><br>%2" ).arg(
tr(
"Eval Error" ) ).arg( exp.
evalErrorString() );
352 lblPreview->setText(
tr(
"Expression is invalid <a href=""more"">(more info)</a>" ) );
353 lblPreview->setStyleSheet(
"color: rgba(255, 6, 10, 255);" );
354 txtExpressionString->setToolTip( tooltip );
355 lblPreview->setToolTip( tooltip );
361 lblPreview->setStyleSheet(
"" );
362 txtExpressionString->setToolTip(
"" );
363 lblPreview->setToolTip(
"" );
370 mProxyModel->setFilterWildcard( txtSearchEdit->text() );
371 if ( txtSearchEdit->text().isEmpty() )
372 expressionTree->collapseAll();
374 expressionTree->expandAll();
381 mv->setWindowTitle(
tr(
"More info on expression error" ) );
388 txtExpressionString->insertPlainText(
" " + item->text() +
" " );
389 txtExpressionString->setFocus();
394 QPushButton* button =
dynamic_cast<QPushButton*
>( sender() );
395 txtExpressionString->insertPlainText(
" " + button->text() +
" " );
396 txtExpressionString->setFocus();
401 QModelIndex idx = expressionTree->indexAt( pt );
409 QMenu* menu =
new QMenu(
this );
410 menu->addAction(
tr(
"Load top 10 unique values" ),
this, SLOT(
loadSampleValues() ) );
411 menu->addAction(
tr(
"Load all unique values" ),
this, SLOT(
loadAllValues() ) );
412 menu->popup( expressionTree->mapToGlobal( pt ) );
418 QModelIndex idx =
mProxyModel->mapToSource( expressionTree->currentIndex() );
425 mValueGroupBox->show();
432 QModelIndex idx =
mProxyModel->mapToSource( expressionTree->currentIndex() );
439 mValueGroupBox->show();
451 if ( !expressionItem )
454 QString helpContents = expressionItem->
getHelpText();
457 if ( helpContents.isEmpty() )
459 QString name = expressionItem->data( Qt::UserRole ).toString();
468 return "<head><style>" + myStyle +
"</style></head><body>" + helpContents +
"</body>";
Class for parsing and evaluation of expressions (formerly called "search strings").
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.
int count() const
Return number of items.
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.
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.
void setGeomCalculator(const QgsDistanceArea &calc)
Sets the geometry calculator used in evaluation of expressions,.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
bool nextFeature(QgsFeature &f)
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.