Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE][style manager] import/export of symbols' tags
and favorite flag
  • Loading branch information
nirvn committed Nov 20, 2016
1 parent a958c8a commit 08f8ca7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 30 deletions.
46 changes: 39 additions & 7 deletions src/core/symbology-ng/qgsstyle.cpp
Expand Up @@ -1533,10 +1533,26 @@ bool QgsStyle::importXml( const QString& filename )
{
if ( e.tagName() == QLatin1String( "symbol" ) )
{
QString name = e.attribute( QStringLiteral( "name" ) );
QStringList tags;
if ( e.hasAttribute( QStringLiteral( "tags" ) ) )
{
tags = e.attribute( QStringLiteral( "tags" ) ).split( "," );
}
bool favorite = false;
if ( e.hasAttribute( QStringLiteral( "favorite" ) ) && e.attribute( QStringLiteral( "favorite" ) ) == "1" )
{
favorite = true;
}

QgsSymbol* symbol = QgsSymbolLayerUtils::loadSymbol( e );
if ( symbol )
{
symbols.insert( e.attribute( QStringLiteral( "name" ) ), symbol );
addSymbol( name, symbol );
if ( mCurrentDB )
{
saveSymbol( name, symbol, favorite, tags );
}
}
}
else
Expand All @@ -1550,12 +1566,12 @@ bool QgsStyle::importXml( const QString& filename )
{
// for the old version, use the utility function to solve @symbol@layer subsymbols
symbols = QgsSymbolLayerUtils::loadSymbols( symbolsElement );
}

// save the symbols with proper name
for ( QMap<QString, QgsSymbol*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
{
addSymbol( it.key(), it.value() );
// save the symbols with proper name
for ( QMap<QString, QgsSymbol*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
{
addSymbol( it.key(), it.value() );
}
}

// load color ramps
Expand All @@ -1565,10 +1581,26 @@ bool QgsStyle::importXml( const QString& filename )
{
if ( e.tagName() == QLatin1String( "colorramp" ) )
{
QString name = e.attribute( QStringLiteral( "name" ) );
QStringList tags;
if ( e.hasAttribute( QStringLiteral( "tags" ) ) )
{
tags = e.attribute( QStringLiteral( "tags" ) ).split( "," );
}
bool favorite = false;
if ( e.hasAttribute( QStringLiteral( "favorite" ) ) && e.attribute( QStringLiteral( "favorite" ) ) == "1" )
{
favorite = true;
}

QgsColorRamp* ramp = QgsSymbolLayerUtils::loadColorRamp( e );
if ( ramp )
{
addColorRamp( e.attribute( QStringLiteral( "name" ) ), ramp );
addColorRamp( name, ramp );
if ( mCurrentDB )
{
saveColorRamp( name, ramp, favorite, tags );
}
}
}
else
Expand Down
54 changes: 35 additions & 19 deletions src/gui/symbology-ng/qgsstyleexportimportdialog.cpp
Expand Up @@ -56,6 +56,8 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle* style, QWidget
this, SLOT( selectionChanged( const QItemSelection&, const QItemSelection& ) ) );

mTempStyle = new QgsStyle();
mTempStyle->createMemoryDB();

// TODO validate
mFileName = QLatin1String( "" );
mProgressDlg = nullptr;
Expand Down Expand Up @@ -92,6 +94,7 @@ QgsStyleExportImportDialog::QgsStyleExportImportDialog( QgsStyle* style, QWidget
locationLineEdit->setHidden( true );

mFavorite->setHidden( true );
mIgnoreXMLTags->setHidden( true );

pb = new QPushButton( tr( "Select by group" ) );
buttonBox->addButton( pb, QDialogButtonBox::ActionRole );
Expand Down Expand Up @@ -215,25 +218,44 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
{
QString symbolName;
QgsSymbol* symbol;
QStringList symbolTags;
bool symbolFavorite;
QgsColorRamp *ramp = nullptr;
QModelIndex index;
bool isSymbol = true;
bool prompt = true;
bool overwrite = true;
QStringList tags;

// get the groupid when going for import
if ( mDialogMode == Import )
{
// get the name the user entered
tags = mSymbolTags->text().split( ',' );
}
QStringList importTags = mSymbolTags->text().split( ',' );

QStringList favoriteSymbols = src->symbolsOfFavorite( QgsStyle::SymbolEntity );
QStringList favoriteColorramps = src->symbolsOfFavorite( QgsStyle::ColorrampEntity );

for ( int i = 0; i < selection->size(); ++i )
{
index = selection->at( i );
symbolName = index.model()->data( index, 0 ).toString();
symbol = src->symbol( symbolName );

if ( !mIgnoreXMLTags->isChecked() )
{
symbolTags = src->tagsOfSymbol( !symbol ? QgsStyle::ColorrampEntity : QgsStyle::SymbolEntity, symbolName );
}
else
{
symbolTags.clear();
}

if ( mDialogMode == Import )
{
symbolTags << importTags;
symbolFavorite = mFavorite->isChecked();
}
else
{
symbolFavorite = !symbol ? favoriteColorramps.contains( symbolName ) : favoriteSymbols.contains( symbolName );
}

if ( !symbol )
{
isSymbol = false;
Expand All @@ -256,8 +278,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
continue;
case QMessageBox::Yes:
dst->addSymbol( symbolName, symbol );
if ( mDialogMode == Import )
dst->saveSymbol( symbolName, symbol, mFavorite->isChecked(), tags );
dst->saveSymbol( symbolName, symbol, symbolFavorite, symbolTags );
continue;
case QMessageBox::YesToAll:
prompt = false;
Expand All @@ -273,8 +294,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
if ( dst->symbolNames().contains( symbolName ) && overwrite )
{
dst->addSymbol( symbolName, symbol );
if ( mDialogMode == Import )
dst->saveSymbol( symbolName, symbol, mFavorite->isChecked(), tags );
dst->saveSymbol( symbolName, symbol, symbolFavorite, symbolTags );
}
else if ( dst->symbolNames().contains( symbolName ) && !overwrite )
{
Expand All @@ -283,8 +303,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
else
{
dst->addSymbol( symbolName, symbol );
if ( mDialogMode == Import )
dst->saveSymbol( symbolName, symbol, mFavorite->isChecked(), tags );
dst->saveSymbol( symbolName, symbol, symbolFavorite, symbolTags );
}
}
else
Expand All @@ -303,8 +322,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
continue;
case QMessageBox::Yes:
dst->addColorRamp( symbolName, ramp );
if ( mDialogMode == Import )
dst->saveColorRamp( symbolName, ramp, mFavorite->isChecked(), tags );
dst->saveColorRamp( symbolName, ramp, symbolFavorite, symbolTags );
continue;
case QMessageBox::YesToAll:
prompt = false;
Expand All @@ -320,8 +338,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
if ( dst->colorRampNames().contains( symbolName ) && overwrite )
{
dst->addColorRamp( symbolName, ramp );
if ( mDialogMode == Import )
dst->saveColorRamp( symbolName, ramp, mFavorite->isChecked(), tags );
dst->saveColorRamp( symbolName, ramp, symbolFavorite, symbolTags );
}
else if ( dst->colorRampNames().contains( symbolName ) && !overwrite )
{
Expand All @@ -330,8 +347,7 @@ void QgsStyleExportImportDialog::moveStyles( QModelIndexList* selection, QgsStyl
else
{
dst->addColorRamp( symbolName, ramp );
if ( mDialogMode == Import )
dst->saveColorRamp( symbolName, ramp, mFavorite->isChecked() , tags );
dst->saveColorRamp( symbolName, ramp, symbolFavorite, symbolTags );
}
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/ui/qgsstyleexportimportdialogbase.ui
Expand Up @@ -43,10 +43,10 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="tagLabel">
<property name="text">
<string>Tag(s)</string>
<string>Additional tag(s)</string>
</property>
</widget>
</item>
Expand All @@ -63,10 +63,23 @@
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="mSymbolTags"/>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="mIgnoreXMLTags">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Do not import embedded tags</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLineEdit" name="mSymbolTags"/>
</item>
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="tagHintLabel">
<property name="text">
<string>Tip: separate multiple tags with commas</string>
Expand Down

0 comments on commit 08f8ca7

Please sign in to comment.