개정판 e1da2013
add library insert function
Change-Id: If9fc0984b0cff11b2b92f54ef4e527f81e06acf5
DTI_PID/DTI_PID/LibraryItem.py | ||
---|---|---|
41 | 41 |
for _, symbol in enumerate(self._symbol_tree_widget.symbols): |
42 | 42 |
matches = [favorite for favorite in self.favorites if symbol.getUid() == favorite['Symbol_UID']] |
43 | 43 |
if matches: |
44 |
self.layout.addWidget(LibraryItem(symbol), idx // LibraryItemWidget.COLUMN, \ |
|
44 |
self.layout.addWidget(LibraryItem(symbol, self._symbol_tree_widget), idx // LibraryItemWidget.COLUMN, \
|
|
45 | 45 |
idx % LibraryItemWidget.COLUMN) |
46 | 46 |
idx += 1 |
47 | 47 |
except Exception as ex: |
... | ... | |
109 | 109 |
|
110 | 110 |
def dropEvent(self, event: QDropEvent) -> None: |
111 | 111 |
if hasattr(event.mimeData(), 'tag'): |
112 |
item = LibraryItem(event.mimeData().tag) |
|
112 |
item = LibraryItem(event.mimeData().tag, self._symbol_tree_widget)
|
|
113 | 113 |
self.add_library(item) |
114 | 114 |
|
115 | 115 |
event.acceptProposedAction() |
... | ... | |
118 | 118 |
class LibraryItem(QFrame): |
119 | 119 |
PIXMAP_SIZE = 32 |
120 | 120 |
|
121 |
def __init__(self, symbol): |
|
121 |
def __init__(self, symbol, symbol_tree_widget):
|
|
122 | 122 |
QFrame.__init__(self) |
123 | 123 |
self.id = f"{symbol.getType()}.{symbol.getName()}" |
124 | 124 |
self._symbol = symbol |
125 |
self._symbol_tree_widget = symbol_tree_widget |
|
125 | 126 |
# An Icon and a label below |
126 | 127 |
icon = QLabel() |
127 | 128 |
icon.setMaximumSize(LibraryItem.PIXMAP_SIZE, LibraryItem.PIXMAP_SIZE) |
... | ... | |
184 | 185 |
originalPoint = self._symbol.getOriginalPoint() |
185 | 186 |
drag.setHotSpot(QPoint(int(float(originalPoint.split(",")[0])), int(float(originalPoint.split(",")[1])))) |
186 | 187 |
drag.setPixmap(self._symbol.pixmap) |
188 |
|
|
189 |
model = self._symbol_tree_widget.model().sourceModel() |
|
190 |
_model = self._symbol_tree_widget.model() |
|
191 |
found = False |
|
192 |
for row in range(model.rowCount()): |
|
193 |
if found: break |
|
194 |
|
|
195 |
category_index = model.index(row, 0) |
|
196 |
_category_index = _model.index(row, 0) |
|
197 |
|
|
198 |
child_count = model.rowCount(category_index) |
|
199 |
for child_row in range(child_count): |
|
200 |
child_index = model.index(child_row, 0, category_index) |
|
201 |
_child_index = _model.index(child_row, 0, _category_index) |
|
202 |
id2_symbol_item = model.itemFromIndex(child_index) |
|
203 |
if id2_symbol_item.text() == self._symbol.getName(): |
|
204 |
self._symbol_tree_widget.selectionModel().setCurrentIndex(_child_index, QItemSelectionModel.Select) |
|
205 |
found = True |
|
206 |
break |
|
207 |
|
|
187 | 208 |
drag.exec(Qt.CopyAction) |
DTI_PID/DTI_PID/SymbolTreeWidget.py | ||
---|---|---|
51 | 51 |
QTreeView.__init__(self) |
52 | 52 |
self.setIconSize(QSize(32, 32)) |
53 | 53 |
|
54 |
self.setDragEnabled(True) # enable drag
|
|
54 |
self.setDragEnabled(True) # enable drag |
|
55 | 55 |
self.initSymbolTreeView() |
56 | 56 |
self.isDoubleClicked = False |
57 | 57 |
self.doubleClicked.connect(self.itemDoubleClickEvent) |
... | ... | |
346 | 346 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
347 | 347 |
|
348 | 348 |
def select_symbol(self, symbol): |
349 |
''' no more used ''' |
|
349 | 350 |
"""select a tree with given symbol""" |
350 | 351 |
|
351 | 352 |
founds = self.findItems(symbol.name, Qt.MatchExactly | Qt.MatchRecursive, 0) |
내보내기 Unified diff