diff --git a/python/core/symbology-ng/qgsstylev2.sip b/python/core/symbology-ng/qgsstylev2.sip index db9debe4199..fb8901021f8 100644 --- a/python/core/symbology-ng/qgsstylev2.sip +++ b/python/core/symbology-ng/qgsstylev2.sip @@ -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 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 diff --git a/src/core/symbology-ng/qgsstylev2.cpp b/src/core/symbology-ng/qgsstylev2.cpp index d6893ab8ee2..d489783383b 100644 --- a/src/core/symbology-ng/qgsstylev2.cpp +++ b/src/core/symbology-ng/qgsstylev2.cpp @@ -475,6 +475,20 @@ QStringList QgsStyleV2::groupNames() return groupNames; } +QList QgsStyleV2::groupIds() const +{ + QList 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 ); diff --git a/src/core/symbology-ng/qgsstylev2.h b/src/core/symbology-ng/qgsstylev2.h index b382f8e154c..76cdb61e726 100644 --- a/src/core/symbology-ng/qgsstylev2.h +++ b/src/core/symbology-ng/qgsstylev2.h @@ -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 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