Skip to content

Commit d3e913c

Browse files
committedNov 7, 2011
Handle function help the same way as context help; Allows easier management of help; Use same style sheet as context help.
1 parent 09f98fc commit d3e913c

File tree

12 files changed

+174
-73
lines changed

12 files changed

+174
-73
lines changed
 

‎resources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ INSTALL(FILES srs.db qgis.db qgis_help.db symbology-ng-style.xml spatialite.db c
22
DESTINATION ${QGIS_DATA_DIR}/resources)
33

44
ADD_SUBDIRECTORY(context_help)
5+
ADD_SUBDIRECTORY(function_help)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FILE(GLOB HELP_FILES *-*)
2+
3+
INSTALL(FILES ${HELP_FILES} DESTINATION ${QGIS_DATA_DIR}/resources/function_help)
4+

‎resources/function_help/length-en_US

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h3>length() function</h3>
2+
Returns the length of a string.
3+
4+
<p><h4>Syntax</h4>
5+
length(<i>string</i>)</p>
6+
7+
<p><h4>Arguments</h4>
8+
<!-- List args for functions here-->
9+
<i> string</i> -> is string. The String to count the length of.</p>
10+
11+
<p><h4>Example</h4>
12+
<!-- Show example of function.-->
13+
length('HELLO') -> 5</p>

‎resources/function_help/lower-en_US

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<h3>lower() function</h3>
2+
Converts a string to lower case letters.
3+
4+
<p><h4> Syntax</h4>
5+
lower(<i>string</i>)</p>
6+
7+
<p><h4> Arguments</h4>
8+
<i> string</i> -> is string. The String to convert to lower case.</p>
9+
10+
<p><h4> Example</h4>
11+
lower('HELLO World') -> 'hello world'</p>

‎resources/function_help/replace-en_US

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h3>replace() function</h3>
2+
Returns a string with the the supplied string replaced.
3+
4+
<p><h4>Syntax</h4>
5+
replace(<i>string,before,after</i>)</p>
6+
7+
<p><h4>Arguments</h4>
8+
<!-- List args for functions here-->
9+
<i> string</i> -> is string. The start string.<br>
10+
<i> before</i> -> is string. The string to replace.<br>
11+
<i> after</i> -> is string. The string that will repalce <i>before</i><br></p>
12+
13+
<p><h4>Example</h4>
14+
<!-- Show example of function.-->
15+
replace('QGIS SHOULD ROCK','SHOULD','DOES') -> 'QGIS DOES ROCK'</p>

‎resources/function_help/substr-en_US

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h3>substr() function</h3>
2+
Return a part of a string
3+
4+
<p><h4>Syntax</h4>
5+
substr(<i>string,startpos,length</i>)</p>
6+
7+
<p><h4>Arguments</h4>
8+
<!-- List args for functions here-->
9+
<i> string</i> -> is string. The full string.<br>
10+
<i> startpos</i> -> is number. The start position to extract from.<br>
11+
<i> length</i> -> is number. The length of the string to extract.<br></p>
12+
13+
<p><h4>Example</h4>
14+
<!-- Show example of function.-->
15+
substr('HELLO WORLD',3,5) -> 'LLO W'</p>

‎resources/function_help/template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h3>{function} function</h3>
2+
Converts a string to lower case letters.
3+
4+
<p><h4>Syntax</h4>
5+
lower(<i>args</i>)</p>
6+
7+
<p><h4>Arguments</h4>
8+
<!-- List args for functions here-->
9+
<i> string</i> -> is string. The String to convert to lower case.</p>
10+
11+
<p><h4>Example</h4>
12+
<!-- Show example of function.-->
13+
lower('HELLO World') -> 'hello world'</p>

‎resources/function_help/upper-en_US

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h3>upper() function</h3>
2+
Converts a string to upper case letters.
3+
4+
<p><h4>Syntax</h4>
5+
upper(<i>string</i>)</p>
6+
7+
<p><h4>Arguments</h4>
8+
<!-- List args for functions here-->
9+
<i> string</i> -> is string. The String to convert to upper case.</p>
10+
11+
<p><h4>Example</h4>
12+
<!-- Show example of function.-->
13+
upper('hello WOrld') -> 'HELLO WORLD'</p>

