Use QStringLiteral and QLatin1String.

This commit is contained in:
joshua 2021-04-02 19:16:32 +02:00
parent bba1f07f57
commit 7f5b446fc9
2 changed files with 139 additions and 139 deletions

View File

@ -46,10 +46,14 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph
if (doc.document_element().attribute("link_type"))
{
QString link_type(doc.document_element().attribute("link_type").as_string());
if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, state));
if (link_type == "master") return (new MasterElement (location, qgi, state));
if (link_type == "slave") return (new SlaveElement (location, qgi, state));
if (link_type == "terminal") return (new TerminalElement (location, qgi, state));
if (link_type == QLatin1String("next_report") || link_type == QLatin1String("previous_report"))
return (new ReportElement(location, link_type, qgi, state));
if (link_type == QLatin1String("master"))
return (new MasterElement (location, qgi, state));
if (link_type == QLatin1String("slave"))
return (new SlaveElement (location, qgi, state));
if (link_type == QLatin1String("terminal"))
return (new TerminalElement (location, qgi, state));
}
//default if nothing match for link_type

View File

@ -62,12 +62,12 @@ class ElementXmlRetroCompatibility
{
autonum::sequentialNumbers sn;
loadSequential(dom_element,"sequ_",&sn.unit);
loadSequential(dom_element,"sequf_",&sn.unit_folio);
loadSequential(dom_element,"seqt_",&sn.ten);
loadSequential(dom_element,"seqtf_",&sn.ten_folio);
loadSequential(dom_element,"seqh_",&sn.hundred);
loadSequential(dom_element,"seqhf_",&sn.hundred_folio);
loadSequential(dom_element, QStringLiteral("sequ_"), &sn.unit);
loadSequential(dom_element, QStringLiteral("sequf_"), &sn.unit_folio);
loadSequential(dom_element, QStringLiteral("seqt_"), &sn.ten);
loadSequential(dom_element, QStringLiteral("seqtf_"), &sn.ten_folio);
loadSequential(dom_element, QStringLiteral("seqh_"), &sn.hundred);
loadSequential(dom_element, QStringLiteral("seqhf_"), &sn.hundred_folio);
element->rSequenceStruct() = sn;
}
@ -326,7 +326,7 @@ void Element::drawAxes(
QPainter *painter,
const QStyleOptionGraphicsItem *options)
{
Q_UNUSED(options);
Q_UNUSED(options)
painter -> setPen(Qt::blue);
painter -> drawLine(0, 0, 10, 0);
painter -> drawLine(7,-3, 10, 0);
@ -348,7 +348,7 @@ void Element::drawSelection(
QPainter *painter,
const QStyleOptionGraphicsItem *options)
{
Q_UNUSED(options);
Q_UNUSED(options)
painter -> save();
// Annulation des renderhints
painter -> setRenderHint(QPainter::Antialiasing, false);
@ -376,7 +376,7 @@ void Element::drawHighlight(
QPainter *painter,
const QStyleOptionGraphicsItem *options)
{
Q_UNUSED(options);
Q_UNUSED(options)
painter -> save();
qreal gradient_radius = qMin(boundingRect().width(),
@ -417,8 +417,8 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
{
m_state = QET::GIBuildingFromXml;
if (xml_def_elmt.tagName() != "definition"
|| xml_def_elmt.attribute("type") != "element")
if (xml_def_elmt.tagName() != QLatin1String("definition")
|| xml_def_elmt.attribute(QStringLiteral("type")) != QLatin1String("element"))
{
if (state) *state = 4;
m_state = QET::GIOK;
@ -426,11 +426,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
}
//Check if the curent version can read the xml description
if (xml_def_elmt.hasAttribute("version"))
if (xml_def_elmt.hasAttribute(QStringLiteral("version")))
{
bool conv_ok;
qreal element_version = xml_def_elmt.attribute(
"version").toDouble(&conv_ok);
QStringLiteral("version")).toDouble(&conv_ok);
if (conv_ok && QET::version.toDouble() < element_version)
{
std::cerr << qPrintable(
@ -442,13 +442,12 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
}
//This attribute must be present and valid
int w, h, hot_x, hot_y;
if (
!QET::attributeIsAnInteger(xml_def_elmt, QString("width"), &w) ||\
!QET::attributeIsAnInteger(xml_def_elmt, QString("height"), &h) ||\
!QET::attributeIsAnInteger(xml_def_elmt, QString("hotspot_x"), &hot_x) ||\
!QET::attributeIsAnInteger(xml_def_elmt, QString("hotspot_y"), &hot_y)
) {
int w = 0, h = 0, hot_x = 0, hot_y = 0;
if (!QET::attributeIsAnInteger(xml_def_elmt, QStringLiteral("width"), &w) ||
!QET::attributeIsAnInteger(xml_def_elmt, QStringLiteral("height"), &h) ||
!QET::attributeIsAnInteger(xml_def_elmt, QStringLiteral("hotspot_x"), &hot_x) ||
!QET::attributeIsAnInteger(xml_def_elmt, QStringLiteral("hotspot_y"), &hot_y))
{
if (state) *state = 5;
m_state = QET::GIOK;
return(false);
@ -470,12 +469,12 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
//load kind informations
m_kind_informations.fromXml(
xml_def_elmt.firstChildElement("kindInformations"),
"kindInformation");
xml_def_elmt.firstChildElement(QStringLiteral("kindInformations")),
QStringLiteral("kindInformation"));
//load element information
m_data.m_informations.fromXml(
xml_def_elmt.firstChildElement("elementInformations"),
"elementInformation");
xml_def_elmt.firstChildElement(QStringLiteral("elementInformations")),
QStringLiteral("elementInformation"));
//scroll of the Children of the Definition: Parts of the Drawing
int parsed_elements_count = 0;
@ -487,27 +486,26 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
if (elmts.isNull())
continue;
if (elmts.tagName() == "description")
if (elmts.tagName() == QLatin1String("description"))
{
//Minor workaround to find if there is a "input" tagg as label.
//If not, we set the tagg "label" to the first "input.
QList <QDomElement> input_field;
bool have_label = false;
for (QDomElement input_node = node.firstChildElement("input") ;
for (QDomElement input_node = node.firstChildElement(QStringLiteral("input")) ;
!input_node.isNull() ;
input_node = input_node.nextSiblingElement("input"))
input_node = input_node.nextSiblingElement(QStringLiteral("input")))
{
if (!input_node.isNull())
{
input_field << input_node;
if (input_node.attribute("tagg", "none")
== "label")
if (input_node.attribute(QStringLiteral("tagg"), QStringLiteral("none"))
== QLatin1String("label"))
have_label = true;
}
}
if(!have_label && !input_field.isEmpty())
input_field.first().setAttribute("tagg",
"label");
input_field.first().setAttribute(QStringLiteral("tagg"), QStringLiteral("label"));
//Parse the definition
for (QDomNode n = node.firstChild() ;
@ -565,9 +563,9 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
*/
bool Element::parseElement(const QDomElement &dom)
{
if (dom.tagName() == "terminal") return(parseTerminal(dom));
else if (dom.tagName() == "input") return(parseInput(dom));
else if (dom.tagName() == "dynamic_text") return(parseDynamicText(dom));
if (dom.tagName() == QLatin1String("terminal")) return(parseTerminal(dom));
else if (dom.tagName() == QLatin1String("input")) return(parseInput(dom));
else if (dom.tagName() == QLatin1String("dynamic_text")) return(parseDynamicText(dom));
else return(true);
}
@ -583,26 +581,24 @@ bool Element::parseInput(const QDomElement &dom_element)
{
qreal pos_x, pos_y;
int size;
if (
!QET::attributeIsAReal(dom_element, "x", &pos_x) ||\
!QET::attributeIsAReal(dom_element, "y", &pos_y) ||\
!QET::attributeIsAnInteger(dom_element, "size", &size)
) return(false);
else
{
if (!QET::attributeIsAReal(dom_element, QStringLiteral("x"), &pos_x) ||
!QET::attributeIsAReal(dom_element, QStringLiteral("y"), &pos_y) ||
!QET::attributeIsAnInteger(dom_element, QStringLiteral("size"), &size)) {
return(false);
} else {
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
deti->setText(dom_element.attribute("text", "_"));
deti->setText(dom_element.attribute(QStringLiteral("text"), QStringLiteral("_")));
QFont font = deti->font();
font.setPointSize(dom_element.attribute("size",
font.setPointSize(dom_element.attribute(QStringLiteral("size"),
QString::number(9)).toInt());
deti->setFont(font);
deti->setRotation(dom_element.attribute("rotation",
deti->setRotation(dom_element.attribute(QStringLiteral("rotation"),
QString::number(0)).toDouble());
if(dom_element.attribute("tagg", "none") != "none")
if(dom_element.attribute(QStringLiteral("tagg"), QStringLiteral("none")) != QLatin1String("none"))
{
deti->setTextFrom(DynamicElementTextItem::ElementInfo);
deti->setInfoName(dom_element.attribute("tagg"));
deti->setInfoName(dom_element.attribute(QStringLiteral("tagg")));
}
//the origin transformation point of PartDynamicTextField is the top left corner, no matter the font size
@ -610,17 +606,17 @@ bool Element::parseInput(const QDomElement &dom_element)
//We need to use a QTransform to find the pos of this text from the saved pos of text item
QTransform transform;
//First make the rotation
transform.rotate(dom_element.attribute("rotation",
"0").toDouble());
transform.rotate(dom_element.attribute(QStringLiteral("rotation"),
QStringLiteral("0")).toDouble());
QPointF pos = transform.map(
QPointF(0,
-deti->boundingRect().height()/2));
QPointF(0,
-deti->boundingRect().height()/2));
transform.reset();
//Second translate to the pos
QPointF p(dom_element.attribute("x",
QString::number(0)).toDouble(),
dom_element.attribute("y",
QString::number(0)).toDouble());
QPointF p(dom_element.attribute(QStringLiteral("x"),
QString::number(0)).toDouble(),
dom_element.attribute(QStringLiteral("y"),
QString::number(0)).toDouble());
transform.translate(p.x(), p.y());
deti->setPos(transform.map(pos));
m_dynamic_text_list.append(deti);
@ -687,23 +683,22 @@ Terminal *Element::parseTerminal(const QDomElement &dom_element)
@param e Le QDomElement a valide
@return true si l'element XML est un Element, false sinon
*/
bool Element::valideXml(QDomElement &e) {
// verifie le nom du tag
if (e.tagName() != "element") return(false);
// verifie la presence des attributs minimaux
if (!e.hasAttribute("type")) return(false);
if (!e.hasAttribute("x")) return(false);
if (!e.hasAttribute("y")) return(false);
bool Element::valideXml(QDomElement &e)
{
if (e.tagName() != QLatin1String("element") ||
!e.hasAttribute(QStringLiteral("type")) ||
!e.hasAttribute(QStringLiteral("x")) ||
!e.hasAttribute(QStringLiteral("y"))) {
return(false);
}
bool conv_ok;
// parse l'abscisse
e.attribute("x").toDouble(&conv_ok);
e.attribute(QStringLiteral("x")).toDouble(&conv_ok);
if (!conv_ok) return(false);
// parse l'ordonnee
e.attribute("y").toDouble(&conv_ok);
e.attribute(QStringLiteral("y")).toDouble(&conv_ok);
if (!conv_ok) return(false);
return(true);
}
@ -719,10 +714,8 @@ bool Element::valideXml(QDomElement &e) {
and the addresses in memory. If the import succeeds, it must be add the right couples (id, address).
@return
*/
bool Element::fromXml(
QDomElement &e,
QHash<int,
Terminal *> &table_id_adr)
bool Element::fromXml(QDomElement &e,
QHash<int,Terminal *> &table_id_adr)
{
m_state = QET::GILoadingFromXml;
/*
@ -730,22 +723,25 @@ bool Element::fromXml(
ce recensement servira lors de la mise en place des fils
*/
QList<QDomElement> liste_terminals;
foreach(QDomElement qde,
QET::findInDomElement(e, "terminals", "terminal")) {
for (auto qde :
QET::findInDomElement(e, QStringLiteral("terminals"), QStringLiteral("terminal"))) {
if (Terminal::valideXml(qde)) liste_terminals << qde;
}
QHash<int, Terminal *> priv_id_adr;
int terminals_non_trouvees = 0;
foreach(QGraphicsItem *qgi, childItems()) {
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
for (auto *qgi : childItems())
{
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi))
{
bool terminal_trouvee = false;
foreach(QDomElement qde, liste_terminals) {
if (p -> fromXml(qde)) {
priv_id_adr.insert(
qde.attribute(
"id").toInt(),
p);
for(auto qde : liste_terminals)
{
if (p -> fromXml(qde))
{
priv_id_adr.insert(qde.attribute(QStringLiteral("id")).toInt(),
p);
terminal_trouvee = true;
// We used to break here, because we did not expect
// several terminals to share the same position.
@ -782,11 +778,11 @@ bool Element::fromXml(
//load uuid of connected elements
QList <QDomElement> uuid_list = QET::findInDomElement(e,
"links_uuids",
"link_uuid");
QStringLiteral("links_uuids"),
QStringLiteral("link_uuid"));
foreach (QDomElement qdo, uuid_list)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
tmp_uuids_link << qdo.attribute("uuid");
tmp_uuids_link << qdo.attribute(QStringLiteral("uuid"));
#else
#if TODO_LIST
#pragma message("@TODO remove code for QT 6 or later")
@ -794,36 +790,36 @@ bool Element::fromXml(
qDebug()<<"Help code for QT 6 or later";
#endif
//uuid of this element
m_uuid= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
m_uuid = QUuid(e.attribute(QStringLiteral("uuid"), QUuid::createUuid().toString()));
//load prefix
m_prefix = e.attribute("prefix");
m_prefix = e.attribute(QStringLiteral("prefix"));
QString fl = e.attribute("freezeLabel", "false");
m_freeze_label = fl == "false"? false : true;
QString fl = e.attribute(QStringLiteral("freezeLabel"), QStringLiteral("false"));
m_freeze_label = fl == QLatin1String("false") ? false : true;
//Load Sequential Values
if (e.hasAttribute("sequ_1")
|| e.hasAttribute("sequf_1")
|| e.hasAttribute("seqt_1")
|| e.hasAttribute("seqtf_1")
|| e.hasAttribute("seqh_1")
|| e.hasAttribute("sequf_1"))
if (e.hasAttribute(QStringLiteral("sequ_1"))
|| e.hasAttribute(QStringLiteral("sequf_1"))
|| e.hasAttribute(QStringLiteral("seqt_1"))
|| e.hasAttribute(QStringLiteral("seqtf_1"))
|| e.hasAttribute(QStringLiteral("seqh_1"))
|| e.hasAttribute(QStringLiteral("sequf_1")))
ElementXmlRetroCompatibility::loadSequential(e, this);
else
m_autoNum_seq.fromXml(e.firstChildElement("sequentialNumbers"));
m_autoNum_seq.fromXml(e.firstChildElement(QStringLiteral("sequentialNumbers")));
//Position and selection.
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
QGraphicsObject::setPos(e.attribute("x").toDouble(),
e.attribute("y").toDouble());
setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
QGraphicsObject::setPos(e.attribute(QStringLiteral("x")).toDouble(),
e.attribute(QStringLiteral("y")).toDouble());
setZValue(e.attribute(QStringLiteral("z"), QString::number(this->zValue())).toDouble());
setFlags(QGraphicsItem::ItemIsMovable
| QGraphicsItem::ItemIsSelectable);
// orientation
bool conv_ok;
int read_ori = e.attribute("orientation").toInt(&conv_ok);
int read_ori = e.attribute(QStringLiteral("orientation")).toInt(&conv_ok);
if (!conv_ok || read_ori < 0 || read_ori > 3) {
read_ori = 0;
}
@ -840,7 +836,7 @@ bool Element::fromXml(
//************************//
for (const QDomElement& qde : QET::findInDomElement(
e,
"dynamic_texts",
QStringLiteral("dynamic_texts"),
DynamicElementTextItem::xmlTagName()))
{
DynamicElementTextItem *deti = new DynamicElementTextItem(this);
@ -850,18 +846,18 @@ bool Element::fromXml(
for (QDomElement qde : QET::findInDomElement(
e,
"texts_groups",
QStringLiteral("texts_groups"),
ElementTextItemGroup::xmlTaggName()))
{
ElementTextItemGroup *group =
addTextGroup("loaded_from_xml_group");
addTextGroup(QStringLiteral("loaded_from_xml_group"));
group->fromXml(qde);
}
//load informations
DiagramContext dc;
dc.fromXml(e.firstChildElement("elementInformations"),
"elementInformation");
dc.fromXml(e.firstChildElement(QStringLiteral("elementInformations")),
QStringLiteral("elementInformation"));
//We must to block the update of the alignment when load the information
//otherwise the pos of the text will not be the same as it was at save time.
@ -896,19 +892,19 @@ QDomElement Element::toXml(
QHash<Terminal *,
int> &table_adr_id) const
{
QDomElement element = document.createElement("element");
QDomElement element = document.createElement(QStringLiteral("element"));
// type
element.setAttribute("type", m_location.path());
element.setAttribute(QStringLiteral("type"), m_location.path());
// uuid
element.setAttribute("uuid", uuid().toString());
element.setAttribute(QStringLiteral("uuid"), uuid().toString());
// prefix
element.setAttribute("prefix", m_prefix);
element.setAttribute(QStringLiteral("prefix"), m_prefix);
//frozen label
element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
element.setAttribute(QStringLiteral("freezeLabel"), m_freeze_label? QStringLiteral("true") : QStringLiteral("false"));
// sequential num
QDomElement seq = m_autoNum_seq.toXml(document);
@ -916,10 +912,10 @@ QDomElement Element::toXml(
element.appendChild(seq);
// position, selection et orientation
element.setAttribute("x", QString::number(pos().x()));
element.setAttribute("y", QString::number(pos().y()));
element.setAttribute("z", QString::number(this->zValue()));
element.setAttribute("orientation", QString::number(orientation()));
element.setAttribute(QStringLiteral("x"), QString::number(pos().x()));
element.setAttribute(QStringLiteral("y"), QString::number(pos().y()));
element.setAttribute(QStringLiteral("z"), QString::number(this->zValue()));
element.setAttribute(QStringLiteral("orientation"), QString::number(orientation()));
/* get the first id to use for the bounds of this element
* recupere le premier id a utiliser pour les bornes de cet element */
@ -935,30 +931,30 @@ QDomElement Element::toXml(
// registration of device terminals
// enregistrement des bornes de l'appareil
QDomElement xml_terminals = document.createElement("terminals");
QDomElement xml_terminals = document.createElement(QStringLiteral("terminals"));
// for each child of the element
// pour chaque enfant de l'element
foreach(Terminal *t, terminals()) {
// alors on enregistre la borne
QDomElement terminal = t -> toXml(document);
terminal.setAttribute("id", id_terminal); // for backward compatibility
terminal.setAttribute(QStringLiteral("id"), id_terminal); // for backward compatibility
table_adr_id.insert(t, id_terminal ++);
xml_terminals.appendChild(terminal);
}
element.appendChild(xml_terminals);
// enregistrement des champ de texte de l'appareil
QDomElement inputs = document.createElement("inputs");
QDomElement inputs = document.createElement(QStringLiteral("inputs"));
element.appendChild(inputs);
//if this element is linked to other elements,
//save the uuid of each other elements
if (! isFree()) {
QDomElement links_uuids = document.createElement("links_uuids");
QDomElement links_uuids = document.createElement(QStringLiteral("links_uuids"));
foreach (Element *elmt, connected_elements) {
QDomElement link_uuid =
document.createElement("link_uuid");
link_uuid.setAttribute("uuid", elmt->uuid().toString());
document.createElement(QStringLiteral("link_uuid"));
link_uuid.setAttribute(QStringLiteral("uuid"), elmt->uuid().toString());
links_uuids.appendChild(link_uuid);
}
element.appendChild(links_uuids);
@ -967,17 +963,17 @@ QDomElement Element::toXml(
//save information of this element
if (! m_data.m_informations.keys().isEmpty()) {
QDomElement infos =
document.createElement("elementInformations");
m_data.m_informations.toXml(infos, "elementInformation");
document.createElement(QStringLiteral("elementInformations"));
m_data.m_informations.toXml(infos, QStringLiteral("elementInformation"));
element.appendChild(infos);
}
//Dynamic texts
QDomElement dyn_text = document.createElement("dynamic_texts");
QDomElement dyn_text = document.createElement(QStringLiteral("dynamic_texts"));
for (DynamicElementTextItem *deti : m_dynamic_text_list)
dyn_text.appendChild(deti->toXml(document));
QDomElement texts_group = document.createElement("texts_groups");
QDomElement texts_group = document.createElement(QStringLiteral("texts_groups"));
//Dynamic texts owned by groups
for(ElementTextItemGroup *group : m_texts_group)
@ -1288,19 +1284,19 @@ QString Element::linkTypeToString() const
switch (m_link_type)
{
case Simple:
return "Simple";
return QStringLiteral("Simple");
case NextReport :
return "NextReport";
return QStringLiteral("NextReport");
case PreviousReport:
return "PreviousReport";
return QStringLiteral("PreviousReport");
case Master:
return "Master";
return QStringLiteral("Master");
case Slave:
return "Slave";
return QStringLiteral("Slave");
case Terminale:
return "Terminale";
return QStringLiteral("Terminale");
default:
return "Unknown";
return QStringLiteral("Unknown");
}
}
@ -1318,7 +1314,7 @@ void Element::setElementInformations(DiagramContext dc)
DiagramContext old_info = m_data.m_informations;
m_data.m_informations = dc;
m_data.m_informations.addValue("label", actualLabel()); //Update the label if there is a formula
m_data.m_informations.addValue(QStringLiteral("label"), actualLabel()); //Update the label if there is a formula
emit elementInfoChange(old_info, m_data.m_informations);
}
@ -1442,7 +1438,7 @@ void Element::setUpFormula(bool code_letter)
->project()
->elementAutoNumCurrentFormula();
m_data.m_informations.addValue("formula", formula);
m_data.m_informations.addValue(QStringLiteral("formula"), formula);
QString element_currentAutoNum = diagram()
->project()
@ -1464,7 +1460,7 @@ void Element::setUpFormula(bool code_letter)
if(!m_freeze_label && !formula.isEmpty())
{
DiagramContext dc = m_data.m_informations;
m_data.m_informations.addValue("label", actualLabel());
m_data.m_informations.addValue(QStringLiteral("label"), actualLabel());
emit elementInfoChange(dc, m_data.m_informations);
}
}
@ -1518,12 +1514,12 @@ void Element::freezeNewAddedElement()
*/
QString Element::actualLabel()
{
if (m_data.m_informations.value("formula").toString().isEmpty()) {
return m_data.m_informations.value("label").toString();
if (m_data.m_informations.value(QStringLiteral("formula")).toString().isEmpty()) {
return m_data.m_informations.value(QStringLiteral("label")).toString();
} else {
return autonum::AssignVariables::formulaToLabel(
m_data.m_informations.value(
"formula").toString(),
QStringLiteral("formula")).toString(),
m_autoNum_seq,
diagram(),
this);