diff --git a/python/gui/layout/qgslayoutview.sip b/python/gui/layout/qgslayoutview.sip index 21434c1cc11..c20d888c40e 100644 --- a/python/gui/layout/qgslayoutview.sip +++ b/python/gui/layout/qgslayoutview.sip @@ -24,12 +24,6 @@ class QgsLayoutView: QGraphicsView %End public: - enum Tool - { - ToolSelect, - ToolAddItem, - }; - QgsLayoutView( QWidget *parent /TransferThis/ = 0 ); %Docstring Constructor for QgsLayoutView. diff --git a/src/gui/layout/qgslayoutview.cpp b/src/gui/layout/qgslayoutview.cpp index 8007a70ec67..566de8d0e0e 100644 --- a/src/gui/layout/qgslayoutview.cpp +++ b/src/gui/layout/qgslayoutview.cpp @@ -67,7 +67,6 @@ void QgsLayoutView::unsetTool( QgsLayoutViewTool *tool ) if ( mTool && mTool == tool ) { mTool->deactivate(); - mTool = nullptr; emit toolSet( nullptr ); setCursor( Qt::ArrowCursor ); } diff --git a/src/gui/layout/qgslayoutview.h b/src/gui/layout/qgslayoutview.h index 0add19022cb..b46ad645afb 100644 --- a/src/gui/layout/qgslayoutview.h +++ b/src/gui/layout/qgslayoutview.h @@ -44,13 +44,6 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView public: - //! Current view tool - enum Tool - { - ToolSelect = 0, //!< Select/move/resize item tool - ToolAddItem, //!< Add new item tool - }; - /** * Constructor for QgsLayoutView. */ diff --git a/src/gui/layout/qgslayoutviewtool.h b/src/gui/layout/qgslayoutviewtool.h index 06dedd84ba7..74f0b0100f9 100644 --- a/src/gui/layout/qgslayoutviewtool.h +++ b/src/gui/layout/qgslayoutviewtool.h @@ -158,6 +158,8 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject //! Translated name of the map tool QString mToolName; + friend class TestQgsLayoutView; + }; #endif // QGSLAYOUTVIEWTOOL_H diff --git a/tests/src/gui/CMakeLists.txt b/tests/src/gui/CMakeLists.txt index 2506cb2119b..52a2effc296 100644 --- a/tests/src/gui/CMakeLists.txt +++ b/tests/src/gui/CMakeLists.txt @@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/gui ${CMAKE_SOURCE_DIR}/src/gui/editorwidgets ${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core + ${CMAKE_SOURCE_DIR}/src/gui/layout ${CMAKE_SOURCE_DIR}/src/gui/symbology-ng ${CMAKE_SOURCE_DIR}/src/gui/raster ${CMAKE_SOURCE_DIR}/src/core @@ -17,6 +18,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/core/auth ${CMAKE_SOURCE_DIR}/src/core/composer ${CMAKE_SOURCE_DIR}/src/core/geometry + ${CMAKE_SOURCE_DIR}/src/core/layout ${CMAKE_SOURCE_DIR}/src/core/metadata ${CMAKE_SOURCE_DIR}/src/core/raster ${CMAKE_SOURCE_DIR}/src/core/symbology-ng @@ -131,3 +133,4 @@ ADD_QGIS_TEST(keyvaluewidgettest testqgskeyvaluewidget.cpp) ADD_QGIS_TEST(listwidgettest testqgslistwidget.cpp) ADD_QGIS_TEST(filedownloader testqgsfiledownloader.cpp) ADD_QGIS_TEST(composergui testqgscomposergui.cpp) +ADD_QGIS_TEST(layoutview testqgslayoutview.cpp) diff --git a/tests/src/gui/testqgslayoutview.cpp b/tests/src/gui/testqgslayoutview.cpp new file mode 100644 index 00000000000..3993af25237 --- /dev/null +++ b/tests/src/gui/testqgslayoutview.cpp @@ -0,0 +1,105 @@ +/*************************************************************************** + testqgslayoutview.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 "qgstest.h" +#include "qgslayout.h" +#include "qgslayoutview.h" +#include "qgslayoutviewtool.h" +#include + +class TestQgsLayoutView: public QObject +{ + Q_OBJECT + private slots: + void initTestCase(); // will be called before the first testfunction is executed. + void cleanupTestCase(); // will be called after the last testfunction was executed. + void init(); // will be called before each testfunction is executed. + void cleanup(); // will be called after every testfunction. + void basic(); + void tool(); + + private: + +}; + +void TestQgsLayoutView::initTestCase() +{ + +} + +void TestQgsLayoutView::cleanupTestCase() +{ +} + +void TestQgsLayoutView::init() +{ +} + +void TestQgsLayoutView::cleanup() +{ +} + +void TestQgsLayoutView::basic() +{ + QgsLayout *layout = new QgsLayout(); + QgsLayoutView *view = new QgsLayoutView(); + + QSignalSpy spyLayoutChanged( view, &QgsLayoutView::layoutSet ); + view->setCurrentLayout( layout ); + QCOMPARE( view->currentLayout(), layout ); + QCOMPARE( spyLayoutChanged.count(), 1 ); + + delete view; + delete layout; +} + +void TestQgsLayoutView::tool() +{ + QgsLayoutView *view = new QgsLayoutView(); + QgsLayoutViewTool *tool = new QgsLayoutViewTool( view, QStringLiteral( "name" ) ); + QgsLayoutViewTool *tool2 = new QgsLayoutViewTool( view, QStringLiteral( "name2" ) ); + + QSignalSpy spySetTool( view, &QgsLayoutView::toolSet ); + QSignalSpy spyToolActivated( tool, &QgsLayoutViewTool::activated ); + QSignalSpy spyToolActivated2( tool2, &QgsLayoutViewTool::activated ); + QSignalSpy spyToolDeactivated( tool, &QgsLayoutViewTool::deactivated ); + QSignalSpy spyToolDeactivated2( tool2, &QgsLayoutViewTool::deactivated ); + view->setTool( tool ); + QCOMPARE( view->tool(), tool ); + QCOMPARE( spySetTool.count(), 1 ); + QCOMPARE( spyToolActivated.count(), 1 ); + QCOMPARE( spyToolDeactivated.count(), 0 ); + + view->setTool( tool2 ); + QCOMPARE( view->tool(), tool2 ); + QCOMPARE( spySetTool.count(), 2 ); + QCOMPARE( spyToolActivated.count(), 1 ); + QCOMPARE( spyToolDeactivated.count(), 1 ); + QCOMPARE( spyToolActivated2.count(), 1 ); + QCOMPARE( spyToolDeactivated2.count(), 0 ); + + delete tool2; + QVERIFY( !view->tool() ); + QCOMPARE( spySetTool.count(), 3 ); + QCOMPARE( spyToolActivated.count(), 1 ); + QCOMPARE( spyToolDeactivated.count(), 1 ); + QCOMPARE( spyToolActivated2.count(), 1 ); + QCOMPARE( spyToolDeactivated2.count(), 1 ); + + delete view; +} + +QGSTEST_MAIN( TestQgsLayoutView ) +#include "testqgslayoutview.moc"