Le 14/05/2020 à 22:29, Jean-Pierre Chrétien a écrit :
My computer uses mechanical drives all right, and runs an AMD
biprocessor since 2009. Does it seem enough disabled for a test ? If so,
what should I do exactly ?
Very good platform. Apply this patch (which is work in progress but
should work) and recompile lyx in release mode.
Then reboot your computer (to avoid caching of files), run LyX, create
new file, insert math equation (to have more icons) and exit.
Note what is output on screen.
Then in GuiApplication/iconName() and repalce the "#if 1" by "#if 0"
(see in the patch). Recompile, repeat the same measurement.
Is this clear enough ?
Note that there are other uses of the resources in the code, I am just
testing this particular path.
JMarc
>From c172471036bba43e9687662b5ce863f178739ab6 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Thu, 14 May 2020 16:35:51 +0200
Subject: [PATCH] WIP: rewite iconName
This is instrumented to see the effect of resources
---
src/frontends/qt/GuiApplication.cpp | 124 +++++++++++++---------------
1 file changed, 58 insertions(+), 66 deletions(-)
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 5c5c2a6739..327b967be7 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -75,6 +75,7 @@
#include "support/os.h"
#include "support/Package.h"
#include "support/TempFile.h"
+#include "support/pmprof.h"
#ifdef Q_OS_MAC
#include "support/AppleScript.h"
@@ -488,84 +489,75 @@ QString themeIconName(QString const & action)
QString iconName(FuncRequest const & f, bool unknown, QString const & suffix)
{
+ PROFILE_THIS_BLOCK(iconName);
initializeResources();
- QString name1;
- QString name2;
- QString path;
- switch (f.action()) {
- case LFUN_MATH_INSERT:
- if (!f.argument().empty()) {
- path = "math/";
- name1 = findImg(toqstr(f.argument()).mid(1));
- }
- break;
- case LFUN_MATH_DELIM:
- case LFUN_MATH_BIGDELIM:
- path = "math/";
- name1 = findImg(toqstr(f.argument()));
- break;
- case LFUN_CALL:
- path = "commands/";
- name1 = toqstr(f.argument());
- break;
- case LFUN_COMMAND_ALTERNATIVES: {
- // use the first of the alternative commands
- docstring firstcom;
- docstring dummy = split(f.argument(), firstcom, ';');
- name1 = toqstr(firstcom);
- name1.replace(' ', '_');
- break;
- }
- default:
- name2 = toqstr(lyxaction.getActionName(f.action()));
- name1 = name2;
-
- if (!f.argument().empty()) {
- name1 = name2 + ' ' + toqstr(f.argument());
+ QStringList names;
+
+ QString lfunname = toqstr(lyxaction.getActionName(f.action()));
+ if (!f.argument().empty()) {
+ // if there are arguments, first search an icon which name is the full thing
+ QString name = lfunname + ' ' + toqstr(f.argument());
+ name.replace(' ', '_');
+ name.replace('\\', "backslash");
+ names << name;
+
+ // then special default icon for some lfuns
+ switch (f.action()) {
+ case LFUN_MATH_INSERT:
+ names << "math/" + findImg(toqstr(f.argument()).mid(1));
+ break;
+ case LFUN_MATH_DELIM:
+ case LFUN_MATH_BIGDELIM:
+ names << "math/" + findImg(toqstr(f.argument()));
+ break;
+ case LFUN_CALL:
+ names << "commands/" + toqstr(f.argument());
+ break;
+ case LFUN_COMMAND_ALTERNATIVES: {
+ // use the first of the alternative commands
+ docstring firstcom;
+ docstring dummy = split(f.argument(), firstcom, ';');
+ QString name1 = toqstr(firstcom);
name1.replace(' ', '_');
- name1.replace('\\', "backslash");
+ names << name1;
+ break;
+ }
+ default:
+ break;
}
}
- // maybe a suffix?
- name1 += suffix;
- name2 += suffix;
+ // last thing to try is function name
+ names << lfunname;
+ search_mode mode = theGuiApp()->imageSearchMode();
+#if 1
QStringList imagedirs;
imagedirs << "images/" << "images/ipa/";
- search_mode mode = theGuiApp()->imageSearchMode();
- for (int i = 0; i < imagedirs.size(); ++i) {
- QString imagedir = imagedirs.at(i) + path;
- FileName fname = imageLibFileSearch(imagedir, name1, "svgz,png", mode);
- if (fname.exists())
- return toqstr(fname.absFileName());
-
- fname = imageLibFileSearch(imagedir, name2, "svgz,png", mode);
- if (fname.exists())
- return toqstr(fname.absFileName());
- }
+ for (QString const & imagedir : imagedirs)
+ for (QString const & name : names) {
+ QString id = imagedir;
+ FileName fname = imageLibFileSearch(id, name + suffix, "svgz,png", mode);
+ if (fname.exists())
+ return toqstr(fname.absFileName());
+ }
+#endif
- path = ":/images/" + path;
- QDir res(path);
+ QString const resdir(":/images/");
+ QDir res(resdir);
if (!res.exists()) {
- LYXERR0("Directory " << path << " not found in resource!");
+ LYXERR0("Directory :/images/ not found in resource!");
return QString();
}
- if (res.exists(name1 + ".svgz"))
- return path + name1 + ".svgz";
- else if (res.exists(name1 + ".png"))
- return path + name1 + ".png";
-
- if (res.exists(name2 + ".svgz"))
- return path + name2 + ".svgz";
- else if (res.exists(name2 + ".png"))
- return path + name2 + ".png";
-
- LYXERR(Debug::GUI, "Cannot find icon with filename "
- << "\"" << name1 << ".{svgz,png}\""
- << " or filename "
- << "\"" << name2 << ".{svgz,png}\""
- << " for command \""
+
+ for (QString const & name : names) {
+ if (res.exists(name + suffix + ".svgz"))
+ return resdir + name + ".svgz";
+ if (res.exists(name + suffix + ".png"))
+ return resdir + name + ".png";
+ }
+
+ LYXERR(Debug::GUI, "Cannot find icon for command \""
<< lyxaction.getActionName(f.action())
<< '(' << to_utf8(f.argument()) << ")\"");
--
2.25.1
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel