mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-11 06:34:14 +02:00
955dfb3a73
Conflicts resolved in 24 files. Notable decisions: - ico/icon-themes.qrc: upstream's icon folder restructure kept; the 36 cable icon entries re-added under the new qet/qet-dark path scheme (XML valid, every referenced file exists). - Toolbar system: upstream's DiagramToolbarSettings now owns the toolbar filling. The cable tool is registered as diagrameditor.add_cable (generic group loop) and listed on the "diagram" toolbar right after the auto-break conductor action, separated by a divider, exactly like before the merge. - Paste: the cable lines of a copy are handed to PasteNumberingImport::push() as extra commands, so paste + cable lines + the numbering question stay ONE undo step on both paste paths (DiagramView::paste and DiagramEventAddPaste::commit). - PDF links: upstream's deterministic link sorting kept together with the cable cross-reference injector (injectLinkTo -> links list). - Element renumbering: upstream's ElementAutoNumSchemeCommand::renumber replaces the old formula-based body of QETProject::renumberElementsBySchemeTitle; the cable numbering rule API (cableAutoNum, axis priority, rule name) is kept in full. - Auto-numbering pages: upstream's scheme management kept, the Câbles tab added as index 4 (changeToCableTab), both entry points changeToCable() and changeToElement() kept side by side. - SelectAutonumW: dirty tracking and the contextEdited signal moved into upstream's insertPartRow() row API, so single-rule mode, the rule-removable button and "confirm without change leaves the project alone" keep working. - xrefpropertieswidget: upstream's offset clamping kept; the cable branch (Texte field, Police button, hidden display options) kept; the stack-overlapping checkbox is hidden for cables. Verified after the merge: build green (515/515, no errors), ctest 85/86 (only the pre-existing headless tst_menubarkeyboard failure), offscreen smoke exit 124.
292 lines
8.9 KiB
C++
292 lines
8.9 KiB
C++
/*
|
|
Copyright 2006-2026 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 "propertieseditorfactory.h"
|
|
|
|
#include "../PropertiesEditor/propertieseditorwidget.h"
|
|
#include "../cable/cablepart.h"
|
|
#include "../cable/cablepropertieseditorwidget.h"
|
|
#include "../cablelist/cablelistmodel.h"
|
|
#include "../cablelist/cablelistmodelpropertieswidget.h"
|
|
#include "../qetgraphicsitem/ViewItem/projectdbmodel.h"
|
|
#include "../qetgraphicsitem/ViewItem/qetgraphicstableitem.h"
|
|
#include "../qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h"
|
|
#include "../qetgraphicsitem/ViewItem/ui/projectdbmodelpropertieswidget.h"
|
|
#include "../qetgraphicsitem/conductor.h"
|
|
#include "../qetgraphicsitem/conductortextitem.h"
|
|
#include "../qetgraphicsitem/diagramimageitem.h"
|
|
#include "../qetgraphicsitem/dynamicelementtextitem.h"
|
|
#include "../qetgraphicsitem/element.h"
|
|
#include "../qetgraphicsitem/elementtextitemgroup.h"
|
|
#include "../qetgraphicsitem/independenttextitem.h"
|
|
#include "../qetgraphicsitem/qetshapeitem.h"
|
|
#include "../ui/dynamicelementtextitemeditor.h"
|
|
#include "../ui/elementpropertieswidget.h"
|
|
#include "../ui/conductorpropertieseditorwidget.h"
|
|
#include "../ui/imagepropertieswidget.h"
|
|
#include "../ui/inditextpropertieswidget.h"
|
|
#include "../ui/shapegraphicsitempropertieswidget.h"
|
|
|
|
#include <QGraphicsItem>
|
|
#include <QSet>
|
|
#include <QSettings>
|
|
|
|
/**
|
|
@brief PropertiesEditorFactory::propertiesEditor
|
|
@param model : the model to be edited
|
|
@param editor :
|
|
if the properties editor to be created is the same class as editor,
|
|
the this function set item as edited item of editor and return editor
|
|
@param parent : parent widget of the returned editor
|
|
@return an editor or nullptr
|
|
*/
|
|
PropertiesEditorWidget *PropertiesEditorFactory::propertiesEditor(
|
|
QAbstractItemModel *model,
|
|
PropertiesEditorWidget *editor,
|
|
QWidget *parent)
|
|
{
|
|
if (auto m = dynamic_cast<ProjectDBModel *>(model))
|
|
{
|
|
if (editor &&
|
|
editor->metaObject()->className()
|
|
== ProjectDBModelPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<ProjectDBModelPropertiesWidget *>(editor)->setModel(m);
|
|
return editor;
|
|
}
|
|
return new ProjectDBModelPropertiesWidget(m, parent);
|
|
}
|
|
if (auto m = dynamic_cast<CableListModel *>(model))
|
|
{
|
|
if (editor &&
|
|
editor->metaObject()->className()
|
|
== CableListModelPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<CableListModelPropertiesWidget *>(editor)->setModel(m);
|
|
return editor;
|
|
}
|
|
return new CableListModelPropertiesWidget(m, parent);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
/**
|
|
@brief propertiesEditor
|
|
@param items : The items to be edited
|
|
@param editor :
|
|
If the properties editor to be created is the same class as editor,
|
|
then this function set item as edited item of editor and return editor
|
|
@param parent : parent widget of the returned editor
|
|
@return : an editor or nullptr;
|
|
*/
|
|
PropertiesEditorWidget *PropertiesEditorFactory::propertiesEditor(
|
|
QList<QGraphicsItem *> items,
|
|
PropertiesEditorWidget *editor,
|
|
QWidget *parent)
|
|
{
|
|
//Selecting a conductor's text label edits its parent conductor (#500),
|
|
//mirroring how double-clicking the label opens the conductor dialog.
|
|
//A rubber band over wires selects their labels too: each label
|
|
//counts as its conductor, once.
|
|
QList<QGraphicsItem *> mapped;
|
|
QSet<QGraphicsItem *> seen;
|
|
for (QGraphicsItem *qgi : std::as_const(items)) {
|
|
if (auto *cti = qgraphicsitem_cast<ConductorTextItem *>(qgi)) {
|
|
if (Conductor *parent_cond = cti->parentConductor()) {
|
|
qgi = parent_cond;
|
|
}
|
|
}
|
|
if (!seen.contains(qgi)) {
|
|
seen.insert(qgi);
|
|
mapped << qgi;
|
|
}
|
|
}
|
|
items = mapped;
|
|
|
|
const int count_ = items.size();
|
|
if (count_ == 0) {
|
|
return nullptr;
|
|
}
|
|
QGraphicsItem *item = items.first();
|
|
const int type_ = item->type();
|
|
|
|
//The editor widget can only edit one item
|
|
//or several items of the same type
|
|
for (auto qgi : items) {
|
|
if (qgi->type() != type_) {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
QString class_name;
|
|
if (editor) {
|
|
class_name = editor->metaObject()->className();
|
|
}
|
|
|
|
switch (type_)
|
|
{
|
|
case Conductor::Type: //1001
|
|
{
|
|
//Off unless enabled in the preferences (General page): selecting
|
|
//a conductor then brings up nothing in the dock, as before.
|
|
if (!QSettings().value(
|
|
QStringLiteral("diagrameditor/conductor_properties_panel"),
|
|
false).toBool()) {
|
|
return nullptr;
|
|
}
|
|
QList<Conductor *> conductors;
|
|
for (QGraphicsItem *qgi : std::as_const(items)) {
|
|
conductors << static_cast<Conductor *>(qgi);
|
|
}
|
|
|
|
if (class_name == ConductorPropertiesEditorWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<ConductorPropertiesEditorWidget*>(editor)->setConductors(conductors);
|
|
return editor;
|
|
}
|
|
return new ConductorPropertiesEditorWidget(conductors, parent);
|
|
}
|
|
case Element::Type: //1000
|
|
{
|
|
if (count_ > 1) {
|
|
return nullptr;
|
|
}
|
|
auto elmt = static_cast<Element*>(item);
|
|
//auto created_editor = new ElementPropertiesWidget(elmt, parent);
|
|
|
|
//We already edit an element, just update the editor with a new element
|
|
if (class_name == ElementPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<ElementPropertiesWidget*>(editor)->setElement(elmt);
|
|
return editor;
|
|
}
|
|
return new ElementPropertiesWidget(elmt, parent);
|
|
}
|
|
case IndependentTextItem::Type: //1005
|
|
{
|
|
QList<IndependentTextItem *> text_list;
|
|
for (QGraphicsItem *qgi : items) {
|
|
text_list.append(static_cast<IndependentTextItem*>(qgi));
|
|
}
|
|
|
|
if (class_name == IndiTextPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<IndiTextPropertiesWidget*>(editor)->setText(text_list);
|
|
return editor;
|
|
}
|
|
|
|
return new IndiTextPropertiesWidget(text_list, parent);
|
|
}
|
|
case DiagramImageItem::Type: //1007
|
|
{
|
|
if (count_ > 1) {
|
|
return nullptr;
|
|
}
|
|
return new ImagePropertiesWidget(static_cast<DiagramImageItem*>(item), parent);
|
|
}
|
|
case QetShapeItem::Type: //1008
|
|
{
|
|
QList<QetShapeItem *> shapes_list;
|
|
for (QGraphicsItem *qgi : items) {
|
|
shapes_list.append(static_cast<QetShapeItem*>(qgi));
|
|
}
|
|
|
|
if (class_name == ShapeGraphicsItemPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<ShapeGraphicsItemPropertiesWidget*>(editor)->setItems(shapes_list);
|
|
return editor;
|
|
}
|
|
|
|
return new ShapeGraphicsItemPropertiesWidget(shapes_list, parent);
|
|
}
|
|
case DynamicElementTextItem::Type: //1010
|
|
{
|
|
if (count_ > 1) {
|
|
return nullptr;
|
|
}
|
|
|
|
DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(item);
|
|
//For dynamic element text, we open the element editor to edit it
|
|
//If we already edit an element, just update the editor with a new element
|
|
if (class_name == ElementPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<ElementPropertiesWidget*>(editor)->setDynamicText(deti);
|
|
return editor;
|
|
}
|
|
return new ElementPropertiesWidget(deti, parent);
|
|
}
|
|
case QGraphicsItemGroup::Type:
|
|
{
|
|
if (count_ > 1) {
|
|
return nullptr;
|
|
}
|
|
|
|
if(ElementTextItemGroup *group = dynamic_cast<ElementTextItemGroup *>(item))
|
|
{
|
|
//For element text item group, we open the element editor to edit it
|
|
//If we already edit an element, just update the editor with a new element
|
|
if(class_name == ElementPropertiesWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<ElementPropertiesWidget *>(editor)->setTextsGroup(group);
|
|
return editor;
|
|
}
|
|
return new ElementPropertiesWidget(group, parent);
|
|
}
|
|
break;
|
|
}
|
|
case QetGraphicsTableItem::Type:
|
|
{
|
|
if (count_ > 1) {
|
|
return nullptr;
|
|
}
|
|
|
|
auto table = static_cast<QetGraphicsTableItem*>(item);
|
|
if (class_name == GraphicsTablePropertiesEditor::staticMetaObject.className())
|
|
{
|
|
static_cast<GraphicsTablePropertiesEditor*>(editor)->setTable(table);
|
|
return editor;
|
|
}
|
|
return new GraphicsTablePropertiesEditor(table, parent);
|
|
}
|
|
case CablePart::Type: //1012
|
|
{
|
|
if (count_ > 1) {
|
|
return nullptr;
|
|
}
|
|
auto part = static_cast<CablePart *>(item);
|
|
//The fields belong to the cable, never to one of its
|
|
//lines: whichever line is picked, it is the cable which
|
|
//is edited.
|
|
Cable *cable = part->cable();
|
|
if (!cable) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (class_name == CablePropertiesEditorWidget::staticMetaObject.className())
|
|
{
|
|
static_cast<CablePropertiesEditorWidget *>(editor)->setCable(cable, part);
|
|
return editor;
|
|
}
|
|
return new CablePropertiesEditorWidget(cable, part, parent);
|
|
}
|
|
default:
|
|
return nullptr;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|