‎src/core/qgsexpression.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,10 @@ FnDef QgsExpression::BuiltinFunctions[] =
392392
FnDef( "toreal", 1, fcnToReal, "Conversions" ),
393393
FnDef( "tostring", 1, fcnToString, "Conversions" ),
394394
// string manipulation
395-
FnDef( "lower", 1, fcnLower, "String", "<b>Convert to lower case</b> "
396-
"<br> Converts a string to lower case letters. "
397-
"<br> <i>Usage:</i><br>lower('HELLO WORLD') will return 'hello world'" ),
398-
FnDef( "upper", 1, fcnUpper, "String" , "<b>Convert to upper case</b> "
399-
"<br> Converts a string to upper case letters. "
400-
"<br> <i>Usage:</i><br>upper('hello world') will return 'HELLO WORLD'" ),
401-
FnDef( "length", 1, fcnLength, "String", "<b>Length of string</b> "
402-
"<br> Returns the legnth of a string. "
403-
"<br> <i>Usage:</i><br>length('hello') will return 5" ),
404-
FnDef( "replace", 3, fcnReplace, "String", "<b>Replace a section of a string.</b> " ),
395+
FnDef( "lower", 1, fcnLower, "String"),
396+
FnDef( "upper", 1, fcnUpper, "String"),
397+
FnDef( "length", 1, fcnLength, "String"),
398+
FnDef( "replace", 3, fcnReplace, "String"),
405399
FnDef( "regexp_replace", 3, fcnRegexpReplace, "String" ),
406400
FnDef( "substr", 3, fcnSubstr, "String" ),
407401
// geometry accessors

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
#include "qgslogger.h"
1818
#include "qgsexpression.h"
1919
#include "qgsmessageviewer.h"
20+
#include "qgsapplication.h"
2021

22+
#include <QSettings>
2123
#include <QMenu>
24+
#include <QFile>
25+
#include <QTextStream>
2226

2327
QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
2428
: QWidget( parent )
@@ -79,7 +83,7 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
7983
QString name = func.mName;
8084
if ( func.mParams >= 1 )
8185
name += "(";
82-
registerItem( func.mGroup, func.mName, " " + name + " ", func.mHelpText );
86+
registerItem( func.mGroup, func.mName, " " + name + " ");
8387
};
8488
}
8589

@@ -106,18 +110,19 @@ void QgsExpressionBuilderWidget::on_expressionTree_clicked( const QModelIndex &i
106110
// right click so we just show the help.
107111
if ( item->getItemType() == QgsExpressionItem::Field )
108112
{
109-
txtHelpText->setText( tr( "Double click to add field name to expression string. <br> "
113+
txtHelpText->setHtml( tr( "Double click to add field name to expression string. <br> "
110114
"Or right click to select loading value options then "
111115
"double click an item in the value list to add it to the expression string." ) );
112-
txtHelpText->setToolTip( txtHelpText->text() );
116+
txtHelpText->setToolTip( txtHelpText->toPlainText() );
113117
}
114118
else
115119
{
116120
// Show the help for the current item.
117121
mValueGroupBox->hide();
118122
mValueListWidget->clear();
119-
txtHelpText->setText( item->getHelpText() );
120-
txtHelpText->setToolTip( txtHelpText->text() );
123+
QString help = loadFunctionHelp( item );
124+
txtHelpText->setText( help );
125+
txtHelpText->setToolTip( txtHelpText->toPlainText() );
121126
}
122127
}
123128

@@ -347,3 +352,74 @@ void QgsExpressionBuilderWidget::loadAllValues()
347352
fillFieldValues( fieldIndex, -1 );
348353
}
349354

355+
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functionName )
356+
{
357+
if ( functionName != NULL )
358+
{
359+
// set up the path to the help file
360+
QString helpFilesPath = QgsApplication::pkgDataPath() + "/resources/function_help/";
361+
/*
362+
* determine the locale and create the file name from
363+
* the context id
364+
*/
365+
QString lang = QLocale::system().name();
366+
367+
QSettings settings;
368+
if ( settings.value( "locale/overrideFlag", false ).toBool() )
369+
{
370+
QLocale l( settings.value( "locale/userLocale", "en_US" ).toString() );
371+
lang = l.name();
372+
}
373+
/*
374+
* If the language isn't set on the system, assume en_US,
375+
* otherwise we get the banner at the top of the help file
376+
* saying it isn't available in "your" language. Some systems
377+
* may be installed without the LANG environment being set.
378+
*/
379+
if ( lang.length() == 0 || lang == "C" )
380+
{
381+
lang = "en_US";
382+
}
383+
QString fullHelpPath = helpFilesPath + functionName->text() + "-" + lang;
384+
// get the help content and title from the localized file
385+
QString helpContents;
386+
QFile file( fullHelpPath );
387+
// check to see if the localized version exists
388+
if ( !file.exists() )
389+
{
390+
// change the file name to the en_US version (default)
391+
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
392+
file.setFileName( fullHelpPath );
393+
394+
// Check for some sort of english locale and if not found, include
395+
// translate this for us message
396+
if ( !lang.contains( "en_" ) )
397+
{
398+
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 />";
399+
}
400+
401+
}
402+
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
403+
{
404+
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" )
405+
.arg( fullHelpPath );
406+
}
407+
else
408+
{
409+
QTextStream in( &file );
410+
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
411+
while ( !in.atEnd() )
412+
{
413+
QString line = in.readLine();
414+
helpContents += line;
415+
}
416+
}
417+
file.close();
418+
419+
// Set the browser text to the help contents
420+
QString myStyle = QgsApplication::reportStyleSheet();
421+
helpContents = "<head><style>" + myStyle + "</style></head><body>" + helpContents + "</body>";
422+
return helpContents;
423+
}
424+
return "";
425+
}

