Skip to content

Commit 878cec9

Browse files
committedJan 16, 2019
Allow additional tags to be set when copying items to default style
1 parent ed797c9 commit 878cec9

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed
 

‎python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ Sets whether the favorites group should be shown. The default is to show the gro
5050
%Docstring
5151
Sets whether smart groups should be shown. The default is to show the groups.
5252

53+
.. versionadded:: 3.6
54+
%End
55+
56+
void setBaseStyleName( const QString &name );
57+
%Docstring
58+
Sets the base ``name`` for the style, which is used by the dialog to reflect the
59+
original style/XML file name.
60+
61+
``name`` should be stripped of any extensions and folder information, e.g. "transport_styles",
62+
not "d:/stuff/transport_styles.xml".
63+
5364
.. versionadded:: 3.6
5465
%End
5566

‎src/app/qgsappbrowserproviders.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,11 @@ void QgsStyleXmlDataItem::browseStyle( const QString &xmlPath )
343343
if ( s.importXml( xmlPath ) )
344344
{
345345
cursorOverride.reset();
346+
QFileInfo fi( xmlPath );
346347
QgsStyleManagerDialog dlg( &s, QgisApp::instance(), Qt::WindowFlags(), true );
347348
dlg.setSmartGroupsVisible( false );
348349
dlg.setFavoritesGroupVisible( false );
350+
dlg.setBaseStyleName( fi.baseName() );
349351
dlg.exec();
350352
}
351353
}

‎src/gui/symbology/qgsstylemanagerdialog.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,25 @@ void QgsStyleManagerDialog::copyItemsToDefault()
427427
const QList< ItemDetails > items = selectedItems();
428428
if ( !items.empty() )
429429
{
430+
bool ok = false;
431+
const QString tags = QInputDialog::getText( this, tr( "Import Items" ),
432+
tr( "Additional tags to add (comma separated)" ), QLineEdit::Normal,
433+
mBaseName, &ok );
434+
if ( !ok )
435+
return;
436+
437+
const QStringList parts = tags.split( ',', QString::SkipEmptyParts );
438+
QStringList additionalTags;
439+
additionalTags.reserve( parts.count() );
440+
for ( const QString &tag : parts )
441+
additionalTags << tag.trimmed();
442+
430443
auto cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
431-
const int count = copyItems( items, mStyle, QgsStyle::defaultStyle(), this, cursorOverride, true, QStringList(), false, false );
444+
const int count = copyItems( items, mStyle, QgsStyle::defaultStyle(), this, cursorOverride, true, additionalTags, false, false );
432445
cursorOverride.reset();
433446
if ( count > 0 )
434447
{
435-
QMessageBox::information( this, tr( "Import Symbols" ),
448+
QMessageBox::information( this, tr( "Import Items" ),
436449
count > 1 ? tr( "Successfully imported %1 items." ).arg( count )
437450
: tr( "Successfully imported item." ) );
438451
}
@@ -930,6 +943,11 @@ void QgsStyleManagerDialog::setSmartGroupsVisible( bool show )
930943
populateGroups();
931944
}
932945

946+
void QgsStyleManagerDialog::setBaseStyleName( const QString &name )
947+
{
948+
mBaseName = name;
949+
}
950+
933951
void QgsStyleManagerDialog::activate()
934952
{
935953
raise();

‎src/gui/symbology/qgsstylemanagerdialog.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
9898
*/
9999
void setSmartGroupsVisible( bool show );
100100

101+
/**
102+
* Sets the base \a name for the style, which is used by the dialog to reflect the
103+
* original style/XML file name.
104+
*
105+
* \a name should be stripped of any extensions and folder information, e.g. "transport_styles",
106+
* not "d:/stuff/transport_styles.xml".
107+
*
108+
* \since QGIS 3.6
109+
*/
110+
void setBaseStyleName( const QString &name );
111+
101112
public slots:
102113

103114
// TODO QGIS 4.0 -- most of this should be private
@@ -377,6 +388,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
377388
bool mReadOnly = false;
378389
bool mFavoritesGroupVisible = true;
379390
bool mSmartGroupVisible = true;
391+
QString mBaseName;
380392

381393
friend class QgsStyleExportImportDialog;
382394
};

0 commit comments

Comments
 (0)
Please sign in to comment.