Skip to content

Commit

Permalink
Refector QgsExpressionBuilderWidget to add API for loading field name…
Browse files Browse the repository at this point in the history
…s; update uses of widget to use new API
  • Loading branch information
NathanW2 committed Dec 28, 2011
1 parent 7f04787 commit bb94e3f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/app/qgslabelinggui.cpp
Expand Up @@ -495,7 +495,7 @@ void QgsLabelingGui::showExpressionDialog()
dlg.setWindowTitle( tr( "Expression based label" ) );
if ( dlg.exec() == QDialog::Accepted )
{
QString expression = dlg.expressionBuilder()->getExpressionString();
QString expression = dlg.getExpressionText();
//Only add the expression if the user has entered some text.
if ( !expression.isEmpty() )
{
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsexpressionbuilderdialog.cpp
Expand Up @@ -42,6 +42,11 @@ void QgsExpressionBuilderDialog::setExpressionText( QString text )
builder->setExpressionString( text );
}

QString QgsExpressionBuilderDialog::getExpressionText()
{
return builder->getExpressionString();
}

void QgsExpressionBuilderDialog::closeEvent( QCloseEvent *event )
{
QDialog::closeEvent( event );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsexpressionbuilderdialog.h
Expand Up @@ -19,6 +19,9 @@
#include <QDialog>
#include "ui_qgsexpressionbuilderdialogbase.h"

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

void setExpressionText( QString text );

QString getExpressionText();

protected:
/**
* Handle closing of the window
Expand Down
131 changes: 67 additions & 64 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -152,10 +152,14 @@ void QgsExpressionBuilderWidget::loadFieldNames()
return;

const QgsFieldMap fieldMap = mLayer->pendingFields();
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
for ( ; fieldIt != fieldMap.constEnd(); ++fieldIt )
loadFieldNames( fieldMap );
}

void QgsExpressionBuilderWidget::loadFieldNames( QgsFieldMap fields )
{
foreach( QgsField field, fields )
{
QString fieldName = fieldIt.value().name();
QString fieldName = field.name();
registerItem( tr( "Fields" ), fieldName, " " + fieldName + " ", "", QgsExpressionItem::Field );
}
}
Expand Down Expand Up @@ -357,72 +361,71 @@ void QgsExpressionBuilderWidget::loadAllValues()

QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functionName )
{
if ( functionName != NULL )
if ( functionName == NULL )
return "";

// set up the path to the help file
QString helpFilesPath = QgsApplication::pkgDataPath() + "/resources/function_help/";
/*
* determine the locale and create the file name from
* the context id
*/
QString lang = QLocale::system().name();

QSettings settings;
if ( settings.value( "locale/overrideFlag", false ).toBool() )
{
// set up the path to the help file
QString helpFilesPath = QgsApplication::pkgDataPath() + "/resources/function_help/";
/*
* determine the locale and create the file name from
* the context id
*/
QString lang = QLocale::system().name();

QSettings settings;
if ( settings.value( "locale/overrideFlag", false ).toBool() )
{
QLocale l( settings.value( "locale/userLocale", "en_US" ).toString() );
lang = l.name();
}
/*
* If the language isn't set on the system, assume en_US,
* otherwise we get the banner at the top of the help file
* saying it isn't available in "your" language. Some systems
* may be installed without the LANG environment being set.
*/
if ( lang.length() == 0 || lang == "C" )
{
lang = "en_US";
}
QString fullHelpPath = helpFilesPath + functionName->text() + "-" + lang;
// get the help content and title from the localized file
QString helpContents;
QFile file( fullHelpPath );
// check to see if the localized version exists
if ( !file.exists() )
{
// change the file name to the en_US version (default)
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
file.setFileName( fullHelpPath );

// Check for some sort of english locale and if not found, include
// translate this for us message
if ( !lang.contains( "en_" ) )
{
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 />";
}
QLocale l( settings.value( "locale/userLocale", "en_US" ).toString() );
lang = l.name();
}
/*
* If the language isn't set on the system, assume en_US,
* otherwise we get the banner at the top of the help file
* saying it isn't available in "your" language. Some systems
* may be installed without the LANG environment being set.
*/
if ( lang.length() == 0 || lang == "C" )
{
lang = "en_US";
}
QString fullHelpPath = helpFilesPath + functionName->text() + "-" + lang;
// get the help content and title from the localized file
QString helpContents;
QFile file( fullHelpPath );
// check to see if the localized version exists
if ( !file.exists() )
{
// change the file name to the en_US version (default)
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
file.setFileName( fullHelpPath );

}
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
// Check for some sort of english locale and if not found, include
// translate this for us message
if ( !lang.contains( "en_" ) )
{
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" )
.arg( fullHelpPath );
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 />";
}
else

}
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
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" )
.arg( fullHelpPath );
}
else
{
QTextStream in( &file );
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
while ( !in.atEnd() )
{
QTextStream in( &file );
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
while ( !in.atEnd() )
{
QString line = in.readLine();
helpContents += line;
}
QString line = in.readLine();
helpContents += line;
}
file.close();

// Set the browser text to the help contents
QString myStyle = QgsApplication::reportStyleSheet();
helpContents = "<head><style>" + myStyle + "</style></head><body>" + helpContents + "</body>";
return helpContents;
}
return "";
file.close();

// Set the browser text to the help contents
QString myStyle = QgsApplication::reportStyleSheet();
helpContents = "<head><style>" + myStyle + "</style></head><body>" + helpContents + "</body>";
return helpContents;
}
3 changes: 3 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.h
Expand Up @@ -119,6 +119,8 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
*/
void loadFieldNames();

void loadFieldNames( QgsFieldMap fields );

/** Gets the expression string that has been set in the expression area.
* @returns The expression as a string. */
QString getExpressionString();
Expand All @@ -137,6 +139,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
QString helpText = "",
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode );


public slots:
void on_expressionTree_clicked( const QModelIndex &index );
void on_expressionTree_doubleClicked( const QModelIndex &index );
Expand Down
6 changes: 1 addition & 5 deletions src/providers/wfs/qgswfssourceselect.cpp
Expand Up @@ -422,11 +422,7 @@ void QgsWFSSourceSelect::on_treeWidget_itemDoubleClicked( QTreeWidgetItem* item,
return;
}

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

if ( d.exec() == QDialog::Accepted )
{
Expand Down

0 comments on commit bb94e3f

Please sign in to comment.