Add cable management: drawing, cores, numbering, cross-references and cable list

Cables are drawn line objects (toolbar button next to the auto
break/reconnect button, click-move-click, right click cancels), not
components. The type comes from a CSV catalog following the material
list pattern (designation, cores, core colours, editable through the
entry dialog with "Nouvelle entrée" / "Modifier l'entrée").

Each core is bound to the wire its colour label stands on, and the
cable reference is generated per core and written into the Conductor
entry via Conductor::setCableReference(label, cable uuid, slot). The
conductor entry is where it has to live because the terminal strip
plan (Klemmenplan) consumes it in the next step.

Numbering: "Cables" rule under Programmeinstellungen/Neues
Projekt/Nummerierung auto (mirrored in project properties), literal
"W" fallback without a rule, French gate dialog when no rule exists,
Nummerierung menu with the renumber dialog (preferred axis, per-folio
counter, rule and counter state written back, hand-typed names ask,
whole-project scope).

Also included: label block and under-line texts with per-text font and
alignment plus the material-list cell margins, free-core placement and
right-click removal, claim questions for wires of other cables,
multi-selection drag as one undo step, type change with confirmation,
cross-references for type "Cable" (%f-%l%c, own font, clickable links
in exported PDFs), report propagation of the cable definition,
Listes menu (table of contents, material list, terminal strip manager,
terminal generator plugin, cable list), cable list with freely
selectable columns (installation/localisation of cable, start and end,
Blatt start/end, length, used cores...), CSV export dialog with column
pick and preview in the Projekt menu, script API (addTable kind
"cable_list", exportCableList) and a unit test for the type catalog.
This commit is contained in:
Kellermorph
2026-10-08 15:56:00 +02:00
parent 1ca13ce62d
commit bf9b34398d
108 changed files with 18482 additions and 293 deletions
+386
View File
@@ -0,0 +1,386 @@
/*
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 "cablenumberingdialog.h"
#include "../autoNum/ui/selectautonumw.h"
#include "../cable/cablerenumber.h"
#include "../cable/editcablecommand.h"
#include "../qetproject.h"
#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
#include <QSettings>
#include <QUndoStack>
#include <QVBoxLayout>
/**
@brief CableNumberingDialog::CableNumberingDialog
Build the window around the numbering rule of the project: the rule
itself, the axis the cables are laid out along when the whole
project is numbered again, and the button which does that numbering.
@param project the project whose cables are numbered
@param parent
*/
CableNumberingDialog::CableNumberingDialog(QETProject *project, QWidget *parent) :
QDialog(parent),
m_project(project)
{
setWindowTitle(tr("Numérotation des câbles"));
//The rule editor needs room to be read: this window opens with
//the size it needs rather than with whatever its contents
//happen to add up to, so nothing of the rule is cramped from
//the first moment
setMinimumSize(QSize(900, 620));
auto *layout = new QVBoxLayout(this);
auto *note = new QLabel(tr(
"Cette fenêtre montre la règle de numérotation automatique des "
"câbles de ce projet et la modifie. Une règle changée ici est "
"celle que le projet garde : elle est écrite dans le projet quand "
"vous validez."), this);
note->setWordWrap(true);
layout->addWidget(note);
m_rule = new SelectAutonumW(3, this);
//One rule only, so the row which picks between several named
//numberings is hidden: what is on show is the project's rule
m_rule->setSingleRuleMode(true);
layout->addWidget(m_rule);
auto *axis_group = new QGroupBox(tr("Priorité des axes"), this);
auto *axis_layout = new QHBoxLayout(axis_group);
m_axis_x = new QRadioButton(tr("Priorité à l'axe X (horizontal)"), axis_group);
m_axis_y = new QRadioButton(tr("Priorité à l'axe Y (vertical)"), axis_group);
axis_layout->addWidget(m_axis_x);
axis_layout->addWidget(m_axis_y);
layout->addWidget(axis_group);
auto *axis_note = new QLabel(tr(
"L'axe choisi décide l'ordre dans lequel les câbles sont "
"renumérotés : X les numérote de gauche à droite, Y les numérote "
"de haut en bas."), this);
axis_note->setWordWrap(true);
layout->addWidget(axis_note);
auto *actions = new QHBoxLayout();
m_renumber_pb = new QPushButton(tr("Renumérotter tous les câbles"), this);
m_renumber_pb->setToolTip(tr(
"Remet le numéro de chaque câble du projet d'après la règle, en "
"partant du début : un numéro manquant après la suppression d'un "
"câble se referme ainsi."));
actions->addWidget(m_renumber_pb);
actions->addStretch();
//No confirm button: this window is there to number the cables
//again and to show the rule which does it. What the window
//holds is written by the editor's own Apply button, and by the
//numbering button which writes it before numbering -- so a
//second button only saving and closing would say the same
//thing twice.
m_box = new QDialogButtonBox(this);
m_box->addButton(QDialogButtonBox::Cancel);
m_box->button(QDialogButtonBox::Cancel)->setText(tr("Annuler"));
actions->addWidget(m_box);
layout->addLayout(actions);
connect(m_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(m_renumber_pb, &QPushButton::clicked, this, &CableNumberingDialog::renumber);
//The editor's own buttons are wired the same way the project
//properties wire them, so this window saves exactly what that
//page would have saved
connect(m_rule, &SelectAutonumW::applyPressed, this, &CableNumberingDialog::applyRule);
connect(m_rule, &SelectAutonumW::removeClicked, this, &CableNumberingDialog::removeRule);
//Filling a rule in lights the numbering button up as soon as
//there is something to number with
connect(m_rule, &SelectAutonumW::contextEdited, this,
&CableNumberingDialog::updateEnabling);
if (m_project)
{
const QString key = m_project->cableCurrentAutoNum();
const bool has_rule = !key.isEmpty()
&& !m_project->cableAutoNum(key).isEmpty();
m_rule->setContext(has_rule ? m_project->cableAutoNum(key)
: NumerotationContext());
//The button which takes the rule away is only worth showing
//when there is one, and only while the project may be
//written to
m_rule->setRuleRemovable(has_rule && !m_project->isReadOnly());
m_axis_x->setChecked(m_project->cableXAxisFirst());
m_axis_y->setChecked(!m_project->cableXAxisFirst());
if (m_project->isReadOnly())
{
m_rule->setEnabled(false);
m_axis_x->setEnabled(false);
m_axis_y->setEnabled(false);
}
}
updateEnabling();
}
/**
@brief CableNumberingDialog::applyRule
What the editor's own Apply button does: write the rule into the
project and leave the window open, the way that button behaves on
the numbering pages of the settings.
*/
void CableNumberingDialog::applyRule()
{
save();
updateEnabling();
}
/**
@brief CableNumberingDialog::save
Write the rule and the axis into the project. Nothing is written
when nothing was changed, so confirming a window which was only
ever looked at leaves the project exactly as it was.
@return true when the window holds nothing which could not be written
*/
bool CableNumberingDialog::save()
{
if (!m_project || m_project->isReadOnly()) return false;
bool changed = false;
if (m_rule->isModified())
{
if (!m_rule->isValid())
{
QMessageBox::warning(this, tr("Numérotation des câbles"),
tr("La règle n'est pas encore complète : "
"il reste un champ vide dedans."));
return false;
}
const QString title = QETProject::cableAutoNumRuleName();
m_project->addCableAutoNum(title, m_rule->toNumContext());
m_project->setCurrentCableAutoNum(title);
//What was edited is written now, so there is nothing of it
//left for a second save to write again
m_rule->setContext(m_rule->toNumContext());
m_rule->setRuleRemovable(true);
changed = true;
}
const bool axis_first = m_axis_x->isChecked();
if (m_project->cableXAxisFirst() != axis_first) changed = true;
m_project->setCableXAxisFirst(axis_first);
if (changed) m_project->setModified(true);
return true;
}
/**
@brief CableNumberingDialog::removeRule
Take the cable numbering rule out of the project. The project then
numbers its cables by no rule at all -- they are called W until one
is defined again -- and the cable tool asks once more whether one
should be defined.
*/
void CableNumberingDialog::removeRule()
{
if (!m_project || m_project->isReadOnly()) return;
const QString title = m_project->cableCurrentAutoNum();
if (title.isEmpty()) return;
m_project->removeCableAutoNum(title);
m_rule->setContext(NumerotationContext());
//No rule left, so the button which takes one away goes too. And
//having just taken the rule away means numbering cables by hand
//again: the question of defining one comes back the next time a
//cable is drawn, so it is not held back any more.
m_rule->setRuleRemovable(false);
QSettings settings;
settings.setValue(QStringLiteral("cable-management/ask_numbering_rule"),
true);
m_project->setModified(true);
updateEnabling();
}
/**
@brief CableNumberingDialog::updateEnabling
Renumbering needs something to number with: a rule filled in well
enough to be one, and a project which may be written to.
*/
void CableNumberingDialog::updateEnabling()
{
if (!m_project || m_project->isReadOnly() || !m_rule) {
m_renumber_pb->setEnabled(false);
return;
}
const QString key = m_project->cableCurrentAutoNum();
const bool saved_rule = !key.isEmpty()
&& !m_project->cableAutoNum(key).isEmpty();
//A rule which is still being filled in counts as soon as it is
//written, and the numbering writes it together with the numbers
//it hands out
const bool drawn_rule = m_rule->isModified() && m_rule->isValid()
&& !m_rule->toNumContext().isEmpty();
m_renumber_pb->setEnabled((saved_rule || drawn_rule)
&& m_rule->isValid()
&& !m_rule->toNumContext().isEmpty());
}
/**
@brief CableNumberingDialog::askAboutHandWritten
Some cables carry a name he typed in himself rather than one the
rule handed out. Taking such a name away is his to allow: yes and
they are numbered like all the others, no and they keep their name
while the rest is numbered around them, and cancelling leaves every
cable exactly where it stands.
@param count how many such names the project holds
@return 1 to number them too, 0 to leave them alone, -1 for nothing
*/
int CableNumberingDialog::askAboutHandWritten(int count)
{
if (count <= 0) return 1;
QMessageBox box(QMessageBox::Question, tr("Numérotation des câbles"),
tr("%n nom(s) de câble(s) de ce projet ont été saisis à "
"la main.\n\n"
"Les renuméroter aussi ?", "", count),
QMessageBox::NoButton, this);
QPushButton *take = box.addButton(
tr("Oui", "Les noms saisis à la main sont remplacés eux aussi."),
QMessageBox::YesRole);
QPushButton *leave = box.addButton(
tr("Non", "Les noms saisis à la main sont laissés tels quels."),
QMessageBox::NoRole);
QPushButton *cancel = box.addButton(
tr("Annuler", "Ne renumérote rien du tout."),
QMessageBox::RejectRole);
//Keeping his own names is the safe answer under his finger
box.setDefaultButton(leave);
box.setEscapeButton(cancel);
box.exec();
const QAbstractButton *clicked = box.clickedButton();
if (clicked == take) return 1;
if (clicked == leave) return 0;
return -1;
}
/**
@brief CableNumberingDialog::renumber
Number every cable of the project again with the rule on show,
from the beginning of that rule and in the order the cables stand
along the chosen axis. One single undo step takes it all back, and
the window closes once the numbering has been written so that he
can see what became of his cables.
*/
void CableNumberingDialog::renumber()
{
if (!m_project || m_project->isReadOnly()) return;
//A rule which is not complete yet is refused before anything is
//worked out at all. What the window holds is written only together
//with the numbering itself, so every way out coming before that
//point -- a rule which does not fit, him saying no, nothing to
//number -- leaves the project exactly as it stands.
const NumerotationContext rule = m_rule->toNumContext();
if (!m_rule->isValid() || rule.isEmpty())
{
QMessageBox::warning(this, tr("Numérotation des câbles"),
tr("La règle n'est pas encore complète."));
return;
}
const bool axis_first = m_axis_x->isChecked();
//Whether he lets his own names be taken away or not, a project
//with nothing to number with says so before he is asked
//anything: the rule has to be one first
CableRenumberPlan plan = CableRenumber::plan(m_project, rule, axis_first,
true);
if (!plan.ok())
{
QMessageBox::warning(this, tr("Numérotation des câbles"), plan.error);
return;
}
const int answer = askAboutHandWritten(CableRenumber::byHandCount(m_project));
if (answer < 0) return;
//Leaving his own names alone means the numbering runs around
//them, which can hand out a number somebody else keeps: that
//is worked out again here and refused if it does not fit
if (answer == 0)
{
plan = CableRenumber::plan(m_project, rule, axis_first, false);
if (!plan.ok())
{
QMessageBox::warning(this, tr("Numérotation des câbles"), plan.error);
return;
}
}
if (plan.cables.isEmpty())
{
QMessageBox::information(this, tr("Numérotation des câbles"),
tr("Aucun câble à renuméroter dans ce projet."));
return;
}
//Every cable already carries the number the rule says: there is
//nothing to write, and an undo step which undoes nothing would
//only be in the way
bool changed = false;
for (int i = 0; i < plan.cables.size(); ++i)
{
if (plan.cables.at(i)->designation() != plan.designations.at(i)
|| plan.cables.at(i)->designationByHand()) {
changed = true;
break;
}
}
if (!changed)
{
QMessageBox::information(this, tr("Numérotation des câbles"),
tr("Tous les câbles portent déjà le numéro "
"que la règle leur donne."));
return;
}
//The rule on show is written now, right with the numbering it
//belongs to, and the numbering then leaves the counters of that
//rule where the last number was taken from: both go into the
//project with the names, as one single act which undo takes
//back together. Nothing was written before this point, which is
//why he may still back out of here without the project having
//been touched.
if (!save()) return;
const QString num_key = QETProject::cableAutoNumRuleName();
if (QUndoStack *stack = m_project->undoStack()) {
stack->push(new RenumberCablesCommand(
plan.cables, plan.designations, m_project, num_key,
m_project->cableAutoNum(num_key), plan.after));
}
accept();
}
+86
View File
@@ -0,0 +1,86 @@
/*
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 CABLENUMBERINGDIALOG_H
#define CABLENUMBERINGDIALOG_H
#include <QDialog>
class QDialogButtonBox;
class QETProject;
class QPushButton;
class QRadioButton;
class SelectAutonumW;
/**
@brief The window behind the "Numérotation des câbles" entry of the
numbering menu: the one numbering rule the project numbers its
cables with, the axis those cables are laid out along when the whole
project is numbered again, and the button which does that numbering.
The rule is the very editor the project properties hold on their
cable tab, read from the project when the window opens and written
back into the project by that editor's own Apply button -- and by
the numbering button, which writes what the window holds before it
numbers, so numbering always happens with the rule on show: a rule
which is changed here is the rule the project keeps, not a rule of
its own. There is no confirm button of this window's own: what the
window holds is either applied by hand or left behind when it is
closed.
Renumbering works every cable of the project out from the beginning
of that rule, so the hole a deleted cable leaves in the numbering
closes -- and it only happens when he asks for it.
*/
class CableNumberingDialog : public QDialog
{
Q_OBJECT
public:
explicit CableNumberingDialog(QETProject *project, QWidget *parent = nullptr);
private slots:
///Put the rule and the axis into the project
void applyRule();
///Take the cable numbering rule out of the project
void removeRule();
///Number every cable of the project with the rule on show
void renumber();
///Let the button say whether there is a rule to number with
void updateEnabling();
private:
///Write what the window holds into the project
bool save();
/**
Ask what to do with the names he typed in himself.
@param count how many such names the project holds
@return 1 to number them too, 0 to leave them alone,
-1 to do nothing at all
*/
int askAboutHandWritten(int count);
private:
QETProject *m_project = nullptr;
SelectAutonumW *m_rule = nullptr;
QRadioButton *m_axis_x = nullptr;
QRadioButton *m_axis_y = nullptr;
QPushButton *m_renumber_pb = nullptr;
QDialogButtonBox *m_box = nullptr;
};
#endif // CABLENUMBERINGDIALOG_H
+83 -16
View File
@@ -108,19 +108,26 @@ NewDiagramPage::NewDiagramPage(QETProject *project,
auto saw_conductor = new SelectAutonumW(1);
auto saw_element = new SelectAutonumW(0);
auto saw_folio = new SelectAutonumW(2);
auto saw_cable = new SelectAutonumW(3);
//A cable is numbered by one rule and that is all there is:
//the row which lists the available numberings is hidden.
saw_cable->setSingleRuleMode(true);
initAutoNumTab(m_autonum_conductor, saw_conductor, QStringLiteral("autonum/conductor"));
initAutoNumTab(m_autonum_element, saw_element, QStringLiteral("autonum/element"));
initAutoNumTab(m_autonum_folio, saw_folio, QStringLiteral("autonum/folio"));
initAutoNumTab(m_autonum_cable, saw_cable, QStringLiteral("autonum/cable"));
m_autonum_cable.fixed_name = QETProject::cableAutoNumRuleName();
QSettings autonum_settings;
loadAutoNumTab(m_autonum_conductor, autonum_settings);
loadAutoNumTab(m_autonum_element, autonum_settings);
loadAutoNumTab(m_autonum_folio, autonum_settings);
loadAutoNumTab(m_autonum_cable, autonum_settings);
// Intercept Return key in the combo line edits so it doesn't
// activate the dialog's default button (OK).
for (auto *tab : {&m_autonum_conductor, &m_autonum_element, &m_autonum_folio}) {
for (auto *tab : {&m_autonum_conductor, &m_autonum_element, &m_autonum_folio, &m_autonum_cable}) {
if (QComboBox *combo = tab->widget->contextComboBox()) {
if (combo->lineEdit()) {
combo->lineEdit()->installEventFilter(this);
@@ -165,6 +172,7 @@ NewDiagramPage::NewDiagramPage(QETProject *project,
autonum_inner_tab->addTab(m_autonum_conductor.widget, tr("Conducteurs"));
autonum_inner_tab->addTab(m_autonum_element.widget, tr("Eléments"));
autonum_inner_tab->addTab(m_autonum_folio.widget, tr("Folios"));
autonum_inner_tab->addTab(m_autonum_cable.widget, tr("Câbles"));
autonum_layout->addWidget(autonum_inner_tab);
tab_widget -> addTab (autonum_widget, tr("Numérotation auto"));
}
@@ -274,6 +282,20 @@ void NewDiagramPage::applyConf()
settings.endArray();
// save global auto-numbering defaults
//
// The cable rule is written here as well as by its own Apply
// button. The cable tool asks a project for that rule the
// moment he tries to draw a cable, and a project built out of
// settings he has just filled in and confirmed must not turn
// up without one -- which is what would happen if only the
// Apply button of that one tab could save it. A rule nobody
// has finished filling in is left alone, and a tab he has not
// touched writes nothing at all.
if (m_autonum_cable.widget
&& m_autonum_cable.widget->isModified()
&& m_autonum_cable.widget->isValid()) {
saveAutoNumContext(m_autonum_cable);
}
persistAutonumSettings();
}
}
@@ -387,6 +409,12 @@ void NewDiagramPage::loadAutoNumTab(AutoNumTab &tab, QSettings &settings)
tab.widget->contextComboBox()->setCurrentText(data.second);
tab.widget->setContext(tab.contexts.value(data.second));
}
//A tab which keeps one single rule can take it away again with
//a button of its own -- the row the others delete from is
//hidden here -- but only when there really is one to take away.
if (!tab.fixed_name.isEmpty()) {
tab.widget->setRuleRemovable(tab.contexts.contains(tab.fixed_name));
}
}
/**
@@ -396,15 +424,25 @@ void NewDiagramPage::loadAutoNumTab(AutoNumTab &tab, QSettings &settings)
*/
void NewDiagramPage::saveAutoNumContext(AutoNumTab &tab)
{
QString name = tab.widget->contextComboBox()->currentText().trimmed();
if (name.isEmpty() || isPlaceholder(tab.widget->contextComboBox(), name)) {
return;
// A tab which keeps one single rule has no visible combo box to name
// it with (the row is hidden): it saves under its fixed name.
QString name = tab.fixed_name;
if (name.isEmpty()) {
name = tab.widget->contextComboBox()->currentText().trimmed();
if (name.isEmpty() || isPlaceholder(tab.widget->contextComboBox(), name)) {
return;
}
}
tab.contexts.insert(name, tab.widget->toNumContext());
if (tab.widget->contextComboBox()->findText(name) == -1) {
tab.widget->contextComboBox()->addItem(name);
}
tab.widget->contextComboBox()->setCurrentText(name);
persistAutonumSettings();
//There is a rule now, so there is something to take away again.
if (!tab.fixed_name.isEmpty()) {
tab.widget->setRuleRemovable(true);
}
}
/**
@@ -413,17 +451,37 @@ void NewDiagramPage::saveAutoNumContext(AutoNumTab &tab)
*/
void NewDiagramPage::removeAutoNumContext(AutoNumTab &tab)
{
QString name = tab.widget->contextComboBox()->currentText().trimmed();
if (name.isEmpty() || isPlaceholder(tab.widget->contextComboBox(), name)) {
return;
QString name = tab.fixed_name;
if (name.isEmpty()) {
name = tab.widget->contextComboBox()->currentText().trimmed();
if (name.isEmpty() || isPlaceholder(tab.widget->contextComboBox(), name)) {
return;
}
}
int idx = tab.widget->contextComboBox()->findText(name);
if (idx == -1) return;
// A name which is not in the list was never saved, so there is
// nothing to take out -- unless it is a single rule, which is
// always under its fixed name whether the combo knows it or not.
if (idx == -1 && tab.fixed_name.isEmpty()) return;
if (idx != -1) {
tab.widget->contextComboBox()->removeItem(idx);
tab.widget->contextComboBox()->setCurrentText(QString());
}
tab.contexts.remove(name);
tab.widget->contextComboBox()->removeItem(idx);
tab.widget->contextComboBox()->setCurrentText(QString());
tab.widget->setContext(NumerotationContext());
persistAutonumSettings();
//A tab which keeps one single rule has no list to delete it
//from, so this is where the button of its own goes away too.
//And having just taken the rule away means numbering cables by
//hand again: the question of defining one comes back the next
//time a cable is drawn, so it is not held back any more.
if (!tab.fixed_name.isEmpty()) {
tab.widget->setRuleRemovable(false);
QSettings settings;
settings.setValue(QStringLiteral("cable-management/ask_numbering_rule"),
true);
}
}
/**
@@ -433,12 +491,21 @@ void NewDiagramPage::removeAutoNumContext(AutoNumTab &tab)
void NewDiagramPage::persistAutonumSettings()
{
QSettings settings;
for (auto *tab : {&m_autonum_conductor, &m_autonum_element, &m_autonum_folio}) {
for (auto *tab : {&m_autonum_conductor, &m_autonum_element, &m_autonum_folio, &m_autonum_cable}) {
QString current;
QComboBox *combo = tab->widget->contextComboBox();
if (!isPlaceholder(combo, combo->currentText().trimmed())
&& tab->contexts.contains(combo->currentText().trimmed())) {
current = combo->currentText().trimmed();
if (!tab->fixed_name.isEmpty()) {
// The one rule of a single-rule tab is in use as soon as
// it exists: there is nothing to choose between.
if (tab->contexts.contains(tab->fixed_name)) {
current = tab->fixed_name;
}
}
else {
QComboBox *combo = tab->widget->contextComboBox();
if (!isPlaceholder(combo, combo->currentText().trimmed())
&& tab->contexts.contains(combo->currentText().trimmed())) {
current = combo->currentText().trimmed();
}
}
NumerotationContext::saveToSettings(tab->contexts, current,
settings, tab->prefix);
@@ -456,7 +523,7 @@ bool NewDiagramPage::eventFilter(QObject *obj, QEvent *event)
auto *ke = static_cast<QKeyEvent *>(event);
if ((ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)) {
// Check if this is a line edit inside one of our autonum combos
for (auto *tab : {&m_autonum_conductor, &m_autonum_element, &m_autonum_folio}) {
for (auto *tab : {&m_autonum_conductor, &m_autonum_element, &m_autonum_folio, &m_autonum_cable}) {
if (QComboBox *combo = tab->widget->contextComboBox()) {
if (combo->lineEdit() && combo->lineEdit() == obj) {
return true; // eat the event
+6
View File
@@ -82,10 +82,16 @@ public slots:
SelectAutonumW *widget = nullptr;
QHash<QString, NumerotationContext> contexts;
QString prefix;
/// When set, this tab keeps one single rule, always saved
/// and read under this name: there is no visible combo box
/// to name a rule with (see SelectAutonumW::
/// setSingleRuleMode). The cable numbering works that way.
QString fixed_name;
};
AutoNumTab m_autonum_conductor;
AutoNumTab m_autonum_element;
AutoNumTab m_autonum_folio;
AutoNumTab m_autonum_cable;
void initAutoNumTab(AutoNumTab &tab, SelectAutonumW *w, const QString &prefix);
void loadAutoNumTab(AutoNumTab &tab, QSettings &settings);
@@ -21,6 +21,7 @@
#include "../../qeticons.h"
#include "ui_generalconfigurationpage.h"
#include "../../materiallist/materiallist.h"
#include "../../cablelist/cabletypelist.h"
#include "../../utils/qetsettings.h"
#include "../../utils/qetutils.h"
#include "../../qetmessagebox.h"
@@ -29,6 +30,7 @@
#include "../../ElementsCollection/qetlabelsfile.h"
#include "../prefixconfigurationdialog.h"
#include "../nokde/kcolorbutton.h"
#include <QCoreApplication>
#include <QDir>
#include <QFileDialog>
#include <QFileInfo>
@@ -36,6 +38,35 @@
#include <QMessageBox>
#include <QSettings>
#include "../../diagram.h"
#include "../../qetproject.h"
namespace {
/**
@brief What one of those font buttons says: the family, the size
and the style, the way it would read on the sheet.
@param font the font that text is written with
@return e.g. "Liberation Sans 8,1 (Regular)"
*/
QString fontButtonLabel(const QFont &font)
{
QString style = font.styleName();
if (font.bold()) {
style = font.italic()
? QCoreApplication::translate("GeneralConfigurationPage",
"Gras et italique")
: QCoreApplication::translate("GeneralConfigurationPage", "Gras");
} else if (font.italic()) {
style = QCoreApplication::translate("GeneralConfigurationPage", "Italique");
} else if (style.isEmpty()) {
style = QCoreApplication::translate("GeneralConfigurationPage", "Normal");
}
return font.family() + QLatin1Char(' ')
+ QString::number(font.pointSizeF(), 'g', 3)
+ QLatin1String(" (") + style + QLatin1Char(')');
}
}
/**
@brief GeneralConfigurationPage::GeneralConfigurationPage
@param parent
@@ -168,6 +199,17 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
font.styleName() + ")";
ui->m_indi_text_font_pb->setText(fontInfos);
} else { ui->m_indi_text_font_pb->setText("Liberation Sans 9 (Regular)"); }
//Cable texts: what every cable writes along its own line when
//it has not been given a font of its own.
ui->m_cable_text_font_pb->setText(fontButtonLabel(QETApp::cableTextsFont()));
ui->m_cable_core_font_pb->setText(fontButtonLabel(QETApp::cableCoreFont()));
//Where those texts stop in relation to the beginning of their
//own line, for the cables which say nothing about it themselves
const int align_index = int(QETApp::cableTextAlignment()) == int(Qt::AlignLeft) ? 2
: (int(QETApp::cableTextAlignment()) == int(Qt::AlignHCenter) ? 1 : 0);
ui->m_cable_align_cb->setCurrentIndex(align_index);
ui->m_highlight_integrated_elements->setChecked(settings.value("diagrameditor/highlight-integrated-elements", true).toBool());
ui->m_default_elements_info->setPlainText(settings.value("elementeditor/default-informations", "").toString());
@@ -247,6 +289,17 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
.arg(MaterialList::defaultPath()));
}
//CABLE TYPE FILE
path = CableTypeList::configuredPath();
ui->m_cable_type_list_path_le->setText(path);
if (path.isEmpty())
{
ui->m_cable_type_list_path_le->setPlaceholderText(
tr("Non configuré (par défaut : %1)",
"hint shown in the cable type file field when no file is configured yet")
.arg(CableTypeList::defaultPath()));
}
fillLang();
}
@@ -438,6 +491,30 @@ void GeneralConfigurationPage::applyConf()
//kept as chosen even when it doesn't exist yet : the user may well
//point QElectroTech at a file he intends to write later.
MaterialList::setConfiguredPath(ui->m_material_list_path_le->text().trimmed());
//CABLE TYPE FILE
//Same rule as the material file : it is a plain file, kept as
//chosen even when it doesn't exist yet.
CableTypeList::setConfiguredPath(ui->m_cable_type_list_path_le->text().trimmed());
//The way a cable lines up its texts at the beginning of its
//line, for every cable which says nothing about it itself --
//written now, so the sheets drawn again just below show it.
const int align_index = ui->m_cable_align_cb->currentIndex();
QETApp::setCableTextAlignment(align_index == 2 ? Qt::AlignLeft
: (align_index == 1
? Qt::AlignHCenter
: Qt::AlignRight));
//Every folio is drawn again: the texts of the cables are written
//from the settings, so that what he just picked reaches the
//sheets without his having to touch anything on them first.
for (QETProject *project : QETApp::registeredProjects())
{
for (Diagram *diagram : project->diagrams()) {
diagram->update();
}
}
}
/**
@@ -556,6 +633,45 @@ void GeneralConfigurationPage::on_m_dyn_text_font_pb_clicked()
}
}
/**
@brief GeneralConfigurationPage::on_m_cable_text_font_pb_clicked
Let him pick the font the texts of a cable are written with by
default: designation, type, installation, location and length.
Every cable which has not been given a font of its own follows it,
from now on: one which has keeps the one it was given, which is why
those are set on the cable itself rather than here.
*/
void GeneralConfigurationPage::on_m_cable_text_font_pb_clicked()
{
bool ok = false;
const QFont font = QFontDialog::getFont(&ok, QETApp::cableTextsFont(), this,
tr("Police des textes de câble"));
if (!ok) return;
QSettings settings;
settings.setValue("cable-management/cable-text-font", QETUtils::fontToString(font));
ui->m_cable_text_font_pb->setText(fontButtonLabel(QETApp::cableTextsFont()));
}
/**
@brief GeneralConfigurationPage::on_m_cable_core_font_pb_clicked
Let him pick the font the colours of the cores are written with by
default -- all of them together, the way they are drawn: one row of
colours beside the line, never set apart from each other.
*/
void GeneralConfigurationPage::on_m_cable_core_font_pb_clicked()
{
bool ok = false;
const QFont font = QFontDialog::getFont(&ok, QETApp::cableCoreFont(), this,
tr("Police des couleurs des âmes"));
if (!ok) return;
QSettings settings;
settings.setValue("cable-management/cable-core-font", QETUtils::fontToString(font));
ui->m_cable_core_font_pb->setText(fontButtonLabel(QETApp::cableCoreFont()));
}
@@ -791,6 +907,70 @@ void GeneralConfigurationPage::on_m_material_list_create_pb_clicked()
ui->m_material_list_path_le->setText(path);
}
/**
@brief GeneralConfigurationPage::on_m_cable_type_list_browse_pb_clicked
Let the user pick an existing cable type file.
*/
void GeneralConfigurationPage::on_m_cable_type_list_browse_pb_clicked()
{
QString start_dir = ui->m_cable_type_list_path_le->text();
start_dir = start_dir.isEmpty()
? QETApp::documentDir()
: QFileInfo(start_dir).absolutePath();
const QString path = QFileDialog::getOpenFileName(
this,
tr("Sélectionner le fichier de la liste des types de câbles"),
start_dir,
tr("Fichiers csv (*.csv)"));
if (!path.isEmpty()) {
ui->m_cable_type_list_path_le->setText(path);
}
}
/**
@brief GeneralConfigurationPage::on_m_cable_type_list_create_pb_clicked
Create the cable type file with its header line, so the columns are
known before the user fills them from his spreadsheet.
*/
void GeneralConfigurationPage::on_m_cable_type_list_create_pb_clicked()
{
QString path = ui->m_cable_type_list_path_le->text();
path = path.isEmpty()
? CableTypeList::defaultPath()
: QFileInfo(path).absolutePath() + QLatin1Char('/') + CableTypeList::defaultFileName();
path = QFileDialog::getSaveFileName(
this,
tr("Créer le fichier de la liste des types de câbles"),
path,
tr("Fichiers csv (*.csv)"));
if (path.isEmpty()) {
return;
}
if (QFileInfo(path).suffix().isEmpty()) {
path += QStringLiteral(".csv");
}
//An existing file is kept as it is : this button creates the
//header, it never overwrites a catalogue.
if (CableTypeList::isEmptyFile(path))
{
QString error;
if (!CableTypeList::createFile(path, &error))
{
QET::QetMessageBox::critical(this,
tr("Création impossible"),
tr("Impossible de créer le fichier :\n%1\n%2")
.arg(path, error));
return;
}
}
ui->m_cable_type_list_path_le->setText(path);
}
void GeneralConfigurationPage::on_m_indi_text_font_pb_clicked()
{
bool ok;
@@ -50,7 +50,11 @@ class GeneralConfigurationPage : public ConfigPage
void on_m_prefix_pb_clicked();
void on_m_material_list_browse_pb_clicked();
void on_m_material_list_create_pb_clicked();
void on_m_cable_type_list_browse_pb_clicked();
void on_m_cable_type_list_create_pb_clicked();
void on_m_indi_text_font_pb_clicked();
void on_m_cable_text_font_pb_clicked();
void on_m_cable_core_font_pb_clicked();
void on_MaxPartsElementEditorList_sb_valueChanged(int value);
void on_DiagramEditor_Grid_PointSize_min_sb_valueChanged(int value);
void on_ElementEditor_Grid_PointSize_min_sb_valueChanged(int value);
@@ -510,6 +510,47 @@
</item>
</layout>
</item>
<item row="9" column="0">
<widget class="QLabel" name="m_cable_type_list_label">
<property name="text">
<string>Fichier de la liste des types de câbles</string>
</property>
</widget>
</item>
<item row="9" column="1">
<layout class="QHBoxLayout" name="m_cable_type_list_layout">
<item>
<widget class="QLineEdit" name="m_cable_type_list_path_le">
<property name="toolTip">
<string extracomment="tooltip of the cable type file path field">Répertoire des types de câbles utilisé pour définir un câble (nombre d'âmes, couleurs, section)</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string extracomment="hint shown when no cable type file is configured yet">Non configuré</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_cable_type_list_browse_pb">
<property name="text">
<string>Parcourir...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_cable_type_list_create_pb">
<property name="toolTip">
<string extracomment="tooltip of the button creating the cable type file with its header line">Créer le fichier de la liste des types de câbles avec ses en-têtes</string>
</property>
<property name="text">
<string>Créer...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -775,6 +816,113 @@ Vous pouvez spécifier ici la valeur par défaut de ce champ pour les éléments
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_cable_textes">
<property name="title">
<string>Textes de câble</string>
</property>
<layout class="QGridLayout" name="gridLayout_cable_textes">
<item row="0" column="0">
<widget class="QLabel" name="label_cable_textes">
<property name="text">
<string>Désignation, type, installation, emplacement, longueur :</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_cable_textes">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="m_cable_text_font_pb">
<property name="toolTip">
<string>Police des textes écrits le long de la ligne d'un câble. Un câble réglé sur mesure garde la sienne.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_cable_core_textes">
<property name="text">
<string>Couleurs des âmes (toutes ensemble) :</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_cable_core_textes">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="m_cable_core_font_pb">
<property name="toolTip">
<string>Police des couleurs des âmes d'un câble, écrites le long de la ligne. Un câble réglé sur mesure garde la sienne.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_cable_align">
<property name="text">
<string>Alignement des textes :</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="m_cable_align_cb">
<property name="toolTip">
<string>Où les textes d'un câble s'arrêtent par rapport au début de sa ligne. Un câble réglé sur mesure garde le sien.</string>
</property>
<item>
<property name="text">
<string>Aligné à droite</string>
</property>
</item>
<item>
<property name="text">
<string>Centré</string>
</property>
</item>
<item>
<property name="text">
<string>Aligné à gauche</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
+131 -2
View File
@@ -33,6 +33,8 @@
#include "../titleblockpropertieswidget.h"
#include "../xrefpropertieswidget.h"
#include <QSettings>
//#include "ui_autonumberingmanagementw.h"
#include <QtWidgets>
@@ -353,9 +355,20 @@ QIcon ProjectAutoNumConfigPage::icon() const
/**
@brief ProjectAutoNumConfigPage::applyProjectConf
Save what this page has to save when the window is confirmed.
The cable rule is written from here as well as by its own Apply
button: the cable tool asks the project for that rule the moment
he tries to draw a cable, so filling it in and confirming this
window only to be asked once more would be a surprise. A rule he
has not finished filling in is left alone, and a page he has not
touched leaves the project exactly as it was.
*/
void ProjectAutoNumConfigPage::applyProjectConf()
{}
{
if (m_saw_cable && m_saw_cable->isModified() && m_saw_cable->isValid()) {
saveContextCable();
}
}
/**
@brief ProjectAutoNumConfigPage::initWidgets
@@ -364,6 +377,7 @@ void ProjectAutoNumConfigPage::applyProjectConf()
void ProjectAutoNumConfigPage::initWidgets()
{
QTabWidget *tab_widget = new QTabWidget(this);
m_tab_widget = tab_widget;
//Management tab
m_amw = new AutoNumberingManagementW(project());
@@ -380,6 +394,12 @@ void ProjectAutoNumConfigPage::initWidgets()
//Folio Tab
m_saw_folio = new SelectAutonumW(2);
tab_widget->addTab(m_saw_folio, tr("Folios"));
//Cable tab: one rule only, so the row which lists the available
//numberings stays hidden and there is nothing to choose between.
m_saw_cable = new SelectAutonumW(3);
m_saw_cable->setSingleRuleMode(true);
tab_widget->addTab(m_saw_cable, tr("Câbles"));
//AutoNumbering Tab
m_faw = new FolioAutonumberingW(project());
@@ -414,6 +434,7 @@ void ProjectAutoNumConfigPage::readValuesFromProject()
m_saw_conductor->contextComboBox()->clear();
m_saw_element->contextComboBox()->clear();
m_saw_folio->contextComboBox()->clear();
m_saw_cable->contextComboBox()->clear();
//Conductor Tab
const QStringList strlc(m_project->conductorAutoNum().keys());
@@ -426,6 +447,25 @@ void ProjectAutoNumConfigPage::readValuesFromProject()
//Folio Tab
const QStringList strlf(m_project->folioAutoNum().keys());
m_saw_folio->contextComboBox()->addItems(strlf);
//Cable tab: the rule goes straight into the editor, since with the
//row of available numberings hidden he can never pick it out of
//the combo box himself. With no rule at all the editor shows an
//empty one to fill in, exactly like a numbering which has just
//been opened for the first time.
const QStringList strlk(m_project->cableAutoNum().keys());
m_saw_cable->contextComboBox()->addItems(strlk);
const QString cable_rule = m_project->cableCurrentAutoNum();
const bool cable_rule_ok = !cable_rule.isEmpty()
&& !m_project->cableAutoNum(cable_rule).isEmpty();
if (cable_rule_ok) {
m_saw_cable->setContext(m_project->cableAutoNum(cable_rule));
} else {
m_saw_cable->setContext(NumerotationContext());
}
//The button which takes the rule away is only worth showing when
//there is one, and only clickable when the project allows changes.
m_saw_cable->setRuleRemovable(cable_rule_ok && !m_project->isReadOnly());
//Folio AutoNumbering Tab
m_faw->setContext(m_project->folioAutoNum().keys());
@@ -440,6 +480,15 @@ void ProjectAutoNumConfigPage::adjustReadOnly()
if (m_import_pb && m_project) {
m_import_pb->setDisabled(m_project->isReadOnly());
}
//The button which takes the cable numbering rule away does the
//same thing as the import button: nothing while the project
//cannot be written.
if (m_saw_cable && m_project) {
const QString title = m_project->cableCurrentAutoNum();
m_saw_cable->setRuleRemovable(!m_project->isReadOnly()
&& !title.isEmpty()
&& !m_project->cableAutoNum(title).isEmpty());
}
}
/**
@@ -466,6 +515,11 @@ void ProjectAutoNumConfigPage::buildConnections()
connect(m_saw_folio, &SelectAutonumW::removeClicked, this, &ProjectAutoNumConfigPage::removeContextFolio);
connect(m_saw_folio->contextComboBox(), &QComboBox::textActivated, this, &ProjectAutoNumConfigPage::updateContextFolio);
//Cable tab: one rule, so there is no name to pick in the hidden
//combo box -- applying always writes the single rule.
connect(m_saw_cable, &SelectAutonumW::applyPressed, this, &ProjectAutoNumConfigPage::saveContextCable);
connect(m_saw_cable, &SelectAutonumW::removeClicked, this, &ProjectAutoNumConfigPage::removeContextCable);
// Auto Folio Numbering
connect(m_faw, &FolioAutonumberingW::applyPressed, this, &ProjectAutoNumConfigPage::applyAutoNum);
@@ -541,6 +595,68 @@ void ProjectAutoNumConfigPage::saveContextElement()
}
}
/**
@brief ProjectAutoNumConfigPage::saveContextCable
Save the cable numbering rule into the project.
There is one rule only, and it has no name the user could have typed
(the row which holds those names is hidden): it always goes in under
the fixed name, and it is the rule in use from the moment it exists.
*/
void ProjectAutoNumConfigPage::saveContextCable()
{
if (!m_project || m_project->isReadOnly()) return;
const QString title = QETProject::cableAutoNumRuleName();
m_project->addCableAutoNum(title, m_saw_cable->toNumContext());
m_project->setCurrentCableAutoNum(title);
//Keep the hidden combo box in step with what the project holds,
//so the next reading of this page shows the rule just saved.
if (m_saw_cable->contextComboBox()->findText(title) == -1) {
m_saw_cable->contextComboBox()->addItem(title);
}
m_saw_cable->contextComboBox()->setCurrentText(title);
//There is a rule now, so there is something to take away again.
m_saw_cable->setRuleRemovable(true);
//This is applied straight away rather than at the end of the
//window, so the project has to say so itself: otherwise the rule
//would be dropped by a Cancel which comes after it.
m_project->setModified(true);
}
/**
@brief ProjectAutoNumConfigPage::removeContextCable
Take the cable numbering rule out of the project. The project then
numbers its cables by no rule at all -- they are called W until one
is defined again -- and the cable tool asks once more whether one
should be defined.
*/
void ProjectAutoNumConfigPage::removeContextCable()
{
if (!m_project || m_project->isReadOnly()) return;
const QString title = m_project->cableCurrentAutoNum();
if (title.isEmpty()) return;
m_project->removeCableAutoNum(title);
const int idx = m_saw_cable->contextComboBox()->findText(title);
if (idx != -1) {
m_saw_cable->contextComboBox()->removeItem(idx);
}
m_saw_cable->contextComboBox()->setCurrentText(QString());
m_saw_cable->setContext(NumerotationContext());
//No rule left, so the button which takes one away goes too. And
//having just taken the rule away means numbering cables by hand
//again: the question of defining one comes back the next time a
//cable is drawn, so it is not held back any more.
m_saw_cable->setRuleRemovable(false);
QSettings settings;
settings.setValue(QStringLiteral("cable-management/ask_numbering_rule"),
true);
m_project->setModified(true);
}
/**
@brief ProjectAutoNumConfigPage::importFromProject
Read the automatic numbering rules stored in another .qet project and
@@ -966,5 +1082,18 @@ void ProjectAutoNumConfigPage::removeContextFolio()
*/
void ProjectAutoNumConfigPage::changeToTab(int i)
{
qDebug()<<"Q_UNUSED"<<i;
if (!m_tab_widget) return;
if (i < 0 || i >= m_tab_widget->count()) return;
m_tab_widget->setCurrentIndex(i);
}
/**
@brief ProjectAutoNumConfigPage::changeToCableTab
Show the cable tab -- the one the cable tool opens when it finds out
that the project has no numbering rule yet.
*/
void ProjectAutoNumConfigPage::changeToCableTab()
{
//Tabs in order : Management, Conducteurs, Eléments, Folios, Câbles
changeToTab(4);
}
@@ -24,6 +24,7 @@ class QComboBox;
class QLineEdit;
class QCheckBox;
class QPushButton;
class QTabWidget;
class QETProject;
class BorderPropertiesWidget;
class ConductorPropertiesWidget;
@@ -142,6 +143,9 @@ class ProjectAutoNumConfigPage : public ProjectConfigPage {
QIcon icon() const override;
void applyProjectConf() override;
virtual void changeToTab(int);
///Jump straight to the cable tab (used when the cable tool
///asks whether a numbering rule should be defined)
void changeToCableTab();
protected:
void initWidgets() override;
void initLayout() override {}
@@ -159,6 +163,8 @@ class ProjectAutoNumConfigPage : public ProjectConfigPage {
void updateContextElement(const QString&);//element
void saveContextElement();
void removeContextElement();
void saveContextCable(); //cable: one rule, no name to pick
void removeContextCable();
void importFromProject();
void applyAutoNum();
@@ -175,9 +181,12 @@ class ProjectAutoNumConfigPage : public ProjectConfigPage {
SelectAutonumW *m_saw_conductor;
SelectAutonumW *m_saw_folio;
SelectAutonumW *m_saw_element;
SelectAutonumW *m_saw_cable;
FolioAutonumberingW *m_faw;
AutoNumberingManagementW *m_amw;
QPushButton *m_import_pb = nullptr;
/// The tabs of this page, kept to switch between them
QTabWidget *m_tab_widget = nullptr;
};
+14
View File
@@ -93,3 +93,17 @@ void ProjectPropertiesDialog::changeToFolio()
m_properties_dialog->pages.at(2));
autoNumPage->changeToTab(3);
}
/**
@brief ProjectPropertiesDialog::changeToCable
Change the current displayed tab to the cable numbering tab.
The caller is the cable tool, which opens this window when it finds
that the project numbers its cables by no rule at all.
*/
void ProjectPropertiesDialog::changeToCable()
{
ProjectAutoNumConfigPage *autoNumPage =
static_cast <ProjectAutoNumConfigPage*>(
m_properties_dialog->pages.at(2));
autoNumPage->changeToCableTab();
}
+2
View File
@@ -41,6 +41,8 @@ class ProjectPropertiesDialog : public QObject {
void exec();
void setCurrentPage(ProjectPropertiesDialog::Page);
void changeToFolio();
///Show the automatic numbering page with the cable tab on top
void changeToCable();
private:
ConfigDialog *m_properties_dialog;
+100 -1
View File
@@ -17,12 +17,16 @@
*/
#include <utility>
#include <QFontDialog>
#include <QHash>
#include <QMetaEnum>
#include <QPushButton>
#include "xrefpropertieswidget.h"
#include "ui_xrefpropertieswidget.h"
#include "qdebug.h"
#include "../qetapp.h"
#include "../utils/qetutils.h"
/**
@brief XRefPropertiesWidget::XRefPropertiesWidget
@@ -37,10 +41,12 @@ XRefPropertiesWidget::XRefPropertiesWidget(QHash <QString, XRefProperties> prope
{
ui->setupUi(this);
buildUi();
fillMissingTypes();
connect(ui->m_display_has_cross_rb, &QRadioButton::toggled, ui->m_cross_properties_gb, &QWidget::setEnabled);
connect(ui->m_display_has_contacts_rb, &QRadioButton::toggled, ui->m_show_all_slaves_cb, &QWidget::setEnabled);
connect(ui->m_type_cb, qOverload<int>(&QComboBox::currentIndexChanged), this, &XRefPropertiesWidget::typeChanged);
connect(ui->m_snap_to_cb, qOverload<int>(&QComboBox::currentIndexChanged), this, &XRefPropertiesWidget::enableOffsetSB);
connect(ui->m_font_pb, &QPushButton::clicked, this, &XRefPropertiesWidget::chooseXRefFont);
updateDisplay();
}
@@ -54,6 +60,7 @@ XRefPropertiesWidget::~XRefPropertiesWidget()
disconnect(ui->m_display_has_contacts_rb, &QRadioButton::toggled, ui->m_show_all_slaves_cb, &QWidget::setEnabled);
disconnect(ui->m_type_cb, qOverload<int>(&QComboBox::currentIndexChanged), this, &XRefPropertiesWidget::typeChanged);
disconnect(ui->m_snap_to_cb, qOverload<int>(&QComboBox::currentIndexChanged), this, &XRefPropertiesWidget::enableOffsetSB);
disconnect(ui->m_font_pb, &QPushButton::clicked, this, &XRefPropertiesWidget::chooseXRefFont);
delete ui;
}
@@ -65,10 +72,33 @@ XRefPropertiesWidget::~XRefPropertiesWidget()
void XRefPropertiesWidget::setProperties(const QHash <QString,
XRefProperties> &properties) {
m_properties = properties;
fillMissingTypes();
updateDisplay();
m_previous_type_index = ui->m_type_cb->currentIndex();
}
/**
@brief XRefPropertiesWidget::fillMissingTypes
Make sure every type the combo box offers has properties of its own.
A project built before a type existed does not hold that type, and
neither does a settings file written before it. Without an entry the
form would make one up out of thin air, and for a cable that would be
the very default of the coil ("%f-%l%c"), which reads as a stray dash
behind the folio number and two empty numbers after it.
*/
void XRefPropertiesWidget::fillMissingTypes()
{
const QHash<QString, XRefProperties> defaults = XRefProperties::defaultProperties();
for (int i = 0; i < ui->m_type_cb->count(); ++i)
{
const QString type = ui->m_type_cb->itemData(i).toString();
if (!m_properties.contains(type)) {
m_properties.insert(type, defaults.value(type));
}
}
}
/**
@brief XRefPropertiesWidget::properties
@return the properties edited by this widget
@@ -88,6 +118,9 @@ void XRefPropertiesWidget::setReadOnly(bool ro) {
ui->m_type_cb->setDisabled(ro);
ui->m_display_gb->setDisabled(ro);
ui->m_cross_properties_gb->setDisabled(ro);
//The texts stand on their own since they are needed for a cable
//too, and they are as much a setting as the rest.
ui->m_labels_gb->setDisabled(ro);
if (!ro && ui->m_display_has_contacts_rb->isChecked()) {
ui->m_cross_properties_gb->setDisabled(true);
@@ -104,6 +137,9 @@ void XRefPropertiesWidget::buildUi()
ui -> m_type_cb -> addItem(tr("Organe de protection"), "protection");
ui -> m_type_cb -> addItem(tr("Commutateur / bouton"), "commutator");
ui -> m_type_cb -> addItem(tr("Automate (PLC)"), "plc");
//Not an element: the type of the cross references a cable writes
//in its own label when it runs on several folios.
ui -> m_type_cb -> addItem(tr("Câble"), "cable");
ui -> m_snap_to_cb -> addItem(tr("En bas de page"), "bottom");
ui -> m_snap_to_cb -> addItem(tr("Sous le label de l'élément"), "label");
@@ -151,6 +187,7 @@ void XRefPropertiesWidget::saveProperties(int index) {
xrp.setPrefix("switch", ui->m_switch_prefix_le->text());
xrp.setMasterLabel(ui->m_master_le->text());
xrp.setSlaveLabel(ui->m_slave_le->text());
xrp.setFont(m_current_font);
xrp.setOffset(ui->m_offset_sb->value());
xrp.setSlaveOffset(ui->m_slave_offset_sb->value());
@@ -177,6 +214,10 @@ void XRefPropertiesWidget::updateDisplay()
QString master = xrp.masterLabel();
ui->m_master_le->setText(master);
//Which font that type's reference is written with: the button
//offers it for a cable alone, but every type carries its own.
m_current_font = xrp.font();
QString slave = xrp.slaveLabel();
ui->m_slave_le->setText(slave);
@@ -226,7 +267,37 @@ void XRefPropertiesWidget::updateDisplay()
ui->m_display_has_cross_rb->setVisible(!is_plc);
ui->m_show_terminal_name_cb->setVisible(!is_plc);
ui->m_show_all_slaves_cb->setVisible(!is_plc);
ui->m_cross_properties_gb->setVisible(!is_plc);
//A cable is not an element: it draws no cross of its own and stands
//at no place of the sheet to be pointed at. Its reference is a line
//of the label of the cable itself, written once per other folio the
//cable runs on, so the whole presentation (where a cross is put, how
//it is drawn) and the text of the slave have no meaning for it: what
//is left is the one text which is written into that line.
const bool is_cable = type == QLatin1String("cable");
ui->m_display_gb->setVisible(!is_cable);
ui->label_7->setVisible(!is_cable);
ui->m_slave_le->setVisible(!is_cable);
ui->label_6->setText(is_cable ? tr("Texte :") : tr("Maitre"));
//Only a cable writes its reference into its own label, so only a
//cable has a text whose font to choose here: the cross references
//of the elements keep the font they have always been drawn with.
ui->m_font_pb->setVisible(is_cable);
if (m_current_font.isEmpty())
{
ui->m_font_pb->setToolTip(tr("Police et taille : celles des textes de câble"));
}
else
{
QFont font;
if (QETUtils::fontFromString(font, m_current_font)) {
ui->m_font_pb->setToolTip(tr("Police et taille : %1, %2 pt")
.arg(font.family()).arg(font.pointSizeF()));
}
}
ui->m_cross_properties_gb->setVisible(!is_plc && !is_cable);
}
/**
@@ -255,3 +326,31 @@ void XRefPropertiesWidget::enableOffsetSB(int i){
else
ui->m_offset_sb->setEnabled(true);
}
/**
@brief XRefPropertiesWidget::chooseXRefFont
Let him pick the font -- family, size and style, all three at once --
the reference of a cable is written with.
The font is only kept when he presses OK: cancelling the dialog
leaves the previous one standing. What he picked is written into the
properties by saveProperties(), the way every other field of this
form is, so leaving the type or pressing OK in the settings window
is what really stores it.
*/
void XRefPropertiesWidget::chooseXRefFont()
{
QFont initial;
if (m_current_font.isEmpty() || !QETUtils::fontFromString(initial, m_current_font)) {
initial = QETApp::cableTextsFont();
}
bool ok = false;
const QFont font = QFontDialog::getFont(&ok, initial, this,
tr("Police du texte de querverweis"));
if (!ok) return;
m_current_font = QETUtils::fontToString(font);
ui->m_font_pb->setToolTip(tr("Police et taille : %1, %2 pt")
.arg(font.family()).arg(font.pointSizeF()));
}
+4
View File
@@ -46,7 +46,9 @@ class XRefPropertiesWidget : public QWidget
private:
void buildUi();
void fillMissingTypes();
void saveProperties(int index);
void chooseXRefFont();
private slots:
void updateDisplay();
@@ -58,6 +60,8 @@ class XRefPropertiesWidget : public QWidget
Ui::XRefPropertiesWidget *ui;
QHash <QString, XRefProperties> m_properties;
int m_previous_type_index;
///The font picked for the type shown, as the settings describe it
QString m_current_font;
};
#endif // XREFPROPERTIESWIDGET_H
+144 -134
View File
@@ -90,56 +90,56 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>XRef slave position</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_xrefpos_cb"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Distance label - slave :</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_slave_offset_sb">
<property name="toolTip">
<string>Distance in pixels between the label and the slave cross reference</string>
</property>
<property name="suffix">
<string notr="true">px</string>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<number>-50</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>XRef slave position</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_xrefpos_cb"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Distance label - slave :</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_slave_offset_sb">
<property name="toolTip">
<string>Distance in pixels between the label and the slave cross reference</string>
</property>
<property name="suffix">
<string notr="true">px</string>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<number>-50</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
@@ -179,100 +179,110 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="m_labels_gb">
<property name="title">
<string>Label des références croisées</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Label des références croisées</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>48</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Maitre</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_master_le">
<property name="inputMask">
<string/>
</property>
<property name="text">
<string>%f-%l%c</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>48</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Esclave</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_slave_le">
<property name="text">
<string>(%f-%l%c)</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Créer votre propre texte en vous aidant des variables suivantes :
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>48</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Maitre</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_master_le">
<property name="inputMask">
<string/>
</property>
<property name="text">
<string>%f-%l%c</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_font_pb">
<property name="toolTip">
<string>Choisir la police et la taille du texte du querverweis du câble</string>
</property>
<property name="text">
<string>Police…</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="m_slave_row">
<item>
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>48</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Esclave</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_slave_le">
<property name="text">
<string>(%f-%l%c)</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Créer votre propre texte en vous aidant des variables suivantes :
%f : le numéro de folio
%F: le label de folio
%l : le numéro de ligne
%c : le numéro de colonne
%M: Installation
%LM: Localisation </string>
</property>
</widget>
</item>
</layout>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="m_cross_properties_gb">