Skip to content

Commit 08f8ca7

Browse files
committed
[FEATURE][style manager] import/export of symbols' tags
and favorite flag
1 parent a958c8a commit 08f8ca7

File tree

3 files changed

+91
-30
lines changed

3 files changed

+91
-30
lines changed

src/core/symbology-ng/qgsstyle.cpp

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,10 +1533,26 @@ bool QgsStyle::importXml( const QString& filename )
15331533
{
15341534
if ( e.tagName() == QLatin1String( "symbol" ) )
15351535
{
1536+
QString name = e.attribute( QStringLiteral( "name" ) );
1537+
QStringList tags;
1538+
if ( e.hasAttribute( QStringLiteral( "tags" ) ) )
1539+
{
1540+
tags = e.attribute( QStringLiteral( "tags" ) ).split( "," );
1541+
}
1542+
bool favorite = false;
1543+
if ( e.hasAttribute( QStringLiteral( "favorite" ) ) && e.attribute( QStringLiteral( "favorite" ) ) == "1" )
1544+
{
1545+
favorite = true;
1546+
}
1547+
15361548
QgsSymbol* symbol = QgsSymbolLayerUtils::loadSymbol( e );
15371549
if ( symbol )
15381550
{
1539-
symbols.insert( e.attribute( QStringLiteral( "name" ) ), symbol );
1551+
addSymbol( name, symbol );
1552+
if ( mCurrentDB )
1553+
{
1554+
saveSymbol( name, symbol, favorite, tags );
1555+
}
15401556
}
15411557
}
15421558
else
@@ -1550,12 +1566,12 @@ bool QgsStyle::importXml( const QString& filename )
15501566
{
15511567
// for the old version, use the utility function to solve @symbol@layer subsymbols
15521568
symbols = QgsSymbolLayerUtils::loadSymbols( symbolsElement );
1553-
}
15541569

1555-
// save the symbols with proper name
1556-
for ( QMap<QString, QgsSymbol*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
1557-
{
1558-
addSymbol( it.key(), it.value() );
1570+
// save the symbols with proper name
1571+
for ( QMap<QString, QgsSymbol*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
1572+
{
1573+
addSymbol( it.key(), it.value() );
1574+
}
15591575
}
15601576

15611577
// load color ramps
@@ -1565,10 +1581,26 @@ bool QgsStyle::importXml( const QString& filename )
15651581
{
15661582
if ( e.tagName() == QLatin1String( "colorramp" ) )
15671583
{
1584+
QString name = e.attribute( QStringLiteral( "name" ) );
1585+
QStringList tags;
1586+
if ( e.hasAttribute( QStringLiteral( "tags" ) ) )
1587+
{
1588+
tags = e.attribute( QStringLiteral( "tags" ) ).split( "," );
1589+
}
1590+
bool favorite = false;
1591+
if ( e.hasAttribute( QStringLiteral( "favorite" ) ) && e.attribute( QStringLiteral( "favorite" ) ) == "1" )
1592+
{
1593+
favorite = true;
1594+
}
1595+
15681596
QgsColorRamp* ramp = QgsSymbolLayerUtils::loadColorRamp( e );
15691597
if ( ramp )
15701598
{
1571-
addColorRamp( e.attribute( QStringLiteral( "name" ) ), ramp );
1599+
addColorRamp( name, ramp );
1600+
if ( mCurrentDB )
1601+
{
1602+
saveColorRamp( name, ramp, favorite, tags );
1603+
}
15721604
}
15731605
}
15741606
else

src/gui/symbology-ng/qgsstyleexportimportdialog.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle* style, QWidget
5656
this, SLOT( selectionChanged( const QItemSelection&, const QItemSelection& ) ) );
5757

5858
mTempStyle = new QgsStyle();
59+
mTempStyle->createMemoryDB();
60+
5961
// TODO validate
6062
mFileName = QLatin1String( "" );
6163
mProgressDlg = nullptr;
@@ -92,6 +94,7 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle* style, QWidget
9294
locationLineEdit->setHidden( true );
9395

9496
mFavorite->setHidden( true );
97+
mIgnoreXMLTags->setHidden( true );
9598

9699
pb = new QPushButton( tr( "Select by group" ) );
97100
buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
@@ -215,25 +218,44 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
215218
{
216219
QString symbolName;
217220
QgsSymbol* symbol;
221+
QStringList symbolTags;
222+
bool symbolFavorite;
218223
QgsColorRamp *ramp = nullptr;
219224
QModelIndex index;
220225
bool isSymbol = true;
221226
bool prompt = true;
222227
bool overwrite = true;
223-
QStringList tags;
224228

225-
// get the groupid when going for import
226-
if ( mDialogMode == Import )
227-
{
228-
// get the name the user entered
229-
tags = mSymbolTags->text().split( ',' );
230-
}
229+
QStringList importTags = mSymbolTags->text().split( ',' );
230+
231+
QStringList favoriteSymbols = src->symbolsOfFavorite( QgsStyle::SymbolEntity );
232+
QStringList favoriteColorramps = src->symbolsOfFavorite( QgsStyle::ColorrampEntity );
231233

232234
for ( int i = 0; i < selection->size(); ++i )
233235
{
234236
index = selection->at( i );
235237
symbolName = index.model()->data( index, 0 ).toString();
236238
symbol = src->symbol( symbolName );
239+
240+
if ( !mIgnoreXMLTags->isChecked() )
241+
{
242+
symbolTags = src->tagsOfSymbol( !symbol ? QgsStyle::ColorrampEntity : QgsStyle::SymbolEntity, symbolName );
243+
}
244+
else
245+
{
246+
symbolTags.clear();
247+
}
248+
249+
if ( mDialogMode == Import )
250+
{
251+
symbolTags << importTags;
252+
symbolFavorite = mFavorite->isChecked();
253+
}
254+
else
255+
{
256+
symbolFavorite = !symbol ? favoriteColorramps.contains( symbolName ) : favoriteSymbols.contains( symbolName );
257+
}
258+
237259
if ( !symbol )
238260
{
239261
isSymbol = false;
@@ -256,8 +278,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
256278
continue;
257279
case QMessageBox::Yes:
258280
dst->addSymbol( symbolName, symbol );
259-
if ( mDialogMode == Import )
260-
dst->saveSymbol( symbolName, symbol, mFavorite->isChecked(), tags );
281+
dst->saveSymbol( symbolName, symbol, symbolFavorite, symbolTags );
261282
continue;
262283
case QMessageBox::YesToAll:
263284
prompt = false;
@@ -273,8 +294,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
273294
if ( dst->symbolNames().contains( symbolName ) && overwrite )
274295
{
275296
dst->addSymbol( symbolName, symbol );
276-
if ( mDialogMode == Import )
277-
dst->saveSymbol( symbolName, symbol, mFavorite->isChecked(), tags );
297+
dst->saveSymbol( symbolName, symbol, symbolFavorite, symbolTags );
278298
}
279299
else if ( dst->symbolNames().contains( symbolName ) && !overwrite )
280300
{
@@ -283,8 +303,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
283303
else
284304
{
285305
dst->addSymbol( symbolName, symbol );
286-
if ( mDialogMode == Import )
287-
dst->saveSymbol( symbolName, symbol, mFavorite->isChecked(), tags );
306+
dst->saveSymbol( symbolName, symbol, symbolFavorite, symbolTags );
288307
}
289308
}
290309
else
@@ -303,8 +322,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
303322
continue;
304323
case QMessageBox::Yes:
305324
dst->addColorRamp( symbolName, ramp );
306-
if ( mDialogMode == Import )
307-
dst->saveColorRamp( symbolName, ramp, mFavorite->isChecked(), tags );
325+
dst->saveColorRamp( symbolName, ramp, symbolFavorite, symbolTags );
308326
continue;
309327
case QMessageBox::YesToAll:
310328
prompt = false;
@@ -320,8 +338,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
320338
if ( dst->colorRampNames().contains( symbolName ) && overwrite )
321339
{
322340
dst->addColorRamp( symbolName, ramp );
323-
if ( mDialogMode == Import )
324-
dst->saveColorRamp( symbolName, ramp, mFavorite->isChecked(), tags );
341+
dst->saveColorRamp( symbolName, ramp, symbolFavorite, symbolTags );
325342
}
326343
else if ( dst->colorRampNames().contains( symbolName ) && !overwrite )
327344
{
@@ -330,8 +347,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
330347
else
331348
{
332349
dst->addColorRamp( symbolName, ramp );
333-
if ( mDialogMode == Import )
334-
dst->saveColorRamp( symbolName, ramp, mFavorite->isChecked() , tags );
350+
dst->saveColorRamp( symbolName, ramp, symbolFavorite, symbolTags );
335351
}
336352
}
337353
}

src/ui/qgsstyleexportimportdialogbase.ui

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
</property>
4444
</widget>
4545
</item>
46-
<item row="3" column="0">
46+
<item row="4" column="0">
4747
<widget class="QLabel" name="tagLabel">
4848
<property name="text">
49-
<string>Tag(s)</string>
49+
<string>Additional tag(s)</string>
5050
</property>
5151
</widget>
5252
</item>
@@ -63,10 +63,23 @@
6363
</property>
6464
</widget>
6565
</item>
66-
<item row="3" column="1" colspan="2">
67-
<widget class="QLineEdit" name="mSymbolTags"/>
66+
<item row="3" column="0" colspan="3">
67+
<widget class="QCheckBox" name="mIgnoreXMLTags">
68+
<property name="sizePolicy">
69+
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
70+
<horstretch>0</horstretch>
71+
<verstretch>0</verstretch>
72+
</sizepolicy>
73+
</property>
74+
<property name="text">
75+
<string>Do not import embedded tags</string>
76+
</property>
77+
</widget>
6878
</item>
6979
<item row="4" column="1" colspan="2">
80+
<widget class="QLineEdit" name="mSymbolTags"/>
81+
</item>
82+
<item row="5" column="1" colspan="2">
7083
<widget class="QLabel" name="tagHintLabel">
7184
<property name="text">
7285
<string>Tip: separate multiple tags with commas</string>

0 commit comments

Comments
 (0)