Skip to content
Permalink
Browse files

[styledock] Add load from file

  • Loading branch information
NathanW2 committed Jun 3, 2016
1 parent 3d941e3 commit 4c286618804ae3524da7a2c1e789c54bf91a0a91
Showing with 57 additions and 1 deletion.
  1. +55 −1 src/gui/qgsmaplayerstylemanagerwidget.cpp
  2. +2 −0 src/gui/qgsmaplayerstylemanagerwidget.h
@@ -17,6 +17,8 @@
#include <QToolBar>
#include <QInputDialog>
#include <QMessageBox>
#include <QSettings>
#include <QFileDialog>

#include "qgsmaplayerstylemanagerwidget.h"
#include "qgslogger.h"
@@ -46,9 +48,15 @@ QgsMapLayerStyleManagerWidget::QgsMapLayerStyleManagerWidget( QgsMapLayer* layer
connect( removeAction, SIGNAL( triggered() ), this, SLOT( removeStyle() ) );
QAction* saveAsDefaultAction = toolbar->addAction( tr( "Save as default" ) );
connect( saveAsDefaultAction, SIGNAL( triggered() ), this, SLOT( saveAsDefault() ) );
QAction* loadDefaultAction = toolbar->addAction( tr( "Load default" ) );
QAction* loadDefaultAction = toolbar->addAction( tr( "Restore default" ) );
connect( loadDefaultAction, SIGNAL( triggered() ), this, SLOT( loadDefault() ) );

QAction* loadFromFileAction = toolbar->addAction( tr( "Load Style" ) );
connect( loadFromFileAction, SIGNAL( triggered() ), this, SLOT( loadStyle() ) );

QAction* saveToFileAction = toolbar->addAction( tr( "Save Style" ) );
connect( saveToFileAction, SIGNAL( triggered() ), this, SLOT( saveStyle() ) );

connect( canvas, SIGNAL( mapCanvasRefreshed() ), this, SLOT( updateCurrent() ) );

connect( mStyleList, SIGNAL( clicked( QModelIndex ) ), this, SLOT( styleClicked( QModelIndex ) ) );
@@ -272,3 +280,49 @@ void QgsMapLayerStyleManagerWidget::loadDefault()
}

}

void QgsMapLayerStyleManagerWidget::saveStyle()
{

}

void QgsMapLayerStyleManagerWidget::loadStyle()
{
QSettings myQSettings; // where we keep last used filter in persistent state
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", QDir::homePath() ).toString();

QString myFileName = QFileDialog::getOpenFileName( this, tr( "Load layer properties from style file" ), myLastUsedDir,
tr( "QGIS Layer Style File" ) + " (*.qml);;" + tr( "SLD File" ) + " (*.sld)" );
if ( myFileName.isNull() )
{
return;
}

QString myMessage;
bool defaultLoadedFlag = false;

if ( myFileName.endsWith( ".sld", Qt::CaseInsensitive ) )
{
// load from SLD
myMessage = mLayer->loadSldStyle( myFileName, defaultLoadedFlag );
}
else
{
myMessage = mLayer->loadNamedStyle( myFileName, defaultLoadedFlag );
}
//reset if the default style was loaded ok only
if ( defaultLoadedFlag )
{
emit widgetChanged();
}
else
{
//let the user know what went wrong
QMessageBox::warning( this, tr( "Load Style" ), myMessage );
}

QFileInfo myFI( myFileName );
QString myPath = myFI.path();
myQSettings.setValue( "style/lastStyleDir", myPath );

}
@@ -55,6 +55,8 @@ class GUI_EXPORT QgsMapLayerStyleManagerWidget : public QgsMapStylePanel
void removeStyle();
void saveAsDefault();
void loadDefault();
void saveStyle();
void loadStyle();

private:
QStandardItemModel* mModel;

0 comments on commit 4c28661

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