Page 1 of 1

switch between mode selection

Posted: Thu Jun 07, 2018 6:15 pm
by sarlaa
Hi,

In qcad, when we keep Shift key pressed, we have selection with mode Add and when we release it we are back to selection with mode replace.
How can I programatically switch with this 2 modes ?

Thanks.

Re: switch between mode selection

Posted: Fri Jun 08, 2018 11:19 am
by andrew
For example when using RDocumentInterface::selectEntity, you can pass true as second parameter to add to selection, false to replace the selection:

Code: Select all

documentInterface.selectEntity(entityId, true);

Re: switch between mode selection

Posted: Fri Jun 08, 2018 12:34 pm
by sarlaa
Hi,

We don't want to do the selection programatically, we want have a button that switch with the 2 modes, the user can employ it and his selection takes in consideration his choice, same as scenario of shift key.

Unless you see we are forced to do it programatically : detect when user selection change; with having the selection before and the new selection, and generate programatically a new selection up to user choice mode.

Re: switch between mode selection

Posted: Fri Jun 08, 2018 1:42 pm
by andrew
Perhaps, what you are looking for is something like the persistent selection mode of QCAD in which the user can click the entities to select or deselect without using shift. To deselect everything, Select > Deselect all can be used.

You can activate this mode as follows:

Code: Select all

RSettings.setValue("GraphicsView/PersistentSelection", true);
Or in QCAD under Edit > Application Preferences > Graphics View > Appearance > Persistent Selection.

Re: switch between mode selection

Posted: Fri Jun 08, 2018 4:22 pm
by sarlaa
This is not really what I need.

In context that our user works with keyboard we don't have probleme, because we know when he will want to select with add mode he will press on key shift.
In other context when the user works with tablet, and then the way pressing on key shift not exists, we need to offer him a tool that does the same thing as keyboard shift, meaning switch to mode add selection, or notify script select that mode is changed.

Re: switch between mode selection

Posted: Mon Jun 11, 2018 11:59 am
by andrew
Thanks for your clarification.

This is not easily achievable, unless your operating system has a way to emulate a shift key press.

The shift key / selection behaviour is implemented in scripts/DefaultAction.js.

I've refactored this class to make it easer to override this behaviour. You can find the refactored version at:
https://github.com/qcad/qcad/blob/maste ... tAction.js

You can override the default action, e.g. as "MyDefaultAction" as follows:

Code: Select all

include("scripts/DefaultAction.js");

function MyDefaultAction(guiAction) {
    DefaultAction.call(this, guiAction);
}

MyDefaultAction.prototype = new DefaultAction();

MyDefaultAction.prototype.getAddToSelection = function(shiftPressed) {
    return (your own condition here) || DefaultAction.prototype.getAddToSelection.call(this, shiftPressed);
};
You can then initialize QCAD to use your own default action:

Code: Select all

setSettingsValue("NewFile/DefaultAction", "scripts/...../MyDefaultAction.js", true);

Re: switch between mode selection

Posted: Mon Jun 18, 2018 10:41 am
by sarlaa
Thanks for your help