Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML notation if missing from tooltips in vector file writer dialog #46508

Closed
1 of 2 tasks
BathoryPeter opened this issue Dec 15, 2021 · 5 comments · Fixed by #47148
Closed
1 of 2 tasks

XML notation if missing from tooltips in vector file writer dialog #46508

BathoryPeter opened this issue Dec 15, 2021 · 5 comments · Fixed by #47148
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! GUI/UX Related to QGIS application GUI or User Experience

Comments

@BathoryPeter
Copy link
Contributor

What is the bug or the crash?

There are numerous tooltip message in vector file writer containing xml <element> tags. Those tags are missing from the appearing tooltip. See example below.

Steps to reproduce the issue

  1. On a vector layer, click Export → Save Feature As
  2. Select GeoRSS format
  3. In Datasource Options fieldset hover mouse over HEADER or USE_EXTENSIONS field.

A tooltip appears, where xml elements like <foo:bar> and <ogr:> are missing from the text.

You can see the difference between screenshot and the actual code

datasetOptions.insert( QStringLiteral( "USE_EXTENSIONS" ), new QgsVectorFileWriter::BoolOption(
QObject::tr( "If defined to YES, extension fields will be written. "
"If the field name not found in the base schema matches "
"the foo_bar pattern, foo will be considered as the namespace "
"of the element, and a <foo:bar> element will be written. "
"Otherwise, elements will be written in the <ogr:> namespace." ),
false // Default value
) );

qgis-tooltip-bug

Versions

<style type="text/css"> p, li { white-space: pre-wrap; } </style>
QGIS version 3.22.1-Białowieża QGIS code revision 663dcf8
Qt version 5.15.2
Python version 3.9.7
GDAL/OGR version 3.2.2
PROJ version 7.2.1
EPSG Registry database version v10.008 (2020-12-16)
GEOS version 3.9.0-CAPI-1.16.2
SQLite version 3.35.5
PDAL version 2.2.0
PostgreSQL client version 13.5 (Ubuntu 13.5-0ubuntu0.21.10.1)
SpatiaLite version 5.0.1
QWT version 6.1.4
QScintilla2 version 2.11.6
OS version Ubuntu 21.10
       
Active Python plugins
QuickWKT 3.1
quick_map_services 0.19.27
latlontools 3.5.9
SentinelHub 2.0.0
numericalDigitize 0.4.6
StreetView 3.2
grassprovider 2.12.99
sagaprovider 2.12.99
processing 2.12.99
MetaSearch 0.3.5
db_manager 0.1.20

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@BathoryPeter BathoryPeter added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Dec 15, 2021
@gioman gioman added the GUI/UX Related to QGIS application GUI or User Experience label Dec 15, 2021
@DelazJ
Copy link
Contributor

DelazJ commented Dec 16, 2021

