A layer control feature I added to my private copy of 2.2.2

(Hoping this forum soon becomes popular enough with LibreCAD users to get some real feedback on usage topics like this).

I added a layer control feature in my own copy that is a very big help to the way I use LibreCAD.

I don’t know whether others use layers this way, so I don’t know whether this deserves a feature request at GitHub.

I have a layer that is normally visible and locked and almost never has reason to be active or unlocked.

I have three other layers, and most of the time I am working on one of those three and that is the only one of the three that should be visible and it should also be active.

But I often switch which one of those three I am working on, a step that before my code change was 3 clicks and error prone (accidentally made the locked layer active when I misclicked, then I would do edits unable to see that because the wrong layer was active, the edits were wrong).

Due to a recent change in 2.2.2 clicking to activate a layer that is not visible did nothing. IIUC, no sequence gets you to the usually wrong, but occasionally useful, state of having a layer active but not visible. That is a separate feature I hope to add later. I agree it should not have been easy to accidentally get there. But there should be some more explicit way to get there.

All the above was just context, not my feature. My feature is:

If you click to activate a layer that is not visible, it makes that layer visible, but also: if the layer that was active wasn’t locked, it makes that other layer invisible.

That gives me a one click (non error prone) place to switch the layer I’m working on. It makes the target layer both visible and active while making the previous layer I was working on invisible.

Rarely I want to see two of those (normally mutually exclusive) layers at once. That remains easy to do, by selecting first the layer I want active and then the visibility of the other layer I want to see (often I want to temporarily lock that other layer at that same time).

I’m still learning my way around the code, so this trivial change was hard. I didn’t (actually still don’t) understand the reason and structure for the event of clicking (in the tree widget) to activate a layer being such a different flow from the event of clicking to toggle the visibility.

The change I wanted was obvious and trivial in RS_LayerList::activate taking about 0% of my total effort. But because I don’t understand the reason those events are handled so differently, I was very slow to figure out that the malfunction was due to failing to call RS_Graphic::refreshLayerVisibility() and once I figured out that needed to be called, there is no correct way to call it. So I called it a working but incorrect way, meaning this is a change that is fine for me, but would never go into a pull request done this way even if others want it. (and I don’t yet know how to do it a cleaner way).

Meanwhile, for my own use, this feature is really great.

I still not sure I understand how the active could be invisible - this is actually the bug if such state is achievable.

As far as I can see, the Layer Widget does not allow to make active layer invisible, and Layers Tree Widget also prohibit this.

So I’m wonder how you could get such state? It seems that there could be some workflow that is not covered.

And why this is useful state? If active layer is not visible, what is the value of this?

Regarding the function you’ve mentioned - it looks similar to behavior of radiobutton (yet with layers) - activating the layer hides other non-locked layers?

Is it so?

If it is true, that might be a bit strange yet useful mode to support it in widgets.

Btw, layers toolbar contains “Hide Other Layers than entity” command - it let’s control layers visibility based on specific entity (yet in a different way).

At this point, I forget which version I used that in. That appears to have been a “bug” that was fixed, but I found it useful.

Have the target layer of a copy operation active but invisible is sometimes a nice feature (rarely, but helps a lot on those rare occasions).

I also had cases where I did want to draw onto an invisible layer (undistracted by the contents of the target layer) while guided by the contents of a visible layer).

My use might be too unusual. For me, there should only rarely be layers visible but neither locked nor active. But if there are some, they should not be affected by changing the active layer. My code change only makes invisible the layer it is making inactive and that only if it is making visible the layer that is being made active.

For more general use, I think it does make sense to include at least one aspect of my change:

Unlike I don’t remember which version (and haven’t retested) the current 2.2.2 makes a layer inactive when you click to make it invisible. That was a good change. But in the same change, it refuses to make a layer active if you click to make an invisible layer active.

I think it makes more sense that a click to make an invisible layer active should make it both visible and active.