From 4615e6d06005ca7c6d12da28ad0c32fb5e3475af Mon Sep 17 00:00:00 2001 From: joshua Date: Mon, 7 Jun 2021 19:45:45 +0200 Subject: [PATCH] Revert "Add terminalStripModel class" This reverts commit a1e18d2bbab70502df3d8ec87ad2d0a895878611. --- sources/TerminalStrip/terminalstrip.cpp | 54 ---------- sources/TerminalStrip/terminalstrip.h | 25 ----- .../TerminalStrip/ui/terminalstripeditor.cpp | 62 ++++------- .../TerminalStrip/ui/terminalstripeditor.h | 4 +- .../TerminalStrip/ui/terminalstripeditor.ui | 10 +- .../TerminalStrip/ui/terminalstripmodel.cpp | 101 ------------------ sources/TerminalStrip/ui/terminalstripmodel.h | 47 -------- sources/autoNum/assignvariables.cpp | 27 ----- sources/autoNum/assignvariables.h | 1 - sources/properties/elementdata.cpp | 16 --- sources/properties/elementdata.h | 1 - 11 files changed, 23 insertions(+), 325 deletions(-) delete mode 100644 sources/TerminalStrip/ui/terminalstripmodel.cpp delete mode 100644 sources/TerminalStrip/ui/terminalstripmodel.h diff --git a/sources/TerminalStrip/terminalstrip.cpp b/sources/TerminalStrip/terminalstrip.cpp index 17f218ab9..04aadd0d6 100644 --- a/sources/TerminalStrip/terminalstrip.cpp +++ b/sources/TerminalStrip/terminalstrip.cpp @@ -21,7 +21,6 @@ #include "../qetgraphicsitem/terminalelement.h" #include "../elementprovider.h" #include "../qetxml.h" -#include "../autoNum/assignvariables.h" using shared_real_terminal = QSharedPointer; using shared_physical_terminal = QSharedPointer; @@ -83,14 +82,6 @@ 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 @@ -243,16 +234,6 @@ 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 @@ -452,16 +433,6 @@ 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_; @@ -566,31 +537,6 @@ 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 61ae60fa4..c147fb14b 100644 --- a/sources/TerminalStrip/terminalstrip.h +++ b/sources/TerminalStrip/terminalstrip.h @@ -21,7 +21,6 @@ #include #include #include "terminalstripdata.h" -#include "../properties/elementdata.h" class Element; class RealTerminal; @@ -30,26 +29,6 @@ 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 @@ -59,8 +38,6 @@ struct RealTerminalData */ class TerminalStrip : public QObject { - friend class TerminalStripModel; - Q_OBJECT public: TerminalStrip(QETProject *project); @@ -90,9 +67,7 @@ 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 b83e8c8a4..d7c21fbc7 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.cpp +++ b/sources/TerminalStrip/ui/terminalstripeditor.cpp @@ -27,7 +27,6 @@ #include "../UndoCommand/changeterminalstripdata.h" #include "terminalstriptreewidget.h" #include "../../qeticons.h" -#include "terminalstripmodel.h" #include @@ -236,46 +235,16 @@ void TerminalStripEditor::addFreeTerminal() } /** - * @brief TerminalStripEditor::setCurrentStrip - * Set the current terminal strip edited to \p strip_ - * @param strip_ + * @brief TerminalStripEditor::clearDataTab */ -void TerminalStripEditor::setCurrentStrip(TerminalStrip *strip_) +void TerminalStripEditor::clearDataTab() { - 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); - } + 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; } /** @@ -341,7 +310,7 @@ void TerminalStripEditor::on_m_reload_pb_clicked() m_uuid_terminal_H.clear(); m_uuid_strip_H.clear(); - qDeleteAll(m_item_strip_H.keyBegin(), m_item_strip_H.keyEnd()); + qDeleteAll(m_item_strip_H.keys()); buildTree(); ui->m_terminal_strip_tw->expandRecursively(ui->m_terminal_strip_tw->rootIndex()); @@ -363,7 +332,7 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI Q_UNUSED(previous) if (!current) { - setCurrentStrip(nullptr); + clearDataTab(); ui->m_remove_terminal_strip_pb->setDisabled(true); return; } @@ -382,7 +351,16 @@ void TerminalStripEditor::on_m_terminal_strip_tw_currentItemChanged(QTreeWidgetI ui->m_remove_terminal_strip_pb->setDisabled(true); } - setCurrentStrip(strip_); + 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(); + } } 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 6de89291b..efdf91d7a 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.h +++ b/sources/TerminalStrip/ui/terminalstripeditor.h @@ -29,7 +29,6 @@ class TerminalStrip; class QTreeWidgetItem; class TerminalElement; class QAbstractButton; -class TerminalStripModel; /** * @brief The TerminalStripEditor class @@ -49,7 +48,7 @@ class TerminalStripEditor : public QDialog void buildTree(); QTreeWidgetItem* addTerminalStrip(TerminalStrip *terminal_strip); void addFreeTerminal(); - void setCurrentStrip(TerminalStrip *strip_); + void clearDataTab(); private slots: void on_m_add_terminal_strip_pb_clicked(); @@ -66,7 +65,6 @@ 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 34a789b84..7db32253b 100644 --- a/sources/TerminalStrip/ui/terminalstripeditor.ui +++ b/sources/TerminalStrip/ui/terminalstripeditor.ui @@ -130,19 +130,13 @@ - + 0 0 - - true - - - false - @@ -268,7 +262,7 @@ m_name_le m_comment_le m_description_te - m_table_widget + tableView diff --git a/sources/TerminalStrip/ui/terminalstripmodel.cpp b/sources/TerminalStrip/ui/terminalstripmodel.cpp deleted file mode 100644 index b81ef3d8d..000000000 --- a/sources/TerminalStrip/ui/terminalstripmodel.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - 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 deleted file mode 100644 index 576cfa457..000000000 --- a/sources/TerminalStrip/ui/terminalstripmodel.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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 40f45adb9..810805270 100644 --- a/sources/autoNum/assignvariables.cpp +++ b/sources/autoNum/assignvariables.cpp @@ -232,33 +232,6 @@ 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 8ac961930..b293bb07d 100644 --- a/sources/autoNum/assignvariables.h +++ b/sources/autoNum/assignvariables.h @@ -63,7 +63,6 @@ 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 1f1f0c859..f8ed284f6 100644 --- a/sources/properties/elementdata.cpp +++ b/sources/properties/elementdata.cpp @@ -339,22 +339,6 @@ 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 e0f9696ec..d2f034990 100644 --- a/sources/properties/elementdata.h +++ b/sources/properties/elementdata.h @@ -108,7 +108,6 @@ 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);