1 /***************************************************************************
2                           qgsmaptoolpinlabels.h
3                           --------------------
4     begin                : 2012-07-12
5     copyright            : (C) 2012 by Larry Shaffer
6     email                : larrys at dakotacarto dot com
7 ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef QGSMAPTOOLPINLABELS_H
19 #define QGSMAPTOOLPINLABELS_H
20 
21 #include "qgsmaptoollabel.h"
22 #include "qgis_app.h"
23 
24 class QgsRubberBand;
25 class QgsLabelPosition;
26 
27 //! A map tool for pinning (writing to attribute table) and unpinning labelpositions and rotation
28 class APP_EXPORT QgsMapToolPinLabels: public QgsMapToolLabel
29 {
30     Q_OBJECT
31 
32   public:
33     QgsMapToolPinLabels( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock );
34     ~QgsMapToolPinLabels() override;
35 
36     //! Overridden mouse move event
37     void canvasMoveEvent( QgsMapMouseEvent *e ) override;
38 
39     //! Overridden mouse press event
40     void canvasPressEvent( QgsMapMouseEvent *e ) override;
41 
42     //! Overridden mouse release event
43     void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
44 
isShowingPinned()45     bool isShowingPinned() const { return mShowPinned; }
setShowingPinned(bool showing)46     void setShowingPinned( bool showing ) { mShowPinned = showing; }
47 
48     //! Called when Show Pinned Labels tool is toggled, via its qgisapp.cpp slot
49     void showPinnedLabels( bool show );
50 
51     //! Remove rectangles from around pinned labels
52     void removePinnedHighlights();
53 
54   public slots:
55 
56     //! Update pinned label highlights on layer edit mode change
57     void updatePinnedLabels();
58 
59     //! Render highlight rectangles around pinned labels
60     void highlightPinnedLabels();
61 
62   protected:
63 
64     //! Mapping of feature ids of layers that have been highlighted
65     QMap<QString, QgsRubberBand *> mHighlights;
66 
67     //! Flag to indicate a map canvas drag operation is taking place
68     bool mDragging;
69     //! Flag to indicate whether to draw the highlight for pinned labels
70     bool mShowPinned;
71 
72     //! Stores actual select rect
73     QRect mSelectRect;
74 
75     //! Stores selection marquee
76     QgsRubberBand *mRubberBand = nullptr;
77 
78   private:
79 
80     //! Highlights a given label relative to whether its pinned and editable
81     void highlightLabel( const QgsLabelPosition &labelpos,
82                          const QString &id,
83                          const QColor &color );
84 
85     //! Highlights a given callout relative to whether its pinned and editable
86     void highlightCallout( bool isOrigin, const QgsCalloutPosition &labelpos,
87                            const QString &id,
88                            const QColor &color );
89 
90     //! Select valid labels to pin or unpin
91     void pinUnpinLabels( const QgsRectangle &ext, QMouseEvent *e );
92 
93     //! Pin or unpin current label relative to whether its editable
94     bool pinUnpinCurrentLabel( bool pin );
95 
96     //! Pin or unpin diagram relative to whether its editable
97     bool pinUnpinCurrentDiagram( bool pin );
98 
99     //! Pin or unpin current feature (diagram or label)
100     bool pinUnpinCurrentFeature( bool pin );
101 };
102 
103 #endif // QGSMAPTOOLPINLABELS_H
104