def mimeData(self, indexes): """ Returns an object that contains serialized items of data corresponding to the list of indexes specified. :param List[qt.QModelIndex] indexes: List of indexes :rtype: qt.QMimeData """ if len(indexes) > 1: return None if len(indexes) == 0: return None qindex = indexes[0] qindex = self.index(qindex.row(), 0, parent=qindex.parent()) item = self.itemFromIndex(qindex) if isinstance(item, _DatasetItemRow): dataset = item.getDataset() if dataset is None: return None else: mimeData = Hdf5DatasetMimeData(dataset=item.getDataset()) else: mimeData = None return mimeData
def testDropAxisDataset(self): dataset = commonh5.Dataset("foo", numpy.array([1, 2, 3, 4])) mimedata = Hdf5DatasetMimeData(dataset=dataset) nxDataIndex = self.model.index(0, 0) axesIndex = self.model.index(1, 0, nxDataIndex) self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, axesIndex) self.assertEqual(self.model.rowCount(qt.QModelIndex()), 1) item = self.model.itemFromIndex(axesIndex) self.assertIsNot(item.getDataset(), None)
def testDropNewNxdata(self): data = numpy.array([[[5]]]) nxdata = commonh5.Group("foo") nxdata.attrs["NX_class"] = "NXdata" nxdata.attrs["signal"] = "signal" nxdata.create_dataset("signal", data=data) mimedata = Hdf5DatasetMimeData(dataset=nxdata) self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, qt.QModelIndex()) self.assertEqual(self.model.rowCount(qt.QModelIndex()), 2)
def testDropNewDataset(self): dataset = commonh5.Dataset("foo", numpy.array([1, 2, 3, 4])) mimedata = Hdf5DatasetMimeData(dataset=dataset) self.model.dropMimeData(mimedata, qt.Qt.CopyAction, -1, -1, qt.QModelIndex()) self.assertEqual(self.model.rowCount(qt.QModelIndex()), 2)