Skip to content

Commit

Permalink
Allow additional tags to be set when copying items to default style
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 16, 2019
1 parent ed797c9 commit 878cec9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions python/gui/auto_generated/symbology/qgsstylemanagerdialog.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsappbrowserproviders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
22 changes: 20 additions & 2 deletions src/gui/symbology/qgsstylemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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." ) );
}
Expand Down Expand Up @@ -930,6 +943,11 @@ void QgsStyleManagerDialog::setSmartGroupsVisible( bool show )
populateGroups();
}

void QgsStyleManagerDialog::setBaseStyleName( const QString &name )
{
mBaseName = name;
}

void QgsStyleManagerDialog::activate()
{
raise();
Expand Down
12 changes: 12 additions & 0 deletions src/gui/symbology/qgsstylemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 878cec9

Please sign in to comment.