Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[feature] Add a new "Annotations" toolbar, currently containing
a single action for creating a new annotation layer in a project
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent 76e20c6 commit ca729cc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -931,6 +931,7 @@
<file>themes/default/mActionNewGpx.svg</file>
<file>themes/default/mActionAddGpsLayer.svg</file>
<file>themes/default/mIconAnnotationLayer.svg</file>
<file>themes/default/mActionCreateAnnotationLayer.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mActionCreateAnnotationLayer.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -2885,6 +2885,8 @@ void QgisApp::createActions()

connect( mActionDiagramProperties, &QAction::triggered, this, &QgisApp::diagramProperties );

connect( mActionCreateAnnotationLayer, &QAction::triggered, this, &QgisApp::createAnnotationLayer );

// we can't set the shortcut these actions, because we need to restrict their context to the canvas and it's children..
for ( QWidget *widget :
{
Expand Down Expand Up @@ -8618,6 +8620,16 @@ void QgisApp::diagramProperties()
activateDeactivateLayerRelatedActions( vlayer );
}

void QgisApp::createAnnotationLayer()
{
QgsAnnotationLayer::LayerOptions options( QgsProject::instance()->transformContext() );
QgsAnnotationLayer *layer = new QgsAnnotationLayer( tr( "Annotations" ), options );

// layer should be created at top of layer tree
QgsProject::instance()->addMapLayer( layer, false );
QgsProject::instance()->layerTreeRoot()->insertLayer( 0, layer );
}

void QgisApp::setCadDockVisible( bool visible )
{
mAdvancedDigitizingDockWidget->setVisible( visible );
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1819,6 +1819,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! diagrams properties
void diagramProperties();

//! Creates a new annotation layer
void createAnnotationLayer();

//! Sets the CAD dock widget visible
void setCadDockVisible( bool visible );

Expand Down
25 changes: 24 additions & 1 deletion src/ui/qgisapp.ui
Expand Up @@ -791,6 +791,18 @@
<bool>false</bool>
</attribute>
</widget>
<widget class="QToolBar" name="mAnnotationsToolBar">
<property name="windowTitle">
<string>Annotations</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionCreateAnnotationLayer"/>
</widget>
<action name="mActionNewProject">
<property name="icon">
<iconset resource="../../images/images.qrc">
Expand Down Expand Up @@ -3573,7 +3585,18 @@ Shows placeholders for labels which could not be placed, e.g. due to overlaps wi
<string>New GPX Layer</string>
</property>
</action>
<action name="mActionCreateAnnotationLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionCreateAnnotationLayer.svg</normaloff>:/images/themes/default/mActionCreateAnnotationLayer.svg</iconset>
</property>
<property name="text">
<string>New Annotation Layer</string>
</property>
</action>
</widget>
<resources/>
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit ca729cc

Please sign in to comment.