Skip to content

Commit

Permalink
Make using recent expressions API simpler and add doxygen comment
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jul 7, 2016
1 parent 56a0af5 commit febcabb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
12 changes: 10 additions & 2 deletions python/gui/qgsexpressionbuilderwidget.sip
Expand Up @@ -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
*/
Expand Down
14 changes: 7 additions & 7 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -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() );

Expand All @@ -414,21 +414,21 @@ 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 );
node->removeRows( 0, node->rowCount() );
}

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 )
Expand Down
12 changes: 10 additions & 2 deletions src/gui/qgsexpressionbuilderwidget.h
Expand Up @@ -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
*/
Expand Down

0 comments on commit febcabb

Please sign in to comment.