QCAD

QCAD - 2D CAD System.

Click here for a documentation of the DokuWiki formatting syntax that can be used in reports

Please search for existing tasks (also closed ones) before opening a new task.

Please make sure that you are using the latest Version of QCAD before posting a bug (menu Help - Check for Updates)

Tasklist

FS#902 - Reduced font selection not working as expected

Attached to Project: QCAD
Opened by Tamas TEVESZ (kazmer) - Thursday, 22 August 2013, 14:30 GMT+1
Last edited by Andrew (andrew) - Tuesday, 27 August 2013, 12:28 GMT+1
Task Type Bug Report
Category Main
Status Closed
Assigned To Andrew (andrew)
Operating System All
Severity Low
Priority Normal
Reported Version 3.2.2
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

QCAD GPL Git reba26f7a, completely new configuration (seemingly important); also happens with the binary QCAD 3.2.2 download.

I wanted to use the Standard CAD font and the Standard CAD font only. To achieve that, in Application Preferences→Draw→Text, I ticked “Use reduced selection of fonts” and hit “Uncheck all”.

My expectation is that in this case the Text tool lists only the Standard font.

What actually happens is that the “Standard” font stays disabled, is deselected, and the Text tool lists every font I have installed on my system (system-wide fonts only, TTF and whatever else), and none of the CAD fonts bundled with QCAD in fonts/ (not even Standard).

There seems to be some inconsistency in the handling of “Standard” – it is apparently meant to be selected no matter what, and its checkbox disabled so the end user isn’t even able to de-select it. What actually happens is that the Text preferences “Check all”/”Uncheck all” buttons do affect its selected state.

At this time, the saved configuration (in ~/.config/QCAD3) contains the following entries:

[Text]
ReducedFontList=@Invalid()
UseReducedFontList=true

Note that at this point the Text preferences screen indicates that the Standard entry is disabled and not selected, see fontsel-1.png

So I did the following as an experiment:

