Repository: pyqtgraph/pyqtgraph

Issue:
LegendItem.setParentItem fails when no offset is provided
### Short description
In the current development version, calling setParentItem() on a LegendItem without offset results in an exception and crash.
This is because the offset value seems now to be saved in self.opts["offset"] while it was in self.offset before.
Right now setParentItem() checks if an offset exists by checking in the wrong place but uses the right offset afterwards. If no offset is set, a crash ensues
```python
if self.offset is not None:
            offset = Point(self.opts['offset'])
```
Changing to the following code fixes the problem:
```python
if self.opts['offset'] is not None:
            offset = Point(self.opts['offset'])
```


### Code to reproduce
<!-- Please provide a minimal working example that reproduces the issue in the code block below.
     Ideally, this should be a full example someone else could run without additional setup. -->
```python
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: Legend')
l = pg.LegendItem((100, 60))
l.setParentItem(plt.graphicsItem())


# Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
```

### Expected behavior
The plot should be displayed normally

### Real behavior
The following exception occurs:

```
Traceback (most recent call last):
  File "/home/vin/test/testlegend.py", line 7, in <module>
    l.setParentItem(plt.graphicsItem())
  File "/home/vin/miniconda3/lib/python3.7/site-packages/pyqtgraph/graphicsItems/LegendItem.py", line 128, in setParentItem
    offset = Point(self.opts['offset'])
  File "/home/vin/miniconda3/lib/python3.7/site-packages/pyqtgraph/Point.py", line 35, in __init__
    QtCore.QPointF.__init__(self, *args)
TypeError: arguments did not match any overloaded call:
  QPointF(): too many arguments
  QPointF(float, float): argument 1 has unexpected type 'NoneType'
  QPointF(QPoint): argument 1 has unexpected type 'NoneType'
  QPointF(QPointF): argument 1 has unexpected type 'NoneType'

```

### Tested environment(s)

 * PyQtGraph version: 0.11.0.dev0+gdb483f8
 * Qt Python binding: PyQt5 5.13.0 Qt 5.13.0 (same problem with PySide2 5.12.2 Qt 5.12.2)
 * Python version: 3.7
 * NumPy version: 1.17.3
 * Operating system: Linux Mint 19.1
 * Installation method: pip from latest github version




Discussion:

Resolving patch:
diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py
--- a/pyqtgraph/graphicsItems/LegendItem.py
+++ b/pyqtgraph/graphicsItems/LegendItem.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 from .GraphicsWidget import GraphicsWidget
 from .LabelItem import LabelItem
 from ..Qt import QtGui, QtCore
@@ -123,7 +124,7 @@ def setLabelTextColor(self, *args, **kargs):
 
     def setParentItem(self, p):
         ret = GraphicsWidget.setParentItem(self, p)
-        if self.offset is not None:
+        if self.opts['offset'] is not None:
             offset = Point(self.opts['offset'])
             anchorx = 1 if offset[0] <= 0 else 0
             anchory = 1 if offset[1] <= 0 else 0
@@ -251,7 +252,3 @@ def paint(self, p, *args):
 
             p.translate(10, 10)
             path = drawSymbol(p, symbol, size, pen, brush)
-
-
-
-


Test patch: