mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
68ffacc9e6
QFont::fromString() of Qt 5.x and Qt <= 6.10 rejects the >= 19 field descriptions QFont::toString() emits since Qt 6.11, silently leaving a broken font at every read site. Add QETUtils::fontFromString(): try the native parser first, and on failure re-compose the legacy 10/11 field form from the known Qt 6.11 field layout (OpenType weight mapped back to the legacy scale) so no font information stored in existing files is lost. Also salvage the 21 field double-serialized descriptions left behind by some historical builds (a complete legacy description embedded as the family name of a second one) by taking the embedded leading description, matching what the lenient parser of Qt 6.11+ resolves them to. All font read sites now go through the helper; on failure the default font of the caller is left untouched instead of a cleared family. Verified end to end on a Qt 5.15 build: a project whose 53 font attributes were rewritten into the 19 field Qt 6.11 format loads and autosaves byte-identical to the original legacy file (family, sizes, bold/italic/underline, style name all preserved), and a mixed file containing the exact 21 field string from the issue comes back normalized as "Caladea,9,-1,5,75,1,0,0,0,0,Bold Italic". See issue #553.
96 lines
2.8 KiB
C++
96 lines
2.8 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "independenttextitem.h"
|
|
|
|
#include "../diagram.h"
|
|
#include "../diagramcommands.h"
|
|
#include "../qet.h"
|
|
#include "../qetapp.h"
|
|
#include "../utils/qetutils.h"
|
|
|
|
#include <QDomElement>
|
|
#include <QSettings>
|
|
|
|
/**
|
|
Constructeur
|
|
@param parent_diagram Le schema auquel est rattache le champ de texte
|
|
*/
|
|
IndependentTextItem::IndependentTextItem() :
|
|
DiagramTextItem(nullptr)
|
|
{
|
|
setFont(QETApp::indiTextsItemFont());
|
|
QSettings settings;
|
|
setRotation(settings.value("diagrameditor/independent_text_rotation", 0).toInt());
|
|
}
|
|
|
|
/**
|
|
@brief IndependentTextItem::IndependentTextItem
|
|
Constructeur
|
|
@param text Le texte affiche par le champ de texte
|
|
*/
|
|
IndependentTextItem::IndependentTextItem(const QString &text) :
|
|
DiagramTextItem(text, nullptr)
|
|
{}
|
|
|
|
/// Destructeur
|
|
IndependentTextItem::~IndependentTextItem()
|
|
{
|
|
}
|
|
|
|
/**
|
|
Permet de lire le texte a mettre dans le champ a partir d'un element XML.
|
|
Cette methode se base sur la position du champ pour assigner ou non la
|
|
valeur a ce champ.
|
|
@param e L'element XML representant le champ de texte
|
|
*/
|
|
void IndependentTextItem::fromXml(const QDomElement &e) {
|
|
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
|
setHtml(e.attribute("text"));
|
|
setRotation(e.attribute("rotation").toDouble());
|
|
if (e.hasAttribute("font"))
|
|
{
|
|
QFont font;
|
|
QETUtils::fontFromString(font, e.attribute("font"));
|
|
setFont(font);
|
|
}
|
|
}
|
|
|
|
/**
|
|
@param document Le document XML a utiliser
|
|
@return L'element XML representant ce champ de texte
|
|
*/
|
|
QDomElement IndependentTextItem::toXml(QDomDocument &document) const
|
|
{
|
|
QDomElement result = document.createElement("input");
|
|
result.setAttribute("x", QString("%1").arg(pos().x()));
|
|
result.setAttribute("y", QString("%1").arg(pos().y()));
|
|
result.setAttribute("text", toHtml());
|
|
result.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
|
result.setAttribute("font", QETUtils::fontToString(font()));
|
|
|
|
return(result);
|
|
}
|
|
|
|
void IndependentTextItem::focusOutEvent(QFocusEvent *event)
|
|
{
|
|
DiagramTextItem::focusOutEvent(event);
|
|
if (diagram() && (m_previous_html_text != this->toHtml())) {
|
|
diagram()->undoStack().push(new ChangeDiagramTextCommand(this, m_previous_html_text, this->toHtml()));
|
|
}
|
|
}
|