Source code for spinetoolbox.widgets.frozen_table_view

######################################################################################################################
# Copyright (C) 2017-2020 Spine project consortium
# This file is part of Spine Toolbox.
# Spine Toolbox is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
# any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Custom QTableView classes that support copy-paste and the like.

:author: M. Marin (KTH)
:date:   18.5.2018
"""

from PySide2.QtWidgets import QTableView, QAbstractItemView
from PySide2.QtCore import Signal
from .tabular_view_header_widget import TabularViewHeaderWidget


[docs]class FrozenTableView(QTableView):
[docs] header_dropped = Signal(object, object)
def __init__(self, parent=None): super().__init__(parent) self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setSelectionMode(QAbstractItemView.SingleSelection) self.horizontalHeader().setVisible(False) self.verticalHeader().setVisible(False) self.setSortingEnabled(True) self.setAcceptDrops(True) @property
[docs] def area(self): return "frozen"
[docs] def dragEnterEvent(self, event): if isinstance(event.source(), TabularViewHeaderWidget): event.accept()
[docs] def dragMoveEvent(self, event): if isinstance(event.source(), TabularViewHeaderWidget): event.accept()
[docs] def dropEvent(self, event): self.header_dropped.emit(event.source(), self)