[Qgis-developer] How to stopediting/rollback in a plugin before changing the project-file

Marco Hugentobler marco.hugentobler at karto.baug.ethz.ch
Fri Dec 5 10:43:43 EST 2008


> - Now there is no dialog anymore when trying to open a new project

You mean the dialog that askes if the old project should be saved? I tested it 
here and the dialog still shows up

> - there is a qgis warning in the console saying Warning:
> QMetaObject::connectSlotsByName: No matching signal for
> on_mActionMoveItemsToBottom()
> I don't know if this depends on the changes you made.

No, it relates to the print composer. Nevertheless, good to know about it.

> - I can call the layer after listening to the SIGNAL now. For example the
> method name gives back the correct name of the layer correct.
> But I can't do rollBack or commitChanges. They give back False and the
> Editing tools are still active in the toolbar thus there is no layer in the
> new project.

Strange that rollBack and commitChanges don't work.

The editing tools are not deactivated by calling QgsVectorLayer::rollBack and 
commitChanges. You need to do that from within your plugin. Because 
QgsVectorLayer is a non-gui class. It does not know about the buttons.

Regards,
Marco

On Friday 05 December 2008 16:16:46 bjsvwpfe wrote:
> Thanks for the help Marco.
> Seems to be better now. When opening a new project layerWillBeRemoved is
> sent now.
> But there are still some problems and a few new problems.
> The new problems:
> - Now there is no dialog anymore when trying to open a new project
> - there is a qgis warning in the console saying Warning:
> QMetaObject::connectSlotsByName: No matching signal for
> on_mActionMoveItemsToBottom()
> I don't know if this depends on the changes you made.
>
> the remaining problems:
> - I can call the layer after listening to the SIGNAL now. For example the
> method name gives back the correct name of the layer correct.
> But I can't do rollBack or commitChanges. They give back False and the
> Editing tools are still active in the toolbar thus there is no layer in the
> new project.
>
> regards,
>
> Michael
>
> > Ok, this looks like a bug to me.
> > In r9743 there is a change such that layerWillBeRemoved is also sent from
> > QgsMapLayerRegistry::removeAllMapLayers()
> >
> > Regards,
> > Marco
> >
> > On Friday 05 December 2008 14:44:22 bjsvwpfe wrote:
> >> Hi Martin,
> >>
> >> > What about using layerWillBeRemoved signal from QgsMapLayerRegistry?
> >>
> >> thanks for your answer. I've already tried layerWillBeRemoved.
> >> But it seems that after clicking the Discard-Button SIGNAL removedAll()
> >> is
> >> sent by QgsMapLayerRegistry.
> >> And after this signal all layers in the QgsMapLayerRegistry have been
> >> deleted. layerWillBeRemoved works very good when I delete one layer but
> >> when changing the project removedAll() is sent and I get the following
> >> error: RuntimeError: underlying C/C++ object has been deleted
> >>
> >> Any other hints?
> >>
> >> Best regards
> >>
> >> Michael

-- 
Dr. Marco Hugentobler
Institute of Cartography
ETH Zurich
Technical Advisor QGIS Project Steering Committee


More information about the Qgis-developer mailing list