Re: [Qgis-developer] Using the QgsBrowserModel in Python

2015-07-30 Thread Ludovic Delauné
Le 30/07/2015 13:47, Hugo Mercier a écrit :
> Hi,
> 
> On 29/07/2015 17:50, Ludovic Delauné wrote:
>> Hi devs,
>>
>> i'm trying to use the QgsBrowserModel in a Python plugin.
>> I need to get the URI from a selected Item in the QTreeView, i expected to 
>> have a QgsLayerItem returned by the dataItem() in order to get the uri() 
>> member but a QgsDataItem
>> is returned instead.
>> Given a QgsDataItem, is it possible to get the uri of my data source ?
>>
>> Is this a bug due to the binding 
>> (https://github.com/qgis/QGIS/blob/feb3bee85837d707b1b10c14064fcb55364e282d/python/core/qgsbrowsermodel.sip)
>>  or i'm not in the right way ?
>>
>> Here are the few steps to reproduce the problem in a console:
>>
>> ---
>> from PyQt4.QtGui import QTreeView
>> tv = QTreeView(None)
>> m = QgsBrowserModel()
>> tv.setModel(m)
>> tv.show()
>> m.dataItem(tv.currentIndex())
>> 
>> output is :
>> 
> 
> Apparently, this is because QgsDataItem has nothing to convert to its
> derived types in the Python bindings. I'll add a %ConvertToSubClassCode.
> 
> Thanks for the report

Thanks for that clarification.

My current workaround is to use the mimeData method and deserialize the item to 
obtain the URI :

Add to the steps above :

from qgis.core import QgsMimeDataUtils
uri_list = QgsMimeDataUtils.decodeUriList(m.mimeData([tv.currentIndex()]))
uri_list[0].uri

--
Ludovic



___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[Qgis-developer] Using the QgsBrowserModel in Python

2015-07-29 Thread Ludovic Delauné
Hi devs,

i'm trying to use the QgsBrowserModel in a Python plugin.
I need to get the URI from a selected Item in the QTreeView, i expected to have 
a QgsLayerItem returned by the dataItem() in order to get the uri() member but 
a QgsDataItem
is returned instead.
Given a QgsDataItem, is it possible to get the uri of my data source ?

Is this a bug due to the binding 
(https://github.com/qgis/QGIS/blob/feb3bee85837d707b1b10c14064fcb55364e282d/python/core/qgsbrowsermodel.sip)
 or i'm not in the right way ?

Here are the few steps to reproduce the problem in a console:

---
from PyQt4.QtGui import QTreeView
tv = QTreeView(None)
m = QgsBrowserModel()
tv.setModel(m)
tv.show()
m.dataItem(tv.currentIndex())

output is :



QGIS version used : 2.8.2

regards.

-- 
Ludovic
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer