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>";