16 #include <QVBoxLayout> 18 #include <QInputDialog> 19 #include <QMessageBox> 21 #include <QFileDialog> 47 connect( addAction, SIGNAL( triggered() ),
this, SLOT( addStyle() ) );
50 connect( removeAction, SIGNAL( triggered() ),
this, SLOT( removeStyle() ) );
53 connect( loadFromFileAction, SIGNAL( triggered() ),
this, SLOT( loadStyle() ) );
55 connect( saveAsDefaultAction, SIGNAL( triggered() ),
this, SLOT( saveAsDefault() ) );
57 connect( loadDefaultAction, SIGNAL( triggered() ),
this, SLOT( loadDefault() ) );
64 connect( canvas, SIGNAL( mapCanvasRefreshed() ),
this, SLOT( updateCurrent() ) );
85 stylename =
"(default)";
92 currentStyleChanged( active );
101 if ( name ==
"(default)" )
107 void QgsMapLayerStyleManagerWidget::currentStyleChanged(
QString name )
118 void QgsMapLayerStyleManagerWidget::styleAdded(
QString name )
125 void QgsMapLayerStyleManagerWidget::styleRemoved(
QString name )
135 void QgsMapLayerStyleManagerWidget::styleRenamed(
QString oldname,
QString newname )
145 void QgsMapLayerStyleManagerWidget::addStyle()
149 tr(
"Style name:" ), QLineEdit::Normal,
165 void QgsMapLayerStyleManagerWidget::removeStyle()
185 void QgsMapLayerStyleManagerWidget::saveAsDefault()
191 if ( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
194 askToUser.
setText(
tr(
"Save default style to: " ) );
195 askToUser.
setIcon( QMessageBox::Question );
196 askToUser.
addButton(
tr(
"Cancel" ), QMessageBox::RejectRole );
197 askToUser.
addButton(
tr(
"Local database" ), QMessageBox::NoRole );
198 askToUser.
addButton(
tr(
"Datasource database" ), QMessageBox::YesRole );
200 switch ( askToUser.
exec() )
205 layer->saveStyleToDatabase(
"",
"",
true,
"", errorMsg );
217 bool defaultSavedFlag =
false;
219 if ( !defaultSavedFlag )
226 void QgsMapLayerStyleManagerWidget::loadDefault()
229 bool defaultLoadedFlag =
false;
233 if ( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
236 askToUser.
setText(
tr(
"Load default style from: " ) );
237 askToUser.
setIcon( QMessageBox::Question );
238 askToUser.
addButton(
tr(
"Cancel" ), QMessageBox::RejectRole );
239 askToUser.
addButton(
tr(
"Local database" ), QMessageBox::NoRole );
240 askToUser.
addButton(
tr(
"Datasource database" ), QMessageBox::YesRole );
242 switch ( askToUser.
exec() )
247 msg = layer->loadNamedStyle(
mLayer->
styleURI(), defaultLoadedFlag );
248 if ( !defaultLoadedFlag )
253 if ( msg.
compare(
tr(
"Loaded from Provider" ) ) )
256 tr(
"No default style was found for this layer" ) );
268 myMessage = layer->loadNamedStyle(
mLayer->
styleURI(), defaultLoadedFlag, true );
272 myMessage = layer->loadNamedStyle(
mLayer->
styleURI(), defaultLoadedFlag );
279 if ( !defaultLoadedFlag )
291 void QgsMapLayerStyleManagerWidget::saveStyle()
296 void QgsMapLayerStyleManagerWidget::loadStyle()
302 tr(
"QGIS Layer Style File" ) +
" (*.qml);;" +
tr(
"SLD File" ) +
" (*.sld)" );
303 if ( myFileName.
isNull() )
309 bool defaultLoadedFlag =
false;
311 if ( myFileName.
endsWith(
".sld", Qt::CaseInsensitive ) )
321 if ( defaultLoadedFlag )
333 myQSettings.
setValue(
"style/lastStyleDir", myPath );
Base class for all map layer types.
QStringList styles() const
Return list of all defined style names.
void setContentsMargins(int left, int top, int right, int bottom)
void setViewMode(ViewMode mode)
virtual QString loadSldStyle(const QString &theURI, bool &theResultFlag)
void setCurrentIndex(const QModelIndex &index)
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
bool removeRow(int row, const QModelIndex &parent)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
virtual void setModel(QAbstractItemModel *model)
void setIcon(const QIcon &icon)
const T & at(int i) const
virtual QString saveDefaultStyle(bool &theResultFlag)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
QgsMapLayerStyleManager * styleManager() const
Get access to the layer's style manager.
void setValue(const QString &key, const QVariant &value)
const char * name() const
bool removeStyle(const QString &name)
Remove a stored style.
void setText(const QString &text)
QList< QStandardItem * > findItems(const QString &text, QFlags< Qt::MatchFlag > flags, int column) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
bool addStyleFromLayer(const QString &name)
Add style by cloning the current one.
QString currentStyle() const
Return name of the current style.
void setText(const QString &text)
QVariant value(const QString &key, const QVariant &defaultValue) const
QVariant data(int role) const
QModelIndex index() const
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
virtual QString loadNamedStyle(const QString &theURI, bool &theResultFlag)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual QString styleURI()
Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users styl...
Represents a vector layer which manages a vector based data sets.
void setResizeMode(ResizeMode mode)
int compare(const QString &other) const
void appendRow(const QList< QStandardItem * > &items)
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.