Make using recent expressions API simpler and add doxygen comment

This commit is contained in:
Matthias Kuhn 2016-07-07 16:31:46 +02:00
parent 56a0af5bd8
commit febcabb0da
3 changed files with 27 additions and 11 deletions

View File

@ -141,9 +141,17 @@ class QgsExpressionBuilderWidget : QWidget
bool isExpressionValid();
void saveToRecent( const QString& key );
/**
* Adds the current expression to the given collection.
* By default it is saved to the collection "generic".
*/
void saveToRecent( const QString& collection = "generic" );
void loadRecent( const QString& key );
/**
* Loads the recent expressions from the given collection.
* By default it is loaded from the collection "generic".
*/
void loadRecent( const QString& collection = "generic" );
/** Create a new file in the function editor
*/

View File

@ -399,10 +399,10 @@ bool QgsExpressionBuilderWidget::isExpressionValid()
return mExpressionValid;
}
void QgsExpressionBuilderWidget::saveToRecent( const QString& key )
void QgsExpressionBuilderWidget::saveToRecent( const QString& collection )
{
QSettings settings;
QString location = QString( "/expressions/recent/%1" ).arg( key );
QString location = QString( "/expressions/recent/%1" ).arg( collection );
QStringList expressions = settings.value( location ).toStringList();
expressions.removeAll( this->expressionText() );
@ -414,13 +414,13 @@ void QgsExpressionBuilderWidget::saveToRecent( const QString& key )
}
settings.setValue( location, expressions );
this->loadRecent( key );
this->loadRecent( collection );
}
void QgsExpressionBuilderWidget::loadRecent( const QString& key )
void QgsExpressionBuilderWidget::loadRecent( const QString& collection )
{
mRecentKey = key;
QString name = tr( "Recent (%1)" ).arg( key );
mRecentKey = collection;
QString name = tr( "Recent (%1)" ).arg( collection );
if ( mExpressionGroups.contains( name ) )
{
QgsExpressionItem* node = mExpressionGroups.value( name );
@ -428,7 +428,7 @@ void QgsExpressionBuilderWidget::loadRecent( const QString& key )
}
QSettings settings;
QString location = QString( "/expressions/recent/%1" ).arg( key );
QString location = QString( "/expressions/recent/%1" ).arg( collection );
QStringList expressions = settings.value( location ).toStringList();
int i = 0;
Q_FOREACH ( const QString& expression, expressions )

View File

@ -186,9 +186,17 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
bool isExpressionValid();
void saveToRecent( const QString& key );
/**
* Adds the current expression to the given collection.
* By default it is saved to the collection "generic".
*/
void saveToRecent( const QString& collection = "generic" );
void loadRecent( const QString& key );
/**
* Loads the recent expressions from the given collection.
* By default it is loaded from the collection "generic".
*/
void loadRecent( const QString& collection = "generic" );
/** Create a new file in the function editor
*/