QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgsmaplayer.h"
18 
20 {
21  if ( !layer )
22  return nullptr;
23 
24  return layer->customProperty( QStringLiteral( "userNotes" ) ).toString();
25 }
26 
27 void QgsLayerNotesUtils::setLayerNotes( QgsMapLayer *layer, const QString &notes )
28 {
29  if ( !layer )
30  return;
31 
32  if ( notes.isEmpty() )
33  layer->removeCustomProperty( QStringLiteral( "userNotes" ) );
34  else
35  layer->setCustomProperty( QStringLiteral( "userNotes" ), notes );
36 }
37 
39 {
40  if ( !layer )
41  return false;
42 
43  return !layer->customProperty( QStringLiteral( "userNotes" ) ).toString().isEmpty();
44 }
45 
47 {
48  if ( layer )
49  layer->removeCustomProperty( QStringLiteral( "userNotes" ) );
50 }
QgsMapLayer::setCustomProperty
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
Definition: qgsmaplayer.cpp:1976
QgsLayerNotesUtils::layerNotes
static QString layerNotes(const QgsMapLayer *layer)
Returns the notes for the specified layer.
Definition: qgslayernotesutils.cpp:19
qgslayernotesutils.h
QgsLayerNotesUtils::layerHasNotes
static bool layerHasNotes(const QgsMapLayer *layer)
Returns true if the specified layer has notes available.
Definition: qgslayernotesutils.cpp:38
qgsmaplayer.h
QgsMapLayer::removeCustomProperty
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Definition: qgsmaplayer.cpp:2004
QgsLayerNotesUtils::removeNotes
static void removeNotes(QgsMapLayer *layer)
Removes any notes for the specified layer.
Definition: qgslayernotesutils.cpp:46
QgsMapLayer::customProperty
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Definition: qgsmaplayer.cpp:1999
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsLayerNotesUtils::setLayerNotes
static void setLayerNotes(QgsMapLayer *layer, const QString &notes)
Sets the notes for the specified layer, where notes is a HTML formatted string.
Definition: qgslayernotesutils.cpp:27