Bugfix 4417

Fix #4417, please see http://hub.qgis.org/issues/4417

I think that http://hub.qgis.org/issues/6514 is a duplicate of 4417.

PS: sorry about rebase mistake.

Thanks in advance