QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslayernotesutils.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayernotesutils.cpp
3 --------------------------------------
4 Date : April 2021
5 Copyright : (C) 2021 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgslayernotesutils.h"
17
18#include "qgsmaplayer.h"
19
21{
22 if ( !layer )
23 return nullptr;
24
25 return layer->customProperty( QStringLiteral( "userNotes" ) ).toString();
26}
27
28void QgsLayerNotesUtils::setLayerNotes( QgsMapLayer *layer, const QString &notes )
29{
30 if ( !layer )
31 return;
32
33 if ( notes.isEmpty() )
34 layer->removeCustomProperty( QStringLiteral( "userNotes" ) );
35 else
36 layer->setCustomProperty( QStringLiteral( "userNotes" ), notes );
37}
38
40{
41 if ( !layer )
42 return false;
43
44 return !layer->customProperty( QStringLiteral( "userNotes" ) ).toString().isEmpty();
45}
46
48{
49 if ( layer )
50 layer->removeCustomProperty( QStringLiteral( "userNotes" ) );
51}
static void setLayerNotes(QgsMapLayer *layer, const QString &notes)
Sets the notes for the specified layer, where notes is a HTML formatted string.
static void removeNotes(QgsMapLayer *layer)
Removes any notes for the specified layer.
static bool layerHasNotes(const QgsMapLayer *layer)
Returns true if the specified layer has notes available.
static QString layerNotes(const QgsMapLayer *layer)
Returns the notes for the specified layer.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.