Skip to content
Permalink
Browse files

Add some unit tests for layout tools

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 99f3430 commit 25034979e3e7ea39e8a2b7ef30ddff9543bb43cf
@@ -24,12 +24,6 @@ class QgsLayoutView: QGraphicsView
%End
public:

enum Tool
{
ToolSelect,
ToolAddItem,
};

QgsLayoutView( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLayoutView.
@@ -67,7 +67,6 @@ void QgsLayoutView::unsetTool( QgsLayoutViewTool *tool )
if ( mTool && mTool == tool )
{
mTool->deactivate();
mTool = nullptr;
emit toolSet( nullptr );
setCursor( Qt::ArrowCursor );
}
@@ -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.
*/
@@ -158,6 +158,8 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
//! Translated name of the map tool
QString mToolName;

friend class TestQgsLayoutView;

};

#endif // QGSLAYOUTVIEWTOOL_H
@@ -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
@@ -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)
@@ -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.
You can’t perform that action at this time.