Repository: biolab/orange3

Issue:
EditDoman doesn't clear editor when data is disconnected
**Describe the bug**

If we give an input to OWEditDomain and then disconnect it the variables remove but the editor keeps the last change.

Steps to reproduce the behavior:
1. Select Iris in File and connect it to EditDomain
2. Remove connection

**Orange version:**
3.25.dev

**Expected behavior**
Widget clears its state when the input data is disconnected.

**Screenshots**
![editdomain](https://user-images.githubusercontent.com/43814754/75663901-e61de480-5c71-11ea-88e8-985c519859c8.png)


**Operating system:**
Windows 10



Discussion:

Resolving patch:
diff --git a/Orange/widgets/data/oweditdomain.py b/Orange/widgets/data/oweditdomain.py
--- a/Orange/widgets/data/oweditdomain.py
+++ b/Orange/widgets/data/oweditdomain.py
@@ -1382,9 +1382,9 @@ def decorate(editor: VariableEditor) -> VariableEditor:
             typecb.activated[int].connect(self.__reinterpret_activated)
             form.insertRow(1, "Type:", typecb)
             # Insert the typecb after name edit in the focus chain
-            nameedit = editor.findChild(QLineEdit, )
-            if nameedit is not None:
-                QWidget.setTabOrder(nameedit, typecb)
+            name_edit = editor.findChild(QLineEdit, )
+            if name_edit is not None:
+                QWidget.setTabOrder(name_edit, typecb)
             return editor
         # This is ugly. Create an editor for each type and insert a type
         # selection combo box into its layout. Switch between widgets
@@ -1632,6 +1632,7 @@ def clear(self):
         """Clear the widget state."""
         self.data = None
         self.variables_model.clear()
+        self.clear_editor()
         assert self.selected_index == -1
         self.selected_index = -1
 
@@ -1751,6 +1752,7 @@ def clear_editor(self):
         except TypeError:
             pass
         current.set_data(None)
+        current.layout().currentWidget().clear()
 
     @Slot()
     def _on_variable_changed(self):


Test patch:
diff --git a/Orange/widgets/data/tests/test_oweditdomain.py b/Orange/widgets/data/tests/test_oweditdomain.py
--- a/Orange/widgets/data/tests/test_oweditdomain.py
+++ b/Orange/widgets/data/tests/test_oweditdomain.py
@@ -112,6 +112,54 @@ def test_input_data_disconnect(self):
         self.send_signal(self.widget.Inputs.data, None)
         self.assertEqual(self.widget.data, None)
 
+    def test_widget_state(self):
+        """Check if widget clears its state when the input is disconnected"""
+        editor = self.widget.findChild(ContinuousVariableEditor)
+        self.send_signal(self.widget.Inputs.data, self.iris)
+        self.assertEqual(editor.name_edit.text(), "sepal length")
+        self.send_signal(self.widget.Inputs.data, None)
+        self.assertEqual(editor.name_edit.text(), "")
+        self.assertEqual(
+            self.widget.variables_model.index(0).data(Qt.EditRole), None)
+
+        editor = self.widget.findChild(DiscreteVariableEditor)
+        self.send_signal(self.widget.Inputs.data, self.iris)
+        index = self.widget.domain_view.model().index(4)
+        self.widget.variables_view.setCurrentIndex(index)
+        self.assertEqual(editor.name_edit.text(), "iris")
+        self.assertEqual(editor.labels_model.get_dict(), {})
+        self.assertNotEqual(
+            self.widget.variables_model.index(0).data(Qt.EditRole), None)
+        model = editor.values_edit.selectionModel().model()
+        self.assertEqual(model.index(0).data(Qt.EditRole), "Iris-setosa")
+        self.send_signal(self.widget.Inputs.data, None)
+        self.assertEqual(editor.name_edit.text(), "")
+        self.assertEqual(editor.labels_model.get_dict(), {})
+        self.assertEqual(model.index(0).data(Qt.EditRole), None)
+        self.assertEqual(
+            self.widget.variables_model.index(0).data(Qt.EditRole), None)
+
+        editor = self.widget.findChild(TimeVariableEditor)
+        table = Table(test_filename("datasets/cyber-security-breaches.tab"))
+        self.send_signal(self.widget.Inputs.data, table)
+        index = self.widget.domain_view.model().index(4)
+        self.widget.variables_view.setCurrentIndex(index)
+        self.assertEqual(editor.name_edit.text(), "Date_Posted_or_Updated")
+        self.send_signal(self.widget.Inputs.data, None)
+        self.assertEqual(editor.name_edit.text(), "")
+        self.assertEqual(
+            self.widget.variables_model.index(0).data(Qt.EditRole), None)
+
+        editor = self.widget.findChild(VariableEditor)
+        self.send_signal(self.widget.Inputs.data, table)
+        index = self.widget.domain_view.model().index(8)
+        self.widget.variables_view.setCurrentIndex(index)
+        self.assertEqual(editor.var.name, "Business_Associate_Involved")
+        self.send_signal(self.widget.Inputs.data, None)
+        self.assertEqual(editor.var, None)
+        self.assertEqual(
+            self.widget.variables_model.index(0).data(Qt.EditRole), None)
+
     def test_output_data(self):
         """Check data on the output after apply"""
         self.send_signal(self.widget.Inputs.data, self.iris)