‎src/gui/qgsexpressionbuilderwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
159159

160160
private:
161161
void fillFieldValues( int fieldIndex, int countLimit );
162+
QString loadFunctionHelp( QgsExpressionItem* functionName );
162163

163164
QgsVectorLayer *mLayer;
164165
QStandardItemModel *mModel;

‎src/ui/qgsexpressionbuilder.ui

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
<property name="flat">
133133
<bool>true</bool>
134134
</property>
135-
<layout class="QGridLayout" name="gridLayout_5">
135+
<layout class="QGridLayout" name="gridLayout_4">
136136
<property name="leftMargin">
137137
<number>0</number>
138138
</property>
@@ -149,65 +149,10 @@
149149
<number>0</number>
150150
</property>
151151
<item row="0" column="0">
152-
<widget class="QScrollArea" name="scrollArea">
153-
<property name="maximumSize">
154-
<size>
155-
<width>16777215</width>
156-
<height>16777215</height>
157-
</size>
158-
</property>
159-
<property name="frameShape">
160-
<enum>QFrame::NoFrame</enum>
161-
</property>
162-
<property name="widgetResizable">
152+
<widget class="QTextEdit" name="txtHelpText">
153+
<property name="readOnly">
163154
<bool>true</bool>
164155
</property>
165-
<widget class="QWidget" name="scrollAreaWidgetContents">
166-
<property name="geometry">
167-
<rect>
168-
<x>0</x>
169-
<y>0</y>
170-
<width>264</width>
171-
<height>153</height>
172-
</rect>
173-
</property>
174-
<layout class="QGridLayout" name="gridLayout_4">
175-
<property name="margin">
176-
<number>3</number>
177-
</property>
178-
<property name="spacing">
179-
<number>0</number>
180-
</property>
181-
<item row="0" column="0">
182-
<widget class="QLabel" name="txtHelpText">
183-
<property name="sizePolicy">
184-
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
185-
<horstretch>0</horstretch>
186-
<verstretch>0</verstretch>
187-
</sizepolicy>
188-
</property>
189-
<property name="text">
190-
<string/>
191-
</property>
192-
<property name="textFormat">
193-
<enum>Qt::AutoText</enum>
194-
</property>
195-
<property name="alignment">
196-
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
197-
</property>
198-
<property name="wordWrap">
199-
<bool>true</bool>
200-
</property>
201-
<property name="openExternalLinks">
202-
<bool>false</bool>
203-
</property>
204-
<property name="textInteractionFlags">
205-
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
206-
</property>
207-
</widget>
208-
</item>
209-
</layout>
210-
</widget>
211156
</widget>
212157
</item>
213158
</layout>

0 commit comments

Comments
 (0)
Please sign in to comment.