HowTo .setCurrentLayer() without an extra undo/redo step?
Posted: Sun Mar 21, 2021 12:17 pm
Andrew,
Similar as in AddLayer.js is setting the current layer to the newly added an extra operation.
Adding a new layer to the QCAD Layer List requires two undo steps to fully undo.
The first undo step is called [Change Document Settings]
The second step is [Add Layer YA]
Snippet AddLayer.js:
In the DrawFromCSV script new entities are casted with one global new RAddObjectsOperation()
But the layers for them are casted on the fly under the same setTransactionGroup(this.doc.getTransactionGroup())
On the fly because these layers must exist before initiating any new document entity for them.
The document is stored in 'this.doc' ... The document interface in 'this.di' ...
And the current layer at script level is stored in 'this.currentLayerName'.
Among the very few I found this example what does About the trick :
About, except that the Layer List isn't updated instantly
Maybe the only thing that is missing is refreshing the Layer List itself ...
That solved, I can update DrawFromCSV with Layers / Colors / Lineweights / Linetypes /.... and much more.
This also uses a method what is the solution for the FlexPainter group casting BUG.
Regards,
CVH
Similar as in AddLayer.js is setting the current layer to the newly added an extra operation.
Adding a new layer to the QCAD Layer List requires two undo steps to fully undo.
The first undo step is called [Change Document Settings]
The second step is [Add Layer YA]
Snippet AddLayer.js:
Code: Select all
AddLayer.prototype.beginEvent = function() {
...
..
.
var di = this.getDocumentInterface();
di.setCurrentLayer(this.layer);
// TODO: make new item the active, selected item
this.terminate();
};
But the layers for them are casted on the fly under the same setTransactionGroup(this.doc.getTransactionGroup())
On the fly because these layers must exist before initiating any new document entity for them.
The document is stored in 'this.doc' ... The document interface in 'this.di' ...
And the current layer at script level is stored in 'this.currentLayerName'.
Among the very few I found this example what does About the trick :
Code: Select all
var layerOp = new RAddObjectOperation();
layerOp.setText(qsTr("Cast CSV")); // translated tool title
layerOp.setTransactionGroup(this.doc.getTransactionGroup());
var docVars = this.doc.queryDocumentVariables();
docVars.setCurrentLayerId(this.doc.getLayerId(this.currentLayerName));
layerOp.addObject(docVars);
this.di.applyOperation(layerOp);
- It gets updated when swapping to another drawing tab and back.
Or
After 'Undo' and then 'Redo'.
Maybe the only thing that is missing is refreshing the Layer List itself ...
That solved, I can update DrawFromCSV with Layers / Colors / Lineweights / Linetypes /.... and much more.
This also uses a method what is the solution for the FlexPainter group casting BUG.
Regards,
CVH