Merge pull request #594 from ispyisail/feature-alpha-autonum

Add alphabetical auto-numbering (a, b, ... z, aa, ab, ...)
This commit is contained in:
Laurent Trinques
2026-08-01 12:55:07 +02:00
committed by GitHub
7 changed files with 196 additions and 4 deletions
+31 -2
View File
@@ -44,6 +44,7 @@ namespace autonum
ten_folio = other.ten_folio; ten_folio = other.ten_folio;
hundred = other.hundred; hundred = other.hundred;
hundred_folio = other.hundred_folio; hundred_folio = other.hundred_folio;
alpha = other.alpha;
} }
sequentialNumbers::~sequentialNumbers() sequentialNumbers::~sequentialNumbers()
@@ -61,6 +62,7 @@ namespace autonum
ten_folio = other.ten_folio; ten_folio = other.ten_folio;
hundred = other.hundred; hundred = other.hundred;
hundred_folio = other.hundred_folio; hundred_folio = other.hundred_folio;
alpha = other.alpha;
return (*this); return (*this);
} }
@@ -72,7 +74,8 @@ namespace autonum
ten == other.ten && \ ten == other.ten && \
ten_folio == other.ten_folio && \ ten_folio == other.ten_folio && \
hundred == other.hundred && \ hundred == other.hundred && \
hundred_folio == other.hundred_folio) hundred_folio == other.hundred_folio && \
alpha == other.alpha)
return true; return true;
else else
return false; return false;
@@ -129,6 +132,11 @@ namespace autonum
document, document,
"hundredFolio", "hundredFolio",
hundred_folio.join(";"))); hundred_folio.join(";")));
if(!alpha.isEmpty())
element.appendChild(QETXML::textToDomElement(
document,
"alpha",
alpha.join(";")));
return element; return element;
} }
@@ -162,6 +170,9 @@ namespace autonum
from = element.firstChildElement("hundredFolio"); from = element.firstChildElement("hundredFolio");
hundred_folio = from.text().split(";"); hundred_folio = from.text().split(";");
from = element.firstChildElement("alpha");
alpha = from.text().split(";");
} }
//Clear this sequence //Clear this sequence
@@ -173,6 +184,7 @@ namespace autonum
ten_folio.clear(); ten_folio.clear();
hundred.clear(); hundred.clear();
hundred_folio.clear(); hundred_folio.clear();
alpha.clear();
} }
/** /**
@@ -414,8 +426,10 @@ namespace autonum
m_seq_struct.ten_folio.size()), m_seq_struct.ten_folio.size()),
qMax(m_seq_struct.hundred_folio.size(), qMax(m_seq_struct.hundred_folio.size(),
m_seq_struct.unit.size())), m_seq_struct.unit.size())),
qMax(
qMax(m_seq_struct.hundred.size(), qMax(m_seq_struct.hundred.size(),
m_seq_struct.ten.size()) m_seq_struct.ten.size()),
m_seq_struct.alpha.size())
); );
for (int i=1; i<=max ; i++) for (int i=1; i<=max ; i++)
@@ -438,6 +452,9 @@ namespace autonum
if (m_assigned_label.contains("%seqhf_" + QString::number(i)) && m_seq_struct.hundred_folio.size() >= i) { if (m_assigned_label.contains("%seqhf_" + QString::number(i)) && m_seq_struct.hundred_folio.size() >= i) {
m_assigned_label.replace("%seqhf_" + QString::number(i),m_seq_struct.hundred_folio.at(i-1)); m_assigned_label.replace("%seqhf_" + QString::number(i),m_seq_struct.hundred_folio.at(i-1));
} }
if (m_assigned_label.contains("%seqa_" + QString::number(i)) && m_seq_struct.alpha.size() >= i) {
m_assigned_label.replace("%seqa_" + QString::number(i),m_seq_struct.alpha.at(i-1));
}
} }
} }
@@ -462,6 +479,9 @@ namespace autonum
number = QString("%1").arg(context.itemAt(i).at(1).toInt(), 2, 10, QChar('0')); number = QString("%1").arg(context.itemAt(i).at(1).toInt(), 2, 10, QChar('0'));
else if (type == "hundred" || type == "hundredfolio") else if (type == "hundred" || type == "hundredfolio")
number = QString("%1").arg(context.itemAt(i).at(1).toInt(), 3, 10, QChar('0')); number = QString("%1").arg(context.itemAt(i).at(1).toInt(), 3, 10, QChar('0'));
else if (type == "alpha")
//Alphabetic value, not an integer -- used as-is.
number = context.itemAt(i).at(1);
else number = QString::number(context.itemAt(i).at(1).toInt()); else number = QString::number(context.itemAt(i).at(1).toInt());
list.append(number); list.append(number);
} }
@@ -551,6 +571,10 @@ namespace autonum
autonum::setSequentialToList(seqStruct.hundred_folio, context,"hundredfolio"); autonum::setSequentialToList(seqStruct.hundred_folio, context,"hundredfolio");
autonum::setFolioSequentialToHash(seqStruct.hundred_folio, diagram->m_elmt_hundredfolio_max, hashKey); autonum::setFolioSequentialToHash(seqStruct.hundred_folio, diagram->m_elmt_hundredfolio_max, hashKey);
} }
if (label.contains("%seqa_"))
{
autonum::setSequentialToList(seqStruct.alpha, context,"alpha");
}
} }
} }
@@ -570,6 +594,7 @@ namespace autonum
int count_tenf = 0; int count_tenf = 0;
int count_hundred = 0; int count_hundred = 0;
int count_hundredf = 0; int count_hundredf = 0;
int count_alpha = 0;
for(int i=0 ; i<nc.size() ; i++) for(int i=0 ; i<nc.size() ; i++)
{ {
@@ -626,6 +651,10 @@ namespace autonum
count_hundredf++; count_hundredf++;
formula.append("%seqhf_" + QString::number(count_hundredf)); formula.append("%seqhf_" + QString::number(count_hundredf));
} }
else if (type == "alpha") {
count_alpha++;
formula.append("%seqa_" + QString::number(count_alpha));
}
} }
return formula; return formula;
+1
View File
@@ -52,6 +52,7 @@ namespace autonum
QStringList ten_folio; QStringList ten_folio;
QStringList hundred; QStringList hundred;
QStringList hundred_folio; QStringList hundred_folio;
QStringList alpha;
}; };
/** /**
+1 -1
View File
@@ -129,7 +129,7 @@ QStringList NumerotationContext::itemAt(const int i) const
*/ */
QString NumerotationContext::validRegExpNum () const QString NumerotationContext::validRegExpNum () const
{ {
return ("unit|unitfolio|ten|tenfolio|hundred|hundredfolio|wrap|string|idfolio|folio|plant|locmach|elementline|elementcolumn|elementprefix"); return ("unit|unitfolio|ten|tenfolio|hundred|hundredfolio|wrap|alpha|string|idfolio|folio|plant|locmach|elementline|elementcolumn|elementprefix");
} }
/** /**
@@ -204,6 +204,10 @@ void NumerotationContextCommands::setNumStrategy(const QString &str) {
strategy_ = new StringNum (diagram_); strategy_ = new StringNum (diagram_);
return; return;
} }
else if (str == "alpha") {
strategy_ = new AlphaNum (diagram_);
return;
}
else if (str == "idfolio") { else if (str == "idfolio") {
strategy_ = new IdFolioNum (diagram_); strategy_ = new IdFolioNum (diagram_);
return; return;
@@ -604,6 +608,120 @@ NumerotationContext StringNum::previous(const NumerotationContext &nc, const int
return (nextString(nc, i)); return (nextString(nc, i));
} }
namespace
{
/**
* @brief incrementAlpha
* Base-26 letter increment (a, b, ... z, aa, ab, ... az, ba, ...),
* the same algorithm as incrementing a spreadsheet column name.
* Carries right-to-left on 'z'/'Z' overflow; if the whole string
* overflows, a new leading letter is prepended (lowercase 'a').
* @param value : current alphabetic value; treated as "a" if empty.
* @return the next value.
*/
QString incrementAlpha(QString value)
{
if (value.isEmpty()) {
return QStringLiteral("a");
}
int i = value.length() - 1;
while (i >= 0 && (value.at(i) == QLatin1Char('z') || value.at(i) == QLatin1Char('Z'))) {
value[i] = value.at(i).isUpper() ? QLatin1Char('A') : QLatin1Char('a');
--i;
}
if (i < 0) {
value.prepend(QLatin1Char('a'));
} else {
value[i] = QChar(value.at(i).unicode() + 1);
}
return value;
}
/**
* @brief decrementAlpha
* Inverse of incrementAlpha(): borrows right-to-left on 'a'/'A'
* underflow. Symmetric shrink case (e.g. "aa" -> "z"): once every
* position has borrowed, the leading letter is dropped rather than
* left as an extra 'z'. A single-letter value already at "a"/"A" has
* no representable predecessor and is left unchanged, the same way
* the numeric parts don't clamp but a blank label would be worse
* here than a value that stops decreasing.
* @param value : current alphabetic value; treated as "a" if empty.
* @return the previous value.
*/
QString decrementAlpha(QString value)
{
if (value.isEmpty()) {
return QStringLiteral("a");
}
if (value.length() == 1) {
//A single letter has no representable predecessor once it
//reaches "a"/"A" -- clamp rather than mutate, since the loop
//below would otherwise turn it into "z"/"Z" (borrowing past
//the only position there is).
if (value.at(0) == QLatin1Char('a') || value.at(0) == QLatin1Char('A')) {
return value;
}
return QChar(value.at(0).unicode() - 1);
}
int i = value.length() - 1;
while (i >= 0 && (value.at(i) == QLatin1Char('a') || value.at(i) == QLatin1Char('A'))) {
value[i] = value.at(i).isUpper() ? QLatin1Char('Z') : QLatin1Char('z');
--i;
}
if (i < 0) {
//Every position borrowed: the whole value was "a...a", whose
//predecessor is one fewer "z" (e.g. "aa" -> "z").
value.remove(0, 1);
} else {
value[i] = QChar(value.at(i).unicode() - 1);
}
return value;
}
}
/**
Constructor
*/
AlphaNum::AlphaNum (Diagram *d):
NumStrategy (d)
{}
/**
@brief AlphaNum::toRepresentedString
@return the represented string of str
*/
QString AlphaNum::toRepresentedString(const QString str) const
{
return (str);
}
/**
@brief AlphaNum::next
@return the next NumerotationContext nc at position i
*/
NumerotationContext AlphaNum::next (const NumerotationContext &nc, const int i) const
{
QStringList strl = nc.itemAt(i);
NumerotationContext newnc;
newnc.addValue(strl.at(0), incrementAlpha(strl.at(1)), strl.at(2).toInt());
return (newnc);
}
/**
@brief AlphaNum::previous
@return the previous NumerotationContext nc at posiiton i
*/
NumerotationContext AlphaNum::previous(const NumerotationContext &nc, const int i) const
{
QStringList strl = nc.itemAt(i);
NumerotationContext newnc;
newnc.addValue(strl.at(0), decrementAlpha(strl.at(1)), strl.at(2).toInt());
return (newnc);
}
/** /**
Constructor Constructor
*/ */
@@ -144,6 +144,23 @@ class StringNum: public NumStrategy
NumerotationContext previous (const NumerotationContext &, const int) const override; NumerotationContext previous (const NumerotationContext &, const int) const override;
}; };
/**
@brief The AlphaNum class
Alphabetic auto-numbering (a, b, ... z, aa, ab, ...). Unlike StringNum
(a fixed, non-incrementing text segment), this is a real base-26
counter: next()/previous() carry/borrow entirely within this part's
own value, the same self-contained shape every other incrementing
NumStrategy already has.
*/
class AlphaNum: public NumStrategy
{
public:
AlphaNum (Diagram *);
QString toRepresentedString(const QString) const override;
NumerotationContext next (const NumerotationContext &, const int) const override;
NumerotationContext previous (const NumerotationContext &, const int) const override;
};
class IdFolioNum: public NumStrategy class IdFolioNum: public NumStrategy
{ {
public: public:
+25
View File
@@ -18,6 +18,8 @@
#include "numparteditorw.h" #include "numparteditorw.h"
#include "ui_numparteditorw.h" #include "ui_numparteditorw.h"
#include <QRegularExpressionValidator>
/** /**
@brief NumPartEditorW::NumPartEditorW @brief NumPartEditorW::NumPartEditorW
Constructor Constructor
@@ -28,6 +30,7 @@ NumPartEditorW::NumPartEditorW(int type, QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::NumPartEditorW), ui(new Ui::NumPartEditorW),
intValidator (new QIntValidator(0,99999,this)), intValidator (new QIntValidator(0,99999,this)),
alphaValidator (new QRegularExpressionValidator(QRegularExpression("[A-Za-z]+"), this)),
m_edited_type(type) m_edited_type(type)
{ {
ui -> setupUi(this); ui -> setupUi(this);
@@ -51,6 +54,7 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context,
QWidget(parent), QWidget(parent),
ui(new Ui::NumPartEditorW), ui(new Ui::NumPartEditorW),
intValidator (new QIntValidator(0,99999,this)), intValidator (new QIntValidator(0,99999,this)),
alphaValidator (new QRegularExpressionValidator(QRegularExpression("[A-Za-z]+"), this)),
m_edited_type(type) m_edited_type(type)
{ {
ui -> setupUi(this); ui -> setupUi(this);
@@ -73,6 +77,8 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context,
setType(NumPartEditorW::hundredfolio, true); setType(NumPartEditorW::hundredfolio, true);
else if (strl.at(0)=="wrap") else if (strl.at(0)=="wrap")
setType(NumPartEditorW::wrap, true); setType(NumPartEditorW::wrap, true);
else if (strl.at(0)=="alpha")
setType(NumPartEditorW::alpha);
else if (strl.at(0)=="string") else if (strl.at(0)=="string")
setType(NumPartEditorW::string); setType(NumPartEditorW::string);
else if (strl.at(0)=="idfolio") else if (strl.at(0)=="idfolio")
@@ -102,6 +108,7 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context,
NumPartEditorW::~NumPartEditorW() NumPartEditorW::~NumPartEditorW()
{ {
delete intValidator; delete intValidator;
delete alphaValidator;
delete ui; delete ui;
} }
@@ -115,6 +122,7 @@ void NumPartEditorW::setVisibleItems()
<< tr("Chiffre 01") << tr("Chiffre 01")
<< tr("Chiffre 001") << tr("Chiffre 001")
<< tr("Cyclique (modulo)") << tr("Cyclique (modulo)")
<< tr("Alphabétique")
<< tr("Texte"); << tr("Texte");
} }
else if (m_edited_type == 1) else if (m_edited_type == 1)
@@ -126,6 +134,7 @@ void NumPartEditorW::setVisibleItems()
<< tr("Chiffre 001") << tr("Chiffre 001")
<< tr("Chiffre 001 - Folio") << tr("Chiffre 001 - Folio")
<< tr("Cyclique (modulo)") << tr("Cyclique (modulo)")
<< tr("Alphabétique")
<< tr("Texte") << tr("Texte")
<< tr("N° folio") << tr("N° folio")
<< tr("Folio") << tr("Folio")
@@ -140,6 +149,7 @@ void NumPartEditorW::setVisibleItems()
<< tr("Chiffre 001") << tr("Chiffre 001")
<< tr("Chiffre 001 - Folio") << tr("Chiffre 001 - Folio")
<< tr("Cyclique (modulo)") << tr("Cyclique (modulo)")
<< tr("Alphabétique")
<< tr("Texte") << tr("Texte")
<< tr("N° folio") << tr("N° folio")
<< tr("Folio") << tr("Folio")
@@ -205,6 +215,9 @@ NumerotationContext NumPartEditorW::toNumContext()
case wrap: case wrap:
type_str = "wrap"; type_str = "wrap";
break; break;
case alpha:
type_str = "alpha";
break;
} }
if (type_str == "unitfolio" if (type_str == "unitfolio"
|| type_str == "tenfolio" || type_str == "tenfolio"
@@ -278,6 +291,8 @@ void NumPartEditorW::on_type_cb_activated(int) {
setType(elementprefix); setType(elementprefix);
else if (ui->type_cb->currentText() == tr("Cyclique (modulo)")) else if (ui->type_cb->currentText() == tr("Cyclique (modulo)"))
setType(wrap); setType(wrap);
else if (ui->type_cb->currentText() == tr("Alphabétique"))
setType(alpha);
emit changed(); emit changed();
} }
@@ -349,6 +364,7 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) {
} }
//@t isn't a numeric type //@t isn't a numeric type
else if (t == string else if (t == string
|| t == alpha
|| t == folio || t == folio
|| t == idfolio || t == idfolio
|| t == elementline || t == elementline
@@ -362,6 +378,13 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) {
ui -> value_field -> setValidator(nullptr); ui -> value_field -> setValidator(nullptr);
ui -> value_field -> setEnabled(true); ui -> value_field -> setEnabled(true);
} }
else if (t==alpha) {
//Alphabetic step is always exactly one letter (a, b, ...);
//there is no numeric "increase" to configure, unlike the
//digit-based part types.
ui -> value_field -> setValidator(alphaValidator);
ui -> value_field -> setEnabled(true);
}
else if (t==folio) { else if (t==folio) {
ui -> value_field -> setDisabled(true); ui -> value_field -> setDisabled(true);
ui -> increase_spinBox -> setDisabled(true); ui -> increase_spinBox -> setDisabled(true);
@@ -414,6 +437,8 @@ void NumPartEditorW::setCurrentIndex(NumPartEditorW::type t) {
i = ui->type_cb->findText(tr("Chiffre 001")); i = ui->type_cb->findText(tr("Chiffre 001"));
else if (t == hundredfolio) else if (t == hundredfolio)
i = ui->type_cb->findText(tr("Chiffre 001 - Folio")); i = ui->type_cb->findText(tr("Chiffre 001 - Folio"));
else if (t == alpha)
i = ui->type_cb->findText(tr("Alphabétique"));
else if (t == string) else if (t == string)
i = ui->type_cb->findText(tr("Texte")); i = ui->type_cb->findText(tr("Texte"));
else if (t == idfolio) else if (t == idfolio)
+2
View File
@@ -47,6 +47,7 @@ class NumPartEditorW : public QWidget
~NumPartEditorW() override; ~NumPartEditorW() override;
enum type {unit,unitfolio,ten,tenfolio, hundred, hundredfolio, enum type {unit,unitfolio,ten,tenfolio, hundred, hundredfolio,
alpha,
string,idfolio,folio,plant,locmach, string,idfolio,folio,plant,locmach,
elementline,elementcolumn,elementprefix, elementline,elementcolumn,elementprefix,
wrap, wrap,
@@ -73,6 +74,7 @@ class NumPartEditorW : public QWidget
private: private:
Ui::NumPartEditorW *ui; Ui::NumPartEditorW *ui;
QValidator *intValidator; QValidator *intValidator;
QValidator *alphaValidator;
int m_edited_type = -1; ///<0 == element : 1 == conductor : 2 == folio int m_edited_type = -1; ///<0 == element : 1 == conductor : 2 == folio