mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	added functions to QgsStyleV2 for getting groups by id
This commit is contained in:
		
							parent
							
								
									17ed9d15fa
								
							
						
					
					
						commit
						95e571c3f8
					
				@ -127,6 +127,8 @@ class QgsStyleV2 : QObject
 | 
			
		||||
    int symbolId( const QString& name );
 | 
			
		||||
    //! return the DB id for the given group name
 | 
			
		||||
    int groupId( const QString& group );
 | 
			
		||||
    //! return the group name for the given DB id
 | 
			
		||||
    QString groupName( int groupId ) const;
 | 
			
		||||
    //! return the DB id for the given tag name
 | 
			
		||||
    int tagId( const QString& tag );
 | 
			
		||||
    //! return the DB id for the given smartgroup name
 | 
			
		||||
@ -135,6 +137,9 @@ class QgsStyleV2 : QObject
 | 
			
		||||
    //! return the all the groups in the style
 | 
			
		||||
    QStringList groupNames();
 | 
			
		||||
 | 
			
		||||
    //! return the ids of all the groups in the style
 | 
			
		||||
    QList<int> groupIds() const;
 | 
			
		||||
 | 
			
		||||
    //! returns the symbolnames of a given groupid
 | 
			
		||||
    /*!
 | 
			
		||||
     *  \param type is either SymbolEntity or ColorampEntity
 | 
			
		||||
@ -270,6 +275,9 @@ class QgsStyleV2 : QObject
 | 
			
		||||
    //! gets the id from the table for the given name from the database, 0 if not found
 | 
			
		||||
    int getId( const QString& table, const QString& name );
 | 
			
		||||
 | 
			
		||||
    //! gets the name from the table for the given id from the database, empty if not found
 | 
			
		||||
    QString getName( const QString& table, int id ) const;
 | 
			
		||||
 | 
			
		||||
    //! updates the properties of an existing symbol/colorramp
 | 
			
		||||
    /*!
 | 
			
		||||
     *  \note This should not be called separately, only called through addSymbol or addColorRamp
 | 
			
		||||
 | 
			
		||||
@ -475,6 +475,20 @@ QStringList QgsStyleV2::groupNames()
 | 
			
		||||
  return groupNames;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<int> QgsStyleV2::groupIds() const
 | 
			
		||||
{
 | 
			
		||||
  QList<int> groupIds;
 | 
			
		||||
  sqlite3_stmt *ppStmt;
 | 
			
		||||
  const char *query = "SELECT * FROM symgroup";
 | 
			
		||||
  int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
 | 
			
		||||
  while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
 | 
			
		||||
  {
 | 
			
		||||
    groupIds << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, SymgroupId ) ) ).toInt();
 | 
			
		||||
  }
 | 
			
		||||
  sqlite3_finalize( ppStmt );
 | 
			
		||||
  return groupIds;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsSymbolGroupMap QgsStyleV2::childGroupNames( const QString& parent )
 | 
			
		||||
{
 | 
			
		||||
  // get the name list from the sqlite database and return as a QStringList
 | 
			
		||||
@ -947,6 +961,24 @@ int QgsStyleV2::getId( const QString& table, const QString& name )
 | 
			
		||||
  return id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsStyleV2::getName( const QString& table, int id ) const
 | 
			
		||||
{
 | 
			
		||||
  char *query = sqlite3_mprintf( "SELECT name FROM %q WHERE id='%q'", table.toUtf8().constData(), QString::number( id ).toUtf8().constData() );
 | 
			
		||||
 | 
			
		||||
  sqlite3_stmt *ppStmt;
 | 
			
		||||
  int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, nullptr );
 | 
			
		||||
 | 
			
		||||
  QString name;
 | 
			
		||||
  if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
 | 
			
		||||
  {
 | 
			
		||||
    name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( ppStmt, 0 ) ) );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  sqlite3_finalize( ppStmt );
 | 
			
		||||
 | 
			
		||||
  return name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int QgsStyleV2::symbolId( const QString& name )
 | 
			
		||||
{
 | 
			
		||||
  return getId( "symbol", name );
 | 
			
		||||
@ -962,6 +994,11 @@ int QgsStyleV2::groupId( const QString& name )
 | 
			
		||||
  return getId( "symgroup", name );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsStyleV2::groupName( int groupId ) const
 | 
			
		||||
{
 | 
			
		||||
  return getName( "symgroup", groupId );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int QgsStyleV2::tagId( const QString& name )
 | 
			
		||||
{
 | 
			
		||||
  return getId( "tag", name );
 | 
			
		||||
 | 
			
		||||
@ -190,6 +190,8 @@ class CORE_EXPORT QgsStyleV2 : public QObject
 | 
			
		||||
    int symbolId( const QString& name );
 | 
			
		||||
    //! return the DB id for the given group name
 | 
			
		||||
    int groupId( const QString& group );
 | 
			
		||||
    //! return the group name for the given DB id
 | 
			
		||||
    QString groupName( int groupId ) const;
 | 
			
		||||
    //! return the DB id for the given tag name
 | 
			
		||||
    int tagId( const QString& tag );
 | 
			
		||||
    //! return the DB id for the given smartgroup name
 | 
			
		||||
@ -198,6 +200,9 @@ class CORE_EXPORT QgsStyleV2 : public QObject
 | 
			
		||||
    //! return the all the groups in the style
 | 
			
		||||
    QStringList groupNames();
 | 
			
		||||
 | 
			
		||||
    //! return the ids of all the groups in the style
 | 
			
		||||
    QList<int> groupIds() const;
 | 
			
		||||
 | 
			
		||||
    //! returns the symbolnames of a given groupid
 | 
			
		||||
    /*!
 | 
			
		||||
     *  \param type is either SymbolEntity or ColorampEntity
 | 
			
		||||
@ -344,6 +349,9 @@ class CORE_EXPORT QgsStyleV2 : public QObject
 | 
			
		||||
    //! gets the id from the table for the given name from the database, 0 if not found
 | 
			
		||||
    int getId( const QString& table, const QString& name );
 | 
			
		||||
 | 
			
		||||
    //! gets the name from the table for the given id from the database, empty if not found
 | 
			
		||||
    QString getName( const QString& table, int id ) const;
 | 
			
		||||
 | 
			
		||||
    //! updates the properties of an existing symbol/colorramp
 | 
			
		||||
    /*!
 | 
			
		||||
     *  \note This should not be called separately, only called through addSymbol or addColorRamp
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user