Setting Sort Orders for New Multi-Level Menus

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
wildspidee
Full Member
Posts: 84
Joined: Sat Nov 03, 2012 2:00 am

Setting Sort Orders for New Multi-Level Menus

Post by wildspidee » Tue Feb 03, 2015 2:19 am

I've created a menu hierarchy for my add-on and the attached image illustrates the structure. The menu system works fine and I'm not getting any errors. However, I've created this by copying existing QCAD menu items. I've tried to understand the sort order numbering system by reading existing QCAD files, but I can't seem to follow the logic. The numbers are kind of all over the place. I'm concerned that I'm going to have problems because my numbers match existing QCAD items.

These are the functions that I've located that refer to sorting:

Main Menu - FMScripts

Code: Select all

FMScripts.getCadToolBarPanel = function() {
    var mtb = EAction.getMainCadToolBarPanel();
    var actionName = "FMScriptsPanelButton";
    if (!isNull(mtb) && mtb.findChild(actionName)==undefined) {
        var action = new RGuiAction(qsTr("FM Scripts"), mtb);
        action.setScriptFile(FMScripts.includeBasePath + "/FMScripts.js");
        action.objectName = actionName;
        action.setRequiresDocument(false);
        action.setStatusTip(qsTr("Show FM Scripts"));
        action.setNoState();
        action.setDefaultCommands(["FMScriptsmenu"]); 
        action.setGroupSortOrder(80); //HERE
        action.setSortOrder(100); //HERE
        action.setWidgetNames(["!MainToolsPanel"]);
    }

    var tb = EAction.getCadToolBarPanel(
        FMScripts.getTitle(),
        "FMScriptsPanel",
        true
    );
    return tb;
};
Sub Menus - FMMeasurements and FMPatterns

Code: Select all

FMMeasurements.getMenu = function() {
    var menu = EAction.getSubMenu(
        FMScripts.getMenu(),
      51200, 100, //HERE
        FMMeasurements.getTitle(),
        "FMMeasurementsMenu"
    );
    return menu;
};
Action Items - FMBodiceFront, Back, etc

Code: Select all

FMBodiceFront.init = function(basePath) {
    var action = new RGuiAction(qsTr("Bodice Front - Adult Female"), RMainWindowQt.getMainWindow());
    action.setRequiresDocument(true);
    action.setScriptFile(basePath + "/FMBodiceFront.js");
    action.setGroupSortOrder(79100); //HERE
    action.setSortOrder(100); //HERE
    action.setWidgetNames(["FMPatternsMenu"]);
};
Can you explain the existing numbering system or give me a series and instructions for numbering my add-on that will not interfere with any existing QCAD structures? I will be adding many more items, so I need a large series to work with.

Thank you for your help.

Lori
Attachments
Hierarchy.jpg
Hierarchy.jpg (34.29 KiB) Viewed 5257 times

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

Re: Setting Sort Orders for New Multi-Level Menus

Post by andrew » Tue Feb 03, 2015 10:09 am

The numbers are intended to define a global, unique sort order over all tools in QCAD.

The reason for this is to ensure a defined order even if tools are moved around. Some customers create their own user interface in which menus and tools are organized in a different way.

Since you are creating your tool in an isolated menu, you can basically use any numbers you like. The worst thing that could ever happen is that your tools would appear in the same group of an existing QCAD tool in the hypothetical case in which your tool would be moved, let's say to the File or Edit menu.

If you want to make absolutely sure that your tools are in separate groups, use group numbers above 1'000'000. The sort orders only affect sorting inside the same group. I usually use sort orders 100, 200, 300, ... to leave room to insert tools in between if desired.

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

Re: Setting Sort Orders for New Multi-Level Menus

Post by andrew » Tue Feb 03, 2015 11:08 am

BTW: You can launch QCAD with the command line switch -debug-action-order to display the group orders and sort orders of all menu entries.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”