Skip to content
Permalink
Browse files

Fixes #39063 : Don't clear document path when its null representation

  • Loading branch information
troopa81 authored and nyalldawson committed Oct 16, 2020
1 parent 0170436 commit e075b879544ab114e7a069006aaed4155fb339c7
@@ -90,6 +90,9 @@ class GUI_EXPORT QgsExternalResourceWidgetWrapper : public QgsEditorWidgetWrappe
QLabel *mLabel = nullptr;
QgsAttributeForm *mForm = nullptr;
QgsExternalResourceWidget *mQgsWidget = nullptr;

friend class TestQgsExternalResourceWidgetWrapper;

};

#endif // QGSEXTERNALRESOURCEWIDGETWRAPPER_H
@@ -17,6 +17,7 @@
#include "qgsexternalresourcewidget.h"
#include "qgspixmaplabel.h"
#include "qgsproject.h"
#include "qgsapplication.h"

#include <QDir>
#include <QGridLayout>
@@ -60,7 +61,7 @@ QgsExternalResourceWidget::QgsExternalResourceWidget( QWidget *parent )
QVariant QgsExternalResourceWidget::documentPath( QVariant::Type type ) const
{
QString path = mFileWidget->filePath();
if ( path.isEmpty() )
if ( path.isEmpty() || path == QgsApplication::nullRepresentation() )
{
return QVariant( type );
}
@@ -92,14 +92,8 @@ QStringList QgsFileWidget::splitFilePaths( const QString &path )

void QgsFileWidget::setFilePath( QString path )
{
if ( path == QgsApplication::nullRepresentation() )
{
path.clear();
}

//will trigger textEdited slot
mLineEdit->setValue( path );

}

void QgsFileWidget::setReadOnly( bool readOnly )
@@ -172,3 +172,4 @@ ADD_QGIS_TEST(ogrproviderguitest testqgsogrprovidergui.cpp)
ADD_QGIS_TEST(singlebandpseudocolorrendererwidget testqgssinglebandpseudocolorrendererwidget.cpp)
ADD_QGIS_TEST(doublevalidator testqgsdoublevalidator.cpp)
ADD_QGIS_TEST(meshlayerpropertiesdialog testqgsmeshlayerpropertiesdialog.cpp)
ADD_QGIS_TEST(externalresourcewidgetwrapper testqgsexternalresourcewidgetwrapper.cpp)
@@ -0,0 +1,103 @@
/***************************************************************************
testqgsexternalresourcewidgetwrapper.cpp
---------------------------
begin : Oct 2020
copyright : (C) 2020 by Julien Cabieces
email : julien dot cabieces at oslandia 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 "qgsvectorlayer.h"
#include "qgsexternalresourcewidgetwrapper.h"
#include "qgsexternalresourcewidget.h"

#include <QLineEdit>

/**
* @ingroup UnitTests
* This is a unit test for the external resource widget wrapper
*
* \see QgsExternalResourceWidgetWrapper
*/
class TestQgsExternalResourceWidgetWrapper : 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 test_setNullValues();

private:
std::unique_ptr<QgsVectorLayer> vl;
};

void TestQgsExternalResourceWidgetWrapper::initTestCase()
{
// Set up the QgsSettings environment
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST-EXTERNAL-RESOURCE-WIDGET-WRAPPER" ) );

QgsApplication::init();
QgsApplication::initQgis();
}

void TestQgsExternalResourceWidgetWrapper::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsExternalResourceWidgetWrapper::init()
{
vl = qgis::make_unique<QgsVectorLayer>( QStringLiteral( "NoGeometry?field=link:string" ),
QStringLiteral( "myvl" ),
QLatin1String( "memory" ) );
}

void TestQgsExternalResourceWidgetWrapper::cleanup()
{
}

void TestQgsExternalResourceWidgetWrapper::test_setNullValues()
{
QgsExternalResourceWidgetWrapper ww( vl.get(), 0, nullptr, nullptr );
QWidget *widget = ww.createWidget( nullptr );
QVERIFY( widget );

ww.initWidget( widget );
QVERIFY( ww.mQgsWidget );
QVERIFY( ww.mLineEdit );

QSignalSpy spy( &ww, &QgsExternalResourceWidgetWrapper::valuesChanged );

ww.updateValues( QStringLiteral( "test" ) );
QCOMPARE( ww.mLineEdit->text(), "test" );
QCOMPARE( ww.mQgsWidget->documentPath(), QStringLiteral( "test" ) );
QCOMPARE( spy.count(), 1 );

ww.updateValues( QVariant() );
QCOMPARE( ww.mLineEdit->text(), QgsApplication::nullRepresentation() );
QCOMPARE( ww.mQgsWidget->documentPath(), QVariant( QVariant::String ) );
QCOMPARE( spy.count(), 2 );

ww.updateValues( QgsApplication::nullRepresentation() );
QCOMPARE( ww.mLineEdit->text(), QgsApplication::nullRepresentation() );
QCOMPARE( ww.mQgsWidget->documentPath(), QVariant( QVariant::String ) );
QCOMPARE( spy.count(), 2 );

delete widget;
}

QGSTEST_MAIN( TestQgsExternalResourceWidgetWrapper )
#include "testqgsexternalresourcewidgetwrapper.moc"

0 comments on commit e075b87

Please sign in to comment.
You can’t perform that action at this time.