Files
qelectrotech-source-mirror/sources/diagramposition.cpp
T
ispyisail acb770909e DiagramPosition: compile the letter filter once
The constructor built QRegularExpression("[^A-Z]") on every call, and
compiling it cost more than the rest of Diagram::convertPosition() put
together -- about 95k instructions a call under callgrind. Every element
row of the project database pays it on each rebuild, as does anything
else that turns a scene point into a folio cell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 11:16:37 +13:00

86 lines
2.3 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 "diagramposition.h"
#include "qetapp.h"
/**
Constructeur
@param letter Lettre(s) composant la position
@param number Numero composant la position
Si une chaine entierement invalide ou vide, ou bien un 0 est passe en
parametre, il en resulte un objet DiagramPosition invalide, dont la methode
isOutOfBounds renverra true.
*/
DiagramPosition::DiagramPosition(const QString &letter, unsigned int number) {
// purifie les lettres
letter_ = letter.toUpper();
//Compiled once: building it here cost more than the rest of the
//position conversion together, once per element and per drawing item
//on every rebuild of the project database.
static const QRegularExpression not_a_letter(QStringLiteral("[^A-Z]"));
letter_.remove(not_a_letter);
number_ = number;
}
/**
Destructeur
*/
DiagramPosition::~DiagramPosition()
{
}
/**
@return les coordonnees stockees dans cet objet, ou un QPointF nul sinon.
*/
QPointF DiagramPosition::position() const
{
return(position_);
}
/**
@param position Position a stocker dans cet objet
*/
void DiagramPosition::setPosition(const QPointF &position) {
position_ = position;
}
/**
@return une representation textuelle de la position
*/
QString DiagramPosition::toString()
{
if (isOutOfBounds()) {
return("-");
}
QSettings settings;
if (settings.value("border-columns_0", true).toBool()){
return(QString("%1%2").arg(letter_).arg(number_ - 1));
}else{
return(QString("%1%2").arg(letter_).arg(number_));
}
}
/**
@return true si l'element est en dehors des bords du schema
*/
bool DiagramPosition::isOutOfBounds() const
{
return(letter_.isEmpty() || !number_);
}