예제 #1
0
void QgsStyleV2::rename( StyleEntity type, int id, QString newName )
{
  char *query;
  switch ( type )
  {
    case SymbolEntity:
      query = sqlite3_mprintf( "UPDATE symbol SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    case GroupEntity:
      query = sqlite3_mprintf( "UPDATE symgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    case TagEntity:
      query = sqlite3_mprintf( "UPDATE tag SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    case ColorrampEntity:
      query = sqlite3_mprintf( "UPDATE colorramp SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    case SmartgroupEntity:
      query = sqlite3_mprintf( "UPDATE smartgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    default:
      QgsDebugMsg( "Invalid Style Entity indicated" );
      return;
  }
  if ( !runEmptyQuery( query ) )
    mErrorString = "Could not rename!";
}
예제 #2
0
void QgsStyleV2::remove( StyleEntity type, int id )
{
  char *query;
  switch ( type )
  {
    case SymbolEntity:
      query = sqlite3_mprintf( "DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d", id, id );
      break;
    case GroupEntity:
      query = getGroupRemoveQuery( id );
      break;
    case TagEntity:
      query = sqlite3_mprintf( "DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d", id, id );
      break;
    case ColorrampEntity:
      query = sqlite3_mprintf( "DELETE FROM colorramp WHERE id=%d", id );
      break;
    case SmartgroupEntity:
      query = sqlite3_mprintf( "DELETE FROM smartgroup WHERE id=%d", id );
      break;
    default:
      QgsDebugMsg( "Invalid Style Entity indicated" );
      return;
  }

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Could not delete entity!" );
  }
}
예제 #3
0
bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int groupid, QStringList tags )
{
  // TODO add support for groups and tags
  Q_UNUSED( tags );

  // insert it into the database
  QDomDocument doc( "dummy" );
  QDomElement rampEl = QgsSymbolLayerV2Utils::saveColorRamp( name, ramp, doc );
  if ( rampEl.isNull() )
  {
    QgsDebugMsg( "Couldn't convert color ramp to valid XML!" );
    return false;
  }

  QByteArray xmlArray;
  QTextStream stream( &xmlArray );
  rampEl.save( stream, 4 );
  char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
                                 name.toUtf8().constData(), xmlArray.constData(), groupid );

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't insert colorramp into the database!" );
    return false;
  }

  return true;
}
예제 #4
0
bool QgsStyle::saveColorRamp( const QString& name, QgsColorRamp* ramp, int groupid, const QStringList& tags )
{
  // insert it into the database
  QDomDocument doc( "dummy" );
  QDomElement rampEl = QgsSymbolLayerUtils::saveColorRamp( name, ramp, doc );
  if ( rampEl.isNull() )
  {
    QgsDebugMsg( "Couldn't convert color ramp to valid XML!" );
    return false;
  }

  QByteArray xmlArray;
  QTextStream stream( &xmlArray );
  stream.setCodec( "UTF-8" );
  rampEl.save( stream, 4 );
  char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
                                 name.toUtf8().constData(), xmlArray.constData(), groupid );

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't insert colorramp into the database!" );
    return false;
  }

  tagSymbol( ColorrampEntity, name, tags );

  return true;
}
예제 #5
0
bool QgsStyle::saveSymbol( const QString& name, QgsSymbol* symbol, int groupid, const QStringList& tags )
{
  // TODO add support for groups
  QDomDocument doc( "dummy" );
  QDomElement symEl = QgsSymbolLayerUtils::saveSymbol( name, symbol, doc );
  if ( symEl.isNull() )
  {
    QgsDebugMsg( "Couldn't convert symbol to valid XML!" );
    return false;
  }

  QByteArray xmlArray;
  QTextStream stream( &xmlArray );
  stream.setCodec( "UTF-8" );
  symEl.save( stream, 4 );
  char *query = sqlite3_mprintf( "INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
                                 name.toUtf8().constData(), xmlArray.constData(), groupid );

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't insert symbol into the database!" );
    return false;
  }

  tagSymbol( SymbolEntity, name, tags );

  emit symbolSaved( name, symbol );

  return true;
}
예제 #6
0
void QgsStyle::createTables()
{
  char *query = sqlite3_mprintf( "CREATE TABLE symbol("\
                                 "id INTEGER PRIMARY KEY,"\
                                 "name TEXT UNIQUE,"\
                                 "xml TEXT,"\
                                 "favorite INTEGER);"\
                                 "CREATE TABLE colorramp("\
                                 "id INTEGER PRIMARY KEY,"\
                                 "name TEXT UNIQUE,"\
                                 "xml TEXT,"\
                                 "favorite INTEGER);"\
                                 "CREATE TABLE tag("\
                                 "id INTEGER PRIMARY KEY,"\
                                 "name TEXT);"\
                                 "CREATE TABLE tagmap("\
                                 "tag_id INTEGER NOT NULL,"\
                                 "symbol_id INTEGER);"\
                                 "CREATE TABLE ctagmap("\
                                 "tag_id INTEGER NOT NULL,"\
                                 "colorramp_id INTEGER);"\
                                 "CREATE TABLE smartgroup("\
                                 "id INTEGER PRIMARY KEY,"\
                                 "name TEXT,"\
                                 "xml TEXT);" );
  runEmptyQuery( query );
}
예제 #7
0
bool QgsStyleV2::removeColorRamp( QString name )
{
  QgsVectorColorRampV2 *ramp = mColorRamps.take( name );
  if ( !ramp )
    return false;

  char *query = sqlite3_mprintf( "DELETE FROM colorramp WHERE name='%q'", name.toUtf8().constData() );
  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Couldn't remove color ramp from the database." );
    return false;
  }

  delete ramp;

  return true;
}
예제 #8
0
bool QgsStyle::group( StyleEntity type, const QString& name, int groupid )
{
  char *query;

  switch ( type )
  {
    case SymbolEntity:
      query = sqlite3_mprintf( "UPDATE symbol SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
      break;
    case ColorrampEntity:
      query = sqlite3_mprintf( "UPDATE colorramp SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
      break;

    default:
      QgsDebugMsg( "Wrong entity value. cannot apply group" );
      return false;
  }

  return runEmptyQuery( query );
}
예제 #9
0
void QgsStyle::remove( StyleEntity type, int id )
{
  bool groupRemoved = false;
  char *query;
  switch ( type )
  {
    case SymbolEntity:
      query = sqlite3_mprintf( "DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d", id, id );
      break;
    case ColorrampEntity:
      query = sqlite3_mprintf( "DELETE FROM colorramp WHERE id=%d", id );
      break;
    case TagEntity:
      query = sqlite3_mprintf( "DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d", id, id );
      groupRemoved = true;
      break;
    case SmartgroupEntity:
      query = sqlite3_mprintf( "DELETE FROM smartgroup WHERE id=%d", id );
      groupRemoved = true;
      break;
    default:
      QgsDebugMsg( "Invalid Style Entity indicated" );
      return;
  }

  if ( !runEmptyQuery( query ) )
  {
    QgsDebugMsg( "Could not delete entity!" );
  }
  else
  {
    if ( groupRemoved )
    {
      QSettings settings;
      settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), 0 );

      emit groupsModified();
    }
  }
}
예제 #10
0
void QgsStyle::rename( StyleEntity type, int id, const QString& newName )
{
  bool groupRenamed = false;
  char *query;
  switch ( type )
  {
    case SymbolEntity:
      query = sqlite3_mprintf( "UPDATE symbol SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    case ColorrampEntity:
      query = sqlite3_mprintf( "UPDATE colorramp SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      break;
    case TagEntity:
      query = sqlite3_mprintf( "UPDATE tag SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      groupRenamed = true;
      break;
    case SmartgroupEntity:
      query = sqlite3_mprintf( "UPDATE smartgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
      groupRenamed = true;
      break;
    default:
      QgsDebugMsg( "Invalid Style Entity indicated" );
      return;
  }
  if ( !runEmptyQuery( query ) )
  {
    mErrorString = QStringLiteral( "Could not rename!" );
  }
  else
  {
    if ( groupRenamed )
    {
      emit groupsModified();
    }
  }
}
예제 #11
0
bool QgsStyle::load( const QString& filename )
{
  mErrorString.clear();

  // Open the sqlite database
  if ( !openDB( filename ) )
  {
    mErrorString = "Unable to open database file specified";
    QgsDebugMsg( mErrorString );
    return false;
  }

  // Make sure there are no Null fields in parenting symbols ang groups
  char *query = sqlite3_mprintf( "UPDATE symbol SET groupid=0 WHERE groupid IS NULL;"
                                 "UPDATE colorramp SET groupid=0 WHERE groupid IS NULL;"
                                 "UPDATE symgroup SET parent=0 WHERE parent IS NULL;" );
  runEmptyQuery( query );

  // First create all the main symbols
  query = sqlite3_mprintf( "SELECT * FROM symbol" );

  sqlite3_stmt *ppStmt;
  int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
  while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  {
    QDomDocument doc;
    QString symbol_name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, SymbolName ) ) );
    QString xmlstring = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, SymbolXML ) ) );
    if ( !doc.setContent( xmlstring ) )
    {
      QgsDebugMsg( "Cannot open symbol " + symbol_name );
      continue;
    }

    QDomElement symElement = doc.documentElement();
    QgsSymbol *symbol = QgsSymbolLayerUtils::loadSymbol( symElement );
    if ( symbol )
      mSymbols.insert( symbol_name, symbol );
  }

  sqlite3_finalize( ppStmt );

  query = sqlite3_mprintf( "SELECT * FROM colorramp" );
  nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
  while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
  {
    QDomDocument doc;
    QString ramp_name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, ColorrampName ) ) );
    QString xmlstring = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, ColorrampXML ) ) );
    if ( !doc.setContent( xmlstring ) )
    {
      QgsDebugMsg( "Cannot open symbol " + ramp_name );
      continue;
    }
    QDomElement rampElement = doc.documentElement();
    QgsColorRamp *ramp = QgsSymbolLayerUtils::loadColorRamp( rampElement );
    if ( ramp )
      mColorRamps.insert( ramp_name, ramp );
  }

  mFileName = filename;
  return true;
}