Skip to content

Commit

Permalink
added searching of colorramps in style manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunmozhi committed Feb 16, 2013
1 parent f22c62a commit 6a2bd62
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
8 changes: 7 additions & 1 deletion python/core/symbology-ng/qgsstylev2.sip
Expand Up @@ -218,7 +218,13 @@ class QgsStyleV2
QString fileName();

//! return the names of the symbols which have a matching 'substring' in its defintion
QStringList findSymbols( QString qword );
/*!
* \param type is either SymbolEntity or ColorrampEntity
* \param qword is the query string to search the symbols or colorramps.
* \return A QStringList of the matched symbols or colorramps
* */
QStringList findSymbols( StyleEntity type, QString qword );


//! return the tags associated with the symbol
/*!
Expand Down
21 changes: 16 additions & 5 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -744,15 +744,17 @@ bool QgsStyleV2::group( StyleEntity type, QString name, int groupid )
return runEmptyQuery( query );
}

QStringList QgsStyleV2::findSymbols( QString qword )
QStringList QgsStyleV2::findSymbols( StyleEntity type, QString qword )
{
if ( !mCurrentDB )
{
QgsDebugMsg( "Sorry! Cannot open database to search" );
return QStringList();
}

char *query = sqlite3_mprintf( "SELECT name FROM symbol WHERE xml LIKE '%%%q%%'", qword.toUtf8().constData() );
QString item = ( type == SymbolEntity ) ? "symbol" : "colorramp";
char *query = sqlite3_mprintf( "SELECT name FROM %q WHERE xml LIKE '%%%q%%'",
item.toUtf8().constData(), qword.toUtf8().constData() );

sqlite3_stmt *ppStmt;
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
Expand All @@ -765,7 +767,6 @@ QStringList QgsStyleV2::findSymbols( QString qword )

sqlite3_finalize( ppStmt );


query = sqlite3_mprintf( "SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );

Expand All @@ -780,7 +781,16 @@ QStringList QgsStyleV2::findSymbols( QString qword )

QString dummy = tagids.join( ", " );

query = sqlite3_mprintf( "SELECT symbol_id FROM tagmap WHERE tag_id IN (%q)", dummy.toUtf8().constData() );
if ( type == SymbolEntity )
{
query = sqlite3_mprintf( "SELECT symbol_id FROM tagmap WHERE tag_id IN (%q)",
dummy.toUtf8().constData() );
}
else
{
query = sqlite3_mprintf( "SELECT colorramp_id FROM ctagmap WHERE tag_id IN (%q)",
dummy.toUtf8().constData() );
}
nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );

QStringList symbolids;
Expand All @@ -793,7 +803,8 @@ QStringList QgsStyleV2::findSymbols( QString qword )


dummy = symbolids.join( ", " );
query = sqlite3_mprintf( "SELECT name FROM symbol WHERE id IN (%q)", dummy.toUtf8().constData() );
query = sqlite3_mprintf( "SELECT name FROM %q WHERE id IN (%q)",
item.toUtf8().constData(), dummy.toUtf8().constData() );
nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
Expand Down
7 changes: 6 additions & 1 deletion src/core/symbology-ng/qgsstylev2.h
Expand Up @@ -278,7 +278,12 @@ class CORE_EXPORT QgsStyleV2
QString fileName() { return mFileName; }

//! return the names of the symbols which have a matching 'substring' in its defintion
QStringList findSymbols( QString qword );
/*!
* \param type is either SymbolEntity or ColorrampEntity
* \param qword is the query string to search the symbols or colorramps.
* \return A QStringList of the matched symbols or colorramps
* */
QStringList findSymbols( StyleEntity type, QString qword );

//! return the tags associated with the symbol
/*!
Expand Down
13 changes: 11 additions & 2 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -1124,8 +1124,17 @@ void QgsStyleV2ManagerDialog::setSymbolsChecked( QStringList symbols )

void QgsStyleV2ManagerDialog::filterSymbols( QString qword )
{
QStringList symbols = mStyle->findSymbols( qword );
populateSymbols( symbols );
QStringList items;
if ( currentItemType() == 3 )
{
items = mStyle->findSymbols( QgsStyleV2::ColorrampEntity, qword );
populateColorRamps( items );
}
else
{
items = mStyle->findSymbols( QgsStyleV2::SymbolEntity, qword );
populateSymbols( items );
}
}

void QgsStyleV2ManagerDialog::tagsChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -103,7 +103,7 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
void populateSymbols( QStringList symbolNames, bool checkable = false );

//! populate list view with color ramps
void populateColorRamps( QStringList colorRamps, bool check );
void populateColorRamps( QStringList colorRamps, bool checkable = false );

int currentItemType();
QString currentItemName();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgssymbolslistwidget.cpp
Expand Up @@ -357,6 +357,6 @@ void QgsSymbolsListWidget::on_groupsCombo_currentIndexChanged( int index )

void QgsSymbolsListWidget::on_groupsCombo_editTextChanged( const QString &text )
{
QStringList symbols = mStyle->findSymbols( text );
QStringList symbols = mStyle->findSymbols( QgsStyleV2::SymbolEntity, text );
populateSymbols( symbols );
}

0 comments on commit 6a2bd62

Please sign in to comment.