Skip to content

Commit

Permalink
Add some unit tests for layout tools
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 99f3430 commit 2503497
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 14 deletions.
6 changes: 0 additions & 6 deletions python/gui/layout/qgslayoutview.sip
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class QgsLayoutView: QGraphicsView
%End
public:

enum Tool
{
ToolSelect,
ToolAddItem,
};

QgsLayoutView( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLayoutView.
Expand Down
1 change: 0 additions & 1 deletion src/gui/layout/qgslayoutview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void QgsLayoutView::unsetTool( QgsLayoutViewTool *tool )
if ( mTool && mTool == tool )
{
mTool->deactivate();
mTool = nullptr;
emit toolSet( nullptr );
setCursor( Qt::ArrowCursor );
}
Expand Down
7 changes: 0 additions & 7 deletions src/gui/layout/qgslayoutview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/gui/layout/qgslayoutviewtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
//! Translated name of the map tool
QString mToolName;

friend class TestQgsLayoutView;

};

#endif // QGSLAYOUTVIEWTOOL_H
3 changes: 3 additions & 0 deletions tests/src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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
${CMAKE_SOURCE_DIR}/src/core/expression
${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
Expand Down Expand Up @@ -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)
105 changes: 105 additions & 0 deletions tests/src/gui/testqgslayoutview.cpp
Original file line number Diff line number Diff line change
@@ -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 <QtTest/QSignalSpy>

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"

0 comments on commit 2503497

Please sign in to comment.