|
|
@@ -2,14 +2,15 @@
|
|
|
@author: olivier.massot
|
|
|
'''
|
|
|
|
|
|
-from PyQt5 import uic
|
|
|
+from PyQt5 import uic, QtCore
|
|
|
from PyQt5.Qt import Qt, QEvent, QGraphicsScene, QPointF, QFileDialog, \
|
|
|
QApplication, QMessageBox, QTreeWidgetItem, \
|
|
|
QGraphicsTextItem, QGraphicsItem, QGraphicsRectItem, \
|
|
|
QBrush, QColor, QGraphicsLineItem, QLineF, \
|
|
|
QPen, QPainter, QSvgGenerator, QSize, QRect, QGraphicsItemGroup, \
|
|
|
QGraphicsColorizeEffect, QFont, QDialog, QTableWidgetItem, \
|
|
|
- QListWidgetItem, QInputDialog, QIcon, QPixmap
|
|
|
+ QListWidgetItem, QInputDialog, QIcon, QPixmap, pyqtSignal, QObject, \
|
|
|
+ QTreeWidgetItemIterator
|
|
|
from PyQt5.QtWidgets import QMainWindow, QGraphicsView
|
|
|
from path import Path
|
|
|
|
|
|
@@ -35,8 +36,12 @@ v_spacing = 120
|
|
|
cell_width = 150
|
|
|
cell_spacing = 25
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
class GraphicsObject(QGraphicsItemGroup):
|
|
|
items = []
|
|
|
+
|
|
|
def __init__(self, obj, parent=None):
|
|
|
super(GraphicsObject, self).__init__(parent=parent)
|
|
|
self.obj = obj
|
|
|
@@ -115,6 +120,9 @@ class GraphicsObject(QGraphicsItemGroup):
|
|
|
def hoverLeaveEvent(self, _):
|
|
|
self.setShining(False)
|
|
|
|
|
|
+ def mouseDoubleClickEvent(self, _):
|
|
|
+ self.scene().itemDoubleClicked.emit(self)
|
|
|
+
|
|
|
class GraphicsRootObject(GraphicsObject):
|
|
|
def __init__(self, obj, parent=None):
|
|
|
super(GraphicsRootObject, self).__init__(obj, parent=parent)
|
|
|
@@ -263,6 +271,10 @@ class GraphicsLink(QGraphicsLineItem):
|
|
|
line = QLineF(self.mapToScene(self.topGraphicsObject.bottomAnchorCenter()), self.mapToScene(self.bottomGraphicsObject.topAnchorCenter()))
|
|
|
self.setLine(line)
|
|
|
|
|
|
+class GraphicsScene(QGraphicsScene):
|
|
|
+ itemDoubleClicked = pyqtSignal(object)
|
|
|
+
|
|
|
+
|
|
|
class Viewer(QMainWindow):
|
|
|
|
|
|
def __init__(self):
|
|
|
@@ -302,8 +314,9 @@ class Viewer(QMainWindow):
|
|
|
self.ui.view.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
|
|
|
self.ui.view.viewport().installEventFilter(self)
|
|
|
|
|
|
- self._scene = QGraphicsScene()
|
|
|
+ self._scene = GraphicsScene()
|
|
|
self._scene.setItemIndexMethod(QGraphicsScene.BspTreeIndex)
|
|
|
+ self._scene.itemDoubleClicked.connect(self.graphicsObjectDoubleClicked)
|
|
|
|
|
|
self.ui.view.setScene(self._scene)
|
|
|
|
|
|
@@ -451,9 +464,13 @@ class Viewer(QMainWindow):
|
|
|
GraphicsObject.items = []
|
|
|
self.enable_view_buttons(False)
|
|
|
|
|
|
- def maj_view_with(self, root_object):
|
|
|
+ def update_view(self, root_object=None):
|
|
|
+ if root_object is None:
|
|
|
+ root_object = next((go.obj for go in GraphicsObject.items if type(go) is GraphicsRootObject))
|
|
|
+
|
|
|
self.switch_graphic_view()
|
|
|
self.clear_scene()
|
|
|
+
|
|
|
root = GraphicsRootObject(root_object)
|
|
|
self._scene.addItem(root)
|
|
|
|
|
|
@@ -522,7 +539,7 @@ class Viewer(QMainWindow):
|
|
|
self.ui.btn_edit_item.setEnabled(False)
|
|
|
return
|
|
|
obj = core.Analyse.objects[index]
|
|
|
- self.maj_view_with(obj)
|
|
|
+ self.update_view(obj)
|
|
|
self.ui.btn_edit_item.setEnabled(True)
|
|
|
|
|
|
def filterTblDeps(self, filterStr):
|
|
|
@@ -552,19 +569,29 @@ class Viewer(QMainWindow):
|
|
|
self.ui.treeWidget.setCurrentItem(match)
|
|
|
self.ui.treeWidget.scrollTo(self.ui.treeWidget.indexFromItem(match, 1))
|
|
|
|
|
|
- def edit_selected_item(self):
|
|
|
- index = self.ui.treeWidget.currentItem().data(2, 0)
|
|
|
- obj = core.Analyse.objects[index]
|
|
|
+ def edit(self, obj):
|
|
|
dlg = DetailsDialog(obj, self)
|
|
|
dlg.show()
|
|
|
r = dlg.exec_()
|
|
|
if r:
|
|
|
core.Analyse.build_trees()
|
|
|
- self.maj_view_with(obj)
|
|
|
+ self.update_view()
|
|
|
+ item = self.find_tree_item(obj)
|
|
|
if any(len(m.warnings) > 0 for m in obj.mentions):
|
|
|
- self.ui.treeWidget.currentItem().setIcon(0, QIcon(QPixmap(core.here / "rsc\\warning_16.png")))
|
|
|
+ item.setIcon(0, QIcon(QPixmap(core.here / "rsc\\warning_16.png")))
|
|
|
else:
|
|
|
- self.ui.treeWidget.currentItem().setIcon(0, QIcon())
|
|
|
+ item.setIcon(0, QIcon())
|
|
|
+
|
|
|
+ def find_tree_item(self, obj):
|
|
|
+ return next((item for item in self.ui.treeWidget.findItems("", Qt.MatchContains | Qt.MatchRecursive, 1) if item.data(2, 0) == core.Analyse.objects.index(obj)))
|
|
|
+
|
|
|
+ def edit_selected_item(self):
|
|
|
+ index = self.ui.treeWidget.currentItem().data(2, 0)
|
|
|
+ obj = core.Analyse.objects[index]
|
|
|
+ self.edit(obj)
|
|
|
+
|
|
|
+ def graphicsObjectDoubleClicked(self, go):
|
|
|
+ self.edit(go.obj)
|
|
|
|
|
|
def keyPressEvent(self, e):
|
|
|
if e.key() == Qt.Key_S and e.modifiers() & Qt.ControlModifier:
|
|
|
@@ -578,8 +605,6 @@ class Viewer(QMainWindow):
|
|
|
if e.key() == Qt.Key_Control:
|
|
|
self.ui.view.setDragMode(QGraphicsView.RubberBandDrag)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
class DetailsDialog(QDialog):
|
|
|
|
|
|
def __init__(self, obj, parent=None):
|