Skip to content

Commit 2503497

Browse files
committedJul 11, 2017
Add some unit tests for layout tools
1 parent 99f3430 commit 2503497

File tree

6 files changed

+110
-14
lines changed

6 files changed

+110
-14
lines changed
 

‎python/gui/layout/qgslayoutview.sip

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ class QgsLayoutView: QGraphicsView
2424
%End
2525
public:
2626

27-
enum Tool
28-
{
29-
ToolSelect,
30-
ToolAddItem,
31-
};
32-
3327
QgsLayoutView( QWidget *parent /TransferThis/ = 0 );
3428
%Docstring
3529
Constructor for QgsLayoutView.

‎src/gui/layout/qgslayoutview.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ void QgsLayoutView::unsetTool( QgsLayoutViewTool *tool )
6767
if ( mTool && mTool == tool )
6868
{
6969
mTool->deactivate();
70-
mTool = nullptr;
7170
emit toolSet( nullptr );
7271
setCursor( Qt::ArrowCursor );
7372
}

‎src/gui/layout/qgslayoutview.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
4444

4545
public:
4646

47-
//! Current view tool
48-
enum Tool
49-
{
50-
ToolSelect = 0, //!< Select/move/resize item tool
51-
ToolAddItem, //!< Add new item tool
52-
};
53-
5447
/**
5548
* Constructor for QgsLayoutView.
5649
*/

‎src/gui/layout/qgslayoutviewtool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
158158
//! Translated name of the map tool
159159
QString mToolName;
160160

161+
friend class TestQgsLayoutView;
162+
161163
};
162164

163165
#endif // QGSLAYOUTVIEWTOOL_H

‎tests/src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
1010
${CMAKE_SOURCE_DIR}/src/gui
1111
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
1212
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
13+
${CMAKE_SOURCE_DIR}/src/gui/layout
1314
${CMAKE_SOURCE_DIR}/src/gui/symbology-ng
1415
${CMAKE_SOURCE_DIR}/src/gui/raster
1516
${CMAKE_SOURCE_DIR}/src/core
1617
${CMAKE_SOURCE_DIR}/src/core/expression
1718
${CMAKE_SOURCE_DIR}/src/core/auth
1819
${CMAKE_SOURCE_DIR}/src/core/composer
1920
${CMAKE_SOURCE_DIR}/src/core/geometry
21+
${CMAKE_SOURCE_DIR}/src/core/layout
2022
${CMAKE_SOURCE_DIR}/src/core/metadata
2123
${CMAKE_SOURCE_DIR}/src/core/raster
2224
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
@@ -131,3 +133,4 @@ ADD_QGIS_TEST(keyvaluewidgettest testqgskeyvaluewidget.cpp)
131133
ADD_QGIS_TEST(listwidgettest testqgslistwidget.cpp)
132134
ADD_QGIS_TEST(filedownloader testqgsfiledownloader.cpp)
133135
ADD_QGIS_TEST(composergui testqgscomposergui.cpp)
136+
ADD_QGIS_TEST(layoutview testqgslayoutview.cpp)

‎tests/src/gui/testqgslayoutview.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
testqgslayoutview.cpp
3+
--------------------
4+
Date : July 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgstest.h"
17+
#include "qgslayout.h"
18+
#include "qgslayoutview.h"
19+
#include "qgslayoutviewtool.h"
20+
#include <QtTest/QSignalSpy>
21+
22+
class TestQgsLayoutView: public QObject
23+
{
24+
Q_OBJECT
25+
private slots:
26+
void initTestCase(); // will be called before the first testfunction is executed.
27+
void cleanupTestCase(); // will be called after the last testfunction was executed.
28+
void init(); // will be called before each testfunction is executed.
29+
void cleanup(); // will be called after every testfunction.
30+
void basic();
31+
void tool();
32+
33+
private:
34+
35+
};
36+
37+
void TestQgsLayoutView::initTestCase()
38+
{
39+
40+
}
41+
42+
void TestQgsLayoutView::cleanupTestCase()
43+
{
44+
}
45+
46+
void TestQgsLayoutView::init()
47+
{
48+
}
49+
50+
void TestQgsLayoutView::cleanup()
51+
{
52+
}
53+
54+
void TestQgsLayoutView::basic()
55+
{
56+
QgsLayout *layout = new QgsLayout();
57+
QgsLayoutView *view = new QgsLayoutView();
58+
59+
QSignalSpy spyLayoutChanged( view, &QgsLayoutView::layoutSet );
60+
view->setCurrentLayout( layout );
61+
QCOMPARE( view->currentLayout(), layout );
62+
QCOMPARE( spyLayoutChanged.count(), 1 );
63+
64+
delete view;
65+
delete layout;
66+
}
67+
68+
void TestQgsLayoutView::tool()
69+
{
70+
QgsLayoutView *view = new QgsLayoutView();
71+
QgsLayoutViewTool *tool = new QgsLayoutViewTool( view, QStringLiteral( "name" ) );
72+
QgsLayoutViewTool *tool2 = new QgsLayoutViewTool( view, QStringLiteral( "name2" ) );
73+
74+
QSignalSpy spySetTool( view, &QgsLayoutView::toolSet );
75+
QSignalSpy spyToolActivated( tool, &QgsLayoutViewTool::activated );
76+
QSignalSpy spyToolActivated2( tool2, &QgsLayoutViewTool::activated );
77+
QSignalSpy spyToolDeactivated( tool, &QgsLayoutViewTool::deactivated );
78+
QSignalSpy spyToolDeactivated2( tool2, &QgsLayoutViewTool::deactivated );
79+
view->setTool( tool );
80+
QCOMPARE( view->tool(), tool );
81+
QCOMPARE( spySetTool.count(), 1 );
82+
QCOMPARE( spyToolActivated.count(), 1 );
83+
QCOMPARE( spyToolDeactivated.count(), 0 );
84+
85+
view->setTool( tool2 );
86+
QCOMPARE( view->tool(), tool2 );
87+
QCOMPARE( spySetTool.count(), 2 );
88+
QCOMPARE( spyToolActivated.count(), 1 );
89+
QCOMPARE( spyToolDeactivated.count(), 1 );
90+
QCOMPARE( spyToolActivated2.count(), 1 );
91+
QCOMPARE( spyToolDeactivated2.count(), 0 );
92+
93+
delete tool2;
94+
QVERIFY( !view->tool() );
95+
QCOMPARE( spySetTool.count(), 3 );
96+
QCOMPARE( spyToolActivated.count(), 1 );
97+
QCOMPARE( spyToolDeactivated.count(), 1 );
98+
QCOMPARE( spyToolActivated2.count(), 1 );
99+
QCOMPARE( spyToolDeactivated2.count(), 1 );
100+
101+
delete view;
102+
}
103+
104+
QGSTEST_MAIN( TestQgsLayoutView )
105+
#include "testqgslayoutview.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.