Skip to content
Permalink
Browse files

add UI form for testing

  • Loading branch information
3nids committed Mar 1, 2018
1 parent 1869929 commit d413c8829a4e82ee2cf2bc768420c969cb1d2bce
@@ -182,7 +182,7 @@ bool QgsEditFormConfig::setUiForm( const QString &ui, QString *errMsg )
loop.exec( QEventLoop::ExcludeUserInputEvents );

QNetworkReply *reply = fetcher.reply();
if ( reply )
if ( reply && reply->error() == QNetworkReply::NoError )
{
QTemporaryFile *localFile = new QTemporaryFile( QStringLiteral( "XXXXXX.ui" ) );
if ( localFile->open() )
@@ -196,7 +196,7 @@ bool QgsEditFormConfig::setUiForm( const QString &ui, QString *errMsg )
}
if ( !success && errMsg )
{
*errMsg = QString( "Could not load UI from %1" ).arg( ui );
*errMsg = QString( "Could not load UI from %1 (%2)" ).arg( ui ).arg( reply->errorString() );
}
}
else
@@ -13,14 +13,19 @@
__revision__ = '$Format:%H$'

import qgis # NOQA
import os
import filecmp

from qgis.core import (QgsVectorLayer,
QgsReadWriteContext)
QgsReadWriteContext,
QgsEditFormConfig)
from qgis.gui import QgsGui

from qgis.testing import start_app, unittest
from qgis.PyQt.QtXml import QDomDocument, QDomElement
from utilities import unitTestDataPath

TEST_DATA_DIR = unitTestDataPath()
start_app()


@@ -57,6 +62,33 @@ def testReadWriteXml(self):
self.assertFalse(config2.labelOnTop(0))
self.assertTrue(config2.labelOnTop(1))

def testFormUi(self):
layer = self.createLayer()
config = layer.editFormConfig()

uiLocal = os.path.join(TEST_DATA_DIR, 'layer_attribute_form.ui')
(ok, _) = config.setUiForm(uiLocal)
self.assertTrue(ok)
self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
self.assertEqual(config.uiForm(QgsEditFormConfig.Original), uiLocal)
self.assertEqual(config.uiForm(QgsEditFormConfig.LocalCopy), uiLocal)

uiUrl = 'https://raw.githubusercontent.com/3nids/QGIS/7ac09b1f9b1921e7f95ab077d97dcf0dfd57be4a/tests/testdata/layer_attribute_form.ui'
(ok, _) = config.setUiForm(uiUrl)
self.assertTrue(ok)
self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
self.assertEqual(config.uiForm(QgsEditFormConfig.Original), uiUrl)
localCopy = config.uiForm(QgsEditFormConfig.LocalCopy)
self.assertNotEqual(localCopy, uiUrl)
filecmp.cmp(localCopy, uiLocal)

uiBadUrl = 'http://www.qwertzuiopasdfghjklyxcvbnm.qwer/xxx.ui'
(ok, _) = config.setUiForm(uiBadUrl)
self.assertFalse(ok)
self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)
self.assertEqual(config.uiForm(QgsEditFormConfig.Original), uiBadUrl)
self.assertEqual(config.uiForm(QgsEditFormConfig.LocalCopy), '')

def testReadOnly(self):
layer = self.createLayer()
config = layer.editFormConfig()
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CustomUiTest</class>
<widget class="QDialog" name="CustomUiTest">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>176</width>
<height>119</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="fldtxt"/>
</item>
<item row="1" column="0">
<widget class="QSpinBox" name="fldint"/>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CustomUiTest</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CustomUiTest</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit d413c88

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