Skip to content

Commit

Permalink
[FEATURE] Double clicking a style .xml in the browser now opens
Browse files Browse the repository at this point in the history
the manager dialog, allowing browsing and non-edit actions for the
style.
  • Loading branch information
nyalldawson committed Jan 16, 2019
1 parent 2c22bea commit 701a29f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/app/qgsappbrowserproviders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "qgsstyle.h"
#include "qgslayertreenode.h"
#include "qgslayertree.h"
#include "qgsstylemanagerdialog.h"
#include "qgsguiutils.h"
#include <QDesktopServices>

//
Expand Down Expand Up @@ -309,24 +311,43 @@ QgsMimeDataUtils::Uri QgsStyleXmlDataItem::mimeUri() const

bool QgsStyleXmlDataItem::handleDoubleClick()
{
QgsStyleExportImportDialog dlg( QgsStyle::defaultStyle(), QgisApp::instance(), QgsStyleExportImportDialog::Import );
dlg.setImportFilePath( mPath );
dlg.exec();

browseStyle( mPath );
return true;
}

QList<QAction *> QgsStyleXmlDataItem::actions( QWidget *parent )
{
QAction *importAction = new QAction( tr( "&Import Style…" ), parent );
QAction *browseAction = new QAction( tr( "&Open Style…" ), parent );
const QString path = mPath;
connect( browseAction, &QAction::triggered, this, [path]
{
browseStyle( path );
} );

QAction *importAction = new QAction( tr( "&Import Style…" ), parent );
connect( importAction, &QAction::triggered, this, [path]
{
QgsStyleExportImportDialog dlg( QgsStyle::defaultStyle(), QgisApp::instance(), QgsStyleExportImportDialog::Import );
dlg.setImportFilePath( path );
dlg.exec();
} );
return QList<QAction *>() << importAction;
return QList<QAction *>() << browseAction << importAction;
}

void QgsStyleXmlDataItem::browseStyle( const QString &xmlPath )
{
QgsStyle s;
s.createMemoryDatabase();

auto cursorOverride = qgis::make_unique< QgsTemporaryCursorOverride >( Qt::WaitCursor );
if ( s.importXml( xmlPath ) )
{
cursorOverride.reset();
QgsStyleManagerDialog dlg( &s, QgisApp::instance(), Qt::WindowFlags(), true );
dlg.setSmartGroupsVisible( false );
dlg.setFavoritesGroupVisible( false );
dlg.exec();
}
}

//
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsappbrowserproviders.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class QgsStyleXmlDataItem : public QgsDataItem
bool handleDoubleClick() override;
QList< QAction * > actions( QWidget *parent ) override;

private:

static void browseStyle( const QString &xmlPath );

};

/**
Expand Down

0 comments on commit 701a29f

Please sign in to comment.