mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
Report salvaged and unreadable font descriptions after opening a project
Until now a font description that could not be parsed only produced console warnings most users never see, so nobody learned that their texts silently lost their formatting (see the reports in issue #553). Count in QETUtils::fontFromString() how many descriptions were salvaged from a foreign or corrupt format and how many stayed unreadable, and show a message box after opening a project when either happened: salvaged descriptions are rewritten in the stable format on the next save, unreadable ones fall back to the default font. Projects without font issues open exactly as before, and non-interactive opens only log the counters. Verified with a Qt 5.15 build on a project carrying 52 19-field and one 21-field description: the dialog reports 53 restored descriptions; the same file on a Qt 6.11 build (which parses those formats natively) shows no dialog. See issue #553.
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include "ui/backupdialog.h"
|
||||
#include "ui/dialogwaiting.h"
|
||||
#include "undocommand/addelementtextcommand.h"
|
||||
#include "utils/qetutils.h"
|
||||
#include "undocommand/rotateselectioncommand.h"
|
||||
#include "undocommand/rotatetextscommand.h"
|
||||
#include "diagram.h"
|
||||
@@ -1168,6 +1169,11 @@ bool QETDiagramEditor::openAndAddProject(
|
||||
//Create the project
|
||||
DialogWaiting::instance(this);
|
||||
|
||||
//Per-project window for the font counters reported below; the folios
|
||||
//(and with them the stored font descriptions) are built between here
|
||||
//and the end of addProject().
|
||||
QETUtils::resetFontRestorationCounters();
|
||||
|
||||
QETProject *project = new QETProject(filepath);
|
||||
if (project -> state() != QETProject::Ok)
|
||||
{
|
||||
@@ -1194,6 +1200,42 @@ bool QETDiagramEditor::openAndAddProject(
|
||||
addProject(project);
|
||||
DialogWaiting::dropInstance();
|
||||
|
||||
//Report font descriptions which could not be read as-is (written by
|
||||
//an incompatible Qt version or corrupted), so the user learns about
|
||||
//it from somewhere else than the console. See issue #553.
|
||||
const int salvaged_fonts = QETUtils::salvagedFontCount();
|
||||
const int unreadable_fonts = QETUtils::unreadableFontCount();
|
||||
if (salvaged_fonts || unreadable_fonts)
|
||||
{
|
||||
qInfo().nospace() << "Project font descriptions: "
|
||||
<< salvaged_fonts << " salvaged from a foreign format, "
|
||||
<< unreadable_fonts << " unreadable (default font applies)";
|
||||
}
|
||||
if (interactive && (salvaged_fonts || unreadable_fonts))
|
||||
{
|
||||
QStringList details;
|
||||
if (salvaged_fonts) {
|
||||
details << tr("%n description(s) de police écrite(s) dans un "
|
||||
"format étranger ou corrompu ont été restaurée(s). "
|
||||
"Elles seront réécrites dans un format stable au "
|
||||
"prochain enregistrement du projet.",
|
||||
"message box content",
|
||||
salvaged_fonts);
|
||||
}
|
||||
if (unreadable_fonts) {
|
||||
details << tr("%n description(s) de police n'ont pas pu être "
|
||||
"lue(s) ; la police par défaut sera utilisée pour "
|
||||
"ces textes.",
|
||||
"message box content",
|
||||
unreadable_fonts);
|
||||
}
|
||||
QET::QetMessageBox::information(
|
||||
this,
|
||||
tr("Polices du projet", "message box title"),
|
||||
details.join("\n\n")
|
||||
);
|
||||
}
|
||||
|
||||
BackupDialog backup_dialog(this);
|
||||
if (backup_dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user