Exemple #1
0
bool QgsStyle::tagSymbol( StyleEntity type, const QString& symbol, const QStringList& tags )
{
  if ( !mCurrentDB )
  {
    QgsDebugMsg( "Sorry! Cannot open database to tag." );
    return false;
  }

  int symbolid = type == SymbolEntity ? symbolId( symbol ) : colorrampId( symbol );
  if ( !symbolid )
  {
    QgsDebugMsg( "No such symbol for tagging in database: " + symbol );
    return false;
  }

  QString tag;
  Q_FOREACH ( const QString &t, tags )
  {
    tag = t.trimmed();
    if ( tag != "" )
    {
      // sql: gets the id of the tag if present or insert the tag and get the id of the tag
      char *query = sqlite3_mprintf( "SELECT id FROM tag WHERE LOWER(name)='%q'", tag.toUtf8().toLower().constData() );

      sqlite3_stmt *ppStmt;
      int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );

      int tagid;
      if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
      {
        tagid = sqlite3_column_int( ppStmt, 0 );
      }
      else
      {
        tagid = addTag( tag );
      }

      sqlite3_finalize( ppStmt );

      // Now map the tag to the symbol if it's not already tagged
      if ( !symbolHasTag( type, symbol, tag ) )
      {
        query = type == SymbolEntity
                ? sqlite3_mprintf( "INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
                : sqlite3_mprintf( "INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );

        char *zErr = nullptr;
        nErr = sqlite3_exec( mCurrentDB, query, nullptr, nullptr, &zErr );
        if ( nErr )
        {
          QgsDebugMsg( zErr );
        }
      }
    }
  }
Exemple #2
0
bool QgsStyleV2::tagSymbol( StyleEntity type, QString symbol, QStringList tags )
{
  if ( !mCurrentDB )
  {
    QgsDebugMsg( "Sorry! Cannot open database to tag." );
    return false;
  }

  int symbolid = type == SymbolEntity ? symbolId( symbol ) : colorrampId( symbol );
  if ( !symbolid )
  {
    QgsDebugMsg( "No such symbol for tagging in database: " + symbol );
    return false;
  }


  foreach ( const QString &tag, tags )
  {
    // sql: gets the id of the tag if present or insert the tag and get the id of the tag
    char *query = sqlite3_mprintf( "SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );

    sqlite3_stmt *ppStmt;
    int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );

    int tagid;
    if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
    {
      tagid = sqlite3_column_int( ppStmt, 0 );
    }
    else
    {
      tagid = addTag( tag );
    }

    sqlite3_finalize( ppStmt );

    // Now map the tag to the symbol
    query = type == SymbolEntity
            ? sqlite3_mprintf( "INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
            : sqlite3_mprintf( "INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );

    char *zErr = 0;
    nErr = sqlite3_exec( mCurrentDB, query, NULL, NULL, &zErr );
    if ( nErr )
    {
      QgsDebugMsg( zErr );
    }
  }