Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add shell for non-functional layout select tool
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 4b89f5e commit 4065a7f
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 1 deletion.
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -282,6 +282,7 @@
%Include layout/qgslayoutviewtool.sip
%Include layout/qgslayoutviewtooladditem.sip
%Include layout/qgslayoutviewtoolpan.sip
%Include layout/qgslayoutviewtoolselect.sip
%Include layout/qgslayoutviewtoolzoom.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
Expand Down
45 changes: 45 additions & 0 deletions python/gui/layout/qgslayoutviewtoolselect.sip
@@ -0,0 +1,45 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtoolselect.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutViewToolSelect : QgsLayoutViewTool
{
%Docstring
Layout view tool for selecting items in the layout.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutviewtoolselect.h"
%End
public:

QgsLayoutViewToolSelect( QgsLayoutView *view );
%Docstring
Constructor for QgsLayoutViewToolSelect.
%End

virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event );

virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );

virtual void deactivate();


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutviewtoolselect.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
5 changes: 5 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgslayoutviewtooladditem.h"
#include "qgslayoutviewtoolpan.h"
#include "qgslayoutviewtoolzoom.h"
#include "qgslayoutviewtoolselect.h"

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
Expand Down Expand Up @@ -106,6 +107,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mZoomTool->setAction( mActionZoomTool );
mToolsActionGroup->addAction( mActionZoomTool );
connect( mActionZoomTool, &QAction::triggered, mZoomTool, [ = ] { mView->setTool( mZoomTool ); } );
mSelectTool = new QgsLayoutViewToolSelect( mView );
mSelectTool->setAction( mActionSelectMoveItem );
mToolsActionGroup->addAction( mActionSelectMoveItem );
connect( mActionSelectMoveItem, &QAction::triggered, mSelectTool, [ = ] { mView->setTool( mSelectTool ); } );


restoreWindowState();
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -25,6 +25,7 @@ class QgsLayoutView;
class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand Down Expand Up @@ -129,7 +130,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
QgsLayoutViewToolAddItem *mAddItemTool = nullptr;
QgsLayoutViewToolPan *mPanTool = nullptr;
QgsLayoutViewToolZoom *mZoomTool = nullptr;

QgsLayoutViewToolSelect *mSelectTool = nullptr;

//! Save window state
void saveWindowState();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -165,6 +165,7 @@ SET(QGIS_GUI_SRCS
layout/qgslayoutviewtool.cpp
layout/qgslayoutviewtooladditem.cpp
layout/qgslayoutviewtoolpan.cpp
layout/qgslayoutviewtoolselect.cpp
layout/qgslayoutviewtoolzoom.cpp

locator/qgslocator.cpp
Expand Down Expand Up @@ -633,6 +634,7 @@ SET(QGIS_GUI_MOC_HDRS
layout/qgslayoutviewtool.h
layout/qgslayoutviewtooladditem.h
layout/qgslayoutviewtoolpan.h
layout/qgslayoutviewtoolselect.h
layout/qgslayoutviewtoolzoom.h

locator/qgslocator.h
Expand Down
76 changes: 76 additions & 0 deletions src/gui/layout/qgslayoutviewtoolselect.cpp
@@ -0,0 +1,76 @@
/***************************************************************************
qgslayoutviewtoolselect.cpp
---------------------------
Date : July 2017
Copyright : (C) 2017 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 "qgslayoutviewtoolselect.h"
#include "qgslayoutviewmouseevent.h"
#include "qgslayoutview.h"

QgsLayoutViewToolSelect::QgsLayoutViewToolSelect( QgsLayoutView *view )
: QgsLayoutViewTool( view, tr( "Select" ) )
{
setCursor( Qt::ArrowCursor );

mRubberBand.reset( new QgsLayoutViewRectangularRubberBand( view ) );
mRubberBand->setBrush( QBrush( QColor( 224, 178, 76, 63 ) ) );
mRubberBand->setPen( QPen( QBrush( QColor( 254, 58, 29, 100 ) ), 0, Qt::DotLine ) );
}

void QgsLayoutViewToolSelect::layoutPressEvent( QgsLayoutViewMouseEvent *event )
{
if ( event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

mIsSelecting = true;
mMousePressStartPos = event->pos();
mRubberBand->start( event->layoutPoint(), 0 );
}

void QgsLayoutViewToolSelect::layoutMoveEvent( QgsLayoutViewMouseEvent *event )
{
if ( mIsSelecting )
{
mRubberBand->update( event->layoutPoint(), 0 );
}
else
{
event->ignore();
}
}

void QgsLayoutViewToolSelect::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
{
if ( !mIsSelecting || event->button() != Qt::LeftButton )
{
event->ignore();
return;
}

mIsSelecting = false;
QRectF rect = mRubberBand->finish( event->layoutPoint(), event->modifiers() );
Q_UNUSED( rect );
}

void QgsLayoutViewToolSelect::deactivate()
{
if ( mIsSelecting )
{
mRubberBand->finish();
mIsSelecting = false;
}
QgsLayoutViewTool::deactivate();
}
62 changes: 62 additions & 0 deletions src/gui/layout/qgslayoutviewtoolselect.h
@@ -0,0 +1,62 @@
/***************************************************************************
qgslayoutviewtoolselect.h
-------------------------
Date : July 2017
Copyright : (C) 2017 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 QGSLAYOUTVIEWTOOLSELECT_H
#define QGSLAYOUTVIEWTOOLSELECT_H

#include "qgis.h"
#include "qgis_gui.h"
#include "qgslayoutviewtool.h"
#include "qgslayoutviewrubberband.h"
#include <memory>

/**
* \ingroup gui
* Layout view tool for selecting items in the layout.
* \since QGIS 3.0
*/
class GUI_EXPORT QgsLayoutViewToolSelect : public QgsLayoutViewTool
{

Q_OBJECT

public:

/**
* Constructor for QgsLayoutViewToolSelect.
*/
QgsLayoutViewToolSelect( QgsLayoutView *view );

void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
void deactivate() override;

private:

bool mIsSelecting = false;

//! Rubber band item
std::unique_ptr< QgsLayoutViewRubberBand > mRubberBand;

//! Start position for mouse press
QPoint mMousePressStartPos;

//! Start of rubber band creation
QPointF mRubberBandStartPos;

};

#endif // QGSLAYOUTVIEWTOOLSELECT_H
19 changes: 19 additions & 0 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -75,6 +75,7 @@
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionZoomTool"/>
<addaction name="mActionSelectMoveItem"/>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
Expand Down Expand Up @@ -143,6 +144,24 @@
<string>Z</string>
</property>
</action>
<action name="mActionSelectMoveItem">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSelect.svg</normaloff>:/images/themes/default/mActionSelect.svg</iconset>
</property>
<property name="text">
<string>Move &amp;Item</string>
</property>
<property name="toolTip">
<string>Select/Move item</string>
</property>
<property name="shortcut">
<string>V</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down

0 comments on commit 4065a7f

Please sign in to comment.