Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

The QgsVectorLayer class emits a selectionChanged() signal . If a QGIS user for example selects a record in the Attribute Table of a Vector Layer - a selectionChanged() signal is emitted an can be connected to an appropriate Slot inside the python code of a plugin. This signal is emitted every time the selection changes. I would need to realize a similar approach, but from a different direction. A signal should only be emitted when a user interaction occurs.

For example:

The user opens an attribute Table (of a vector layer) and selects one ore more records in this Table View with a mouse click. Is it possible to receive this click or select signal within a python plugin?

Does the Attribute TableView in QGIS itself emits a kind of itemSelectionChanged Signal whenever the selection of Attributes in the Table View changes? Which classes could be used to get this signal? I couldn't find any Information concerning my problem in the QGIS-API Documentation.

share|improve this question
    
I..don t get it. Elaborate please.. –  Shepherdjo Aug 16 '12 at 12:15
add comment

1 Answer 1

klausb,

Unless some signal is blocked or overridden somewhere along the way, QAbstractItemModel's signals should be available, e.g. dataChanged(). Also, you could access the QItemSelectionModel from QgsAttributeTableView and work with its signals, e.g. selectionChanged().

However, I'm not sure about the best means of accessing that dialog to build a signal/slot connection. It appears to be instantiated and deleted on-demand. I guess you could set up a watcher signal/slot connection at the QApplication level to the focusChanged() signal.

This would mean you either have to figure out if the focused widget is of the QgsAttributeTableDialog class or sniff out its name. Then, you could build the connection, which will disconnect when the attribute table dialog is closed and deleted.

There may be a better way, but currently the QGIS app does not emit a signal when the attribute table dialog is opened. You may want to submit a feature request for this.


Alternatively, you could create a custom feature form and add your own Python logic to it. That would work only in the instance where the user was editing a single feature, i.e. single row of the attribute table, though it is an ideal means of including verification of data input and opens up the possibilities to what you can do with what the user has entered.

share|improve this answer
1  
dakcarto, thank for your answer! Unfortunately it seams, that Python Bindings do not exist for the QgsAttributeTableModel Class, so I can't use it for my Python Plugin. But your alternative suggestion could be part of a solution. The Plugin could have the necessary Table Views itself (based on QtableWidget). That would allow the best control of user interaction. Thank you! –  klausb Aug 17 '12 at 10:48
    
@klausb please upvote if the answer was useful and accept if the answer solved your problem –  underdark Nov 15 '12 at 6:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.