mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-17 11:22:28 +12:00
Adds moving World items. #219
This commit is contained in:
parent
42bda30331
commit
fe617f871f
|
@ -2,7 +2,7 @@
|
|||
# --!-- coding: utf8 --!--
|
||||
from PyQt5.QtCore import QModelIndex
|
||||
from PyQt5.QtCore import QSize
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtCore import Qt, QMimeData, QByteArray
|
||||
from PyQt5.QtGui import QStandardItem, QBrush, QFontMetrics
|
||||
from PyQt5.QtGui import QStandardItemModel, QColor
|
||||
from PyQt5.QtWidgets import QMenu, QAction, qApp
|
||||
|
@ -122,6 +122,14 @@ class worldModel(QStandardItemModel):
|
|||
path = " > ".join(path)
|
||||
return path
|
||||
|
||||
def copyRowFromIndex(self, index):
|
||||
row_i = index.row()
|
||||
row = []
|
||||
for column_i in range(self.columnCount()):
|
||||
item = self.itemFromIndex(index.sibling(row_i, column_i)).clone()
|
||||
row.append(item)
|
||||
return row
|
||||
|
||||
###############################################################################
|
||||
# ADDING AND REMOVE
|
||||
###############################################################################
|
||||
|
@ -162,6 +170,42 @@ class worldModel(QStandardItemModel):
|
|||
index = self.selectedIndexes()[0]
|
||||
self.removeRows(index.row(), 1, index.parent())
|
||||
|
||||
###############################################################################
|
||||
# DRAG & DROP
|
||||
###############################################################################
|
||||
|
||||
"""Mime type for worldModel"""
|
||||
MIME_TYPE = "application/x.manuskript.worldmodel"
|
||||
|
||||
def mimeTypes(self):
|
||||
"""Returns available MIME types
|
||||
|
||||
Returns only worldModel MIME type to allow only internal drag & drop"""
|
||||
return [self.MIME_TYPE]
|
||||
|
||||
def mimeData(self, indexes):
|
||||
"""Returns dragged data as MIME data"""
|
||||
mime_data = QMimeData()
|
||||
"""set MIME type"""
|
||||
mime_data.setData(self.MIME_TYPE, QByteArray())
|
||||
rows = []
|
||||
for i in indexes:
|
||||
"""copy not move, because these rows will be deleted automatically
|
||||
after dropMimeData"""
|
||||
rows.append(self.copyRowFromIndex(i))
|
||||
"""mime_data.rows available only in the application"""
|
||||
mime_data.rows = rows
|
||||
return mime_data
|
||||
|
||||
def dropMimeData(self, mime_data, action, row, column, parent):
|
||||
"""insert MIME data"""
|
||||
parent_item = self.itemFromIndex(parent)
|
||||
if not parent_item:
|
||||
parent_item = self.invisibleRootItem()
|
||||
for row in mime_data.rows:
|
||||
parent_item.appendRow(row)
|
||||
return True
|
||||
|
||||
###############################################################################
|
||||
# TEMPLATES
|
||||
###############################################################################
|
||||
|
|
|
@ -737,6 +737,9 @@ class Ui_MainWindow(object):
|
|||
self.verticalLayout_32.setObjectName("verticalLayout_32")
|
||||
self.treeWorld = QtWidgets.QTreeView(self.frame_3)
|
||||
self.treeWorld.setEditTriggers(QtWidgets.QAbstractItemView.EditKeyPressed)
|
||||
self.treeWorld.setDragEnabled(True)
|
||||
self.treeWorld.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
|
||||
self.treeWorld.setDefaultDropAction(QtCore.Qt.MoveAction)
|
||||
self.treeWorld.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
|
||||
self.treeWorld.setIndentation(15)
|
||||
self.treeWorld.setRootIsDecorated(False)
|
||||
|
|
|
@ -1531,6 +1531,15 @@
|
|||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditKeyPressed</set>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::MoveAction</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
|
|
Loading…
Reference in a new issue