@BathoryPeter a fix is to replace < with &lt; and > with &gt; (unless there's some encoding things possible directly - but changing the signs works)
Mind giving it a shot and create a PR fixing them?

@BathoryPeter
Copy link
Contributor Author

BathoryPeter commented Dec 16, 2021

@DelazJ Fixing this one occurrence seems simple but in my opinion it would be better to find for all the problematic tooltips in QGIS. At first we should make a list of potential strings (containing < > marks), filter the list by hand or semi-automatic then fix the occurrences in the code.
Do you have any idea where to start?

@DelazJ
Copy link
Contributor

DelazJ commented Dec 16, 2021

Fixing this one occurrence seems simple but in my opinion it would be better to find for all the problematic tooltips in QGIS.

@BathoryPeter I was suggesting to do it for all 😃. But sorry, no real trick to suggest for (semi-)automation. Or maybe, with a regex within tr(...)?

@BathoryPeter
Copy link
Contributor Author

@DelazJ I can try to do it. Is tr() the only function to look for or are us using other functions (eg. for plural)? Just drop me a link if you have some related documentation.

@BathoryPeter
Copy link
Contributor Author

So here is the ugly but (hopefully) working solution:

pcre2grep -MInHro --include "\.cpp$" "tr(\((?:[^)(]+|(?R))*+\))" src | \
sed ':a;N;$!ba;s/"\n\s\s*"/ /g' | \
pcre2grep -i --color '<(?!\/?(a|abbr|address|area|article|aside|audio|b|base|bdi|bdo|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|data|datalist|dd|del|dfn|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|head|header|hr|html|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|main|map|mark|meta|meter|nav|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|rb|rp|rt|rtc|ruby|s|samp|script|section|select|small|source|span|strong|style|sub|sup|table|tbody|td|template|textarea|tfoot|th|thead|time|title|tr|track|u|ul|var|video|wbr)[>\s\/]).+?>'

The first pcre2grep matches tr( ) blocks in multi line, balanced mode. Runs recursively in src directory and includes only .cpp files. In next step sed joins multi line strings. Finally the second pcre2grep filters for invalid html tags. This regexp uses negative lookahead to exclude valid html tags. Note that I'm using the list of HTML5 tags, but it seems QGIS uses some deprecated tag like <font> or <nobr>.

Results

src/gui/providers/ogr/qgsogrsourceselect.cpp:730:tr( "<Default>" )
src/gui/providers/ogr/qgsogrsourceselect.cpp:742:tr( "<Default>" )
src/gui/providers/gdal/qgsgdalsourceselect.cpp:317:tr( "<Default>" )
src/gui/providers/gdal/qgsgdalsourceselect.cpp:329:tr( "<Default>" )
src/gui/ogr/qgsvectorlayersaveasdialog.cpp:258:tr( "<Default>" )
src/gui/symbology/qgsrulebasedrendererwidget.cpp:986:tr( "<li><nobr>%1 features also in rule %2</nobr></li>" )
src/gui/locator/qgslocatorwidget.cpp:320:tr( "<type here>" )
src/gui/vector/qgsfieldcalculator.cpp:530:tr( "<geometry>" )
src/analysis/processing/qgsalgorithmmeancoordinates.cpp:62:tr( "This algorithm computes a point layer with the center of mass of geometries in an input layer.\n\n An attribute can be specified as containing weights to be applied to each feature when computing the center of mass.\n\n If an attribute is selected in the <Unique ID field> parameter, features will be grouped according  to values in this field. Instead of a single point with the center of mass of the whole layer,  the output layer will contain a center of mass for the features in each category." )
src/core/vectortile/qgsvectortilelayer.cpp:273:tr( "Missing <renderer> tag" )
src/core/qgsunittypes.cpp:228:tr( "<unknown>", "distance" )
src/core/qgsunittypes.cpp:722:tr( "<unknown>", "area" )
src/core/qgsunittypes.cpp:1351:tr( "<unknown>", "temporal" )
src/core/qgsunittypes.cpp:1383:tr( "<unknown>", "temporal" )
src/core/qgsunittypes.cpp:1802:tr( "<unknown>", "volume" )
src/core/qgsunittypes.cpp:1832:tr( "<unknown>", "volume" )
src/core/qgsunittypes.cpp:2320:tr( "<unknown>", "angle" )
src/core/qgsunittypes.cpp:2995:tr( "<unknown>", "render" )
src/core/raster/qgsrasterlayer.cpp:2210:tr( "<maplayer> not found." )
src/core/qgsmaplayer.cpp:1218:tr( "Root <qgis> element could not be found" )
src/core/qgsmaplayer.cpp:1230:tr( "Root <qgis> element could not be found" )
src/core/symbology/qgssymbollayer.cpp:93:tr( "[<b><dash>;<space></b>] e.g. '8;2;1;2'" )
src/core/layout/qgslayoutframe.cpp:154:tr( "<Frame>" )
src/core/layout/qgslayoutmultiframe.cpp:275:tr( "<Multiframe>" )
src/core/layout/qgslayoutitempolygon.cpp:102:tr( "<Polygon>" )
src/core/layout/qgslayoutitemshape.cpp:88:tr( "<Ellipse>" )
src/core/layout/qgslayoutitemshape.cpp:90:tr( "<Rectangle>" )
src/core/layout/qgslayoutitemshape.cpp:92:tr( "<Triangle>" )
src/core/layout/qgslayoutitemshape.cpp:95:tr( "<Shape>" )
src/core/layout/qgslayoutitempolyline.cpp:277:tr( "<Polyline>" )
src/core/layout/qgslayoutitemtexttable.cpp:36:tr( "<Text table frame>" )
src/core/layout/qgslayoutitemattributetable.cpp:70:tr( "<Attribute table frame>" )
src/core/layout/qgslayoutitemgroup.cpp:61:tr( "<Group>" )
src/core/layout/qgslayoutitem.cpp:118:tr( "<%1>" )
src/core/layout/qgslayoutitem.cpp:121:tr( "<item>" )
src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp:43:tr( "<unknown>" )
src/core/fieldformatter/qgsrelationreferencefieldformatter.cpp:111:tr( "<unknown>" )
src/core/qgsvectorfilewriter.cpp:1268:tr( "If defined to YES, extension fields will be written.  If the field name not found in the base schema matches  the foo_bar pattern, foo will be considered as the namespace  of the element, and a <foo:bar> element will be written.  Otherwise, elements will be written in the <ogr:> namespace." )
src/core/qgsvectorfilewriter.cpp:1277:tr( "If defined to NO, only <entry> or <item> elements will be written.  The user will have to provide the appropriate header and footer of the document." )
src/core/qgsvectorfilewriter.cpp:1283:tr( "XML content that will be put between the <channel> element and the  first <item> element for a RSS document, or between the xml tag and  the first <entry> element for an Atom document." )
src/core/qgsvectorfilewriter.cpp:1296:tr( "Value put inside the <description> element in the header.  If not provided, a dummy value will be used as that element is compulsory." )
src/core/qgsvectorfilewriter.cpp:1308:tr( "Value put inside the <updated> element in the header.  Should be formatted as a XML datetime.  If not provided, a dummy value will be used as that element is compulsory." )
src/core/qgsvectorfilewriter.cpp:1315:tr( "Value put inside the <author><name> element in the header.  If not provided, a dummy value will be used as that element is compulsory." )
src/core/qgsvectorfilewriter.cpp:1321:tr( "Value put inside the <id> element in the header.  If not provided, a dummy value will be used as that element is compulsory." )
src/core/qgsvectorfilewriter.cpp:1506:tr( "If GPX_USE_EXTENSIONS=YES is specified,  extra fields will be written inside the <extensions> tag." )
src/core/qgsvectorfilewriter.cpp:1583:tr( "Allows you to specify the field to use for the KML <name> element." )
src/core/qgsvectorfilewriter.cpp:1588:tr( "Allows you to specify the field to use for the KML <description> element." )
src/core/qgsvectorfilewriter.cpp:1603:tr( "The DOCUMENT_ID datasource creation option can be used to specified  the id of the root <Document> node. The default value is root_doc." )
src/app/3d/qgs3danimationwidget.cpp:44:tr( "<none>" )
src/app/3d/qgs3danimationwidget.cpp:81:tr( "<none>" )
src/app/qgisapp.cpp:5326:tr( "< Blank >" )
src/app/qgisapp.cpp:6614:tr( "< Blank >" )
src/plugins/grass/qgsgrassutils.cpp:156:tr( "<font color='red'>Enter a name!</font>" )
src/plugins/grass/qgsgrassutils.cpp:167:tr( "<font color='red'>This is name of the source!</font>" )
src/plugins/grass/qgsgrassutils.cpp:173:tr( "<font color='red'>Exists!</font>" )
src/plugins/grass/qtermwidget/TerminalDisplay.cpp:3055:tr( "<qt>Output has been  <a href=\"http://en.wikipedia.org/wiki/Flow_control\">suspended</a>  by pressing Ctrl+S.   Press <b>Ctrl+Q</b> to resume.</qt>" )

Conclusion

The list above contains potentially problematic strings. Actually they are only a problem if used in an HTML widget. We cannot simply escape all the occurrences because it would have bad side effect in non-HTML parsed places.
I'm not familiar with QT (and even with C++) so I cannot decide it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! GUI/UX Related to QGIS application GUI or User Experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants