Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Allow users to create notes for map layers
These notes are saved per layer, per project, and can be used as place to store important messages for users of the project like to do lists, etc. Notes can be created via the "Add Layer Notes" action in the layer right click menu. Any layers with notes will show a little notepad indicator icon to alert users as to the notes. Clicking the indicator will edit the note. Sponsored by Alta Ehf
- Loading branch information
1 parent
b0c09ac
commit ceff950
Showing
10 changed files
with
311 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*************************************************************************** | ||
qgslayernotesmanager.cpp | ||
-------------------------------------- | ||
Date : April 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayernotesmanager.h" | ||
#include "qgsmaplayer.h" | ||
#include "qgsrichtexteditor.h" | ||
#include "qgsgui.h" | ||
#include <QDialogButtonBox> | ||
#include <QPushButton> | ||
|
||
QString QgsLayerNotesManager::layerNotes( QgsMapLayer *layer ) | ||
{ | ||
if ( !layer ) | ||
return nullptr; | ||
|
||
return layer->customProperty( QStringLiteral( "userNotes" ) ).toString(); | ||
} | ||
|
||
void QgsLayerNotesManager::setLayerNotes( QgsMapLayer *layer, const QString ¬es ) | ||
{ | ||
if ( !layer ) | ||
return; | ||
|
||
if ( notes.isEmpty() ) | ||
layer->removeCustomProperty( QStringLiteral( "userNotes" ) ); | ||
else | ||
layer->setCustomProperty( QStringLiteral( "userNotes" ), notes ); | ||
} | ||
|
||
bool QgsLayerNotesManager::layerHasNotes( QgsMapLayer *layer ) | ||
{ | ||
if ( !layer ) | ||
return false; | ||
|
||
return !layer->customProperty( QStringLiteral( "userNotes" ) ).toString().isEmpty(); | ||
} | ||
|
||
void QgsLayerNotesManager::removeNotes( QgsMapLayer *layer ) | ||
{ | ||
if ( layer ) | ||
layer->removeCustomProperty( QStringLiteral( "userNotes" ) ); | ||
} | ||
|
||
void QgsLayerNotesManager::editLayerNotes( QgsMapLayer *layer, QWidget *parent ) | ||
{ | ||
const QString notes = layerNotes( layer ); | ||
QgsLayerNotesDialog *editor = new QgsLayerNotesDialog( parent ); | ||
editor->setNotes( notes ); | ||
editor->setWindowTitle( QObject::tr( "Layer Notes — %1" ).arg( layer->name() ) ); | ||
if ( editor->exec() ) | ||
{ | ||
QgsLayerNotesManager::setLayerNotes( layer, editor->notes() ); | ||
} | ||
} | ||
|
||
// | ||
// QgsLayerNotesDialog | ||
// | ||
QgsLayerNotesDialog::QgsLayerNotesDialog( QWidget *parent ) | ||
: QDialog( parent, Qt::Tool ) | ||
{ | ||
QVBoxLayout *layout = new QVBoxLayout(); | ||
mEditor = new QgsRichTextEditor(); | ||
layout->addWidget( mEditor ); | ||
|
||
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Save | QDialogButtonBox::Cancel ); | ||
connect( buttonBox->button( QDialogButtonBox::Save ), &QPushButton::clicked, this, &QDialog::accept ); | ||
connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject ); | ||
layout->addWidget( buttonBox ); | ||
|
||
layout->setContentsMargins( 3, 0, 3, 3 ); | ||
setLayout( layout ); | ||
|
||
QgsGui::enableAutoGeometryRestore( this ); | ||
} | ||
|
||
void QgsLayerNotesDialog::setNotes( const QString ¬es ) | ||
{ | ||
mEditor->setText( notes ); | ||
} | ||
|
||
QString QgsLayerNotesDialog::notes() const | ||
{ | ||
return mEditor->toHtml(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
qgslayernotesmanager.h | ||
-------------------------------------- | ||
Date : April 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYERNOTESMANAGER_H | ||
#define QGSLAYERNOTESMANAGER_H | ||
|
||
#include <QString> | ||
#include <QDialog> | ||
|
||
class QgsMapLayer; | ||
class QWidget; | ||
class QgsRichTextEditor; | ||
|
||
class QgsLayerNotesManager | ||
{ | ||
public: | ||
|
||
/** | ||
* Returns the notes for the specified \a layer. | ||
* | ||
* The returned string is a HTML formatted set of user notations for the layer. | ||
*/ | ||
static QString layerNotes( QgsMapLayer *layer ); | ||
|
||
/** | ||
* Sets the \a notes for the specified \a layer, where \a notes is a HTML formatted string. | ||
*/ | ||
static void setLayerNotes( QgsMapLayer *layer, const QString ¬es ); | ||
|
||
/** | ||
* Returns TRUE if the specified \a layer has notes available. | ||
*/ | ||
static bool layerHasNotes( QgsMapLayer *layer ); | ||
|
||
/** | ||
* Removes any notes for the specified \a layer. | ||
*/ | ||
static void removeNotes( QgsMapLayer *layer ); | ||
|
||
/** | ||
* Shows a dialog allowing users to edit the notes for the specified \a layer. | ||
*/ | ||
static void editLayerNotes( QgsMapLayer *layer, QWidget *parent ); | ||
}; | ||
|
||
class QgsLayerNotesDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsLayerNotesDialog( QWidget *parent ); | ||
|
||
void setNotes( const QString ¬es ); | ||
QString notes() const; | ||
|
||
private: | ||
QgsRichTextEditor *mEditor = nullptr; | ||
}; | ||
|
||
#endif // QGSLAYERNOTESMANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*************************************************************************** | ||
qgslayertreeviewnotesindicator.h | ||
-------------------------------------- | ||
Date : April 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayertreeviewnotesindicator.h" | ||
#include "qgslayertreeview.h" | ||
#include "qgslayertree.h" | ||
#include "qgslayertreemodel.h" | ||
#include "qgslayertreeutils.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgslayernotesmanager.h" | ||
#include "qgisapp.h" | ||
|
||
QgsLayerTreeViewNotesIndicatorProvider::QgsLayerTreeViewNotesIndicatorProvider( QgsLayerTreeView *view ) | ||
: QgsLayerTreeViewIndicatorProvider( view ) | ||
{ | ||
} | ||
|
||
void QgsLayerTreeViewNotesIndicatorProvider::onIndicatorClicked( const QModelIndex &index ) | ||
{ | ||
QgsLayerTreeNode *node = mLayerTreeView->index2node( index ); | ||
if ( !QgsLayerTree::isLayer( node ) ) | ||
return; | ||
|
||
if ( QgsMapLayer *layer = QgsLayerTree::toLayer( node )->layer() ) | ||
{ | ||
QgsLayerNotesManager::editLayerNotes( layer, QgisApp::instance() ); | ||
} | ||
} | ||
|
||
void QgsLayerTreeViewNotesIndicatorProvider::connectSignals( QgsMapLayer *layer ) | ||
{ | ||
QgsLayerTreeViewIndicatorProvider::connectSignals( layer ); | ||
connect( layer, &QgsMapLayer::customPropertyChanged, this, &QgsLayerTreeViewNotesIndicatorProvider::onLayerChanged ); | ||
} | ||
|
||
void QgsLayerTreeViewNotesIndicatorProvider::disconnectSignals( QgsMapLayer *layer ) | ||
{ | ||
QgsLayerTreeViewIndicatorProvider::disconnectSignals( layer ); | ||
disconnect( layer, &QgsMapLayer::customPropertyChanged, this, &QgsLayerTreeViewNotesIndicatorProvider::onLayerChanged ); | ||
} | ||
|
||
bool QgsLayerTreeViewNotesIndicatorProvider::acceptLayer( QgsMapLayer *layer ) | ||
{ | ||
if ( !layer ) | ||
return false; | ||
|
||
return QgsLayerNotesManager::layerHasNotes( layer ); | ||
} | ||
|
||
QString QgsLayerTreeViewNotesIndicatorProvider::iconName( QgsMapLayer *layer ) | ||
{ | ||
Q_UNUSED( layer ) | ||
return QStringLiteral( "/mIndicatorNotes.svg" ); | ||
} | ||
|
||
QString QgsLayerTreeViewNotesIndicatorProvider::tooltipText( QgsMapLayer *layer ) | ||
{ | ||
return QgsLayerNotesManager::layerNotes( layer ); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*************************************************************************** | ||
qgslayertreeviewnotesindicator.h | ||
-------------------------------------- | ||
Date : April 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYERTREEVIEWNOTESINDICATOR_H | ||
#define QGSLAYERTREEVIEWNOTESINDICATOR_H | ||
|
||
#include "qgslayertreeviewindicatorprovider.h" | ||
|
||
//! Adds indicators showing whether layers have notes attached. | ||
class QgsLayerTreeViewNotesIndicatorProvider : public QgsLayerTreeViewIndicatorProvider | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsLayerTreeViewNotesIndicatorProvider( QgsLayerTreeView *view ); | ||
|
||
protected slots: | ||
|
||
void onIndicatorClicked( const QModelIndex &index ) override; | ||
protected: | ||
void connectSignals( QgsMapLayer *layer ) override ; | ||
void disconnectSignals( QgsMapLayer *layer ) override; | ||
|
||
private: | ||
bool acceptLayer( QgsMapLayer *layer ) override; | ||
QString iconName( QgsMapLayer *layer ) override; | ||
QString tooltipText( QgsMapLayer *layer ) override; | ||
}; | ||
|
||
#endif // QGSLAYERTREEVIEWNOTESINDICATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters