Skip to content

Commit 488b41f

Browse files
committedJan 13, 2016
add test for QgsFilePickerWidget
1 parent cc9f000 commit 488b41f

File tree

5 files changed

+101
-4
lines changed

5 files changed

+101
-4
lines changed
 

‎src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void QgsExternalResourceWidgetWrapper::initWidget( QWidget* editor )
8282

8383
if ( mQgsWidget )
8484
{
85+
mQgsWidget->filePickerwidget()->setStorageMode( QgsFilePickerWidget::File );
8586
if ( config().contains( "UseLink" ) )
8687
{
8788
mQgsWidget->filePickerwidget()->setUseLink( config( "UseLink" ).toBool() );

‎src/gui/qgsfilepickerwidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,17 @@ QString QgsFilePickerWidget::relativePath( QString filePath, bool removeRelative
249249
{
250250
RelativePath = QDir::toNativeSeparators( QDir::cleanPath( mDefaultRoot ) );
251251
}
252+
252253
if ( !RelativePath.isEmpty() )
253254
{
254255
if ( removeRelative )
256+
{
255257
return QDir::cleanPath( QDir( RelativePath ).relativeFilePath( filePath ) );
258+
}
256259
else
260+
{
257261
return QDir::cleanPath( QDir( RelativePath ).filePath( filePath ) );
262+
}
258263
}
259264

260265
return filePath;

‎src/gui/qgsfilepickerwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class GUI_EXPORT QgsFilePickerWidget : public QWidget
122122

123123
//! Returns a filePath with relative path options applied (or not) !
124124
QString relativePath( QString filePath, bool removeRelative ) const;
125+
126+
friend class TestQgsFilePickerWidget;
125127
};
126128

127129
#endif // QGSFILEPICKERWIDGET_H

‎tests/src/gui/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ ADD_QGIS_TEST(zoomtest testqgsmaptoolzoom.cpp)
121121
#ADD_EXECUTABLE(qgis_rendererv2gui ${rendererv2gui_SRCS} ${rendererv2gui_MOC_SRCS})
122122

123123
#ADD_QGIS_TEST(histogramtest testqgsrasterhistogram.cpp)
124+
ADD_QGIS_TEST(doublespinbox testqgsdoublespinbox.cpp)
125+
ADD_QGIS_TEST(dualviewtest testqgsdualview.cpp )
126+
ADD_QGIS_TEST(filepickerwidget testqgsfilepickerwidget.cpp )
127+
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp )
124128
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
125129
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
130+
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp )
126131
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
127-
ADD_QGIS_TEST(dualviewtest testqgsdualview.cpp )
128-
ADD_QGIS_TEST(doublespinbox testqgsdoublespinbox.cpp)
129132
ADD_QGIS_TEST(spinbox testqgsspinbox.cpp)
130-
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp )
131-
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp )
133+
132134

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/***************************************************************************
2+
testqgsdoublespinbox.cpp
3+
--------------------------------------
4+
Date : December 2014
5+
Copyright : (C) 2014 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+
17+
#include <QtTest/QtTest>
18+
19+
#include "qgsfilepickerwidget.h"
20+
21+
class TestQgsFilePickerWidget: public QObject
22+
{
23+
Q_OBJECT
24+
private slots:
25+
void initTestCase(); // will be called before the first testfunction is executed.
26+
void cleanupTestCase(); // will be called after the last testfunction was executed.
27+
void init(); // will be called before each testfunction is executed.
28+
void cleanup(); // will be called after every testfunction.
29+
30+
void relativePath();
31+
void toUrl();
32+
33+
};
34+
35+
void TestQgsFilePickerWidget::initTestCase()
36+
{
37+
38+
}
39+
40+
void TestQgsFilePickerWidget::cleanupTestCase()
41+
{
42+
}
43+
44+
void TestQgsFilePickerWidget::init()
45+
{
46+
}
47+
48+
void TestQgsFilePickerWidget::cleanup()
49+
{
50+
}
51+
52+
void TestQgsFilePickerWidget::relativePath()
53+
{
54+
QgsFilePickerWidget* w = new QgsFilePickerWidget();
55+
w->setDefaultRoot( "/home/test" );
56+
w->setRelativeStorage( QgsFilePickerWidget::Absolute );
57+
QCOMPARE( w->relativePath( "/home/test2/file1.ext", true ), QString( "/home/test2/file1.ext" ) );
58+
QCOMPARE( w->relativePath( "/home/test2/file2.ext", false ), QString( "/home/test2/file2.ext" ) );
59+
w->setRelativeStorage( QgsFilePickerWidget::RelativeDefaultPath );
60+
QCOMPARE( w->relativePath( "/home/test2/file3.ext", true ), QString( "../test2/file3.ext" ) );
61+
QCOMPARE( w->relativePath( "../test2/file4.ext", true ), QString( "../test2/file4.ext" ) );
62+
QCOMPARE( w->relativePath( "/home/test2/file5.ext", false ), QString( "/home/test2/file5.ext" ) );
63+
QCOMPARE( w->relativePath( "../test2/file6.ext", false ), QString( "/home/test2/file6.ext" ) );
64+
}
65+
66+
void TestQgsFilePickerWidget::toUrl()
67+
{
68+
QgsFilePickerWidget* w = new QgsFilePickerWidget();
69+
w->setDefaultRoot( "/home/test" );
70+
w->setRelativeStorage( QgsFilePickerWidget::Absolute );
71+
w->setFullUrl( true );
72+
QCOMPARE( w->toUrl( "/home/test2/file1.ext" ), QString( "<a href=\"file:///home/test2/file1.ext\">/home/test2/file1.ext</a>" ) );
73+
w->setFullUrl( false );
74+
QCOMPARE( w->toUrl( "/home/test2/file2.ext" ), QString( "<a href=\"file:///home/test2/file2.ext\">file2.ext</a>" ) );
75+
w->setRelativeStorage( QgsFilePickerWidget::RelativeDefaultPath );
76+
w->setFullUrl( true );
77+
QCOMPARE( w->toUrl( "/home/test2/file3.ext" ), QString( "<a href=\"file:///home/test2/file3.ext\">/home/test2/file3.ext</a>" ) );
78+
QCOMPARE( w->toUrl( "../test2/file4.ext" ), QString( "<a href=\"file:///home/test2/file4.ext\">../test2/file4.ext</a>" ) );
79+
w->setFullUrl( false );
80+
QCOMPARE( w->toUrl( "/home/test2/file5.ext" ), QString( "<a href=\"file:///home/test2/file5.ext\">file5.ext</a>" ) );
81+
QCOMPARE( w->toUrl( "../test2/file6.ext" ), QString( "<a href=\"file:///home/test2/file6.ext\">file6.ext</a>" ) );
82+
}
83+
84+
85+
86+
QTEST_MAIN( TestQgsFilePickerWidget )
87+
#include "testqgsfilepickerwidget.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.