Allow additional tags to be set when copying items to default style

This commit is contained in:
Nyall Dawson 2019-01-16 07:33:32 +10:00
parent ed797c98f4
commit 878cec9977
4 changed files with 45 additions and 2 deletions

View File

@ -50,6 +50,17 @@ Sets whether the favorites group should be shown. The default is to show the gro
%Docstring %Docstring
Sets whether smart groups should be shown. The default is to show the groups. 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 .. versionadded:: 3.6
%End %End

View File

@ -343,9 +343,11 @@ void QgsStyleXmlDataItem::browseStyle( const QString &xmlPath )
if ( s.importXml( xmlPath ) ) if ( s.importXml( xmlPath ) )
{ {
cursorOverride.reset(); cursorOverride.reset();
QFileInfo fi( xmlPath );
QgsStyleManagerDialog dlg( &s, QgisApp::instance(), Qt::WindowFlags(), true ); QgsStyleManagerDialog dlg( &s, QgisApp::instance(), Qt::WindowFlags(), true );
dlg.setSmartGroupsVisible( false ); dlg.setSmartGroupsVisible( false );
dlg.setFavoritesGroupVisible( false ); dlg.setFavoritesGroupVisible( false );
dlg.setBaseStyleName( fi.baseName() );
dlg.exec(); dlg.exec();
} }
} }

View File

@ -427,12 +427,25 @@ void QgsStyleManagerDialog::copyItemsToDefault()
const QList< ItemDetails > items = selectedItems(); const QList< ItemDetails > items = selectedItems();
if ( !items.empty() ) 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 ); 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(); cursorOverride.reset();
if ( count > 0 ) if ( count > 0 )
{ {
QMessageBox::information( this, tr( "Import Symbols" ), QMessageBox::information( this, tr( "Import Items" ),
count > 1 ? tr( "Successfully imported %1 items." ).arg( count ) count > 1 ? tr( "Successfully imported %1 items." ).arg( count )
: tr( "Successfully imported item." ) ); : tr( "Successfully imported item." ) );
} }
@ -930,6 +943,11 @@ void QgsStyleManagerDialog::setSmartGroupsVisible( bool show )
populateGroups(); populateGroups();
} }
void QgsStyleManagerDialog::setBaseStyleName( const QString &name )
{
mBaseName = name;
}
void QgsStyleManagerDialog::activate() void QgsStyleManagerDialog::activate()
{ {
raise(); raise();

View File

@ -98,6 +98,17 @@ class GUI_EXPORT QgsStyleManagerDialog : public QDialog, private Ui::QgsStyleMan
*/ */
void setSmartGroupsVisible( bool show ); 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: public slots:
// TODO QGIS 4.0 -- most of this should be private // 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 mReadOnly = false;
bool mFavoritesGroupVisible = true; bool mFavoritesGroupVisible = true;
bool mSmartGroupVisible = true; bool mSmartGroupVisible = true;
QString mBaseName;
friend class QgsStyleExportImportDialog; friend class QgsStyleExportImportDialog;
}; };