Skip to content

Commit 4065a7f

Browse files
committedJul 11, 2017
Add shell for non-functional layout select tool
1 parent 4b89f5e commit 4065a7f

File tree

8 files changed

+212
-1
lines changed

8 files changed

+212
-1
lines changed
 

‎python/gui/gui_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
%Include layout/qgslayoutviewtool.sip
283283
%Include layout/qgslayoutviewtooladditem.sip
284284
%Include layout/qgslayoutviewtoolpan.sip
285+
%Include layout/qgslayoutviewtoolselect.sip
285286
%Include layout/qgslayoutviewtoolzoom.sip
286287
%Include locator/qgslocator.sip
287288
%Include locator/qgslocatorfilter.sip
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/layout/qgslayoutviewtoolselect.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsLayoutViewToolSelect : QgsLayoutViewTool
12+
{
13+
%Docstring
14+
Layout view tool for selecting items in the layout.
15+
.. versionadded:: 3.0
16+
%End
17+
18+
%TypeHeaderCode
19+
#include "qgslayoutviewtoolselect.h"
20+
%End
21+
public:
22+
23+
QgsLayoutViewToolSelect( QgsLayoutView *view );
24+
%Docstring
25+
Constructor for QgsLayoutViewToolSelect.
26+
%End
27+
28+
virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );
29+
30+
virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );
31+
32+
virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );
33+
34+
virtual void deactivate();
35+
36+
37+
};
38+
39+
/************************************************************************
40+
* This file has been generated automatically from *
41+
* *
42+
* src/gui/layout/qgslayoutviewtoolselect.h *
43+
* *
44+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
45+
************************************************************************/

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgslayoutviewtooladditem.h"
2626
#include "qgslayoutviewtoolpan.h"
2727
#include "qgslayoutviewtoolzoom.h"
28+
#include "qgslayoutviewtoolselect.h"
2829

2930
QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
3031
: QgsLayoutDesignerInterface( dialog )
@@ -106,6 +107,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
106107
mZoomTool->setAction( mActionZoomTool );
107108
mToolsActionGroup->addAction( mActionZoomTool );
108109
connect( mActionZoomTool, &QAction::triggered, mZoomTool, [ = ] { mView->setTool( mZoomTool ); } );
110+
mSelectTool = new QgsLayoutViewToolSelect( mView );
111+
mSelectTool->setAction( mActionSelectMoveItem );
112+
mToolsActionGroup->addAction( mActionSelectMoveItem );
113+
connect( mActionSelectMoveItem, &QAction::triggered, mSelectTool, [ = ] { mView->setTool( mSelectTool ); } );
109114

110115

111116
restoreWindowState();

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class QgsLayoutView;
2525
class QgsLayoutViewToolAddItem;
2626
class QgsLayoutViewToolPan;
2727
class QgsLayoutViewToolZoom;
28+
class QgsLayoutViewToolSelect;
2829

