def editorEvent(self, event, model, option, index):
"""
When editing of an item starts, this function is called with the event
that triggered the editing, the model, the index of the item,
and the option used for rendering the item.
Mouse events are sent to editorEvent() even if they don't start editing
of the item. This can, for instance, be useful if you wish to open a
context menu when the right mouse button is pressed on an item.
The base implementation returns false (indicating that it has not
handled the event).
This is needed so when the createEditor is clicked then this is called.
This actually opens the import spatial data dialog.
"""
if event.
type() == QtCore.
QEvent.
MouseButtonPress: self.button_signal.emit(index.row(), index.column())
return True
elif event.
type() == QtCore.
QEvent.
MouseButtonRelease: return True
else:
return super(IssueDelegate, self).editorEvent(event, model, option, index)
# signal
self.delegate.button_signal.connect(self.importGIS)
def importGIS(self, val, val2):
## Instantiate the class.
self.file_browser = importGIS.ImportGIS(db,
title="Issues", fcType_filter=["Polyline", "Point", "Polygon"], sel_count="one", parent = self)
index = self.model.index(val, val2)
# Execute the file dialog.
# This will return the dialog to the user as a modal dialog.
if self.file_browser.exec_():
if self.file_browser.file_list_new > 0:
# Setdata method.
self.model.setData(index, os.path.basename(self.file_browser.file_list_new[0]))
def editorEvent(self, event, model, option, index):
"""
When editing of an item starts, this function is called with the event
that triggered the editing, the model, the index of the item,
and the option used for rendering the item.
Mouse events are sent to editorEvent() even if they don't start editing
of the item. This can, for instance, be useful if you wish to open a
context menu when the right mouse button is pressed on an item.
The base implementation returns false (indicating that it has not
handled the event).
This is needed so when the createEditor is clicked then this is called.
This actually opens the import spatial data dialog.
"""
if event.type() == QtCore.QEvent.MouseButtonPress:
self.button_signal.emit(index.row(), index.column())
return True
elif event.type() == QtCore.QEvent.MouseButtonRelease:
return True
else:
return super(IssueDelegate, self).editorEvent(event, model, option, index)
# signal
self.delegate.button_signal.connect(self.importGIS)
def importGIS(self, val, val2):
## Instantiate the class.
self.file_browser = importGIS.ImportGIS(db,
title="Issues", fcType_filter=["Polyline", "Point", "Polygon"], sel_count="one", parent = self)
index = self.model.index(val, val2)
# Execute the file dialog.
# This will return the dialog to the user as a modal dialog.
if self.file_browser.exec_():
if self.file_browser.file_list_new > 0:
# Setdata method.
self.model.setData(index, os.path.basename(self.file_browser.file_list_new[0]))
To copy to clipboard, switch view to plain text mode
Bookmarks