Use QStringLiteral and QLatin1String.

This commit is contained in:
joshua 2021-03-30 20:48:56 +02:00
parent f2f50084e0
commit 8960981f09

View File

@ -189,12 +189,12 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
// If user allow zoom out beyond of folio, // If user allow zoom out beyond of folio,
// we draw grid outside of border. // we draw grid outside of border.
QSettings settings; QSettings settings;
int xGrid = settings.value("diagrameditor/Xgrid", int xGrid = settings.value(QStringLiteral("diagrameditor/Xgrid"),
Diagram::xGrid).toInt(); Diagram::xGrid).toInt();
int yGrid = settings.value("diagrameditor/Ygrid", int yGrid = settings.value(QStringLiteral("diagrameditor/Ygrid"),
Diagram::yGrid).toInt(); Diagram::yGrid).toInt();
QRectF rect = settings.value( QRectF rect = settings.value(
"diagrameditor/zoom-out-beyond-of-folio", QStringLiteral("diagrameditor/zoom-out-beyond-of-folio"),
false).toBool() ? r false).toBool() ? r
: border_and_titleblock : border_and_titleblock
.insideBorderRect() .insideBorderRect()
@ -324,15 +324,6 @@ void Diagram::wheelEvent(QGraphicsSceneWheelEvent *event)
*/ */
void Diagram::keyPressEvent(QKeyEvent *event) void Diagram::keyPressEvent(QKeyEvent *event)
{ {
QSettings settings;
int xKeyGrid = settings.value("diagrameditor/key_Xgrid",
Diagram::xKeyGrid).toInt();
int yKeyGrid = settings.value("diagrameditor/key_Ygrid",
Diagram::yKeyGrid).toInt();
int xKeyGridFine = settings.value("diagrameditor/key_fine_Xgrid",
Diagram::xKeyGridFine).toInt();
int yKeyGridFine = settings.value("diagrameditor/key_fine_Ygrid",
Diagram::yKeyGridFine).toInt();
event->setAccepted(false); event->setAccepted(false);
if (m_event_interface) { if (m_event_interface) {
@ -361,6 +352,11 @@ void Diagram::keyPressEvent(QKeyEvent *event)
//Move item with the keyboard arrow //Move item with the keyboard arrow
if(event->modifiers() == Qt::NoModifier) if(event->modifiers() == Qt::NoModifier)
{ {
QSettings settings;
int xKeyGrid = settings.value(QStringLiteral("diagrameditor/key_Xgrid"),
Diagram::xKeyGrid).toInt();
int yKeyGrid = settings.value(QStringLiteral("diagrameditor/key_Ygrid"),
Diagram::yKeyGrid).toInt();
switch(event->key()) switch(event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
@ -399,6 +395,11 @@ void Diagram::keyPressEvent(QKeyEvent *event)
} }
else if(event->modifiers() == Qt::AltModifier) else if(event->modifiers() == Qt::AltModifier)
{ {
QSettings settings;
int xKeyGridFine = settings.value(QStringLiteral("diagrameditor/key_fine_Xgrid"),
Diagram::xKeyGridFine).toInt();
int yKeyGridFine = settings.value(QStringLiteral("diagrameditor/key_fine_Ygrid"),
Diagram::yKeyGridFine).toInt();
switch(event->key()) switch(event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
@ -732,7 +733,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
// XML tree root // XML tree root
// racine de l'arbre XML // racine de l'arbre XML
auto dom_root = document.createElement("diagram"); auto dom_root = document.createElement(QStringLiteral("diagram"));
// schema properties // schema properties
// proprietes du schema // proprietes du schema
@ -742,24 +743,24 @@ QDomDocument Diagram::toXml(bool whole_content) {
// Default conductor properties // Default conductor properties
QDomElement default_conductor = QDomElement default_conductor =
document.createElement("defaultconductor"); document.createElement(QStringLiteral("defaultconductor"));
defaultConductorProperties.toXml(default_conductor); defaultConductorProperties.toXml(default_conductor);
dom_root.appendChild(default_conductor); dom_root.appendChild(default_conductor);
// Conductor autonum // Conductor autonum
if (!m_conductors_autonum_name.isEmpty()) { if (!m_conductors_autonum_name.isEmpty()) {
dom_root.setAttribute("conductorAutonum", dom_root.setAttribute(QStringLiteral("conductorAutonum"),
m_conductors_autonum_name); m_conductors_autonum_name);
} }
//Default New Element //Default New Element
dom_root.setAttribute("freezeNewElement", dom_root.setAttribute(QStringLiteral("freezeNewElement"),
m_freeze_new_elements ? "true" : "false"); m_freeze_new_elements ? QStringLiteral("true") : QStringLiteral("false"));
//Default New Conductor //Default New Conductor
dom_root.setAttribute("freezeNewConductor", dom_root.setAttribute(QStringLiteral("freezeNewConductor"),
m_freeze_new_conductors_ m_freeze_new_conductors_
? "true" : "false"); ? QStringLiteral("true") : QStringLiteral("false"));
//Element Folio Sequential Variables //Element Folio Sequential Variables
if (!m_elmt_unitfolio_max.isEmpty() if (!m_elmt_unitfolio_max.isEmpty()
@ -767,37 +768,37 @@ QDomDocument Diagram::toXml(bool whole_content) {
|| !m_elmt_hundredfolio_max.isEmpty()) { || !m_elmt_hundredfolio_max.isEmpty()) {
QDomElement elmtfoliosequential = QDomElement elmtfoliosequential =
document.createElement( document.createElement(
"elementautonumfoliosequentials"); QStringLiteral("elementautonumfoliosequentials"));
if (!m_elmt_unitfolio_max.isEmpty()) { if (!m_elmt_unitfolio_max.isEmpty()) {
QDomElement elmtfolioseq = QDomElement elmtfolioseq =
document.createElement( document.createElement(
"elementunitfolioseq"); QStringLiteral("elementunitfolioseq"));
folioSequentialsToXml(&m_elmt_unitfolio_max, folioSequentialsToXml(&m_elmt_unitfolio_max,
&elmtfolioseq, &elmtfolioseq,
"sequf_", QStringLiteral("sequf_"),
"unitfolioseq", QStringLiteral("unitfolioseq"),
&document); &document);
elmtfoliosequential.appendChild(elmtfolioseq); elmtfoliosequential.appendChild(elmtfolioseq);
} }
if (!m_elmt_tenfolio_max.isEmpty()) { if (!m_elmt_tenfolio_max.isEmpty()) {
QDomElement elmtfolioseq = QDomElement elmtfolioseq =
document.createElement( document.createElement(
"elementtenfolioseq"); QStringLiteral("elementtenfolioseq"));
folioSequentialsToXml(&m_elmt_tenfolio_max, folioSequentialsToXml(&m_elmt_tenfolio_max,
&elmtfolioseq, &elmtfolioseq,
"seqtf_", QStringLiteral("seqtf_"),
"tenfolioseq", QStringLiteral("tenfolioseq"),
&document); &document);
elmtfoliosequential.appendChild(elmtfolioseq); elmtfoliosequential.appendChild(elmtfolioseq);
} }
if (!m_elmt_hundredfolio_max.isEmpty()) { if (!m_elmt_hundredfolio_max.isEmpty()) {
QDomElement elmtfolioseq = QDomElement elmtfolioseq =
document.createElement( document.createElement(
"elementhundredfolioseq"); QStringLiteral("elementhundredfolioseq"));
folioSequentialsToXml(&m_elmt_hundredfolio_max, folioSequentialsToXml(&m_elmt_hundredfolio_max,
&elmtfolioseq, &elmtfolioseq,
"seqhf_", QStringLiteral("seqhf_"),
"hundredfolioseq", QStringLiteral("hundredfolioseq"),
&document); &document);
elmtfoliosequential.appendChild(elmtfolioseq); elmtfoliosequential.appendChild(elmtfolioseq);
} }
@ -809,38 +810,38 @@ QDomDocument Diagram::toXml(bool whole_content) {
!m_cnd_hundredfolio_max.isEmpty()) { !m_cnd_hundredfolio_max.isEmpty()) {
QDomElement cndfoliosequential = QDomElement cndfoliosequential =
document.createElement( document.createElement(
"conductorautonumfoliosequentials"); QStringLiteral("conductorautonumfoliosequentials"));
QHash<QString, QStringList>::iterator i; QHash<QString, QStringList>::iterator i;
if (!m_cnd_unitfolio_max.isEmpty()) { if (!m_cnd_unitfolio_max.isEmpty()) {
QDomElement cndfolioseq = QDomElement cndfolioseq =
document.createElement( document.createElement(
"conductorunitfolioseq"); QStringLiteral("conductorunitfolioseq"));
folioSequentialsToXml(&m_cnd_unitfolio_max, folioSequentialsToXml(&m_cnd_unitfolio_max,
&cndfolioseq, &cndfolioseq,
"sequf_", QStringLiteral("sequf_"),
"unitfolioseq", QStringLiteral("unitfolioseq"),
&document); &document);
cndfoliosequential.appendChild(cndfolioseq); cndfoliosequential.appendChild(cndfolioseq);
} }
if (!m_cnd_tenfolio_max.isEmpty()) { if (!m_cnd_tenfolio_max.isEmpty()) {
QDomElement cndfolioseq = QDomElement cndfolioseq =
document.createElement( document.createElement(
"conductortenfolioseq"); QStringLiteral("conductortenfolioseq"));
folioSequentialsToXml(&m_cnd_tenfolio_max, folioSequentialsToXml(&m_cnd_tenfolio_max,
&cndfolioseq, &cndfolioseq,
"seqtf_", QStringLiteral("seqtf_"),
"tenfolioseq", QStringLiteral("tenfolioseq"),
&document); &document);
cndfoliosequential.appendChild(cndfolioseq); cndfoliosequential.appendChild(cndfolioseq);
} }
if (!m_cnd_hundredfolio_max.isEmpty()) { if (!m_cnd_hundredfolio_max.isEmpty()) {
QDomElement cndfolioseq = QDomElement cndfolioseq =
document.createElement( document.createElement(
"conductorhundredfolioseq"); QStringLiteral("conductorhundredfolioseq"));
folioSequentialsToXml(&m_cnd_hundredfolio_max, folioSequentialsToXml(&m_cnd_hundredfolio_max,
&cndfolioseq, &cndfolioseq,
"seqhf_", QStringLiteral("seqhf_"),
"hundredfolioseq", QStringLiteral("hundredfolioseq"),
&document); &document);
cndfoliosequential.appendChild(cndfolioseq); cndfoliosequential.appendChild(cndfolioseq);
} }
@ -851,7 +852,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
//this method with whole_content to false, //this method with whole_content to false,
//is often use to copy and paste the current selection //is often use to copy and paste the current selection
//so we add the id of the project where copy occur. //so we add the id of the project where copy occur.
dom_root.setAttribute("projectId", QETApp::projectId(m_project)); dom_root.setAttribute(QStringLiteral("projectId"), QETApp::projectId(m_project));
} }
document.appendChild(dom_root); document.appendChild(dom_root);
@ -921,7 +922,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
QHash<Terminal *, int> table_adr_id; QHash<Terminal *, int> table_adr_id;
if (!list_elements.isEmpty()) { if (!list_elements.isEmpty()) {
auto dom_elements = document.createElement("elements"); auto dom_elements = document.createElement(QStringLiteral("elements"));
for (auto elmt : list_elements) { for (auto elmt : list_elements) {
dom_elements.appendChild(elmt->toXml(document, dom_elements.appendChild(elmt->toXml(document,
table_adr_id)); table_adr_id));
@ -930,7 +931,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
} }
if (!list_conductors.isEmpty()) { if (!list_conductors.isEmpty()) {
auto dom_conductors = document.createElement("conductors"); auto dom_conductors = document.createElement(QStringLiteral("conductors"));
for (auto cond : list_conductors) { for (auto cond : list_conductors) {
dom_conductors.appendChild(cond->toXml(document, dom_conductors.appendChild(cond->toXml(document,
table_adr_id)); table_adr_id));
@ -939,7 +940,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
} }
if (!list_texts.isEmpty()) { if (!list_texts.isEmpty()) {
auto dom_texts = document.createElement("inputs"); auto dom_texts = document.createElement(QStringLiteral("inputs"));
for (auto dti : list_texts) { for (auto dti : list_texts) {
dom_texts.appendChild(dti->toXml(document)); dom_texts.appendChild(dti->toXml(document));
} }
@ -947,7 +948,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
} }
if (!list_images.isEmpty()) { if (!list_images.isEmpty()) {
auto dom_images = document.createElement("images"); auto dom_images = document.createElement(QStringLiteral("images"));
for (auto dii : list_images) { for (auto dii : list_images) {
dom_images.appendChild(dii->toXml(document)); dom_images.appendChild(dii->toXml(document));
} }
@ -955,7 +956,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
} }
if (!list_shapes.isEmpty()) { if (!list_shapes.isEmpty()) {
auto dom_shapes = document.createElement("shapes"); auto dom_shapes = document.createElement(QStringLiteral("shapes"));
for (auto dii : list_shapes) { for (auto dii : list_shapes) {
dom_shapes.appendChild(dii -> toXml(document)); dom_shapes.appendChild(dii -> toXml(document));
} }
@ -963,7 +964,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
} }
if (table_vector.size()) { if (table_vector.size()) {
auto tables = document.createElement("tables"); auto tables = document.createElement(QStringLiteral("tables"));
for (auto table : table_vector) { for (auto table : table_vector) {
tables.appendChild(table->toXml(document)); tables.appendChild(table->toXml(document));
} }
@ -987,11 +988,15 @@ void Diagram::folioSequentialsToXml(QHash<QString,
QDomElement *domElement, QDomElement *domElement,
const QString& seq_type, const QString& seq_type,
const QString& type, const QString& type,
QDomDocument *doc) { QDomDocument *doc)
{
QHash<QString, QStringList>::iterator i; QHash<QString, QStringList>::iterator i;
for (i = hash->begin(); i != hash->end(); i++) {
for (i = hash->begin(); i != hash->end(); i++)
{
QDomElement folioseq = doc->createElement(type); QDomElement folioseq = doc->createElement(type);
folioseq.setAttribute("title", i.key()); folioseq.setAttribute(QStringLiteral("title"), i.key());
for (int j = 0; j < i.value().size(); j++) { for (int j = 0; j < i.value().size(); j++) {
folioseq.setAttribute(seq_type + QString::number(j+1), folioseq.setAttribute(seq_type + QString::number(j+1),
i.value().at(j)); i.value().at(j));
@ -1096,14 +1101,15 @@ bool Diagram::initFromXml(QDomElement &document,
@return @return
*/ */
Terminal* findTerminal(int conductor_index, Terminal* findTerminal(int conductor_index,
QDomElement& f, QDomElement& f,
QHash<int, QHash<int,Terminal *>& table_adr_id,
Terminal *>& table_adr_id, QList<Element *>& added_elements)
QList<Element *>& added_elements) { {
assert(conductor_index == 1 || conductor_index == 2); assert(conductor_index == 1 || conductor_index == 2);
QString element_index = "element" + QString::number(conductor_index); auto str_index = QString::number(conductor_index);
QString terminal_index = "terminal" + QString::number(conductor_index); QString element_index = QStringLiteral("element") + str_index;
QString terminal_index = QStringLiteral("terminal") + str_index;
if (f.hasAttribute(element_index)) { if (f.hasAttribute(element_index)) {
QUuid element_uuid = QUuid(f.attribute(element_index)); QUuid element_uuid = QUuid(f.attribute(element_index));
@ -1185,10 +1191,13 @@ Terminal* findTerminal(int conductor_index,
bool Diagram::fromXml(QDomElement &document, bool Diagram::fromXml(QDomElement &document,
QPointF position, QPointF position,
bool consider_informations, bool consider_informations,
DiagramContent *content_ptr) { DiagramContent *content_ptr)
{
const QDomElement& root = document; const QDomElement& root = document;
// The first element must be a diagram // The first element must be a diagram
if (root.tagName() != "diagram") return(false); if (root.tagName() != QLatin1String("diagram")) {
return(false);
}
// Read attributes of this diagram // Read attributes of this diagram
if (consider_informations) if (consider_informations)
@ -1197,56 +1206,57 @@ bool Diagram::fromXml(QDomElement &document,
border_and_titleblock.titleBlockFromXml(root); border_and_titleblock.titleBlockFromXml(root);
border_and_titleblock.borderFromXml(root); border_and_titleblock.borderFromXml(root);
// Find the element "defaultconductor". // Find the element "defaultconductor".
// If found, load default conductor properties. // If found, load default conductor properties.
QDomElement default_conductor_elmt = QDomElement default_conductor_elmt =
root.firstChildElement("defaultconductor"); root.firstChildElement(QStringLiteral("defaultconductor"));
if (!default_conductor_elmt.isNull()) { if (!default_conductor_elmt.isNull()) {
defaultConductorProperties.fromXml(default_conductor_elmt); defaultConductorProperties.fromXml(default_conductor_elmt);
} }
// Load the autonum // Load the autonum
m_conductors_autonum_name = root.attribute("conductorAutonum"); m_conductors_autonum_name = root.attribute(QStringLiteral("conductorAutonum"));
// Load Freeze New Element // Load Freeze New Element
m_freeze_new_elements = root.attribute("freezeNewElement").toInt(); m_freeze_new_elements = root.attribute(QStringLiteral("freezeNewElement")).toInt();
// Load Freeze New Conductor // Load Freeze New Conductor
m_freeze_new_conductors_ = root.attribute("freezeNewConductor").toInt(); m_freeze_new_conductors_ = root.attribute(QStringLiteral("freezeNewConductor")).toInt();
//Load Element Folio Sequential //Load Element Folio Sequential
folioSequentialsFromXml(root, folioSequentialsFromXml(root,
&m_elmt_unitfolio_max, &m_elmt_unitfolio_max,
"elementunitfolioseq", QStringLiteral("elementunitfolioseq"),
"sequf_", QStringLiteral("sequf_"),
"unitfolioseq", QStringLiteral("unitfolioseq"),
"elementautonumfoliosequentials"); QStringLiteral("elementautonumfoliosequentials"));
folioSequentialsFromXml(root, &m_elmt_tenfolio_max, folioSequentialsFromXml(root, &m_elmt_tenfolio_max,
"elementtenfolioseq", QStringLiteral("elementtenfolioseq"),
"seqtf_", QStringLiteral("seqtf_"),
"tenfolioseq", QStringLiteral("tenfolioseq"),
"elementautonumfoliosequentials"); QStringLiteral("elementautonumfoliosequentials"));
folioSequentialsFromXml(root, &m_elmt_hundredfolio_max, folioSequentialsFromXml(root, &m_elmt_hundredfolio_max,
"elementhundredfolioseq", QStringLiteral("elementhundredfolioseq"),
"seqhf_", QStringLiteral("seqhf_"),
"hundredfolioseq", QStringLiteral("hundredfolioseq"),
"elementautonumfoliosequentials"); QStringLiteral("elementautonumfoliosequentials"));
//Load Conductor Folio Sequential //Load Conductor Folio Sequential
folioSequentialsFromXml(root, &m_cnd_unitfolio_max, folioSequentialsFromXml(root, &m_cnd_unitfolio_max,
"conductorunitfolioseq", QStringLiteral("conductorunitfolioseq"),
"sequf_", QStringLiteral("sequf_"),
"unitfolioseq", QStringLiteral("unitfolioseq"),
"conductorautonumfoliosequentials"); QStringLiteral("conductorautonumfoliosequentials"));
folioSequentialsFromXml(root, &m_cnd_tenfolio_max, folioSequentialsFromXml(root, &m_cnd_tenfolio_max,
"conductortenfolioseq", QStringLiteral("conductortenfolioseq"),
"seqtf_","tenfolioseq", QStringLiteral("seqtf_"),
"conductorautonumfoliosequentials"); QStringLiteral("tenfolioseq"),
QStringLiteral("conductorautonumfoliosequentials"));
folioSequentialsFromXml(root, &m_cnd_hundredfolio_max, folioSequentialsFromXml(root, &m_cnd_hundredfolio_max,
"conductorhundredfolioseq", QStringLiteral("conductorhundredfolioseq"),
"seqhf_", QStringLiteral("seqhf_"),
"hundredfolioseq", QStringLiteral("hundredfolioseq"),
"conductorautonumfoliosequentials"); QStringLiteral("conductorautonumfoliosequentials"));
} }
// if child haven't got a child, loading is finish (diagram is empty) // if child haven't got a child, loading is finish (diagram is empty)
@ -1255,10 +1265,10 @@ bool Diagram::fromXml(QDomElement &document,
} }
//If paste from another project //If paste from another project
if (root.hasAttribute("projectId")) { if (root.hasAttribute(QStringLiteral("projectId")))
QETProject *other_project = QETApp::project( {
root.attribute("projectId", QETProject *other_project = QETApp::project(root.attribute(QStringLiteral("projectId"),
"-1").toInt()); QStringLiteral("-1")).toInt());
/* We try to paste from another project, /* We try to paste from another project,
* then befor paste elements, * then befor paste elements,
@ -1266,17 +1276,18 @@ bool Diagram::fromXml(QDomElement &document,
* (owned by other project) * (owned by other project)
* in the embedded collection of this project * in the embedded collection of this project
*/ */
if (other_project && other_project != m_project) { if (other_project && other_project != m_project)
{
ElementCollectionHandler ech; ElementCollectionHandler ech;
foreach (QDomElement element_xml, for (auto element_xml :
QET::findInDomElement(root, QET::findInDomElement(root,
"elements", QStringLiteral("elements"),
"element")) { QStringLiteral("element"))) {
if (!Element::valideXml(element_xml)) continue; if (!Element::valideXml(element_xml)) continue;
QString type_id = element_xml.attribute("type"); QString type_id = element_xml.attribute(QStringLiteral("type"));
if (type_id.startsWith("embed://")) { if (type_id.startsWith(QStringLiteral("embed://"))) {
ElementsLocation location( ElementsLocation location(
type_id, type_id,
other_project); other_project);
@ -1289,15 +1300,15 @@ bool Diagram::fromXml(QDomElement &document,
//Load all elements from the XML //Load all elements from the XML
QList<Element *> added_elements; QList<Element *> added_elements;
QHash<int, Terminal *> table_adr_id; QHash<int, Terminal *> table_adr_id;
foreach (QDomElement element_xml, for (auto element_xml :
QET::findInDomElement(root, "elements", "element")) QET::findInDomElement(root, QStringLiteral("elements"), QStringLiteral("element")))
{ {
if (!Element::valideXml(element_xml)) continue; if (!Element::valideXml(element_xml)) continue;
// cree un element dont le type correspond a l'id type // cree un element dont le type correspond a l'id type
QString type_id = element_xml.attribute("type"); QString type_id = element_xml.attribute(QStringLiteral("type"));
ElementsLocation element_location; ElementsLocation element_location;
if (type_id.startsWith("embed://")) { if (type_id.startsWith(QStringLiteral("embed://"))) {
element_location = ElementsLocation(type_id, m_project); element_location = ElementsLocation(type_id, m_project);
} }
else { else {
@ -1326,8 +1337,7 @@ bool Diagram::fromXml(QDomElement &document,
{ {
removeItem(nvel_elmt); removeItem(nvel_elmt);
delete nvel_elmt; delete nvel_elmt;
qDebug() << "Diagram::fromXml() : Le chargement des " qDebug() << QStringLiteral("Diagram::fromXml() : Le chargement des parametres d'un element a echoue");
"parametres d'un element a echoue";
} else { } else {
added_elements << nvel_elmt; added_elements << nvel_elmt;
} }
@ -1335,9 +1345,9 @@ bool Diagram::fromXml(QDomElement &document,
// Load text // Load text
QList<IndependentTextItem *> added_texts; QList<IndependentTextItem *> added_texts;
foreach (QDomElement text_xml, QET::findInDomElement(root, for (auto text_xml : QET::findInDomElement(root,
"inputs", QStringLiteral("inputs"),
"input")) { QStringLiteral("input"))) {
IndependentTextItem *iti = new IndependentTextItem(); IndependentTextItem *iti = new IndependentTextItem();
iti -> fromXml(text_xml); iti -> fromXml(text_xml);
addItem(iti); addItem(iti);
@ -1346,9 +1356,9 @@ bool Diagram::fromXml(QDomElement &document,
// Load image // Load image
QList<DiagramImageItem *> added_images; QList<DiagramImageItem *> added_images;
foreach (QDomElement image_xml, QET::findInDomElement(root, for (auto image_xml : QET::findInDomElement(root,
"images", QStringLiteral("images"),
"image")) { QStringLiteral("image"))) {
DiagramImageItem *dii = new DiagramImageItem (); DiagramImageItem *dii = new DiagramImageItem ();
dii -> fromXml(image_xml); dii -> fromXml(image_xml);
addItem(dii); addItem(dii);
@ -1357,9 +1367,9 @@ bool Diagram::fromXml(QDomElement &document,
// Load shape // Load shape
QList<QetShapeItem *> added_shapes; QList<QetShapeItem *> added_shapes;
foreach (QDomElement shape_xml, QET::findInDomElement(root, for (auto shape_xml : QET::findInDomElement(root,
"shapes", QStringLiteral("shapes"),
"shape")) { QStringLiteral("shape"))) {
QetShapeItem *dii = new QetShapeItem (QPointF(0,0)); QetShapeItem *dii = new QetShapeItem (QPointF(0,0));
dii -> fromXml(shape_xml); dii -> fromXml(shape_xml);
addItem(dii); addItem(dii);
@ -1368,9 +1378,9 @@ bool Diagram::fromXml(QDomElement &document,
// Load conductor // Load conductor
QList<Conductor *> added_conductors; QList<Conductor *> added_conductors;
foreach (QDomElement f, QET::findInDomElement(root, for (auto f : QET::findInDomElement(root,
"conductors", QStringLiteral("conductors"),
"conductor")) QStringLiteral("conductor")))
{ {
if (!Conductor::valideXml(f)) continue; if (!Conductor::valideXml(f)) continue;
@ -1395,10 +1405,9 @@ bool Diagram::fromXml(QDomElement &document,
//Load tables //Load tables
QVector<QetGraphicsTableItem *> added_tables; QVector<QetGraphicsTableItem *> added_tables;
for (auto dom_table for (const auto &dom_table : QETXML::subChild(root,
: QETXML::subChild(root, QStringLiteral("tables"),
"tables", QetGraphicsTableItem::xmlTagName()))
QetGraphicsTableItem::xmlTagName()))
{ {
auto table = new QetGraphicsTableItem(); auto table = new QetGraphicsTableItem();
addItem(table); addItem(table);
@ -1410,12 +1419,12 @@ bool Diagram::fromXml(QDomElement &document,
if (position != QPointF()) if (position != QPointF())
{ {
QVector <QGraphicsItem *> added_items; QVector <QGraphicsItem *> added_items;
for (auto element : added_elements ) added_items << element; for (auto element : qAsConst(added_elements )) added_items << element;
for (auto cond : added_conductors) added_items << cond; for (auto cond : qAsConst(added_conductors )) added_items << cond;
for (auto shape : added_shapes ) added_items << shape; for (auto shape : qAsConst(added_shapes )) added_items << shape;
for (auto text : added_texts ) added_items << text; for (auto text : qAsConst(added_texts )) added_items << text;
for (auto image : added_images ) added_items << image; for (auto image : qAsConst(added_images )) added_items << image;
for (auto table : added_tables ) added_items << table; for (auto table : qAsConst(added_tables )) added_items << table;
//Get the top left corner of the rectangle that contain all added items //Get the top left corner of the rectangle that contain all added items
QRectF items_rect; QRectF items_rect;
@ -1487,7 +1496,7 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root,
= folioSeqAutoNum.firstChildElement(type); = folioSeqAutoNum.firstChildElement(type);
!folioseq.isNull(); !folioseq.isNull();
folioseq = folioseq.nextSiblingElement(type)) { folioseq = folioseq.nextSiblingElement(type)) {
QString title = folioseq.attribute("title"); QString title = folioseq.attribute(QStringLiteral("title"));
QStringList list; QStringList list;
int i = 1; int i = 1;
while (folioseq.hasAttribute(seq while (folioseq.hasAttribute(seq
@ -1871,10 +1880,10 @@ void Diagram::loadElmtFolioSeq()
|| !m_elmt_unitfolio_max.contains(title)) { || !m_elmt_unitfolio_max.contains(title)) {
//Insert Initial Value //Insert Initial Value
if (project()->elementAutoNumCurrentFormula().contains( if (project()->elementAutoNumCurrentFormula().contains(
"%sequf_")) { QStringLiteral("%sequf_"))) {
insertFolioSeqHash(&m_elmt_unitfolio_max, insertFolioSeqHash(&m_elmt_unitfolio_max,
title, title,
"unitfolio", QStringLiteral("unitfolio"),
&nc); &nc);
project()->addElementAutoNum(title,nc); project()->addElementAutoNum(title,nc);
} }
@ -1882,10 +1891,10 @@ void Diagram::loadElmtFolioSeq()
else if (m_elmt_unitfolio_max.contains(title)) { else if (m_elmt_unitfolio_max.contains(title)) {
//Load Folio Current Value //Load Folio Current Value
if (project()->elementAutoNumCurrentFormula().contains( if (project()->elementAutoNumCurrentFormula().contains(
"%sequf_")) { QStringLiteral("%sequf_"))) {
loadFolioSeqHash(&m_elmt_unitfolio_max, loadFolioSeqHash(&m_elmt_unitfolio_max,
title, title,
"unitfolio", QStringLiteral("unitfolio"),
&nc); &nc);
project()->addElementAutoNum(title,nc); project()->addElementAutoNum(title,nc);
} }
@ -1896,10 +1905,10 @@ void Diagram::loadElmtFolioSeq()
|| !m_elmt_tenfolio_max.contains(title)) { || !m_elmt_tenfolio_max.contains(title)) {
//Insert Initial Value //Insert Initial Value
if (project()->elementAutoNumCurrentFormula().contains( if (project()->elementAutoNumCurrentFormula().contains(
"%seqtf_")) { QStringLiteral("%seqtf_"))) {
insertFolioSeqHash(&m_elmt_tenfolio_max, insertFolioSeqHash(&m_elmt_tenfolio_max,
title, title,
"tenfolio", QStringLiteral("tenfolio"),
&nc); &nc);
project()->addElementAutoNum(title,nc); project()->addElementAutoNum(title,nc);
} }
@ -1907,10 +1916,10 @@ void Diagram::loadElmtFolioSeq()
else if (m_elmt_tenfolio_max.contains(title)) { else if (m_elmt_tenfolio_max.contains(title)) {
//Load Folio Current Value //Load Folio Current Value
if (project()->elementAutoNumCurrentFormula().contains( if (project()->elementAutoNumCurrentFormula().contains(
"%seqtf_")) { QStringLiteral("%seqtf_"))) {
loadFolioSeqHash(&m_elmt_tenfolio_max, loadFolioSeqHash(&m_elmt_tenfolio_max,
title, title,
"tenfolio", QStringLiteral("tenfolio"),
&nc); &nc);
project()->addElementAutoNum(title,nc); project()->addElementAutoNum(title,nc);
} }
@ -1921,10 +1930,10 @@ void Diagram::loadElmtFolioSeq()
|| !m_elmt_hundredfolio_max.contains(title)) { || !m_elmt_hundredfolio_max.contains(title)) {
//Insert Initial Value //Insert Initial Value
if (project()->elementAutoNumCurrentFormula().contains( if (project()->elementAutoNumCurrentFormula().contains(
"%seqhf_")) { QStringLiteral("%seqhf_"))) {
insertFolioSeqHash(&m_elmt_hundredfolio_max, insertFolioSeqHash(&m_elmt_hundredfolio_max,
title, title,
"hundredfolio", QStringLiteral("hundredfolio"),
&nc); &nc);
project()->addElementAutoNum(title,nc); project()->addElementAutoNum(title,nc);
} }
@ -1932,10 +1941,10 @@ void Diagram::loadElmtFolioSeq()
else if (m_elmt_hundredfolio_max.contains(title)) { else if (m_elmt_hundredfolio_max.contains(title)) {
//Load Folio Current Value //Load Folio Current Value
if (project()->elementAutoNumCurrentFormula().contains( if (project()->elementAutoNumCurrentFormula().contains(
"%seqhf_")) { QStringLiteral("%seqhf_"))) {
loadFolioSeqHash(&m_elmt_hundredfolio_max, loadFolioSeqHash(&m_elmt_hundredfolio_max,
title, title,
"hundredfolio", QStringLiteral("hundredfolio"),
&nc); &nc);
project()->addElementAutoNum(title,nc); project()->addElementAutoNum(title,nc);
} }
@ -1958,20 +1967,20 @@ void Diagram::loadCndFolioSeq()
if (m_cnd_unitfolio_max.isEmpty() if (m_cnd_unitfolio_max.isEmpty()
|| !m_cnd_unitfolio_max.contains(title)) { || !m_cnd_unitfolio_max.contains(title)) {
//Insert Initial Value //Insert Initial Value
if (formula.contains("%sequf_")) { if (formula.contains(QStringLiteral("%sequf_"))) {
insertFolioSeqHash(&m_cnd_unitfolio_max, insertFolioSeqHash(&m_cnd_unitfolio_max,
title, title,
"unitfolio", QStringLiteral("unitfolio"),
&nc); &nc);
project()->addConductorAutoNum(title,nc); project()->addConductorAutoNum(title,nc);
} }
} }
else if (m_cnd_unitfolio_max.contains(title)) { else if (m_cnd_unitfolio_max.contains(title)) {
//Load Folio Current Value //Load Folio Current Value
if (formula.contains("%sequf_")) { if (formula.contains(QStringLiteral("%sequf_"))) {
loadFolioSeqHash(&m_cnd_unitfolio_max, loadFolioSeqHash(&m_cnd_unitfolio_max,
title, title,
"unitfolio", QStringLiteral("unitfolio"),
&nc); &nc);
project()->addConductorAutoNum(title,nc); project()->addConductorAutoNum(title,nc);
} }
@ -1981,20 +1990,20 @@ void Diagram::loadCndFolioSeq()
if (m_cnd_tenfolio_max.isEmpty() if (m_cnd_tenfolio_max.isEmpty()
|| !m_cnd_tenfolio_max.contains(title)) { || !m_cnd_tenfolio_max.contains(title)) {
//Insert Initial Value //Insert Initial Value
if (formula.contains("%seqtf_")) { if (formula.contains(QStringLiteral("%seqtf_"))) {
insertFolioSeqHash(&m_cnd_tenfolio_max, insertFolioSeqHash(&m_cnd_tenfolio_max,
title, title,
"tenfolio", QStringLiteral("tenfolio"),
&nc); &nc);
project()->addConductorAutoNum(title,nc); project()->addConductorAutoNum(title,nc);
} }
} }
else if (m_cnd_tenfolio_max.contains(title)) { else if (m_cnd_tenfolio_max.contains(title)) {
//Load Folio Current Value //Load Folio Current Value
if (formula.contains("%seqtf_")) { if (formula.contains(QStringLiteral("%seqtf_"))) {
loadFolioSeqHash(&m_cnd_tenfolio_max, loadFolioSeqHash(&m_cnd_tenfolio_max,
title, title,
"tenfolio", QStringLiteral("tenfolio"),
&nc); &nc);
project()->addConductorAutoNum(title,nc); project()->addConductorAutoNum(title,nc);
} }
@ -2004,20 +2013,20 @@ void Diagram::loadCndFolioSeq()
if (m_cnd_hundredfolio_max.isEmpty() if (m_cnd_hundredfolio_max.isEmpty()
|| !m_cnd_hundredfolio_max.contains(title)) { || !m_cnd_hundredfolio_max.contains(title)) {
//Insert Initial Value //Insert Initial Value
if (formula.contains("%seqhf_")) { if (formula.contains(QStringLiteral("%seqhf_"))) {
insertFolioSeqHash(&m_cnd_hundredfolio_max, insertFolioSeqHash(&m_cnd_hundredfolio_max,
title, title,
"hundredfolio", QStringLiteral("hundredfolio"),
&nc); &nc);
project()->addConductorAutoNum(title,nc); project()->addConductorAutoNum(title,nc);
} }
} }
else if (m_cnd_hundredfolio_max.contains(title)) { else if (m_cnd_hundredfolio_max.contains(title)) {
//Load Folio Current Value //Load Folio Current Value
if (formula.contains("%seqhf_")) { if (formula.contains(QStringLiteral("%seqhf_"))) {
loadFolioSeqHash(&m_cnd_hundredfolio_max, loadFolioSeqHash(&m_cnd_hundredfolio_max,
title, title,
"hundredfolio", QStringLiteral("hundredfolio"),
&nc); &nc);
project()->addConductorAutoNum(title,nc); project()->addConductorAutoNum(title,nc);
} }
@ -2257,10 +2266,10 @@ DiagramPosition Diagram::convertPosition(const QPointF &pos) {
QPointF Diagram::snapToGrid(const QPointF &p) QPointF Diagram::snapToGrid(const QPointF &p)
{ {
QSettings settings; QSettings settings;
int xGrid = settings.value("diagrameditor/Xgrid", int xGrid = settings.value(QStringLiteral("diagrameditor/Xgrid"),
Diagram::xGrid).toInt(); Diagram::xGrid).toInt();
int yGrid = settings.value("diagrameditor/Ygrid", int yGrid = settings.value(QStringLiteral("diagrameditor/Ygrid"),
Diagram::yGrid).toInt(); Diagram::yGrid).toInt();
//Return a point rounded to the nearest pixel //Return a point rounded to the nearest pixel
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
@ -2330,8 +2339,8 @@ QSet<Conductor *> Diagram::selectedConductors() const
bool Diagram::clipboardMayContainDiagram() bool Diagram::clipboardMayContainDiagram()
{ {
QString clipboard_text = QApplication::clipboard() -> text().trimmed(); QString clipboard_text = QApplication::clipboard() -> text().trimmed();
bool may_be_diagram = clipboard_text.startsWith("<diagram") bool may_be_diagram = clipboard_text.startsWith(QStringLiteral("<diagram"))
&& clipboard_text.endsWith("</diagram>"); && clipboard_text.endsWith(QStringLiteral("</diagram>"));
return(may_be_diagram); return(may_be_diagram);
} }