Files
qelectrotech-source-mirror/sources/autoNum/ui/numparteditorw.h
T
ispyisail d192d609ec Add a display format to numbering parts: a spreadsheet-style zero mask
A cyclic part could only ever be rendered at its natural width, which is
fine for one of @scorpio810's two real layouts and wrong for the other:

  April 5000/2000, 32-point cards   %IX0.0 .. %IX0.31, then %IX1.0
  Schneider M340, 64-point cards    I1.00 .. I1.63,    then I2.00

The first wants no padding, the second wants two digits. Since the two
conflict, the width cannot be derived from the modulus or from the part
type -- it has to be the user's to set.

Add a format field holding a run of zeros, the same convention a
spreadsheet uses for integer padding: "00" renders 7 as 07, "000" as 007.
The field's length is the minimum number of digits. It applies to every
numeric part type, not only cyclic ones, so "Chiffre 01" can be widened
past two digits without inventing another type for it.

An empty mask means the part type's own natural width, so it reproduces
exactly what every existing context does today -- Chiffre 1 stays 7,
Chiffre 01 stays 07, Chiffre 001 stays 007. That is what makes this safe
for existing projects: absent is the default, and absent changes nothing.

Stored as a sixth field on the context part and as an XML attribute
written only when set, following how modulus was added: readers guard on
size() and treat a short item as "no format". All seven places that
rebuild a part while incrementing it now carry the format through --
missing one would have silently dropped the padding on the second element
numbered.

The editor field is restricted to zeros by a validator, and is enabled
only for types that render as a number.

Measured:

  April, mask empty     %IX0.29 %IX0.30 %IX0.31 %IX1.0 %IX1.1
  M340,  mask "00"      I1.00 I1.01 ... I1.62 I1.63 I2.00 I2.01
  no mask               unit 7,8,9   ten 07,08,09   hundred 007,008,009
  ten with mask "0000"  0007 0008 0009
2026-08-02 20:29:02 +12:00

86 lines
2.2 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/>.
*/
#ifndef NUMPARTEDITORW_H
#define NUMPARTEDITORW_H
#include "../numerotationcontext.h"
#include <QValidator>
#include <QWidget>
namespace Ui {
class NumPartEditorW;
}
/**
@brief The NumPartEditorW class
This class represent a single part num widget.
By this widget, we can define and edit how the num auto must work.
This widget is called by selectautonumw.
*/
class NumPartEditorW : public QWidget
{
Q_OBJECT
//METHODS
public:
explicit NumPartEditorW(int type, QWidget *parent = nullptr);
NumPartEditorW (NumerotationContext &,
int,
int type,
QWidget *parent=nullptr);
~NumPartEditorW() override;
enum type {unit,unitfolio,ten,tenfolio, hundred, hundredfolio,
alpha,
string,idfolio,folio,plant,locmach,
elementline,elementcolumn,elementprefix,
wrap,
};
NumerotationContext toNumContext();
bool isValid ();
type type_;
private:
void setVisibleItems();
void disableItem(int index);
void setCurrentIndex(NumPartEditorW::type);
private slots:
void on_type_cb_activated(int);
void on_value_field_textEdited();
void on_increase_spinBox_valueChanged(int);
void on_modulus_spinBox_valueChanged(int);
void on_format_le_textEdited(const QString &);
void setType (NumPartEditorW::type t, bool=false);
signals:
void changed ();
private:
Ui::NumPartEditorW *ui;
QValidator *intValidator;
QValidator *alphaValidator;
int m_edited_type = -1; ///<0 == element : 1 == conductor : 2 == folio
};
#endif // NUMPARTEDITORW_H