Skip to content

Commit febcabb

Browse files
committedJul 7, 2016
Make using recent expressions API simpler and add doxygen comment
1 parent 56a0af5 commit febcabb

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed
 

‎python/gui/qgsexpressionbuilderwidget.sip

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,17 @@ class QgsExpressionBuilderWidget : QWidget
141141

142142
bool isExpressionValid();
143143

144-
void saveToRecent( const QString& key );
144+
/**
145+
* Adds the current expression to the given collection.
146+
* By default it is saved to the collection "generic".
147+
*/
148+
void saveToRecent( const QString& collection = "generic" );
145149

146-
void loadRecent( const QString& key );
150+
/**
151+
* Loads the recent expressions from the given collection.
152+
* By default it is loaded from the collection "generic".
153+
*/
154+
void loadRecent( const QString& collection = "generic" );
147155

148156
/** Create a new file in the function editor
149157
*/

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ bool QgsExpressionBuilderWidget::isExpressionValid()
399399
return mExpressionValid;
400400
}
401401

402-
void QgsExpressionBuilderWidget::saveToRecent( const QString& key )
402+
void QgsExpressionBuilderWidget::saveToRecent( const QString& collection )
403403
{
404404
QSettings settings;
405-
QString location = QString( "/expressions/recent/%1" ).arg( key );
405+
QString location = QString( "/expressions/recent/%1" ).arg( collection );
406406
QStringList expressions = settings.value( location ).toStringList();
407407
expressions.removeAll( this->expressionText() );
408408

@@ -414,21 +414,21 @@ void QgsExpressionBuilderWidget::saveToRecent( const QString& key )
414414
}
415415

416416
settings.setValue( location, expressions );
417-
this->loadRecent( key );
417+
this->loadRecent( collection );
418418
}
419419

420-
void QgsExpressionBuilderWidget::loadRecent( const QString& key )
420+
void QgsExpressionBuilderWidget::loadRecent( const QString& collection )
421421
{
422-
mRecentKey = key;
423-
QString name = tr( "Recent (%1)" ).arg( key );
422+
mRecentKey = collection;
423+
QString name = tr( "Recent (%1)" ).arg( collection );
424424
if ( mExpressionGroups.contains( name ) )
425425
{
426426
QgsExpressionItem* node = mExpressionGroups.value( name );
427427
node->removeRows( 0, node->rowCount() );
428428
}
429429

430430
QSettings settings;
431-
QString location = QString( "/expressions/recent/%1" ).arg( key );
431+
QString location = QString( "/expressions/recent/%1" ).arg( collection );
432432
QStringList expressions = settings.value( location ).toStringList();
433433
int i = 0;
434434
Q_FOREACH ( const QString& expression, expressions )

‎src/gui/qgsexpressionbuilderwidget.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,17 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
186186

187187
bool isExpressionValid();
188188

189-
void saveToRecent( const QString& key );
189+
/**
190+
* Adds the current expression to the given collection.
191+
* By default it is saved to the collection "generic".
192+
*/
193+
void saveToRecent( const QString& collection = "generic" );
190194

191-
void loadRecent( const QString& key );
195+
/**
196+
* Loads the recent expressions from the given collection.
197+
* By default it is loaded from the collection "generic".
198+
*/
199+
void loadRecent( const QString& collection = "generic" );
192200

193201
/** Create a new file in the function editor
194202
*/

0 commit comments

Comments
 (0)
Please sign in to comment.