mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-27 18:59:58 +01:00
Revert "Feature: Implement max_slaves limit for Master elements"
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2026 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@@ -96,18 +96,8 @@ void ElementPropertiesEditorWidget::upDateInterface()
|
||||
}
|
||||
else if (m_data.m_type == ElementData::Master) {
|
||||
ui->m_master_type_cb->setCurrentIndex(
|
||||
ui->m_master_type_cb->findData (
|
||||
m_data.m_master_type));
|
||||
|
||||
// NEU: Checkbox und Zahlenbox für max_slaves einstellen
|
||||
if (m_data.m_max_slaves == -1) {
|
||||
ui->max_slaves_checkbox->setChecked(false);
|
||||
ui->max_slaves_spinbox->setEnabled(false);
|
||||
} else {
|
||||
ui->max_slaves_checkbox->setChecked(true);
|
||||
ui->max_slaves_spinbox->setEnabled(true);
|
||||
ui->max_slaves_spinbox->setValue(m_data.m_max_slaves);
|
||||
}
|
||||
ui->m_master_type_cb->findData (
|
||||
m_data.m_master_type));
|
||||
} else if (m_data.m_type == ElementData::Terminal) {
|
||||
ui->m_terminal_type_cb->setCurrentIndex(
|
||||
ui->m_terminal_type_cb->findData(
|
||||
@@ -161,14 +151,10 @@ void ElementPropertiesEditorWidget::setUpInterface()
|
||||
ui->m_terminal_func_cb->addItem(tr("Phase"), ElementData::TFPhase);
|
||||
ui->m_terminal_func_cb->addItem(tr("Neutre"), ElementData::TFNeutral);
|
||||
|
||||
//Disable the edition of the first column of the information tree
|
||||
//by this little workaround
|
||||
//Disable the edition of the first column of the information tree
|
||||
//by this little workaround
|
||||
ui->m_tree->setItemDelegate(new EditorDelegate(this));
|
||||
ui->m_tree->header()->resizeSection(0, 150);
|
||||
|
||||
// NEU: Checkbox mit der Zahlenbox verbinden (Aktivieren/Deaktivieren)
|
||||
connect(ui->max_slaves_checkbox, SIGNAL(toggled(bool)), ui->max_slaves_spinbox, SLOT(setEnabled(bool)));
|
||||
|
||||
populateTree();
|
||||
}
|
||||
|
||||
@@ -240,13 +226,6 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
|
||||
}
|
||||
else if (m_data.m_type == ElementData::Master) {
|
||||
m_data.m_master_type = ui->m_master_type_cb->currentData().value<ElementData::MasterType>();
|
||||
|
||||
// NEU: Wenn Häkchen gesetzt, speichere die Zahl, ansonsten -1 (unendlich)
|
||||
if (ui->max_slaves_checkbox->isChecked()) {
|
||||
m_data.m_max_slaves = ui->max_slaves_spinbox->value();
|
||||
} else {
|
||||
m_data.m_max_slaves = -1;
|
||||
}
|
||||
}
|
||||
else if (m_data.m_type == ElementData::Terminal)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>527</width>
|
||||
<height>492</height>
|
||||
<height>442</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -104,23 +104,6 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="m_master_type_cb"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="max_slaves_checkbox">
|
||||
<property name="text">
|
||||
<string>max. Slaves definieren</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="max_slaves_spinbox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -76,14 +76,6 @@ QDomElement ElementData::kindInfoToXml(QDomDocument &document)
|
||||
xml_type.appendChild(type_txt);
|
||||
|
||||
returned_elmt.appendChild(xml_type);
|
||||
|
||||
// NEU: max_slaves speichern
|
||||
auto xml_max_slaves = document.createElement(QStringLiteral("kindInformation"));
|
||||
xml_max_slaves.setAttribute(QStringLiteral("name"), QStringLiteral("max_slaves"));
|
||||
auto max_slaves_txt = document.createTextNode(QString::number(m_max_slaves));
|
||||
xml_max_slaves.appendChild(max_slaves_txt);
|
||||
|
||||
returned_elmt.appendChild(xml_max_slaves);
|
||||
}
|
||||
else if (m_type == ElementData::Slave)
|
||||
{
|
||||
@@ -566,12 +558,9 @@ void ElementData::kindInfoFromXml(const QDomElement &xml_element)
|
||||
}
|
||||
auto name = dom_elmt.attribute(QStringLiteral("name"));
|
||||
|
||||
if (m_type == ElementData::Master) {
|
||||
if (name == QLatin1String("type")) {
|
||||
m_master_type = masterTypeFromString(dom_elmt.text());
|
||||
} else if (name == QLatin1String("max_slaves")) {
|
||||
m_max_slaves = dom_elmt.text().toInt();
|
||||
}
|
||||
if (m_type == ElementData::Master &&
|
||||
name == QLatin1String("type")) {
|
||||
m_master_type = masterTypeFromString(dom_elmt.text());
|
||||
}
|
||||
else if (m_type == ElementData::Slave ) {
|
||||
if (name == QLatin1String("type")) {
|
||||
|
||||
@@ -134,7 +134,6 @@ class ElementData : public PropertiesInterface
|
||||
ElementData::Type m_type = ElementData::Simple;
|
||||
|
||||
ElementData::MasterType m_master_type = ElementData::Coil;
|
||||
int m_max_slaves = -1;
|
||||
|
||||
ElementData::SlaveType m_slave_type = ElementData::SSimple;
|
||||
ElementData::SlaveState m_slave_state = ElementData::NO;
|
||||
|
||||
@@ -183,34 +183,3 @@ void MasterElement::aboutDeleteXref()
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MasterElement::isFull
|
||||
* @return true if the master has reached its maximum number of slaves
|
||||
*/
|
||||
bool MasterElement::isFull() const
|
||||
{
|
||||
// Lese das Limit aus den XML-Daten (kindInformations)
|
||||
// Die value() Funktion im DiagramContext nimmt nur einen Parameter!
|
||||
QVariant max_slaves_variant = kindInformations().value("max_slaves");
|
||||
|
||||
// Wenn der Wert nicht existiert oder leer ist, ist das Bauteil nie voll
|
||||
if (!max_slaves_variant.isValid() || max_slaves_variant.toString().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// In Integer umwandeln
|
||||
int max_slaves = max_slaves_variant.toInt();
|
||||
|
||||
// Wenn Limit -1 ist, ist der Master nie voll
|
||||
if (max_slaves == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wenn die Anzahl der verbundenen Elemente größer oder gleich dem Limit ist, ist er voll
|
||||
if (connected_elements.size() >= max_slaves) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,6 @@ class MasterElement : public Element
|
||||
void unlinkElement (Element *elmt) override;
|
||||
void initLink (QETProject *project) override;
|
||||
QRectF XrefBoundingRect() const;
|
||||
|
||||
bool isFull() const; // NEU: Prüft, ob das Slave-Limit erreicht ist
|
||||
|
||||
protected:
|
||||
QVariant itemChange(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "linksingleelementwidget.h"
|
||||
#include "../qetgraphicsitem/masterelement.h"
|
||||
|
||||
#include "../qetgraphicsitem/conductor.h"
|
||||
#include "../diagram.h"
|
||||
#include "../diagramposition.h"
|
||||
@@ -386,22 +386,7 @@ QVector <QPointer<Element>> LinkSingleElementWidget::availableElements()
|
||||
|
||||
//If element is linked, remove is parent from the list
|
||||
if(!m_element->isFree()) elmt_vector.removeAll(m_element->linkedElements().first());
|
||||
// NEU: Filtere volle Master-Elemente aus der Liste heraus
|
||||
for (int i = elmt_vector.size() - 1; i >= 0; --i) {
|
||||
Element *elmt = elmt_vector.at(i);
|
||||
|
||||
// Wenn das Element in der Liste ein Master ist
|
||||
if (elmt->linkType() == Element::Master) {
|
||||
|
||||
// Wir wandeln den generischen Element-Pointer in einen MasterElement-Pointer um
|
||||
MasterElement *master = static_cast<MasterElement*>(elmt);
|
||||
|
||||
// Wenn der Master voll ist, werfen wir ihn aus der Liste!
|
||||
if (master->isFull()) {
|
||||
elmt_vector.removeAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elmt_vector;
|
||||
}
|
||||
|
||||
|
||||
@@ -348,34 +348,16 @@ void MasterPropertiesWidget::headerCustomContextMenuRequested(const QPoint &pos)
|
||||
@brief MasterPropertiesWidget::on_link_button_clicked
|
||||
move current item in the free_list to linked_list
|
||||
*/
|
||||
/**
|
||||
* @brief MasterPropertiesWidget::on_link_button_clicked
|
||||
* move current item in the free_list to linked_list
|
||||
*/
|
||||
void MasterPropertiesWidget::on_link_button_clicked()
|
||||
{
|
||||
// --- NEU: Prüfen, ob das Master-Limit im UI bereits erreicht ist ---
|
||||
QVariant max_slaves_variant = m_element->kindInformations().value("max_slaves");
|
||||
|
||||
if (max_slaves_variant.isValid() && !max_slaves_variant.toString().isEmpty()) {
|
||||
int max_slaves = max_slaves_variant.toInt();
|
||||
|
||||
// Wir zählen, wie viele Elemente schon in der "Verbunden"-Liste liegen
|
||||
if (max_slaves != -1 && ui->m_link_tree_widget->topLevelItemCount() >= max_slaves) {
|
||||
// Limit erreicht! Wir brechen die Aktion einfach ab.
|
||||
return;
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
//take the current item from free_list and push it to linked_list
|
||||
//take the current item from free_list and push it to linked_list
|
||||
QTreeWidgetItem *qtwi = ui->m_free_tree_widget->currentItem();
|
||||
if (qtwi)
|
||||
{
|
||||
ui->m_free_tree_widget->takeTopLevelItem(
|
||||
ui->m_free_tree_widget->indexOfTopLevelItem(qtwi));
|
||||
ui->m_free_tree_widget->indexOfTopLevelItem(qtwi));
|
||||
ui->m_link_tree_widget->insertTopLevelItem(0, qtwi);
|
||||
|
||||
|
||||
if(m_live_edit)
|
||||
apply();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user