switch between mode selection

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

switch between mode selection

Post by sarlaa » Thu Jun 07, 2018 6:15 pm

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.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: switch between mode selection

Post by andrew » Fri Jun 08, 2018 11:19 am

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);

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: switch between mode selection

Post by sarlaa » Fri Jun 08, 2018 12:34 pm

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.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: switch between mode selection

Post by andrew » Fri Jun 08, 2018 1:42 pm

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.

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: switch between mode selection

Post by sarlaa » Fri Jun 08, 2018 4:22 pm

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.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: switch between mode selection

Post by andrew » Mon Jun 11, 2018 11:59 am

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);

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: switch between mode selection

Post by sarlaa » Mon Jun 18, 2018 10:41 am

Thanks for your help

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”