mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 20:44:16 +02:00
ce0798bb18
Selecting several elements left the Selection properties panel blank and Edit (Ctrl+E) disabled, so giving many elements the same supplier or manufacturer meant editing them one by one. The panel now shows the Information fields for two or more elements, or for elements selected with other items (left unchanged, and counted in the panel's header). Ctrl+E opens the same editor as a dialog when only elements are selected. - A field shows the value every element shares, or "Multiple values". Left alone, each element keeps its own value; typed text goes to every element; the erase box clears the field on every element. - A restore button per field, and Reset, bring back the values the elements had. - One apply is one undo step. The keystrokes typed in the panel merge into one step but never into an earlier change of the same elements (a paste of element information, another edit). - Numbering scheme, label freezing and the number picker are left out: they are about one element. Custom properties are kept as they are. Also: - An element's own texts, selected with it by Select all, count as part of the element, not as other items. - ElementInfoWidget::reset(): Reset in the element dialog now brings back the Information tab's values; it did nothing. - The panel opens an element's editor on the tab picked last, instead of the first tab, after the selection went to something else and back. Test: tst_multielementinfo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
508 lines
15 KiB
C++
508 lines
15 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "elementpropertieswidget.h"
|
|
|
|
#include "../diagram.h"
|
|
#include "../diagramposition.h"
|
|
#include "../qetapp.h"
|
|
#include "../qetgraphicsitem/dynamicelementtextitem.h"
|
|
#include "../qetgraphicsitem/element.h"
|
|
#include "../qetgraphicsitem/elementtextitemgroup.h"
|
|
#include "../qetgraphicsitem/masterelement.h"
|
|
#include "../qeticons.h"
|
|
#include "dynamicelementtextitemeditor.h"
|
|
#include "elementinfowidget.h"
|
|
#include "linksingleelementwidget.h"
|
|
#include "masterpropertieswidget.h"
|
|
#include "plclinkwidget.h"
|
|
|
|
#include <QCheckBox>
|
|
#include <QLabel>
|
|
#include <QUndoStack>
|
|
#include <QVBoxLayout>
|
|
|
|
namespace {
|
|
//The tab last picked in the selection properties panel
|
|
QString s_live_tab;
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::ElementPropertiesWidget
|
|
Default constructor
|
|
@param elmt
|
|
@param parent
|
|
*/
|
|
ElementPropertiesWidget::ElementPropertiesWidget(Element *elmt,
|
|
QWidget *parent) :
|
|
AbstractElementPropertiesEditorWidget (parent),
|
|
m_diagram (elmt->diagram()),
|
|
m_tab (nullptr),
|
|
m_general_widget(nullptr)
|
|
{
|
|
buildGui();
|
|
setElement(elmt);
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::ElementPropertiesWidget
|
|
Same as default constructor, the edited element,
|
|
is the parent element of text.
|
|
The only difference with default constructor,
|
|
is that the current tab is the tab for dynamic texts,
|
|
and the item in the tree that represent text is expanded and selected.
|
|
@param text
|
|
@param parent
|
|
*/
|
|
ElementPropertiesWidget::ElementPropertiesWidget(DynamicElementTextItem *text,
|
|
QWidget *parent) :
|
|
AbstractElementPropertiesEditorWidget (parent),
|
|
m_tab (nullptr),
|
|
m_general_widget(nullptr)
|
|
{
|
|
if(text->parentElement())
|
|
{
|
|
m_diagram = text->parentElement()->diagram();
|
|
buildGui();
|
|
setDynamicText(text);
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::ElementPropertiesWidget
|
|
Same as default constructor, the edited element,
|
|
is the parent element of group.
|
|
The only difference with default constructor,
|
|
is that the current tab is the tab for dynamic texts,
|
|
and the item in the tree that represent group is expanded and selected.
|
|
@param group
|
|
@param parent
|
|
*/
|
|
ElementPropertiesWidget::ElementPropertiesWidget(ElementTextItemGroup *group,
|
|
QWidget *parent) :
|
|
AbstractElementPropertiesEditorWidget (parent),
|
|
m_tab (nullptr),
|
|
m_general_widget(nullptr)
|
|
{
|
|
if(group->parentItem() && group->parentItem()->type() == Element::Type)
|
|
{
|
|
Element *elmt = static_cast<Element *>(group->parentItem());
|
|
m_diagram = elmt->diagram();
|
|
buildGui();
|
|
setTextsGroup(group);
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::setElement
|
|
Set element to be the edited element
|
|
@param element
|
|
*/
|
|
void ElementPropertiesWidget::setElement(Element *element)
|
|
{
|
|
if (m_element == element) return;
|
|
Element *previous_element = m_element;
|
|
m_element = element;
|
|
|
|
if (previous_element)
|
|
{
|
|
//If previous element is same type as new element we just call setElement for each editor
|
|
if(previous_element->linkType() == m_element->linkType())
|
|
{
|
|
foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
|
|
{
|
|
aepew->setElement(m_element);
|
|
addGeneralWidget();
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
updateUi();
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::setDynamicText
|
|
convenience function:
|
|
same as call : ElementPropertiesWidget::setElement,
|
|
with parameter the parent element of text.
|
|
Set the dynamics text tab as current tab,
|
|
expand and select the item that represent text
|
|
@param text
|
|
*/
|
|
void ElementPropertiesWidget::setDynamicText(DynamicElementTextItem *text)
|
|
{
|
|
if(text->parentElement())
|
|
{
|
|
setElement(text->parentElement());
|
|
for(AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
|
|
{
|
|
if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
|
|
{
|
|
DynamicElementTextItemEditor *detie = static_cast<DynamicElementTextItemEditor *>(aepew);
|
|
m_tab->setCurrentWidget(detie);
|
|
m_text_tab_wanted = true;
|
|
detie->setCurrentText(text);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::setTextsGroup
|
|
Convenience function :
|
|
same as call : ElementPropertiesWidget::setElement,
|
|
with parameter the parent element of group.
|
|
Set the dynamics text tab as current tab,
|
|
expand and select the item that represent group
|
|
@param group
|
|
*/
|
|
void ElementPropertiesWidget::setTextsGroup(ElementTextItemGroup *group)
|
|
{
|
|
if(group->parentItem() && group->parentItem()->type() == Element::Type)
|
|
{
|
|
setElement(static_cast<Element *>(group->parentItem()));
|
|
for(AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
|
|
{
|
|
if (QString(aepew->metaObject()->className()) == "DynamicElementTextItemEditor")
|
|
{
|
|
DynamicElementTextItemEditor *detie = static_cast<DynamicElementTextItemEditor *>(aepew);
|
|
m_tab->setCurrentWidget(detie);
|
|
m_text_tab_wanted = true;
|
|
detie->setCurrentGroup(group);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::apply
|
|
Apply the new properties by pushing an undo command
|
|
to the parent project's undo stack of element
|
|
*/
|
|
void ElementPropertiesWidget::apply()
|
|
{
|
|
QList <QUndoCommand *> undo_list;
|
|
|
|
foreach (PropertiesEditorWidget *pew, m_list_editor)
|
|
if (QUndoCommand *undo = pew->associatedUndo())
|
|
undo_list << undo;
|
|
|
|
if (undo_list.isEmpty()) return;
|
|
|
|
QString str;
|
|
foreach(QUndoCommand *uc, undo_list) str += uc->text() += " ";
|
|
|
|
QUndoStack &stack = m_element -> diagram() -> undoStack();
|
|
stack.beginMacro(str);
|
|
foreach(QUndoCommand *uc, undo_list) stack.push(uc);
|
|
stack.endMacro();
|
|
|
|
foreach(PropertiesEditorWidget *pew, m_list_editor)
|
|
pew->updateUi();
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::reset
|
|
Reset the edited properties
|
|
*/
|
|
void ElementPropertiesWidget::reset()
|
|
{
|
|
foreach (PropertiesEditorWidget *pew, m_list_editor) pew->reset();
|
|
}
|
|
|
|
bool ElementPropertiesWidget::setLiveEdit(bool live_edit)
|
|
{
|
|
if (m_live_edit == live_edit) return true;
|
|
m_live_edit = live_edit;
|
|
|
|
foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
|
|
aepew->setLiveEdit(m_live_edit);
|
|
|
|
if (m_live_edit && !m_text_tab_wanted && !s_live_tab.isEmpty())
|
|
{
|
|
for (int i = 0 ; i < m_tab->count() ; ++i)
|
|
{
|
|
if (m_tab->tabText(i) == s_live_tab)
|
|
{
|
|
m_tab->setCurrentIndex(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::findInPanel
|
|
If m_element is a custom element, emit findElementRequired
|
|
*/
|
|
void ElementPropertiesWidget::findInPanel()
|
|
{
|
|
if (m_element && m_diagram)
|
|
{
|
|
m_diagram->findElementRequired(m_element.data()->location());
|
|
emit findEditClicked();
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::editElement
|
|
If m_element is a custom element, emit findElementRequired and editElementRequired
|
|
*/
|
|
void ElementPropertiesWidget::editElement()
|
|
{
|
|
if (m_element && m_diagram)
|
|
{
|
|
m_diagram->findElementRequired(m_element.data()->location());
|
|
QETApp::instance()->openElementLocations(QList<ElementsLocation>() << m_element.data()->location());
|
|
emit findEditClicked();
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::build
|
|
Build the content of this widget
|
|
*/
|
|
void ElementPropertiesWidget::buildGui()
|
|
{
|
|
m_tab = new QTabWidget(this);
|
|
//The selection properties panel builds a new editor each time
|
|
//the selection goes from one element to something else and back:
|
|
//it opens on the tab last picked there (#1439)
|
|
connect(m_tab, &QTabWidget::tabBarClicked, this, [this](int index) {
|
|
if (m_live_edit && index >= 0) {
|
|
s_live_tab = m_tab->tabText(index);
|
|
}
|
|
});
|
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
|
main_layout -> addWidget(m_tab);
|
|
setLayout(main_layout);
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::updateUi
|
|
Update the content of this widget
|
|
*/
|
|
void ElementPropertiesWidget::updateUi()
|
|
{
|
|
//We keep the current title of the tab, to return to the same tab
|
|
//if possible, at the end of this method
|
|
QString tab_text;
|
|
tab_text = m_tab->tabText(m_tab->currentIndex());
|
|
|
|
//Purge the tab widget and delete all widget
|
|
m_tab->clear();
|
|
qDeleteAll(m_list_editor);
|
|
m_list_editor.clear();
|
|
if(m_general_widget) {
|
|
delete m_general_widget;
|
|
m_general_widget = nullptr;
|
|
}
|
|
|
|
//Create editor according to the type of element
|
|
switch (m_element -> linkType()) {
|
|
case Element::Simple:
|
|
m_list_editor << new ElementInfoWidget(m_element, this);
|
|
break;
|
|
case Element::Thumbnail:
|
|
m_list_editor << new ElementInfoWidget(m_element, this);
|
|
break;
|
|
case Element::NextReport:
|
|
m_list_editor << new LinkSingleElementWidget(m_element, this);
|
|
break;
|
|
case Element::PreviousReport:
|
|
m_list_editor << new LinkSingleElementWidget(m_element, this);
|
|
break;
|
|
case Element::Master:
|
|
m_list_editor << new MasterPropertiesWidget(m_element, this);
|
|
m_list_editor << new ElementInfoWidget(m_element, this);
|
|
break;
|
|
case Element::Slave:
|
|
if (m_element->elementData().m_slave_type == ElementData::PLCSlave)
|
|
m_list_editor << new PlcLinkWidget(m_element, this);
|
|
else
|
|
m_list_editor << new LinkSingleElementWidget(m_element, this);
|
|
break;
|
|
case Element::Terminale:
|
|
m_list_editor << new ElementInfoWidget(m_element, this);
|
|
break;
|
|
case Element::ConductorDefinition:
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
m_list_editor << new DynamicElementTextItemEditor(m_element, this);
|
|
|
|
//Add each editors in tab widget
|
|
for (AbstractElementPropertiesEditorWidget *aepew : m_list_editor)
|
|
{
|
|
aepew->setLiveEdit(m_live_edit);
|
|
m_tab->addTab(aepew, aepew->title());
|
|
}
|
|
addGeneralWidget();
|
|
|
|
//Go to the tab, edited at the beginning of this method
|
|
if (!tab_text.isEmpty())
|
|
{
|
|
for(int i=0 ; i<m_tab->count() ; ++i)
|
|
{
|
|
if (tab_text == m_tab->tabBar()->tabText(i))
|
|
{
|
|
m_tab->setCurrentIndex(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::addGeneralWidget
|
|
Add or update the general widget on this tab widget
|
|
*/
|
|
void ElementPropertiesWidget::addGeneralWidget()
|
|
{
|
|
int index = m_tab->currentIndex();
|
|
if (m_general_widget)
|
|
{
|
|
m_tab->removeTab(m_tab->indexOf(m_general_widget));
|
|
delete m_general_widget;
|
|
}
|
|
m_general_widget = generalWidget();
|
|
m_tab -> addTab(m_general_widget, tr("General"));
|
|
m_tab->setCurrentIndex(index);
|
|
}
|
|
|
|
/**
|
|
@brief ElementPropertiesWidget::generalWidget
|
|
@return build and return the "general" widget
|
|
*/
|
|
QWidget *ElementPropertiesWidget::generalWidget()
|
|
{
|
|
QString description_string(tr("Element\n"));
|
|
|
|
// some element characteristic
|
|
description_string += QString(tr("Name : %1\n")).arg(m_element -> name());
|
|
int folio_index = m_diagram -> folioIndex();
|
|
if (folio_index != -1) {
|
|
description_string += QString(tr("Sheet : %1\n")).arg(folio_index + 1);
|
|
}
|
|
description_string += QString(tr("Type: %1\n")).arg(m_element->elementData().typeToString());
|
|
description_string += QString(tr("Sub-type : %1\n")).arg(m_element ->kindInformations()["type"].toString());
|
|
description_string += QString(tr("Position : %1\n")).arg(m_diagram -> convertPosition(m_element -> scenePos()).toString());
|
|
description_string += QString(tr("Rotation : %1°\n")).arg(m_element.data()->rotation());
|
|
description_string += QString(tr("Dimensions : %1*%2\n")).arg(m_element -> size().width()).arg(m_element -> size().height());
|
|
description_string += QString(tr("Terminals : %1\n")).arg(m_element -> terminals().count());
|
|
if (m_element->linkType() == Element::Master)
|
|
{
|
|
//The declared limit is optional: -1 means the element sets no
|
|
//limit at all, which is worth saying rather than printing "-1".
|
|
const int max_slaves = m_element->elementData().m_max_slaves;
|
|
description_string += max_slaves == -1
|
|
? QString(tr("Maximum number of slave contacts defined: not defined\n"))
|
|
: QString(tr("Maximum number of slave contacts defined: %1\n")).arg(max_slaves);
|
|
|
|
//Left as a count of linked elements: the line above is a number
|
|
//of slots, and a slave fills one slot however many contacts it
|
|
//carries, so the two stay in the same unit.
|
|
description_string += QString(tr("Number of slave contacts used : %1\n")).arg(m_element->linkedElements().count());
|
|
|
|
//The breakdown below is in contacts, not slots: it answers how
|
|
//many contacts an auxiliary block must provide.
|
|
const MasterElement *master =
|
|
static_cast<const MasterElement *>(m_element.data());
|
|
const ContactUsage usage = master->contactUsage();
|
|
const ContactUsage capacity = master->contactCapacity();
|
|
|
|
if (capacity.total() > 0)
|
|
{
|
|
//The element declares contact groups, so it can say not
|
|
//only what has been used but what it has to offer. A type
|
|
//used beyond what is declared shows as e.g. "1/0", which
|
|
//is the point: it says this contact does not fit the part.
|
|
description_string += QString(tr(" Contacts : NO : %1/%2, NC : %3/%4, changeover : %5/%6, other : %7/%8\n"))
|
|
.arg(usage.no).arg(capacity.no)
|
|
.arg(usage.nc).arg(capacity.nc)
|
|
.arg(usage.sw).arg(capacity.sw)
|
|
.arg(usage.other).arg(capacity.other);
|
|
}
|
|
else if (usage.total() > 0)
|
|
{
|
|
//No declared groups, so a plain count of what is in use.
|
|
description_string += QString(tr(" Contacts : NO : %1, NC : %2, changeover : %3, other : %4\n"))
|
|
.arg(usage.no)
|
|
.arg(usage.nc)
|
|
.arg(usage.sw)
|
|
.arg(usage.other);
|
|
}
|
|
}
|
|
description_string += QString(tr("Location : %1\n")).arg(m_element.data()->location().toString());
|
|
|
|
// widget himself
|
|
QWidget *general_widget = new QWidget (m_tab);
|
|
QVBoxLayout *vlayout_ = new QVBoxLayout (general_widget);
|
|
general_widget -> setLayout(vlayout_);
|
|
|
|
//widget for the text
|
|
QLabel *label = new QLabel (description_string, general_widget);
|
|
label->setWordWrap(true);
|
|
label->setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
vlayout_->addWidget(label);
|
|
|
|
//checkbox to lock the element position on the diagram
|
|
//(same mechanism already used by images and drawn shapes)
|
|
QCheckBox *lock_pos_cb = new QCheckBox(tr("Lock Position"), general_widget);
|
|
lock_pos_cb->setChecked(!m_element->isMovable());
|
|
QPointer<Element> element = m_element;
|
|
connect(lock_pos_cb, &QCheckBox::clicked, this, [element](bool checked) {
|
|
if (element) {
|
|
element->setMovable(!checked);
|
|
}
|
|
});
|
|
vlayout_->addWidget(lock_pos_cb);
|
|
|
|
//widget for the pixmap
|
|
QLabel *pix = new QLabel(general_widget);
|
|
vlayout_->addWidget(pix, 0, Qt::AlignHCenter);
|
|
vlayout_ -> addStretch();
|
|
|
|
//button widget
|
|
QPushButton *find_in_panel = new QPushButton(QET::Icons::ZoomDraw, tr("Find in the panel"), general_widget);
|
|
connect(find_in_panel, &QPushButton::clicked, this, &ElementPropertiesWidget::findInPanel);
|
|
QPushButton *edit_element = new QPushButton(QET::Icons::ElementEdit, tr("Edit element"), general_widget);
|
|
connect(edit_element, &QPushButton::clicked, this, &ElementPropertiesWidget::editElement);
|
|
QHBoxLayout *hlayout_ = new QHBoxLayout;
|
|
hlayout_->addWidget(find_in_panel);
|
|
hlayout_->addWidget(edit_element);
|
|
vlayout_->addLayout(hlayout_);
|
|
|
|
//Set the maximum size of the pixmap to the minimum size of the layout
|
|
QPixmap pixmap = m_element->pixmap();
|
|
int margin = vlayout_->contentsMargins().left() + vlayout_->contentsMargins().right();
|
|
int width_ = vlayout_->minimumSize().width()-margin;
|
|
|
|
if (pixmap.size().width() > width_ || pixmap.size().height() > width_) {
|
|
pix->setPixmap(m_element->pixmap().scaled (width_, width_, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
}
|
|
else {
|
|
pix->setPixmap(pixmap);
|
|
}
|
|
|
|
return general_widget;
|
|
}
|