diff --git a/sources/autoNum/assignvariables.cpp b/sources/autoNum/assignvariables.cpp index 8f58adff1..237941261 100644 --- a/sources/autoNum/assignvariables.cpp +++ b/sources/autoNum/assignvariables.cpp @@ -44,6 +44,7 @@ namespace autonum ten_folio = other.ten_folio; hundred = other.hundred; hundred_folio = other.hundred_folio; + alpha = other.alpha; } sequentialNumbers::~sequentialNumbers() @@ -61,6 +62,7 @@ namespace autonum ten_folio = other.ten_folio; hundred = other.hundred; hundred_folio = other.hundred_folio; + alpha = other.alpha; return (*this); } @@ -72,7 +74,8 @@ namespace autonum ten == other.ten && \ ten_folio == other.ten_folio && \ hundred == other.hundred && \ - hundred_folio == other.hundred_folio) + hundred_folio == other.hundred_folio && \ + alpha == other.alpha) return true; else return false; @@ -129,6 +132,11 @@ namespace autonum document, "hundredFolio", hundred_folio.join(";"))); + if(!alpha.isEmpty()) + element.appendChild(QETXML::textToDomElement( + document, + "alpha", + alpha.join(";"))); return element; } @@ -162,6 +170,9 @@ namespace autonum from = element.firstChildElement("hundredFolio"); hundred_folio = from.text().split(";"); + + from = element.firstChildElement("alpha"); + alpha = from.text().split(";"); } //Clear this sequence @@ -173,6 +184,7 @@ namespace autonum ten_folio.clear(); hundred.clear(); hundred_folio.clear(); + alpha.clear(); } /** @@ -414,8 +426,10 @@ namespace autonum m_seq_struct.ten_folio.size()), qMax(m_seq_struct.hundred_folio.size(), m_seq_struct.unit.size())), - qMax(m_seq_struct.hundred.size(), - m_seq_struct.ten.size()) + qMax( + qMax(m_seq_struct.hundred.size(), + m_seq_struct.ten.size()), + m_seq_struct.alpha.size()) ); 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) { 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')); else if (type == "hundred" || type == "hundredfolio") 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()); list.append(number); } @@ -551,6 +571,10 @@ namespace autonum autonum::setSequentialToList(seqStruct.hundred_folio, context,"hundredfolio"); 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_hundred = 0; int count_hundredf = 0; + int count_alpha = 0; for(int i=0 ; 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 */ diff --git a/sources/autoNum/numerotationcontextcommands.h b/sources/autoNum/numerotationcontextcommands.h index 14b44d670..2d7d75d40 100644 --- a/sources/autoNum/numerotationcontextcommands.h +++ b/sources/autoNum/numerotationcontextcommands.h @@ -144,6 +144,23 @@ class StringNum: public NumStrategy 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 { public: diff --git a/sources/autoNum/ui/numparteditorw.cpp b/sources/autoNum/ui/numparteditorw.cpp index 7ca2d2290..3f248c4d5 100644 --- a/sources/autoNum/ui/numparteditorw.cpp +++ b/sources/autoNum/ui/numparteditorw.cpp @@ -18,6 +18,8 @@ #include "numparteditorw.h" #include "ui_numparteditorw.h" +#include + /** @brief NumPartEditorW::NumPartEditorW Constructor @@ -28,6 +30,7 @@ NumPartEditorW::NumPartEditorW(int type, QWidget *parent) : QWidget(parent), ui(new Ui::NumPartEditorW), intValidator (new QIntValidator(0,99999,this)), + alphaValidator (new QRegularExpressionValidator(QRegularExpression("[A-Za-z]+"), this)), m_edited_type(type) { ui -> setupUi(this); @@ -51,6 +54,7 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context, QWidget(parent), ui(new Ui::NumPartEditorW), intValidator (new QIntValidator(0,99999,this)), + alphaValidator (new QRegularExpressionValidator(QRegularExpression("[A-Za-z]+"), this)), m_edited_type(type) { ui -> setupUi(this); @@ -73,6 +77,8 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context, setType(NumPartEditorW::hundredfolio, true); else if (strl.at(0)=="wrap") setType(NumPartEditorW::wrap, true); + else if (strl.at(0)=="alpha") + setType(NumPartEditorW::alpha); else if (strl.at(0)=="string") setType(NumPartEditorW::string); else if (strl.at(0)=="idfolio") @@ -102,6 +108,7 @@ NumPartEditorW::NumPartEditorW (NumerotationContext &context, NumPartEditorW::~NumPartEditorW() { delete intValidator; + delete alphaValidator; delete ui; } @@ -115,6 +122,7 @@ void NumPartEditorW::setVisibleItems() << tr("Chiffre 01") << tr("Chiffre 001") << tr("Cyclique (modulo)") + << tr("Alphabétique") << tr("Texte"); } else if (m_edited_type == 1) @@ -126,6 +134,7 @@ void NumPartEditorW::setVisibleItems() << tr("Chiffre 001") << tr("Chiffre 001 - Folio") << tr("Cyclique (modulo)") + << tr("Alphabétique") << tr("Texte") << tr("N° folio") << tr("Folio") @@ -140,6 +149,7 @@ void NumPartEditorW::setVisibleItems() << tr("Chiffre 001") << tr("Chiffre 001 - Folio") << tr("Cyclique (modulo)") + << tr("Alphabétique") << tr("Texte") << tr("N° folio") << tr("Folio") @@ -205,6 +215,9 @@ NumerotationContext NumPartEditorW::toNumContext() case wrap: type_str = "wrap"; break; + case alpha: + type_str = "alpha"; + break; } if (type_str == "unitfolio" || type_str == "tenfolio" @@ -278,6 +291,8 @@ void NumPartEditorW::on_type_cb_activated(int) { setType(elementprefix); else if (ui->type_cb->currentText() == tr("Cyclique (modulo)")) setType(wrap); + else if (ui->type_cb->currentText() == tr("Alphabétique")) + setType(alpha); emit changed(); } @@ -349,6 +364,7 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) { } //@t isn't a numeric type else if (t == string + || t == alpha || t == folio || t == idfolio || t == elementline @@ -362,6 +378,13 @@ void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) { ui -> value_field -> setValidator(nullptr); 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) { ui -> value_field -> 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")); else if (t == hundredfolio) 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) i = ui->type_cb->findText(tr("Texte")); else if (t == idfolio) diff --git a/sources/autoNum/ui/numparteditorw.h b/sources/autoNum/ui/numparteditorw.h index 332711eda..e33560aba 100644 --- a/sources/autoNum/ui/numparteditorw.h +++ b/sources/autoNum/ui/numparteditorw.h @@ -47,6 +47,7 @@ class NumPartEditorW : public QWidget ~NumPartEditorW() override; enum type {unit,unitfolio,ten,tenfolio, hundred, hundredfolio, + alpha, string,idfolio,folio,plant,locmach, elementline,elementcolumn,elementprefix, wrap, @@ -73,6 +74,7 @@ class NumPartEditorW : public QWidget private: Ui::NumPartEditorW *ui; QValidator *intValidator; + QValidator *alphaValidator; int m_edited_type = -1; ///<0 == element : 1 == conductor : 2 == folio