def parent(self, index): if not index.isValid() or not index.internalPointer(): return QtCore.QModelIndex() child_item = index.internalPointer() parent_item = child_item.parent() if parent_item == self._root_node: return QtCore.QModelIndex() return self.createIndex(parent_item.row(), 0, parent_item)
def index(self, row, column, parent): if not self.hasIndex(row, column, parent): return QtCore.QModelIndex() if not parent.isValid(): parent_node = self._root_node else: parent_node = parent.internalPointer() child_item = parent_node.child(row) if child_item: return self.createIndex(row, column, child_item) else: return QtCore.QModelIndex()
def expand_tree(self, root_node): """Expands all the collapsed elements in a tree starting at the root_node""" parent = root_node.parent() parent_idx = self.model.createIndex(parent.row(), 0, parent) if parent else QtCore.QModelIndex() index = self.model.index(root_node.row(), 0, parent_idx) self.test_view.setExpanded(index, True) for child in root_node.children: self.expand_tree(child)
def mousePressEvent(self, event): child = self.childAt(event.pos()) if not child: return if not isinstance(child, ComponentWidget): return pos = child.mapFromParent(event.pos()) if not child.grab_rect().contains(pos): return # Create the drag object with the component data we are moving mime_data = QtCore.QMimeData() mime_data.setText(json.dumps(child.comp.data())) drag = QtGui.QDrag(self) drag.setMimeData(mime_data) hotspot = event.pos() - child.pos() drag.setHotSpot(hotspot) # Resize the indicator so it has the same height as the ComponentWidget we are dragging self.drop_indicator.setFixedHeight(child.height()) QtWidgets.qApp.setOverrideCursor( QtGui.QCursor(QtCore.Qt.ClosedHandCursor)) index = self.get_component_index_at_position(event.pos()) component_widget_index = self.queue_layout.indexOf(child) self.queue_layout.takeAt(component_widget_index) child.hide() self.place_indicator(index) if drag.exec_(QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction: # The drag reorder was accepted so do the actual move drop_indicator_index = self.queue_layout.indexOf( self.drop_indicator) self.hide_indicator() self.queue_layout.insertWidget(drop_indicator_index, child) child.show() self.queue.clear() components = self.get_ordered_component_widgets() for widget in components: self.queue.add(widget.comp) else: self.queue_layout.insertWidget(component_widget_index, child) child.show() restore_cursor()
def grab_rect(self): """Get the rectangle describing the grab hotspot.""" return QtCore.QRect(0, 0, 16, self.height() - 1)
def mimeData(self, indices): pks = ' '.join( [idx.internalPointer().component_path for idx in indices]) data = QtCore.QMimeData() data.setText(pks) return data
import json import webbrowser from functools import partial from cmt.qt import QtWidgets from cmt.qt import QtGui from cmt.qt import QtCore import maya.cmds as cmds from maya.app.general.mayaMixin import MayaQWidgetDockableMixin import cmt.shortcuts as shortcuts import cmt.cqueue.core as core import cmt.cqueue.fields as fields COMPONENT_FOLDER = 0 COMPONENT_ITEM = 1 SETTINGS = QtCore.QSettings('CMT', 'cqueue') SETTINGS_QUEUES = 'cqueue_queues' def delete_layout_contents(layout): """Delete the contents of a layout. :param layout: The layout to clear. """ try: count = layout.count() except AttributeError: count = 0 for i in range(count): widget = layout.takeAt(0) try:
def get_index_of_node(self, node): if node is self._root_node: return QtCore.QModelIndex() return self.index(node.row(), 0, self.get_index_of_node(node.parent()))
def parent(self, index): node = index.internalPointer() parent_node = node.parent() if parent_node == self._root_node: return QtCore.QModelIndex() return self.createIndex(parent_node.row(), 0, parent_node)