2930
class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
3031
{
@@ -129,7 +130,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
129130
QgsLayoutViewToolAddItem *mAddItemTool = nullptr;
130131
QgsLayoutViewToolPan *mPanTool = nullptr;
131132
QgsLayoutViewToolZoom *mZoomTool = nullptr;
132-
133+
QgsLayoutViewToolSelect *mSelectTool = nullptr;
133134

134135
//! Save window state
135136
void saveWindowState();

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ SET(QGIS_GUI_SRCS
165165
layout/qgslayoutviewtool.cpp
166166
layout/qgslayoutviewtooladditem.cpp
167167
layout/qgslayoutviewtoolpan.cpp
168+
layout/qgslayoutviewtoolselect.cpp
168169
layout/qgslayoutviewtoolzoom.cpp
169170

170171
locator/qgslocator.cpp
@@ -633,6 +634,7 @@ SET(QGIS_GUI_MOC_HDRS
633634
layout/qgslayoutviewtool.h
634635
layout/qgslayoutviewtooladditem.h
635636
layout/qgslayoutviewtoolpan.h
637+
layout/qgslayoutviewtoolselect.h
636638
layout/qgslayoutviewtoolzoom.h
637639

638640
locator/qgslocator.h
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/***************************************************************************
2+
qgslayoutviewtoolselect.cpp
3+
---------------------------
4+
Date : July 2017
5+
Copyright : (C) 2017 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 "qgslayoutviewtoolselect.h"
17+
#include "qgslayoutviewmouseevent.h"
18+
#include "qgslayoutview.h"
19+
20+
QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
21+
: QgsLayoutViewTool( view, tr( "Select" ) )
22+
{
23+
setCursor( Qt::ArrowCursor );
24+
25+
mRubberBand.reset( new QgsLayoutViewRectangularRubberBand( view ) );
26+
mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) );
27+
mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) );
28+
}
29+
30+
void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event )
31+
{
32+
if ( event->button() != Qt::LeftButton )
33+
{
34+
event->ignore();
35+
return;
36+
}
37+
38+
mIsSelecting = true;
39+
mMousePressStartPos = event->pos();
40+
mRubberBand->start( event->layoutPoint(), 0 );
41+
}
42+
43+
void QgsLayoutViewToolSelect::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
44+
{
45+
if ( mIsSelecting )
46+
{
47+
mRubberBand->update( event->layoutPoint(), 0 );
48+
}
49+
else
50+
{
51+
event->ignore();
52+
}
53+
}
54+
55+
void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
56+
{
57+
if ( !mIsSelecting || event->button() != Qt::LeftButton )
58+
{
59+
event->ignore();
60+
return;
61+
}
62+
63+
mIsSelecting = false;
64+
QRectF rect = mRubberBand->finish( event->layoutPoint(), event->modifiers() );
65+
Q_UNUSED( rect );
66+
}
67+
68+
void QgsLayoutViewToolSelect::deactivate()
69+
{
70+
if ( mIsSelecting )
71+
{
72+
mRubberBand->finish();
73+
mIsSelecting = false;
74+
}
75+
QgsLayoutViewTool::deactivate();
76+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/***************************************************************************
2+
qgslayoutviewtoolselect.h
3+
-------------------------
4+
Date : July 2017
5+
Copyright : (C) 2017 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+
#ifndef QGSLAYOUTVIEWTOOLSELECT_H
17+
#define QGSLAYOUTVIEWTOOLSELECT_H
18+
19+
#include "qgis.h"
20+
#include "qgis_gui.h"
21+
#include "qgslayoutviewtool.h"
22+
#include "qgslayoutviewrubberband.h"
23+
#include <memory>
24+
25+
/**
26+
* \ingroup gui
27+
* Layout view tool for selecting items in the layout.
28+
* \since QGIS 3.0
29+
*/
30+
class GUI_EXPORT QgsLayoutViewToolSelect : public QgsLayoutViewTool
31+
{
32+
33+
Q_OBJECT
34+
35+
public:
36+
37+
/**
38+
* Constructor for QgsLayoutViewToolSelect.
39+
*/
40+
QgsLayoutViewToolSelect( QgsLayoutView *view );
41+
42+
void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
43+
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
44+
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
45+
void deactivate() override;
46+
47+
private:
48+
49+
bool mIsSelecting = false;
50+
51+
//! Rubber band item
52+
std::unique_ptr< QgsLayoutViewRubberBand > mRubberBand;
53+
54+
//! Start position for mouse press
55+
QPoint mMousePressStartPos;
56+
57+
//! Start of rubber band creation
58+
QPointF mRubberBandStartPos;
59+
60+
};
61+
62+
#endif // QGSLAYOUTVIEWTOOLSELECT_H

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
</attribute>
7676
<addaction name="mActionPan"/>
7777
<addaction name="mActionZoomTool"/>
78+
<addaction name="mActionSelectMoveItem"/>
7879
</widget>
7980
<widget class="QMenuBar" name="menuBar">
8081
<property name="geometry">
@@ -143,6 +144,24 @@
143144
<string>Z</string>
144145
</property>
145146
</action>
147+
<action name="mActionSelectMoveItem">
148+
<property name="checkable">
149+
<bool>true</bool>
150+
</property>
151+
<property name="icon">
152+
<iconset resource="../../../images/images.qrc">
153+
<normaloff>:/images/themes/default/mActionSelect.svg</normaloff>:/images/themes/default/mActionSelect.svg</iconset>
154+
</property>
155+
<property name="text">
156+
<string>Move &amp;Item</string>
157+
</property>
158+
<property name="toolTip">
159+
<string>Select/Move item</string>
160+
</property>
161+
<property name="shortcut">
162+
<string>V</string>
163+
</property>
164+
</action>
146165
</widget>
147166
<resources>
148167
<include location="../../../images/images.qrc"/>

0 commit comments

Comments
 (0)
Please sign in to comment.