Add shell for non-functional layout select tool

This commit is contained in:
Nyall Dawson 2017-07-05 18:47:53 +10:00
parent 4b89f5e474
commit 4065a7ff67
8 changed files with 212 additions and 1 deletions

View File

@ -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

View File

@ -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 *
************************************************************************/

View File

@ -25,6 +25,7 @@
#include "qgslayoutviewtooladditem.h"
#include "qgslayoutviewtoolpan.h"
#include "qgslayoutviewtoolzoom.h"
#include "qgslayoutviewtoolselect.h"
QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
@ -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();

View File

@ -25,6 +25,7 @@ class QgsLayoutView;
class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
@ -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();

View File

@ -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
@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -75,6 +75,7 @@
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionZoomTool"/>
<addaction name="mActionSelectMoveItem"/>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
@ -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"/>