diff --git a/sources/TerminalStrip/terminalstrip.cpp b/sources/TerminalStrip/terminalstrip.cpp index 04aadd0d6..17f218ab9 100644 --- a/sources/TerminalStrip/terminalstrip.cpp +++ b/sources/TerminalStrip/terminalstrip.cpp @@ -21,6 +21,7 @@ #include "../qetgraphicsitem/terminalelement.h" #include "../elementprovider.h" #include "../qetxml.h" +#include "../autoNum/assignvariables.h" using shared_real_terminal = QSharedPointer; using shared_physical_terminal = QSharedPointer; @@ -82,6 +83,14 @@ class RealTerminal } } + ElementData::TerminalType type() const { + if (m_element) { + return m_element->elementData().m_terminal_type; + } else { + return ElementData::TTGeneric; + } + } + /** * @brief elementUuid * @return if this real terminal is an element @@ -234,6 +243,16 @@ class PhysicalTerminal return m_real_terminal.size(); } + /** + * @brief levelOf + * @param terminal + * @return the level of real terminal \p terminal or + * -1 if \terminal is not a part of this physicalTerminal + */ + int levelOf(shared_real_terminal terminal) const { + return m_real_terminal.indexOf(terminal); + } + /** * @brief terminals * @return A vector of real terminal who compose this physical terminal @@ -433,6 +452,16 @@ int TerminalStrip::physicalTerminalCount() const { return m_physical_terminals.size(); } +/** + * @brief TerminalStrip::realTerminalCount + * @return the number of real terminal. + * A real terminal is a part of a physical terminal. + */ +int TerminalStrip::realTerminalCount() const +{ + return m_real_terminals.size(); +} + TerminalStripIndex TerminalStrip::index(int index) { TerminalStripIndex tsi_; @@ -537,6 +566,31 @@ bool TerminalStrip::fromXml(QDomElement &xml_element) return true; } +RealTerminalData TerminalStrip::realTerminalData(int real_terminal_index) +{ + RealTerminalData rtd; + if (m_real_terminals.isEmpty() || + real_terminal_index >= m_real_terminals.size()) { + return rtd; + } + + auto real_terminal = m_real_terminals.at(real_terminal_index); + auto physical_terminal = physicalTerminal(real_terminal); + + rtd.m_real_terminal = m_real_terminals.at(real_terminal_index); + rtd.pos_ = m_physical_terminals.indexOf(physical_terminal); + rtd.level_ = physical_terminal->levelOf(real_terminal); + rtd.label_ = real_terminal->label(); + + if (real_terminal->isElement()) { + rtd.Xref_ = autonum::AssignVariables::genericXref(real_terminal->element()); + } + rtd.type_ = real_terminal->type(); + rtd.is_element = real_terminal->isElement(); + + return rtd; +} + /** * @brief TerminalStrip::realTerminal * @param terminal diff --git a/sources/TerminalStrip/terminalstrip.h b/sources/TerminalStrip/terminalstrip.h index c147fb14b..61ae60fa4 100644 --- a/sources/TerminalStrip/terminalstrip.h +++ b/sources/TerminalStrip/terminalstrip.h @@ -21,6 +21,7 @@ #include #include #include "terminalstripdata.h" +#include "../properties/elementdata.h" class Element; class RealTerminal; @@ -29,6 +30,26 @@ class PhysicalTerminal; class TerminalStripIndex; class TerminalElement; + +struct RealTerminalData +{ + QSharedPointer m_real_terminal; + + int pos_ = 0, + level_ = 0; + + QString label_, + Xref_, + cable_, + cable_wire_, + conductor_; + + ElementData::TerminalType type_; + + bool led_ = false, + is_element = false; +}; + /** * @brief The TerminalStrip class * This class hold all the datas and configurations @@ -38,6 +59,8 @@ class TerminalElement; */ class TerminalStrip : public QObject { + friend class TerminalStripModel; + Q_OBJECT public: TerminalStrip(QETProject *project); @@ -67,7 +90,9 @@ class TerminalStrip : public QObject bool haveTerminal (Element *terminal); int physicalTerminalCount() const; + int realTerminalCount() const; TerminalStripIndex index(int index = 0); + RealTerminalData realTerminalData(int real_terminal_index); QVector> terminalElement() const; diff --git a/sources/TerminalStrip/ui/terminalstripeditor.cpp b/sources/TerminalStrip/ui/terminalstripeditor.cpp index d7c21fbc7..b83e8c8a4 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -27,6 +27,7 @@ #include "../UndoCommand/changeterminalstripdata.h" #include "terminalstriptreewidget.h" #include "../../qeticons.h" +#include "terminalstripmodel.h" #include @@ -235,16 +236,46 @@ void TerminalStripEditor::addFreeTerminal() } /** - * @brief TerminalStripEditor::clearDataTab + * @brief TerminalStripEditor::setCurrentStrip + * Set the current terminal strip edited to \p strip_ + * @param strip_ */ -void TerminalStripEditor::clearDataTab() +void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_) { - ui->m_installation_le ->clear(); - ui->m_location_le ->clear(); - ui->m_name_le ->clear(); - ui->m_comment_le ->clear(); - ui->m_description_te ->clear(); - m_current_strip = nullptr; + if (strip_ == m_current_strip) { + return; + } + + if (!strip_) + { + ui->m_installation_le ->clear(); + ui->m_location_le ->clear(); + ui->m_name_le ->clear(); + ui->m_comment_le ->clear(); + ui->m_description_te ->clear(); + m_current_strip = nullptr; + + ui->m_table_widget->setModel(nullptr); + if (m_model) { + m_model->deleteLater(); + m_model = nullptr; + } + } + else + { + ui->m_installation_le ->setText(strip_->installation()); + ui->m_location_le ->setText(strip_->location()); + ui->m_name_le ->setText(strip_->name()); + ui->m_comment_le ->setText(strip_->comment()); + ui->m_description_te ->setPlainText(strip_->description()); + m_current_strip = strip_; + + if (m_model) + m_model->deleteLater(); + + m_model = new TerminalStripModel(strip_, this); + ui->m_table_widget->setModel(m_model); + } } /** @@ -310,7 +341,7 @@ void TerminalStripEditor::on_m_reload_pb_clicked() m_uuid_terminal_H.clear(); m_uuid_strip_H.clear(); - qDeleteAll(m_item_strip_H.keys()); + qDeleteAll(m_item_strip_H.keyBegin(), m_item_strip_H.keyEnd()); buildTree(); ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex()); @@ -332,7 +363,7 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI Q_UNUSED(previous) if (!current) { - clearDataTab(); + setCurrentStrip(nullptr); ui->m_remove_terminal_strip_pb->setDisabled(true); return; } @@ -351,16 +382,7 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI ui->m_remove_terminal_strip_pb->setDisabled(true); } - if (strip_) { - m_current_strip = strip_; - ui->m_installation_le ->setText(strip_->installation()); - ui->m_location_le ->setText(strip_->location()); - ui->m_name_le ->setText(strip_->name()); - ui->m_comment_le ->setText(strip_->comment()); - ui->m_description_te ->setPlainText(strip_->description()); - } else { - clearDataTab(); - } + setCurrentStrip(strip_); } void TerminalStripEditor::on_m_apply_data_pb_clicked(QAbstractButton *button) diff --git a/sources/TerminalStrip/ui/terminalstripeditor.h b/sources/TerminalStrip/ui/terminalstripeditor.h index efdf91d7a..6de89291b 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.h +++ b/sources/TerminalStrip/ui/terminalstripeditor.h @@ -29,6 +29,7 @@ class TerminalStrip; class QTreeWidgetItem; class TerminalElement; class QAbstractButton; +class TerminalStripModel; /** * @brief The TerminalStripEditor class @@ -48,7 +49,7 @@ class TerminalStripEditor : public QDialog void buildTree(); QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip); void addFreeTerminal(); - void clearDataTab(); + void setCurrentStrip(TerminalStrip *strip_); private slots: void on_m_add_terminal_strip_pb_clicked(); @@ -65,6 +66,7 @@ class TerminalStripEditor : public QDialog QHash> m_uuid_terminal_H; QHash> m_uuid_strip_H; TerminalStrip *m_current_strip = nullptr; + TerminalStripModel *m_model = nullptr; }; #endif // TERMINALSTRIPEDITOR_H diff --git a/sources/TerminalStrip/ui/terminalstripeditor.ui b/sources/TerminalStrip/ui/terminalstripeditor.ui index 7db32253b..34a789b84 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.ui +++ b/sources/TerminalStrip/ui/terminalstripeditor.ui @@ -130,13 +130,19 @@ - + 0 0 + + true + + + false + @@ -262,7 +268,7 @@ m_name_le m_comment_le m_description_te - tableView + m_table_widget diff --git a/sources/TerminalStrip/ui/terminalstripmodel.cpp b/sources/TerminalStrip/ui/terminalstripmodel.cpp new file mode 100644 index 000000000..b81ef3d8d --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstripmodel.cpp @@ -0,0 +1,101 @@ +/* + Copyright 2006-2021 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 . +*/ +#include "terminalstripmodel.h" +#include "../terminalstrip.h" +#include + +/** + * @brief TerminalStripModel::TerminalStripModel + * @param terminal_strip + * @param parent + */ +TerminalStripModel::TerminalStripModel(TerminalStrip *terminal_strip, QObject *parent) : + QAbstractTableModel(parent), + m_terminal_strip(terminal_strip) +{ + fillRealTerminalData(); +} + +int TerminalStripModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + + if (!m_terminal_strip) { + return 0; + } + + return m_terminal_strip->realTerminalCount(); +} + +int TerminalStripModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return 9; +} + +QVariant TerminalStripModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole || + index.row() >= m_real_terminal_data.size()) { + return QVariant(); + } + + auto rtd = m_real_terminal_data.at(index.row()); + switch (index.column()) { + case 0 : return rtd.pos_; + case 1 : return rtd.level_; + case 2 : return rtd.label_; + case 3 : return rtd.Xref_; + case 4 : return rtd.cable_; + case 5 : return rtd.cable_wire_; + case 6 : return ElementData::translatedTerminalType(rtd.type_); + case 7 : return rtd.led_; + case 8 : return rtd.conductor_; + default : return QVariant(); + } +} + +QVariant TerminalStripModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation != Qt::Horizontal || + role != Qt::DisplayRole) { + return QVariant(); + } + + switch (section) { + case 0: return tr("Position"); + case 1: return tr("Étage"); + case 2: return tr("Label"); + case 3: return tr("Référence croisé"); + case 4: return tr("Câble"); + case 5: return tr("Couleur / numéro de fil câble"); + case 6: return tr("Type"); + case 7: return tr("led"); + case 8: return tr("Numéro de conducteur"); + default : return QVariant(); + } +} + +void TerminalStripModel::fillRealTerminalData() +{ + if (m_terminal_strip) { + for (int i=0 ; i < m_terminal_strip->realTerminalCount() ; ++i) { + m_real_terminal_data.append(m_terminal_strip->realTerminalData(i)); + } + } +} diff --git a/sources/TerminalStrip/ui/terminalstripmodel.h b/sources/TerminalStrip/ui/terminalstripmodel.h new file mode 100644 index 000000000..576cfa457 --- /dev/null +++ b/sources/TerminalStrip/ui/terminalstripmodel.h @@ -0,0 +1,47 @@ +/* + Copyright 2006-2021 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 . +*/ +#ifndef TERMINALSTRIPMODEL_H +#define TERMINALSTRIPMODEL_H + +#include +#include +#include +#include "../terminalstrip.h" + +class TerminalStrip; + +class TerminalStripModel : public QAbstractTableModel +{ + Q_OBJECT + public: + TerminalStripModel(TerminalStrip *terminal_strip, QObject *parent = nullptr); + + virtual int rowCount (const QModelIndex &parent = QModelIndex()) const override; + virtual int columnCount (const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override; + virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + + private: + void fillRealTerminalData(); + + private: + QPointer m_terminal_strip; + QVector m_real_terminal_data; +}; + +#endif // TERMINALSTRIPMODEL_H diff --git a/sources/autoNum/assignvariables.cpp b/sources/autoNum/assignvariables.cpp index 810805270..40f45adb9 100644 --- a/sources/autoNum/assignvariables.cpp +++ b/sources/autoNum/assignvariables.cpp @@ -232,6 +232,33 @@ namespace autonum return str; } + + /** + * @brief AssignVariables::genericXref + * @param element + * @return a simple Xref string in form of 'folio-letterNumber' + */ + QString AssignVariables::genericXref(const Element *element) + { + QString str; + if (!element->diagram()) { + return str; + } + + + QSettings settings; + auto diagram = element->diagram(); + if (settings.value(QLatin1String("genericpanel/folio"), true).toBool()) { + str = diagram->border_and_titleblock.finalfolio(); + } else { + str = QString::number(diagram->folioIndex()+1); + } + + str.append("-"); + str.append(diagram->convertPosition(element->scenePos()).toString()); + + return str; + } AssignVariables::AssignVariables(const QString& formula, diff --git a/sources/autoNum/assignvariables.h b/sources/autoNum/assignvariables.h index b293bb07d..8ac961930 100644 --- a/sources/autoNum/assignvariables.h +++ b/sources/autoNum/assignvariables.h @@ -63,6 +63,7 @@ namespace autonum public: static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt = nullptr); static QString replaceVariable (const QString &formula, const DiagramContext &dc); + static QString genericXref (const Element *element); private: AssignVariables(const QString& formula, const sequentialNumbers& seqStruct , Diagram *diagram, const Element *elmt = nullptr); diff --git a/sources/properties/elementdata.cpp b/sources/properties/elementdata.cpp index f8ed284f6..1f1f0c859 100644 --- a/sources/properties/elementdata.cpp +++ b/sources/properties/elementdata.cpp @@ -339,6 +339,22 @@ ElementData::TerminalType ElementData::terminalTypeFromString(const QString &str return ElementData::TTGeneric; } +QString ElementData::translatedTerminalType(ElementData::TerminalType type) +{ + switch (type) { + case ElementData::TTGeneric : + return QObject::tr("generique", "generic terminal element type"); + case ElementData::TTFuse : + return QObject::tr("fusible", "fuse terminal element type"); + case ElementData::TTSectional: + return QObject::tr("sectionable", "sectional terminal element type"); + case ElementData::TTDiode: + return QObject::tr("diode", "diode terminal element type"); + case ElementData::TTGround: + return QObject::tr("terre", "ground terminal element type"); + } +} + QString ElementData::terminalFunctionToString(ElementData::TerminalFunction function) { switch (function) { diff --git a/sources/properties/elementdata.h b/sources/properties/elementdata.h index d2f034990..e0f9696ec 100644 --- a/sources/properties/elementdata.h +++ b/sources/properties/elementdata.h @@ -108,6 +108,7 @@ class ElementData : public PropertiesInterface static QString terminalTypeToString(ElementData::TerminalType type); static ElementData::TerminalType terminalTypeFromString(const QString &string); + static QString translatedTerminalType(ElementData::TerminalType type); static QString terminalFunctionToString(ElementData::TerminalFunction function); static ElementData::TerminalFunction terminalFunctionFromString(const QString &string);