mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Improve handling of favorites in QgsStyleModel and proxy model
Fixes favorite entities sometimes incorrectly filtered out
This commit is contained in:
parent
7757a5ae7a
commit
554d23b324
@ -182,7 +182,7 @@ takes responsibility for deleting the returned object.
|
||||
Returns count of color ramps
|
||||
%End
|
||||
|
||||
QStringList colorRampNames();
|
||||
QStringList colorRampNames() const;
|
||||
%Docstring
|
||||
Returns a list of names of color ramps
|
||||
%End
|
||||
@ -298,7 +298,7 @@ Returns a const pointer to a symbol (doesn't create new instance)
|
||||
Returns count of symbols in style
|
||||
%End
|
||||
|
||||
QStringList symbolNames();
|
||||
QStringList symbolNames() const;
|
||||
%Docstring
|
||||
Returns a list of names of symbols
|
||||
%End
|
||||
@ -315,6 +315,13 @@ Returns the DB id for the given tag name
|
||||
int smartgroupId( const QString &smartgroup );
|
||||
%Docstring
|
||||
Returns the DB id for the given smartgroup name
|
||||
%End
|
||||
|
||||
QStringList allNames( StyleEntity type ) const;
|
||||
%Docstring
|
||||
Returns a list of the names of all existing entities of the specified ``type``.
|
||||
|
||||
.. versionadded:: 3.10
|
||||
%End
|
||||
|
||||
QStringList symbolsOfFavorite( StyleEntity type ) const;
|
||||
@ -518,6 +525,14 @@ Returns the tags associated with the symbol
|
||||
:param symbol: is the name of the symbol or color ramp
|
||||
|
||||
:return: A QStringList of the tags that have been applied to that symbol/colorramp
|
||||
%End
|
||||
|
||||
bool isFavorite( StyleEntity type, const QString &name );
|
||||
%Docstring
|
||||
Returns ``True`` if the symbol with matching ``type`` and \name is
|
||||
marked as a favorite.
|
||||
|
||||
.. versionadded:: 3.10
|
||||
%End
|
||||
|
||||
bool symbolHasTag( StyleEntity type, const QString &symbol, const QString &tag );
|
||||
@ -541,7 +556,7 @@ Returns the tag name for the given id
|
||||
Returns the smart groups map with id as key and name as value
|
||||
%End
|
||||
|
||||
QStringList smartgroupNames();
|
||||
QStringList smartgroupNames() const;
|
||||
%Docstring
|
||||
Returns the smart groups list
|
||||
%End
|
||||
|
@ -37,6 +37,7 @@ within a QgsStyle database.
|
||||
TypeRole,
|
||||
TagRole,
|
||||
SymbolTypeRole,
|
||||
IsFavoriteRole,
|
||||
};
|
||||
|
||||
explicit QgsStyleModel( QgsStyle *style, QObject *parent /TransferThis/ = 0 );
|
||||
|
@ -85,6 +85,10 @@ void QgsStyle::clear()
|
||||
mCachedColorRampTags.clear();
|
||||
mCachedSymbolTags.clear();
|
||||
mCachedTextFormatTags.clear();
|
||||
|
||||
mCachedSymbolFavorites.clear();
|
||||
mCachedColorRampFavorites.clear();
|
||||
mCachedTextFormatFavorites.clear();
|
||||
}
|
||||
|
||||
bool QgsStyle::addSymbol( const QString &name, QgsSymbol *symbol, bool update )
|
||||
@ -135,6 +139,8 @@ bool QgsStyle::saveSymbol( const QString &name, QgsSymbol *symbol, bool favorite
|
||||
return false;
|
||||
}
|
||||
|
||||
mCachedSymbolFavorites[ name ] = favorite;
|
||||
|
||||
tagSymbol( SymbolEntity, name, tags );
|
||||
|
||||
emit symbolSaved( name, symbol );
|
||||
@ -169,6 +175,7 @@ bool QgsStyle::removeSymbol( const QString &name )
|
||||
if ( result )
|
||||
{
|
||||
mCachedSymbolTags.remove( name );
|
||||
mCachedSymbolFavorites.remove( name );
|
||||
emit symbolRemoved( name );
|
||||
}
|
||||
return result;
|
||||
@ -190,7 +197,7 @@ int QgsStyle::symbolCount()
|
||||
return mSymbols.count();
|
||||
}
|
||||
|
||||
QStringList QgsStyle::symbolNames()
|
||||
QStringList QgsStyle::symbolNames() const
|
||||
{
|
||||
return mSymbols.keys();
|
||||
}
|
||||
@ -265,6 +272,8 @@ bool QgsStyle::saveColorRamp( const QString &name, QgsColorRamp *ramp, bool favo
|
||||
return false;
|
||||
}
|
||||
|
||||
mCachedColorRampFavorites[ name ] = favorite;
|
||||
|
||||
tagSymbol( ColorrampEntity, name, tags );
|
||||
|
||||
emit rampAdded( name );
|
||||
@ -286,6 +295,7 @@ bool QgsStyle::removeColorRamp( const QString &name )
|
||||
}
|
||||
|
||||
mCachedColorRampTags.remove( name );
|
||||
mCachedColorRampFavorites.remove( name );
|
||||
|
||||
emit rampRemoved( name );
|
||||
|
||||
@ -308,7 +318,7 @@ int QgsStyle::colorRampCount()
|
||||
return mColorRamps.count();
|
||||
}
|
||||
|
||||
QStringList QgsStyle::colorRampNames()
|
||||
QStringList QgsStyle::colorRampNames() const
|
||||
{
|
||||
return mColorRamps.keys();
|
||||
}
|
||||
@ -565,6 +575,7 @@ bool QgsStyle::renameSymbol( const QString &oldName, const QString &newName )
|
||||
}
|
||||
|
||||
mCachedSymbolTags.remove( oldName );
|
||||
mCachedSymbolFavorites.remove( oldName );
|
||||
|
||||
const bool result = rename( SymbolEntity, symbolid, newName );
|
||||
if ( result )
|
||||
@ -587,6 +598,7 @@ bool QgsStyle::renameColorRamp( const QString &oldName, const QString &newName )
|
||||
|
||||
mColorRamps.insert( newName, ramp );
|
||||
mCachedColorRampTags.remove( oldName );
|
||||
mCachedColorRampFavorites.remove( oldName );
|
||||
|
||||
int rampid = 0;
|
||||
sqlite3_statement_unique_ptr statement;
|
||||
@ -628,6 +640,8 @@ bool QgsStyle::saveTextFormat( const QString &name, const QgsTextFormat &format,
|
||||
return false;
|
||||
}
|
||||
|
||||
mCachedTextFormatFavorites[ name ] = favorite;
|
||||
|
||||
tagSymbol( TextFormatEntity, name, tags );
|
||||
|
||||
emit textFormatAdded( name );
|
||||
@ -650,6 +664,7 @@ bool QgsStyle::removeTextFormat( const QString &name )
|
||||
}
|
||||
|
||||
mCachedTextFormatTags.remove( name );
|
||||
mCachedTextFormatFavorites.remove( name );
|
||||
|
||||
emit textFormatRemoved( name );
|
||||
|
||||
@ -671,6 +686,7 @@ bool QgsStyle::renameTextFormat( const QString &oldName, const QString &newName
|
||||
|
||||
mTextFormats.insert( newName, format );
|
||||
mCachedTextFormatTags.remove( oldName );
|
||||
mCachedTextFormatFavorites.remove( oldName );
|
||||
|
||||
int textFormatId = 0;
|
||||
sqlite3_statement_unique_ptr statement;
|
||||
@ -872,6 +888,9 @@ bool QgsStyle::rename( StyleEntity type, int id, const QString &newName )
|
||||
mCachedColorRampTags.clear();
|
||||
mCachedSymbolTags.clear();
|
||||
mCachedTextFormatTags.clear();
|
||||
mCachedSymbolFavorites.clear();
|
||||
mCachedColorRampFavorites.clear();
|
||||
mCachedTextFormatFavorites.clear();
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
@ -931,6 +950,9 @@ bool QgsStyle::remove( StyleEntity type, int id )
|
||||
mCachedColorRampTags.clear();
|
||||
mCachedSymbolTags.clear();
|
||||
mCachedTextFormatTags.clear();
|
||||
mCachedSymbolFavorites.clear();
|
||||
mCachedColorRampFavorites.clear();
|
||||
mCachedTextFormatFavorites.clear();
|
||||
|
||||
if ( groupRemoved )
|
||||
{
|
||||
@ -985,7 +1007,24 @@ bool QgsStyle::addFavorite( StyleEntity type, const QString &name )
|
||||
|
||||
const bool res = runEmptyQuery( query );
|
||||
if ( res )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case SymbolEntity:
|
||||
mCachedSymbolFavorites[ name ] = true;
|
||||
break;
|
||||
case ColorrampEntity:
|
||||
mCachedColorRampFavorites[ name ] = true;
|
||||
break;
|
||||
case TextFormatEntity:
|
||||
mCachedTextFormatFavorites[ name ] = true;
|
||||
break;
|
||||
case TagEntity:
|
||||
case SmartgroupEntity:
|
||||
break;
|
||||
}
|
||||
emit favoritedChanged( type, name, true );
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -1014,7 +1053,24 @@ bool QgsStyle::removeFavorite( StyleEntity type, const QString &name )
|
||||
|
||||
const bool res = runEmptyQuery( query );
|
||||
if ( res )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case SymbolEntity:
|
||||
mCachedSymbolFavorites[ name ] = false;
|
||||
break;
|
||||
case ColorrampEntity:
|
||||
mCachedColorRampFavorites[ name ] = false;
|
||||
break;
|
||||
case TextFormatEntity:
|
||||
mCachedTextFormatFavorites[ name ] = false;
|
||||
break;
|
||||
case TagEntity:
|
||||
case SmartgroupEntity:
|
||||
break;
|
||||
}
|
||||
emit favoritedChanged( type, name, false );
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -1482,6 +1538,71 @@ QStringList QgsStyle::tagsOfSymbol( StyleEntity type, const QString &symbol )
|
||||
return tagList;
|
||||
}
|
||||
|
||||
bool QgsStyle::isFavorite( QgsStyle::StyleEntity type, const QString &name )
|
||||
{
|
||||
if ( !mCurrentDB )
|
||||
{
|
||||
QgsDebugMsg( QStringLiteral( "Sorry! Cannot open database for getting the tags." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case SymbolEntity:
|
||||
if ( mCachedSymbolFavorites.contains( name ) )
|
||||
return mCachedSymbolFavorites.value( name );
|
||||
break;
|
||||
|
||||
case ColorrampEntity:
|
||||
if ( mCachedColorRampFavorites.contains( name ) )
|
||||
return mCachedColorRampFavorites.value( name );
|
||||
break;
|
||||
|
||||
case TextFormatEntity:
|
||||
if ( mCachedTextFormatFavorites.contains( name ) )
|
||||
return mCachedTextFormatFavorites.value( name );
|
||||
break;
|
||||
|
||||
case TagEntity:
|
||||
case SmartgroupEntity:
|
||||
return false;
|
||||
}
|
||||
|
||||
const QStringList names = allNames( type );
|
||||
if ( !names.contains( name ) )
|
||||
return false; // entity doesn't exist
|
||||
|
||||
// for efficiency, retrieve names of all favorited symbols and store them in cache
|
||||
const QStringList favorites = symbolsOfFavorite( type );
|
||||
bool res = false;
|
||||
for ( const QString &n : names )
|
||||
{
|
||||
const bool isFav = favorites.contains( n );
|
||||
if ( n == name )
|
||||
res = isFav;
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case SymbolEntity:
|
||||
mCachedSymbolFavorites[n] = isFav;
|
||||
break;
|
||||
|
||||
case ColorrampEntity:
|
||||
mCachedColorRampFavorites[ n ] = isFav;
|
||||
break;
|
||||
|
||||
case TextFormatEntity:
|
||||
mCachedTextFormatFavorites[ n ] = isFav;
|
||||
break;
|
||||
|
||||
case TagEntity:
|
||||
case SmartgroupEntity:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool QgsStyle::symbolHasTag( StyleEntity type, const QString &symbol, const QString &tag )
|
||||
{
|
||||
if ( !mCurrentDB )
|
||||
@ -1652,6 +1773,28 @@ int QgsStyle::smartgroupId( const QString &name )
|
||||
return getId( QStringLiteral( "smartgroup" ), name );
|
||||
}
|
||||
|
||||
QStringList QgsStyle::allNames( QgsStyle::StyleEntity type ) const
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case SymbolEntity:
|
||||
return symbolNames();
|
||||
|
||||
case ColorrampEntity:
|
||||
return colorRampNames();
|
||||
|
||||
case TextFormatEntity:
|
||||
return textFormatNames();
|
||||
|
||||
case TagEntity:
|
||||
return tags();
|
||||
|
||||
case SmartgroupEntity:
|
||||
return smartgroupNames();
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
int QgsStyle::addSmartgroup( const QString &name, const QString &op, const QgsSmartConditionMap &conditions )
|
||||
{
|
||||
return addSmartgroup( name, op, conditions.values( QStringLiteral( "tag" ) ),
|
||||
@ -1729,7 +1872,7 @@ QgsSymbolGroupMap QgsStyle::smartgroupsListMap()
|
||||
return groupNames;
|
||||
}
|
||||
|
||||
QStringList QgsStyle::smartgroupNames()
|
||||
QStringList QgsStyle::smartgroupNames() const
|
||||
{
|
||||
if ( !mCurrentDB )
|
||||
{
|
||||
|
@ -252,7 +252,7 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
int colorRampCount();
|
||||
|
||||
//! Returns a list of names of color ramps
|
||||
QStringList colorRampNames();
|
||||
QStringList colorRampNames() const;
|
||||
|
||||
//! Returns a const pointer to a symbol (doesn't create new instance)
|
||||
const QgsColorRamp *colorRampRef( const QString &name ) const;
|
||||
@ -348,7 +348,7 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
int symbolCount();
|
||||
|
||||
//! Returns a list of names of symbols
|
||||
QStringList symbolNames();
|
||||
QStringList symbolNames() const;
|
||||
|
||||
/**
|
||||
* Returns the id in the style database for the given symbol name
|
||||
@ -360,6 +360,12 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
//! Returns the DB id for the given smartgroup name
|
||||
int smartgroupId( const QString &smartgroup );
|
||||
|
||||
/**
|
||||
* Returns a list of the names of all existing entities of the specified \a type.
|
||||
* \since QGIS 3.10
|
||||
*/
|
||||
QStringList allNames( StyleEntity type ) const;
|
||||
|
||||
/**
|
||||
* Returns the symbol names which are flagged as favorite
|
||||
*
|
||||
@ -531,6 +537,14 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
*/
|
||||
QStringList tagsOfSymbol( StyleEntity type, const QString &symbol );
|
||||
|
||||
/**
|
||||
* Returns TRUE if the symbol with matching \a type and \name is
|
||||
* marked as a favorite.
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
*/
|
||||
bool isFavorite( StyleEntity type, const QString &name );
|
||||
|
||||
/**
|
||||
* Returns whether a given tag is associated with the symbol
|
||||
*
|
||||
@ -548,7 +562,7 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
QgsSymbolGroupMap smartgroupsListMap();
|
||||
|
||||
//! Returns the smart groups list
|
||||
QStringList smartgroupNames();
|
||||
QStringList smartgroupNames() const;
|
||||
|
||||
//! Returns the QgsSmartConditionMap for the given id
|
||||
QgsSmartConditionMap smartgroup( int id );
|
||||
@ -714,6 +728,10 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
QHash< QString, QStringList > mCachedColorRampTags;
|
||||
QHash< QString, QStringList > mCachedTextFormatTags;
|
||||
|
||||
QHash< QString, bool > mCachedSymbolFavorites;
|
||||
QHash< QString, bool > mCachedColorRampFavorites;
|
||||
QHash< QString, bool > mCachedTextFormatFavorites;
|
||||
|
||||
QString mErrorString;
|
||||
QString mFileName;
|
||||
|
||||
|
@ -250,6 +250,9 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
|
||||
case TagRole:
|
||||
return mStyle->tagsOfSymbol( entityType, name );
|
||||
|
||||
case IsFavoriteRole:
|
||||
return mStyle->isFavorite( entityType, name );
|
||||
|
||||
case SymbolTypeRole:
|
||||
{
|
||||
if ( entityType != QgsStyle::SymbolEntity )
|
||||
@ -720,7 +723,7 @@ bool QgsStyleProxyModel::filterAcceptsRow( int source_row, const QModelIndex &so
|
||||
if ( mSmartGroupId >= 0 && !mSmartGroupSymbolNames.contains( name ) )
|
||||
return false;
|
||||
|
||||
if ( mFavoritesOnly && !mFavoritedSymbolNames.contains( name ) )
|
||||
if ( mFavoritesOnly && !sourceModel()->data( index, QgsStyleModel::IsFavoriteRole ).toBool() )
|
||||
return false;
|
||||
|
||||
if ( !mFilterString.isEmpty() )
|
||||
@ -768,17 +771,6 @@ bool QgsStyleProxyModel::favoritesOnly() const
|
||||
void QgsStyleProxyModel::setFavoritesOnly( bool favoritesOnly )
|
||||
{
|
||||
mFavoritesOnly = favoritesOnly;
|
||||
|
||||
if ( mFavoritesOnly )
|
||||
{
|
||||
mFavoritedSymbolNames = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
|
||||
mFavoritedSymbolNames.append( mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity ) );
|
||||
mFavoritedSymbolNames.append( mStyle->symbolsOfFavorite( QgsStyle::TextFormatEntity ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
mFavoritedSymbolNames.clear();
|
||||
}
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
|
||||
TypeRole = Qt::UserRole + 1, //!< Style entity type, see QgsStyle::StyleEntity
|
||||
TagRole, //!< String list of tags
|
||||
SymbolTypeRole, //!< Symbol type (for symbol entities)
|
||||
IsFavoriteRole, //!< Whether entity is flagged as a favorite
|
||||
};
|
||||
|
||||
/**
|
||||
@ -311,7 +312,6 @@ class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
|
||||
QStringList mSmartGroupSymbolNames;
|
||||
|
||||
bool mFavoritesOnly = false;
|
||||
QStringList mFavoritedSymbolNames;
|
||||
|
||||
bool mEntityFilterEnabled = false;
|
||||
QgsStyle::StyleEntity mEntityFilter = QgsStyle::SymbolEntity;
|
||||
|
@ -62,6 +62,7 @@ class TestStyle : public QObject
|
||||
void cleanup() {}// will be called after every testfunction.
|
||||
// void initStyles();
|
||||
|
||||
void testCreateSymbols();
|
||||
void testCreateColorRamps();
|
||||
void testCreateTextFormats();
|
||||
void testLoadColorRamps();
|
||||
@ -122,6 +123,25 @@ void TestStyle::cleanupTestCase()
|
||||
}
|
||||
}
|
||||
|
||||
void TestStyle::testCreateSymbols()
|
||||
{
|
||||
// add some symbols to favorites
|
||||
QgsStyle s;
|
||||
s.createMemoryDatabase();
|
||||
|
||||
std::unique_ptr< QgsMarkerSymbol > sym1( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
|
||||
std::unique_ptr< QgsMarkerSymbol > sym2( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
|
||||
std::unique_ptr< QgsMarkerSymbol > sym3( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
|
||||
s.addSymbol( QStringLiteral( "symbolA" ), sym1.release(), true );
|
||||
s.addSymbol( QStringLiteral( "symbolB" ), sym2.release(), true );
|
||||
s.addSymbol( QStringLiteral( "symbolC" ), sym3.release(), true );
|
||||
|
||||
QCOMPARE( s.allNames( QgsStyle::SymbolEntity ),
|
||||
QStringList() << QStringLiteral( "symbolA" )
|
||||
<< QStringLiteral( "symbolB" )
|
||||
<< QStringLiteral( "symbolC" ) );
|
||||
}
|
||||
|
||||
bool TestStyle::imageCheck( QgsMapSettings &ms, const QString &testName )
|
||||
{
|
||||
QgsMultiRenderChecker checker;
|
||||
@ -175,6 +195,14 @@ void TestStyle::testCreateColorRamps()
|
||||
// continuous ramp
|
||||
QgsCptCityColorRamp *cc3Ramp = new QgsCptCityColorRamp( QStringLiteral( "grass/byr" ), QString() );
|
||||
QVERIFY( mStyle->addColorRamp( "test_cc3", cc3Ramp, true ) );
|
||||
|
||||
QCOMPARE( mStyle->allNames( QgsStyle::ColorrampEntity ), QStringList() << QStringLiteral( "test_cb1" )
|
||||
<< QStringLiteral( "test_cb2" )
|
||||
<< QStringLiteral( "test_cc1" )
|
||||
<< QStringLiteral( "test_cc2" )
|
||||
<< QStringLiteral( "test_cc3" )
|
||||
<< QStringLiteral( "test_gradient" )
|
||||
<< QStringLiteral( "test_random" ) );
|
||||
}
|
||||
|
||||
void TestStyle::testCreateTextFormats()
|
||||
@ -226,7 +254,8 @@ void TestStyle::testCreateTextFormats()
|
||||
QCOMPARE( style2.textFormat( QString( "test_format" ) ).color().name(), QStringLiteral( "#ffff00" ) );
|
||||
QCOMPARE( style2.textFormat( QString( "test_format2" ) ).color().name(), QStringLiteral( "#ffffff" ) );
|
||||
|
||||
|
||||
QCOMPARE( mStyle->allNames( QgsStyle::TextFormatEntity ), QStringList() << QStringLiteral( "test_format" )
|
||||
<< QStringLiteral( "test_format2" ) );
|
||||
}
|
||||
|
||||
void TestStyle::testLoadColorRamps()
|
||||
@ -306,6 +335,10 @@ void TestStyle::testFavorites()
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
|
||||
int count = favorites.count();
|
||||
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "AaaaaaaaaA" ) ) );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::TextFormatEntity, QStringLiteral( "AaaaaaaaaA" ) ) );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::ColorrampEntity, QStringLiteral( "AaaaaaaaaA" ) ) );
|
||||
|
||||
// add some symbols to favorites
|
||||
std::unique_ptr< QgsMarkerSymbol > sym1( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
|
||||
std::unique_ptr< QgsMarkerSymbol > sym2( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
|
||||
@ -314,11 +347,15 @@ void TestStyle::testFavorites()
|
||||
mStyle->saveSymbol( QStringLiteral( "symbolB" ), sym2.get(), false, QStringList() );
|
||||
mStyle->saveSymbol( QStringLiteral( "symbolC" ), sym3.get(), true, QStringList() );
|
||||
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolA" ) ) );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolB" ) ) );
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolC" ) ) );
|
||||
|
||||
// check for added symbols to favorites
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
|
||||
QCOMPARE( favorites.count(), count + 2 );
|
||||
QVERIFY( favorites.contains( "symbolA" ) );
|
||||
QVERIFY( favorites.contains( "symbolC" ) );
|
||||
QVERIFY( favorites.contains( QStringLiteral( "symbolA" ) ) );
|
||||
QVERIFY( favorites.contains( QStringLiteral( "symbolC" ) ) );
|
||||
|
||||
QSignalSpy favoriteChangedSpy( mStyle, &QgsStyle::favoritedChanged );
|
||||
|
||||
@ -329,6 +366,10 @@ void TestStyle::testFavorites()
|
||||
QCOMPARE( favoriteChangedSpy.at( 0 ).at( 1 ).toString(), QStringLiteral( "symbolA" ) );
|
||||
QCOMPARE( favoriteChangedSpy.at( 0 ).at( 2 ).toBool(), false );
|
||||
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolA" ) ) );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolB" ) ) );
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolC" ) ) );
|
||||
|
||||
// insure favorites updated after removal
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
|
||||
QCOMPARE( favorites.count(), count + 1 );
|
||||
@ -343,11 +384,17 @@ void TestStyle::testFavorites()
|
||||
QCOMPARE( favorites.count(), count + 2 );
|
||||
QVERIFY( favorites.contains( "symbolA" ) );
|
||||
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolA" ) ) );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolB" ) ) );
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::SymbolEntity, QStringLiteral( "symbolC" ) ) );
|
||||
|
||||
QgsGradientColorRamp *gradientRamp = new QgsGradientColorRamp( QColor( Qt::red ), QColor( Qt::blue ) );
|
||||
QVERIFY( mStyle->addColorRamp( "gradient_1", gradientRamp, true ) );
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
|
||||
QCOMPARE( favorites.count(), 0 );
|
||||
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::ColorrampEntity, QStringLiteral( "gradient_1" ) ) );
|
||||
|
||||
mStyle->addFavorite( QgsStyle::ColorrampEntity, QStringLiteral( "gradient_1" ) );
|
||||
QCOMPARE( favoriteChangedSpy.count(), 3 );
|
||||
QCOMPARE( favoriteChangedSpy.at( 2 ).at( 0 ).toInt(), static_cast< int >( QgsStyle::ColorrampEntity ) );
|
||||
@ -356,6 +403,7 @@ void TestStyle::testFavorites()
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
|
||||
QCOMPARE( favorites.count(), 1 );
|
||||
QVERIFY( favorites.contains( "gradient_1" ) );
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::ColorrampEntity, QStringLiteral( "gradient_1" ) ) );
|
||||
|
||||
mStyle->removeFavorite( QgsStyle::ColorrampEntity, QStringLiteral( "gradient_1" ) );
|
||||
QCOMPARE( favoriteChangedSpy.count(), 4 );
|
||||
@ -364,12 +412,14 @@ void TestStyle::testFavorites()
|
||||
QCOMPARE( favoriteChangedSpy.at( 3 ).at( 2 ).toBool(), false );
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity );
|
||||
QCOMPARE( favorites.count(), 0 );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::ColorrampEntity, QStringLiteral( "gradient_1" ) ) );
|
||||
|
||||
// text formats
|
||||
QgsTextFormat format1;
|
||||
QVERIFY( mStyle->addTextFormat( "format_1", format1, true ) );
|
||||
QVERIFY( mStyle->addTextFormat( QStringLiteral( "format_1" ), format1, true ) );
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::TextFormatEntity );
|
||||
QCOMPARE( favorites.count(), 0 );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::TextFormatEntity, QStringLiteral( "format_1" ) ) );
|
||||
|
||||
mStyle->addFavorite( QgsStyle::TextFormatEntity, QStringLiteral( "format_1" ) );
|
||||
QCOMPARE( favoriteChangedSpy.count(), 5 );
|
||||
@ -378,7 +428,8 @@ void TestStyle::testFavorites()
|
||||
QCOMPARE( favoriteChangedSpy.at( 4 ).at( 2 ).toBool(), true );
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::TextFormatEntity );
|
||||
QCOMPARE( favorites.count(), 1 );
|
||||
QVERIFY( favorites.contains( "format_1" ) );
|
||||
QVERIFY( favorites.contains( QStringLiteral( "format_1" ) ) );
|
||||
QVERIFY( mStyle->isFavorite( QgsStyle::TextFormatEntity, QStringLiteral( "format_1" ) ) );
|
||||
|
||||
mStyle->removeFavorite( QgsStyle::TextFormatEntity, QStringLiteral( "format_1" ) );
|
||||
QCOMPARE( favoriteChangedSpy.count(), 6 );
|
||||
@ -387,6 +438,7 @@ void TestStyle::testFavorites()
|
||||
QCOMPARE( favoriteChangedSpy.at( 5 ).at( 2 ).toBool(), false );
|
||||
favorites = mStyle->symbolsOfFavorite( QgsStyle::TextFormatEntity );
|
||||
QCOMPARE( favorites.count(), 0 );
|
||||
QVERIFY( !mStyle->isFavorite( QgsStyle::TextFormatEntity, QStringLiteral( "format_1" ) ) );
|
||||
}
|
||||
|
||||
void TestStyle::testTags()
|
||||
@ -407,6 +459,13 @@ void TestStyle::testTags()
|
||||
QCOMPARE( id, mStyle->tagId( "purple" ) );
|
||||
QCOMPARE( QStringLiteral( "purple" ), mStyle->tag( id ) );
|
||||
|
||||
QCOMPARE( mStyle->allNames( QgsStyle::TagEntity ),
|
||||
QStringList() << QStringLiteral( "red" )
|
||||
<< QStringLiteral( "starry" )
|
||||
<< QStringLiteral( "circle" )
|
||||
<< QStringLiteral( "blue" )
|
||||
<< QStringLiteral( "purple" ) );
|
||||
|
||||
// Cyrillic
|
||||
id = mStyle->addTag( QStringLiteral( "МЕТЕОР" ) );
|
||||
QCOMPARE( id, mStyle->tagId( "МЕТЕОР" ) );
|
||||
@ -726,6 +785,9 @@ void TestStyle::testSmartGroup()
|
||||
QCOMPARE( style.smartgroupId( QStringLiteral( "mine" ) ), 1 );
|
||||
QCOMPARE( groupModifiedSpy.count(), 1 );
|
||||
|
||||
QCOMPARE( style.allNames( QgsStyle::SmartgroupEntity ),
|
||||
QStringList() << QStringLiteral( "mine" ) );
|
||||
|
||||
QCOMPARE( style.symbolsOfSmartgroup( QgsStyle::SymbolEntity, 1 ), QStringList() << QStringLiteral( "symbolA" ) );
|
||||
QCOMPARE( style.symbolsOfSmartgroup( QgsStyle::ColorrampEntity, 1 ), QStringList() << QStringLiteral( "ramp a" ) );
|
||||
QCOMPARE( style.symbolsOfSmartgroup( QgsStyle::TextFormatEntity, 1 ), QStringList() << QStringLiteral( "format a" ) );
|
||||
|
@ -74,6 +74,7 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
symbol_C.setColor(QColor(10, 255, 10))
|
||||
self.assertTrue(style.addSymbol('C', symbol_C, True))
|
||||
style.tagSymbol(QgsStyle.SymbolEntity, 'C', ['tag 3'])
|
||||
style.addFavorite(QgsStyle.SymbolEntity, 'C')
|
||||
symbol_C = createMarkerSymbol()
|
||||
symbol_C.setColor(QColor(10, 255, 10))
|
||||
self.assertTrue(style.addSymbol(' ----c/- ', symbol_C, True))
|
||||
@ -125,6 +126,12 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.TypeRole), QgsStyle.SymbolEntity)
|
||||
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.TypeRole), QgsStyle.SymbolEntity)
|
||||
|
||||
self.assertEqual(model.data(model.index(0, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(2, 0), QgsStyleModel.IsFavoriteRole), True)
|
||||
self.assertEqual(model.data(model.index(3, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
|
||||
def test_style_with_ramps(self):
|
||||
style = QgsStyle()
|
||||
style.createMemoryDatabase()
|
||||
@ -141,6 +148,7 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
symbol_C = QgsLimitedRandomColorRamp()
|
||||
self.assertTrue(style.addColorRamp('C', symbol_C, True))
|
||||
style.tagSymbol(QgsStyle.ColorrampEntity, 'C', ['tag 3'])
|
||||
style.addFavorite(QgsStyle.ColorrampEntity, 'C')
|
||||
symbol_C = QgsLimitedRandomColorRamp()
|
||||
self.assertTrue(style.addColorRamp(' ----c/- ', symbol_C, True))
|
||||
|
||||
@ -182,6 +190,12 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.TypeRole), QgsStyle.ColorrampEntity)
|
||||
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.TypeRole), QgsStyle.ColorrampEntity)
|
||||
|
||||
self.assertEqual(model.data(model.index(0, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(2, 0), QgsStyleModel.IsFavoriteRole), True)
|
||||
self.assertEqual(model.data(model.index(3, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
|
||||
def test_style_with_text_formats(self):
|
||||
style = QgsStyle()
|
||||
style.createMemoryDatabase()
|
||||
@ -198,6 +212,7 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
format_C = QgsTextFormat()
|
||||
self.assertTrue(style.addTextFormat('C', format_C, True))
|
||||
style.tagSymbol(QgsStyle.TextFormatEntity, 'C', ['tag 3'])
|
||||
style.addFavorite(QgsStyle.TextFormatEntity, 'C')
|
||||
format_C = QgsTextFormat()
|
||||
self.assertTrue(style.addTextFormat(' ----c/- ', format_C, True))
|
||||
|
||||
@ -239,6 +254,12 @@ class TestQgsStyleModel(unittest.TestCase):
|
||||
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.TypeRole), QgsStyle.TextFormatEntity)
|
||||
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.TypeRole), QgsStyle.TextFormatEntity)
|
||||
|
||||
self.assertEqual(model.data(model.index(0, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(2, 0), QgsStyleModel.IsFavoriteRole), True)
|
||||
self.assertEqual(model.data(model.index(3, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.IsFavoriteRole), False)
|
||||
|
||||
def test_mixed_style(self):
|
||||
"""
|
||||
Test style with both symbols and ramps
|
||||
|
Loading…
x
Reference in New Issue
Block a user