Repository: pyqtgraph/pyqtgraph

Issue:
PlotWidget (and other plotting widgets) unhides all Items after removing single item
### Short description
I am plotting some spectral curves which overlaps. For my application it is practical to pre-add all spectras (curves) into plot and `hide()`, "unhide"/`show()` them with some checkboxes in `QListView`. Now I want to add and remove some preview vertical lines, for fast visual identification of peaks. When I finalize the preview and want the vertical lines to be removed from Plot with `removeItem`, it somehow triggers all spectral curves to unhide (probably with `show()` method). I made very simple minimal test to isolate the problem from my software code. See the minimal example below.

### Code to reproduce
```python
import pyqtgraph as pg

pw = pg.PlotWidget()
pw.show()
curves = {i: pg.PlotCurveItem([j ** i for j in range(10)]) for i in range(7)}

# 7 curves should be generated.
for i in curves:
    curves[i].hide()
    pw.addItem(curves[i])
curves[0].show()
curves[1].show()
# there should be only two lines on the plot visible at this point.
pw.removeItem(curves[5])
# but after this all items (except removed curve) are unhided()
```

### Expected behavior
`removeItem` should only remove the item without triggering sibling items into show() state.

### Real behavior
all sibling items are triggered to become visible.

### Tested environment(s)

 * PyQtGraph version: 0.11.0.dev0+g73c440a
 * Qt Python binding: PyQt5 5.11.3 Qt 5.11.2
 * Python version: 3.6.8 (default, Jan 14 2019, 11:02:34)
                             [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
 * isolated in python-virtual-environment without inclusion of system site packages. 
 * Operating system: KDE neon
 * Installation method: `pip git+https://pyqtgraph/pyqtgraph.git`



Discussion:
### I had thought about a few work arounds for my problem:
1. pre-add all vertical identification lines (and annotation TextItems), and use `show()`/`hide()` (instead of `addItem`/`removeItem` for preview). Unfortunately, the height of preview lines should be relative to physical size of canvas, not the coordinate system of main data curves, and needs to be re-scaled every time before showing it, and thus it is not good idea.
2. use separate fully overlapping (over `PlotWidget.PlotItem`) `ViewBox` dedicated for preview of identification vertical lines. Such Viewbox X axis would be in sync X with the main Viewbox of PlotWidget, but fixed Y range (0. to 1.), so vertical lines does not need to be vertically rescaled, every time. That actually was tested and works very snappy (the lines changes by hovering mouse over buttons of different element in  periodic table - that worked so snappy and was very satisfying)... but I got into other issues with that approach. The preview annotation items (vertical lines and texts) was being plotted behind the main Viewbox and its curve items (spectral curves). By setting the preview ViewBox Z  value to higher values, I could bring the preview items to be shown in front of the main Viewbox and its items, however that would brake mouse controlling of main Viewbox: Y axis of it would not change with mouse interaction, but scaling of preview ViewBox Y axis would change (opposite to the intended behavior). I had tried to force the preview ViewBox to be transparent for mouse event with applying the method `setAttribute(PyQt5.QtCore.Qt.WA_TransparentForMouseEvents, True)`, but it made no difference. Disabling the mouse for secondary ViewBox would completely switch mouse interaction off for primary ViewBox too. I could not find the way to have Viewbox in front of PlotWidget, and pass all mouse event to the PlotWidget and its primary ViewBox behind, thus I started to experiment again with trying to plot the preview Items in the single ViewBox shared by preview items and spectral curve items, thus I had run into the issue which I reported at the top.
3. Do not pre-add all spectral curves. Instead of `show()`/`hide()` them, do `addItem()`/`removeItem()`. In that way removing preview Items (vertical lines and annotation texts) would not unhide unintendently the curves.
It turns out that what you observe is caused by this line in `PlotItem.updateDecimation` https://github.com/pyqtgraph/pyqtgraph/blob/b0bc5b8931b8430b82e7fab4114811176272a994/pyqtgraph/graphicsItems/PlotItem/PlotItem.py#L929 as part of this commit https://github.com/pyqtgraph/pyqtgraph/commit/44b453eb812500adaae5170dccf6848829e453eb. Has anyone an idea of how `PlotItem.updateDecimation` is supposed to work and why this line may exist in the first place?

Resolving patch:
diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
--- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
+++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
@@ -924,15 +924,13 @@ def updateDecimation(self):
             
         curves = self.curves[:]
         split = len(curves) - numCurves
-        for i in range(len(curves)):
-            if numCurves == -1 or i >= split:
-                curves[i].show()
-            else:
+        for curve in curves[split:]:
+            if numCurves != -1:
                 if self.ctrl.forgetTracesCheck.isChecked():
-                    curves[i].clear()
+                    curve.clear()
                     self.removeItem(curves[i])
                 else:
-                    curves[i].hide()        
+                    curve.hide()        
       
     def updateAlpha(self, *args):
         (alpha, auto) = self.alphaState()


Test patch: