Skip to content

Commit bb94e3f

Browse files
committedDec 28, 2011
Refector QgsExpressionBuilderWidget to add API for loading field names; update uses of widget to use new API
1 parent 7f04787 commit bb94e3f

File tree

6 files changed

+82
-70
lines changed

6 files changed

+82
-70
lines changed
 

‎src/app/qgslabelinggui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void QgsLabelingGui::showExpressionDialog()
495495
dlg.setWindowTitle( tr( "Expression based label" ) );
496496
if ( dlg.exec() == QDialog::Accepted )
497497
{
498-
QString expression = dlg.expressionBuilder()->getExpressionString();
498+
QString expression = dlg.getExpressionText();
499499
//Only add the expression if the user has entered some text.
500500
if ( !expression.isEmpty() )
501501
{

‎src/gui/qgsexpressionbuilderdialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ void QgsExpressionBuilderDialog::setExpressionText( QString text )
4242
builder->setExpressionString( text );
4343
}
4444

45+
QString QgsExpressionBuilderDialog::getExpressionText()
46+
{
47+
return builder->getExpressionString();
48+
}
49+
4550
void QgsExpressionBuilderDialog::closeEvent( QCloseEvent *event )
4651
{
4752
QDialog::closeEvent( event );

‎src/gui/qgsexpressionbuilderdialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include <QDialog>
2020
#include "ui_qgsexpressionbuilderdialogbase.h"
2121

22+
/** A generic dialog for building expression strings
23+
* @remarks This class also shows an example on how to use QgsExpressionBuilderWidget
24+
*/
2225
class GUI_EXPORT QgsExpressionBuilderDialog : public QDialog, private Ui::QgsExpressionBuilderDialogBase
2326
{
2427
public:
@@ -29,6 +32,8 @@ class GUI_EXPORT QgsExpressionBuilderDialog : public QDialog, private Ui::QgsExp
2932

3033
void setExpressionText( QString text );
3134

35+
QString getExpressionText();
36+
3237
protected:
3338
/**
3439
* Handle closing of the window

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ void QgsExpressionBuilderWidget::loadFieldNames()
152152
return;
153153

154154
const QgsFieldMap fieldMap = mLayer->pendingFields();
155-
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
156-
for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
155+
loadFieldNames( fieldMap );
156+
}
157+
158+
void QgsExpressionBuilderWidget::loadFieldNames( QgsFieldMap fields )
159+
{
160+
foreach( QgsField field, fields )
157161
{
158-
QString fieldName = fieldIt.value().name();
162+
QString fieldName = field.name();
159163
registerItem( tr( "Fields" ), fieldName, " " + fieldName + " ", "", QgsExpressionItem::Field );
160164
}
161165
}
@@ -357,72 +361,71 @@ void QgsExpressionBuilderWidget::loadAllValues()
357361

358362
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functionName )
359363
{
360-
if ( functionName != NULL )
364+
if ( functionName == NULL )
365+
return "";
366+
367+
// set up the path to the help file
368+
QString helpFilesPath = QgsApplication::pkgDataPath() + "/resources/function_help/";
369+
/*
370+
* determine the locale and create the file name from
371+
* the context id
372+
*/
373+
QString lang = QLocale::system().name();
374+
375+
QSettings settings;
376+
if ( settings.value( "locale/overrideFlag", false ).toBool() )
361377
{
362-
// set up the path to the help file
363-
QString helpFilesPath = QgsApplication::pkgDataPath() + "/resources/function_help/";
364-
/*
365-
* determine the locale and create the file name from
366-
* the context id
367-
*/
368-
QString lang = QLocale::system().name();
369-
370-
QSettings settings;
371-
if ( settings.value( "locale/overrideFlag", false ).toBool() )
372-
{
373-
QLocale l( settings.value( "locale/userLocale", "en_US" ).toString() );
374-
lang = l.name();
375-
}
376-
/*
377-
* If the language isn't set on the system, assume en_US,
378-
* otherwise we get the banner at the top of the help file
379-
* saying it isn't available in "your" language. Some systems
380-
* may be installed without the LANG environment being set.
381-
*/
382-
if ( lang.length() == 0 || lang == "C" )
383-
{
384-
lang = "en_US";
385-
}
386-
QString fullHelpPath = helpFilesPath + functionName->text() + "-" + lang;
387-
// get the help content and title from the localized file
388-
QString helpContents;
389-
QFile file( fullHelpPath );
390-
// check to see if the localized version exists
391-
if ( !file.exists() )
392-
{
393-
// change the file name to the en_US version (default)
394-
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
395-
file.setFileName( fullHelpPath );
396-
397-
// Check for some sort of english locale and if not found, include
398-
// translate this for us message
399-
if ( !lang.contains( "en_" ) )
400-
{
401-
helpContents = "<i>" + tr( "This help file is not available in your language %1. If you would like to translate it, please contact the QGIS development team." ).arg( lang ) + "</i><hr />";
402-
}
378+
QLocale l( settings.value( "locale/userLocale", "en_US" ).toString() );
379+
lang = l.name();
380+
}
381+
/*
382+
* If the language isn't set on the system, assume en_US,
383+
* otherwise we get the banner at the top of the help file
384+
* saying it isn't available in "your" language. Some systems
385+
* may be installed without the LANG environment being set.
386+
*/
387+
if ( lang.length() == 0 || lang == "C" )
388+
{
389+
lang = "en_US";
390+
}
391+
QString fullHelpPath = helpFilesPath + functionName->text() + "-" + lang;
392+
// get the help content and title from the localized file
393+
QString helpContents;
394+
QFile file( fullHelpPath );
395+
// check to see if the localized version exists
396+
if ( !file.exists() )
397+
{
398+
// change the file name to the en_US version (default)
399+
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
400+
file.setFileName( fullHelpPath );
403401

404-
}
405-
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
402+
// Check for some sort of english locale and if not found, include
403+
// translate this for us message
404+
if ( !lang.contains( "en_" ) )
406405
{
407-
helpContents = tr( "This help file does not exist for your language:<p><b>%1</b><p>If you would like to create it, contact the QGIS development team" )
408-
.arg( fullHelpPath );
406+
helpContents = "<i>" + tr( "This help file is not available in your language %1. If you would like to translate it, please contact the QGIS development team." ).arg( lang ) + "</i><hr />";
409407
}
410-
else
408+
409+
}
410+
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
411+
{
412+
helpContents = tr( "This help file does not exist for your language:<p><b>%1</b><p>If you would like to create it, contact the QGIS development team" )
413+
.arg( fullHelpPath );
414+
}
415+
else
416+
{
417+
QTextStream in( &file );
418+
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
419+
while ( !in.atEnd() )
411420
{
412-
QTextStream in( &file );
413-
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
414-
while ( !in.atEnd() )
415-
{
416-
QString line = in.readLine();
417-
helpContents += line;
418-
}
421+
QString line = in.readLine();
422+
helpContents += line;
419423
}
420-
file.close();
421-
422-
// Set the browser text to the help contents
423-
QString myStyle = QgsApplication::reportStyleSheet();
424-
helpContents = "<head><style>" + myStyle + "</style></head><body>" + helpContents + "</body>";
425-
return helpContents;
426424
}
427-
return "";
425+
file.close();
426+
427+
// Set the browser text to the help contents
428+
QString myStyle = QgsApplication::reportStyleSheet();
429+
helpContents = "<head><style>" + myStyle + "</style></head><body>" + helpContents + "</body>";
430+
return helpContents;
428431
}

‎src/gui/qgsexpressionbuilderwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
119119
*/
120120
void loadFieldNames();
121121

122+
void loadFieldNames( QgsFieldMap fields );
123+
122124
/** Gets the expression string that has been set in the expression area.
123125
* @returns The expression as a string. */
124126
QString getExpressionString();
@@ -137,6 +139,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
137139
QString helpText = "",
138140
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode );
139141

142+
140143
public slots:
141144
void on_expressionTree_clicked( const QModelIndex &index );
142145
void on_expressionTree_doubleClicked( const QModelIndex &index );

‎src/providers/wfs/qgswfssourceselect.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,7 @@ void QgsWFSSourceSelect::on_treeWidget_itemDoubleClicked( QTreeWidgetItem* item,
422422
return;
423423
}
424424

425-
QgsFieldMap::const_iterator fieldIt = fields.constBegin();
426-
for ( ; fieldIt != fields.constEnd(); ++fieldIt )
427-
{
428-
w->registerItem( tr( "Fields" ), fieldIt->name(), " " + fieldIt->name() + " ", "", QgsExpressionItem::Field );
429-
}
425+
w->loadFieldNames( fields );
430426

431427
if ( d.exec() == QDialog::Accepted )
432428
{

0 commit comments

Comments
 (0)
Please sign in to comment.