--- a/scripts/Edit/AppPreferences/TextPreferences/TextPreferences.js
+++ b/scripts/Edit/AppPreferences/TextPreferences/TextPreferences.js
@@ -58,7 +58,7 @@ TextPreferences.initPreferences = function(pageWidget, calledByPrefDialog, docum
         // always check 'standard':
         if (item.text().toLowerCase()==="standard") {
             item.setCheckState(Qt.Checked);
-            flags = new Qt.ItemFlags(item.flags() & ~Qt.ItemIsEnabled);
+            // flags = new Qt.ItemFlags(item.flags() & ~Qt.ItemIsEnabled);
         }
         if (list.contains(item.text())) {
             item.setCheckState(Qt.Checked);

At this point, the Text preferences screen has the “Standard” font enabled and still not selected, see fontsel-2.png

The saved configuration file still contains an invalid entry for the font list:

[Text]
ReducedFontList=@Invalid()
UseReducedFontList=true

(This is probably is as intended, since the list is not supposed to be empty, but it really is now.)

Now let’s select “Standard” in the Text preferences screen, Apply, and undo the above change to TextPreferences.js.

At this point, the configuration file contains what seems correct:

[Text]
ReducedFontList=@Variant(\0\0\0\t\0\0\0\x1\0\0\0\n\0\0\0\x10\0S\0t\0\x61\0n\0\x64\0\x61\0r\0\x64)
UseReducedFontList=true

The font list on the Text preferences screen has changed as seen on fontsel-3.png.

Note that now the “Standard” font is again disabled, but now it is selected.

At this point, the Text tool behaves as expected: there is only one entry, the “Standard” CAD font.

Summary: I see two related issues:

  • If I tick “Use reduced selection of fonts” for the first time, “Standard” starts as being unselected, and it can not as such be selected by ticking its checkbox, because it is disabled
  • “Check all” does select it, but then “Uncheck all” also unselects it, whereas it should be immutable to these operations (and be selected in the first place).

What *can* be done is “Check all”, then manually unselect every other font one by one, but this is probably not how it was intended to work.

This task depends upon

Closed by  Andrew (andrew)
Tuesday, 27 August 2013, 12:28 GMT+1
Reason for closing:  Fixed
Comment by Tamas TEVESZ (kazmer) - Thursday, 22 August 2013, 18:52 GMT+1

This seems to be a relatively clean way of making it work as expected:

diff --git a/scripts/Edit/AppPreferences/TextPreferences/TextPreferences.js b/scripts/Edit/AppPreferences/TextPreferences/TextPreferences.js
index 8f183f5..287f33d 100644
--- a/scripts/Edit/AppPreferences/TextPreferences/TextPreferences.js
+++ b/scripts/Edit/AppPreferences/TextPreferences/TextPreferences.js
@@ -42,6 +42,16 @@ TextPreferences.initPreferences = function(pageWidget, calledByPrefDialog, docum
     var cadList = RFontList.getNames();
     lReducedList.addItems(cadList);
 
+    // select Standard font and mark it immutable
+    for (var row = 0; row<lReducedList.count; row++) {
+        var item = lReducedList.item(row);
+        if (item.text().toLowerCase()==="standard") {
+            item.setCheckState(Qt.Checked);
+            item.setFlags(item.flags & ~(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled));
+            break;
+        }
+    }
+
     // add system fonts to list:
     var fontDb = new RFontDatabase();
     var families = fontDb.families();
@@ -55,10 +65,8 @@ TextPreferences.initPreferences = function(pageWidget, calledByPrefDialog, docum
     for (var row = 0; row<lReducedList.count; row++) {
         var item = lReducedList.item(row);
         var flags = new Qt.ItemFlags(item.flags() | Qt.ItemIsUserCheckable);
-        // always check 'standard':
         if (item.text().toLowerCase()==="standard") {
-            item.setCheckState(Qt.Checked);
-            flags = new Qt.ItemFlags(item.flags() & ~Qt.ItemIsEnabled);
+            continue;
         }
         if (list.contains(item.text())) {
             item.setCheckState(Qt.Checked);
@@ -78,6 +86,9 @@ TextPreferences.initPreferences = function(pageWidget, calledByPrefDialog, docum
     bUncheckAll.clicked.connect(function() {
         for (var row = 0; row<lReducedList.count; row++) {
             var item = lReducedList.item(row);
+            if (item.text().toLowerCase()==="standard") {
+                continue;
+            }
             item.setCheckState(Qt.Unchecked);
         }
     });
Comment by Andrew (andrew) - Tuesday, 27 August 2013, 12:28 GMT+1

Thanks for the fix.

I ended up using this slightly modified fix:

TextPreferences.initPreferences = function(pageWidget, calledByPrefDialog, document) {
    var cbUseReducedList = pageWidget.findChild("UseReducedFontList");
    var lReducedList = pageWidget.findChild("ReducedFontList");
    var bCheckAll = pageWidget.findChild("CheckAll");
    var bUncheckAll = pageWidget.findChild("UncheckAll");

    lReducedList.enabled = cbUseReducedList.checked;

    // add CAD fonts to list:
    var cadList = RFontList.getNames();
    lReducedList.addItems(cadList);

    // add system fonts to list:
    var fontDb = new RFontDatabase();
    var families = fontDb.families();
    lReducedList.addItems(families);

    var list = RSettings.getValue("Text/ReducedFontList", []);
    if (isNull(list)) {
        list = [];
    }

    for (var row = 0; row<lReducedList.count; row++) {
        var item = lReducedList.item(row);
        var flags = new Qt.ItemFlags(item.flags() | Qt.ItemIsUserCheckable);

        // always check 'standard' and make it immutable:
        if (item.text().toLowerCase()==="standard") {
            item.setCheckState(Qt.Checked);
            flags = new Qt.ItemFlags(item.flags() & ~(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled));
        }
        else if (list.contains(item.text())) {
            item.setCheckState(Qt.Checked);
        }
        else {
            item.setCheckState(Qt.Unchecked);
        }
        item.setFlags(flags);
    }

    bCheckAll.clicked.connect(function() {
        for (var row = 0; row<lReducedList.count; row++) {
            var item = lReducedList.item(row);
            item.setCheckState(Qt.Checked);
        }
    });
    bUncheckAll.clicked.connect(function() {
        for (var row = 0; row<lReducedList.count; row++) {
            var item = lReducedList.item(row);
            if (item.text().toLowerCase()==="standard") {
                continue;
            }
            item.setCheckState(Qt.Unchecked);
        }
    });

    lReducedList.setProperty("Loaded", true);
};

Loading...