Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Jan 16, 2019
1 parent ed797c9 commit 878cec9977883894a776cc9560e75c526bd0e65c
@@ -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

@@ -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();
}
}
@@ -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();
@@ -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;
};

0 comments on commit 878cec9

Please sign in to comment.
You can’t perform that action at this time.