diff --git a/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in b/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in index cd9dbf26632..337933bfb1e 100644 --- a/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in +++ b/python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in @@ -50,6 +50,17 @@ Sets whether the favorites group should be shown. The default is to show the gro %Docstring Sets whether smart groups should be shown. The default is to show the groups. +.. versionadded:: 3.6 +%End + + void setBaseStyleName( const QString &name ); +%Docstring +Sets the base ``name`` for the style, which is used by the dialog to reflect the +original style/XML file name. + +``name`` should be stripped of any extensions and folder information, e.g. "transport_styles", +not "d:/stuff/transport_styles.xml". + .. versionadded:: 3.6 %End diff --git a/src/app/qgsappbrowserproviders.cpp b/src/app/qgsappbrowserproviders.cpp index e674ba15a52..9c3ef0494d3 100644 --- a/src/app/qgsappbrowserproviders.cpp +++ b/src/app/qgsappbrowserproviders.cpp @@ -343,9 +343,11 @@ void QgsStyleXmlDataItem::browseStyle( const QString &xmlPath ) if ( s.importXml( xmlPath ) ) { cursorOverride.reset(); + QFileInfo fi( xmlPath ); QgsStyleManagerDialog dlg( &s, QgisApp::instance(), Qt::WindowFlags(), true ); dlg.setSmartGroupsVisible( false ); dlg.setFavoritesGroupVisible( false ); + dlg.setBaseStyleName( fi.baseName() ); dlg.exec(); } } diff --git a/src/gui/symbology/qgsstylemanagerdialog.cpp b/src/gui/symbology/qgsstylemanagerdialog.cpp index 318951dd84c..56d576adb5b 100644 --- a/src/gui/symbology/qgsstylemanagerdialog.cpp +++ b/src/gui/symbology/qgsstylemanagerdialog.cpp @@ -427,12 +427,25 @@ void QgsStyleManagerDialog::copyItemsToDefault() const QList< ItemDetails > items = selectedItems(); if ( !items.empty() ) { + bool ok = false; + const QString tags = QInputDialog::getText( this, tr( "Import Items" ), + tr( "Additional tags to add (comma separated)" ), QLineEdit::Normal, + mBaseName, &ok ); + if ( !ok ) + return; + + const QStringList parts = tags.split( ',', QString::SkipEmptyParts ); + QStringList additionalTags; + additionalTags.reserve( parts.count() ); + for ( const QString &tag : parts ) + additionalTags << tag.trimmed(); + auto cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor ); - const int count = copyItems( items, mStyle, QgsStyle::defaultStyle(), this, cursorOverride, true, QStringList(), false, false ); + const int count = copyItems( items, mStyle, QgsStyle::defaultStyle(), this, cursorOverride, true, additionalTags, false, false ); cursorOverride.reset(); if ( count > 0 ) { - QMessageBox::information( this, tr( "Import Symbols" ), + QMessageBox::information( this, tr( "Import Items" ), count > 1 ? tr( "Successfully imported %1 items." ).arg( count ) : tr( "Successfully imported item." ) ); } @@ -930,6 +943,11 @@ void QgsStyleManagerDialog::setSmartGroupsVisible( bool show ) populateGroups(); } +void QgsStyleManagerDialog::setBaseStyleName( const QString &name ) +{ + mBaseName = name; +} + void QgsStyleManagerDialog::activate() { raise(); diff --git a/src/gui/symbology/qgsstylemanagerdialog.h b/src/gui/symbology/qgsstylemanagerdialog.h index 34a7ba64db6..449518a36fe 100644 --- a/src/gui/symbology/qgsstylemanagerdialog.h +++ b/src/gui/symbology/qgsstylemanagerdialog.h @@ -98,6 +98,17 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan */ void setSmartGroupsVisible( bool show ); + /** + * Sets the base \a name for the style, which is used by the dialog to reflect the + * original style/XML file name. + * + * \a name should be stripped of any extensions and folder information, e.g. "transport_styles", + * not "d:/stuff/transport_styles.xml". + * + * \since QGIS 3.6 + */ + void setBaseStyleName( const QString &name ); + public slots: // TODO QGIS 4.0 -- most of this should be private @@ -377,6 +388,7 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan bool mReadOnly = false; bool mFavoritesGroupVisible = true; bool mSmartGroupVisible = true; + QString mBaseName; friend class QgsStyleExportImportDialog; };