2014-03-12 09:32:56 +00:00
|
|
|
/*
|
2021-02-20 12:13:46 +01:00
|
|
|
Copyright 2006-2021 The QElectroTech Team
|
2014-03-12 09:32:56 +00:00
|
|
|
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 "linksingleelementwidget.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
2022-06-13 20:22:10 +02:00
|
|
|
#include "../qetgraphicsitem/conductor.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../diagram.h"
|
|
|
|
#include "../diagramposition.h"
|
2022-06-13 20:22:10 +02:00
|
|
|
#include "../qetgraphicsitem/element.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
#include "../elementprovider.h"
|
|
|
|
#include "../undocommand/linkelementcommand.h"
|
2017-01-26 10:09:07 +00:00
|
|
|
|
2022-06-13 20:22:10 +02:00
|
|
|
#include "../ui_linksingleelementwidget.h"
|
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
#include <QTreeWidgetItem>
|
2014-03-12 09:32:56 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::LinkSingleElementWidget
|
|
|
|
Default constructor
|
|
|
|
@param elmt
|
|
|
|
the edited element
|
|
|
|
@param parent
|
|
|
|
the parent widget
|
|
|
|
*/
|
2020-08-16 14:23:59 +02:00
|
|
|
LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt,
|
|
|
|
QWidget *parent) :
|
2015-05-25 10:22:00 +00:00
|
|
|
AbstractElementPropertiesEditorWidget(parent),
|
2017-01-26 10:09:07 +00:00
|
|
|
ui(new Ui::LinkSingleElementWidget)
|
2014-03-12 09:32:56 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
ui->m_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
m_context_menu = new QMenu(this);
|
|
|
|
m_link_action = new QAction(tr("Lier l'élément"), this);
|
|
|
|
m_show_qtwi = new QAction(tr("Montrer l'élément"), this);
|
|
|
|
m_show_element = new QAction(tr("Montrer l'élément esclave"), this);
|
2017-01-30 14:29:01 +00:00
|
|
|
m_save_header_state = new QAction(tr("Enregistrer la disposition"), this);
|
2017-01-26 10:09:07 +00:00
|
|
|
|
2020-08-16 14:23:59 +02:00
|
|
|
connect(m_show_qtwi,
|
|
|
|
&QAction::triggered,
|
|
|
|
[this]()
|
|
|
|
{this->on_m_tree_widget_itemDoubleClicked(this->m_qtwi_at_context_menu, 0);});
|
|
|
|
connect(m_link_action,
|
|
|
|
&QAction::triggered,
|
|
|
|
this,
|
|
|
|
&LinkSingleElementWidget::linkTriggered);
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
connect(m_show_element, &QAction::triggered, [this]()
|
|
|
|
{
|
|
|
|
this->m_element->diagram()->showMe();
|
|
|
|
this->m_element->setHighlighted(true);
|
|
|
|
if(this->m_showed_element)
|
|
|
|
m_showed_element->setHighlighted(false);
|
|
|
|
});
|
2017-01-29 18:43:42 +00:00
|
|
|
|
2017-01-30 14:29:01 +00:00
|
|
|
QHeaderView *qhv = ui->m_tree_widget->header();
|
|
|
|
qhv->setContextMenuPolicy(Qt::CustomContextMenu);
|
2020-08-16 14:23:59 +02:00
|
|
|
connect(qhv,
|
|
|
|
&QHeaderView::customContextMenuRequested,
|
|
|
|
this,
|
|
|
|
&LinkSingleElementWidget::headerCustomContextMenuRequested);
|
2017-01-30 14:29:01 +00:00
|
|
|
connect(m_save_header_state, &QAction::triggered, [this, qhv]()
|
|
|
|
{
|
|
|
|
QByteArray qba = qhv->saveState();
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
if (this->m_element->linkType() & Element::AllReport)
|
|
|
|
settings.setValue("link-element-widget/report-state", qba);
|
|
|
|
else if (this->m_element->linkType() == Element::Slave)
|
|
|
|
settings.setValue("link-element-widget/slave-state", qba);
|
|
|
|
});
|
2017-01-26 10:09:07 +00:00
|
|
|
|
2015-05-21 20:46:23 +00:00
|
|
|
setElement(elmt);
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::~LinkSingleElementWidget
|
|
|
|
Default destructor
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
LinkSingleElementWidget::~LinkSingleElementWidget()
|
|
|
|
{
|
|
|
|
if(m_showed_element)
|
|
|
|
m_showed_element->setHighlighted(false);
|
|
|
|
|
2017-08-27 11:27:41 +00:00
|
|
|
if(m_element)
|
|
|
|
{
|
|
|
|
m_element->setHighlighted(false);
|
|
|
|
if (!m_element->isFree())
|
|
|
|
m_element->linkedElements().first()->setHighlighted(false);
|
|
|
|
}
|
2014-03-12 09:32:56 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2015-05-21 20:46:23 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::setElement
|
|
|
|
Set element to be the edited element.
|
|
|
|
@param element
|
|
|
|
*/
|
2015-05-21 20:46:23 +00:00
|
|
|
void LinkSingleElementWidget::setElement(Element *element)
|
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
if (m_element == element)
|
|
|
|
return;
|
2015-05-27 07:22:50 +00:00
|
|
|
|
|
|
|
//Remove connection of previous edited element
|
2015-05-21 20:46:23 +00:00
|
|
|
if (m_element)
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
disconnect(m_element->diagram()->project(),
|
|
|
|
&QETProject::diagramRemoved,
|
|
|
|
this,
|
|
|
|
&LinkSingleElementWidget::diagramWasRemovedFromProject);
|
|
|
|
disconnect(m_element.data(),
|
|
|
|
&Element::linkedElementChanged,
|
|
|
|
this,
|
|
|
|
&LinkSingleElementWidget::updateUi);
|
2017-01-26 10:09:07 +00:00
|
|
|
m_element->setHighlighted(false);
|
2015-05-21 20:46:23 +00:00
|
|
|
}
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
if(m_showed_element)
|
|
|
|
m_showed_element->setHighlighted(false);
|
|
|
|
|
|
|
|
m_unlink = false;
|
|
|
|
m_showed_element = nullptr;
|
|
|
|
m_element_to_link = nullptr;
|
|
|
|
m_pending_qtwi = nullptr;
|
2015-05-21 20:46:23 +00:00
|
|
|
|
2015-05-27 07:22:50 +00:00
|
|
|
//Setup the new element, connection and ui
|
2015-05-21 20:46:23 +00:00
|
|
|
m_element = element;
|
|
|
|
|
2022-06-13 20:22:10 +02:00
|
|
|
const auto elmt_type{m_element->elementData().m_type};
|
|
|
|
if (elmt_type == ElementData::Slave)
|
|
|
|
m_filter = ElementData::Master;
|
|
|
|
else if (elmt_type & ElementData::AllReport)
|
|
|
|
m_filter = elmt_type == ElementData::NextReport
|
|
|
|
? ElementData::PreviousReport
|
|
|
|
: ElementData::NextReport;
|
2015-05-21 20:46:23 +00:00
|
|
|
else
|
2022-06-13 20:22:10 +02:00
|
|
|
m_filter = ElementData::Simple;
|
2015-05-21 20:46:23 +00:00
|
|
|
|
2020-08-16 14:23:59 +02:00
|
|
|
connect(m_element->diagram()->project(), &QETProject::diagramRemoved,
|
|
|
|
this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
|
|
|
|
connect(m_element.data(), &Element::linkedElementChanged,
|
|
|
|
this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection);
|
2015-05-21 20:46:23 +00:00
|
|
|
|
2015-05-27 07:22:50 +00:00
|
|
|
updateUi();
|
2015-05-21 20:46:23 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 09:32:56 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::apply
|
|
|
|
Apply the new property of the edited element by pushing
|
|
|
|
the associated undo command to parent project undo stack
|
|
|
|
*/
|
2015-05-09 11:35:00 +00:00
|
|
|
void LinkSingleElementWidget::apply()
|
|
|
|
{
|
2015-05-03 17:32:28 +00:00
|
|
|
QUndoCommand *undo = associatedUndo();
|
|
|
|
if (undo)
|
2015-05-21 20:46:23 +00:00
|
|
|
m_element->diagram()->undoStack().push(undo);
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
m_unlink = false;
|
|
|
|
m_element_to_link = nullptr;
|
|
|
|
m_pending_qtwi = nullptr;
|
2015-05-03 17:32:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::associatedUndo
|
|
|
|
@return the undo command associated to the current edition
|
|
|
|
if there isn't change, return nulptr
|
|
|
|
*/
|
2015-05-03 17:32:28 +00:00
|
|
|
QUndoCommand *LinkSingleElementWidget::associatedUndo() const
|
|
|
|
{
|
2018-07-30 15:24:29 +00:00
|
|
|
LinkElementCommand *undo = new LinkElementCommand(m_element);
|
2015-06-08 18:18:35 +00:00
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
if (m_element_to_link || m_unlink)
|
|
|
|
{
|
|
|
|
if (m_element_to_link)
|
|
|
|
undo->setLink(m_element_to_link);
|
|
|
|
else if (m_unlink)
|
2015-06-08 18:18:35 +00:00
|
|
|
undo->unlinkAll();
|
|
|
|
|
|
|
|
return undo;
|
|
|
|
}
|
2015-05-03 17:32:28 +00:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-05-27 07:22:50 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::title
|
|
|
|
@return the title used for this editor
|
|
|
|
*/
|
2015-05-03 17:32:28 +00:00
|
|
|
QString LinkSingleElementWidget::title() const
|
|
|
|
{
|
2017-01-29 18:43:42 +00:00
|
|
|
if (m_element->linkType() & Element::AllReport)
|
2015-05-03 17:32:28 +00:00
|
|
|
return tr("Report de folio");
|
|
|
|
else
|
|
|
|
return tr("Référence croisée (esclave)");
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
2015-05-09 11:35:00 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::updateUi
|
|
|
|
Update the content of this widget
|
|
|
|
*/
|
2015-05-27 07:22:50 +00:00
|
|
|
void LinkSingleElementWidget::updateUi()
|
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
m_unlink = false;
|
2015-05-27 07:22:50 +00:00
|
|
|
|
|
|
|
//Update the behavior of link/unlink button
|
|
|
|
if (m_element->isFree())
|
2017-01-26 10:09:07 +00:00
|
|
|
hideButtons();
|
2015-05-27 07:22:50 +00:00
|
|
|
else
|
2017-01-26 10:09:07 +00:00
|
|
|
showButtons();
|
|
|
|
|
|
|
|
buildTree();
|
|
|
|
}
|
2015-05-27 07:22:50 +00:00
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::buildTree
|
|
|
|
Build the content of the QTreeWidget
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::buildTree()
|
|
|
|
{
|
|
|
|
clearTreeWidget();
|
2017-01-29 18:43:42 +00:00
|
|
|
setUpHeaderLabels();
|
2017-02-02 18:00:53 +00:00
|
|
|
QSettings settings;
|
2017-01-29 18:43:42 +00:00
|
|
|
|
2022-06-13 20:46:22 +02:00
|
|
|
const auto elmt_vector{availableElements()};
|
|
|
|
|
|
|
|
if (m_element->elementData().m_type == ElementData::Slave)
|
2017-01-26 10:09:07 +00:00
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
|
2022-06-13 20:46:22 +02:00
|
|
|
for(const auto &elmt : elmt_vector)
|
2017-01-26 10:09:07 +00:00
|
|
|
{
|
2017-01-29 18:43:42 +00:00
|
|
|
QStringList search_list;
|
|
|
|
QStringList str_list;
|
2019-11-07 21:21:07 +01:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
str_list << elmt->actualLabel();
|
|
|
|
if(!str_list.last().isEmpty()) {
|
|
|
|
search_list << str_list.last();
|
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
|
|
|
|
str_list << elmt->elementInformations()["comment"].toString();
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
|
|
|
|
|
|
|
if (Diagram *diag = elmt->diagram())
|
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
if (settings.value("genericpanel/folio", false).toBool())
|
|
|
|
{
|
|
|
|
autonum::sequentialNumbers seq;
|
2020-08-16 14:23:59 +02:00
|
|
|
QString F =autonum::AssignVariables::formulaToLabel(
|
|
|
|
diag->border_and_titleblock.folio(), seq, diag, elmt);
|
2017-02-15 16:10:07 +00:00
|
|
|
str_list << F;
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
str_list << QString::number(diag->folioIndex() + 1);
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
str_list << diag->convertPosition(elmt->scenePos()).toString();
|
|
|
|
str_list << diag->title();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
qDebug() << "In method void LinkSingleElementWidget::updateUi(), provided element must be in a diagram";
|
2017-01-29 18:43:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree_widget, str_list);
|
2017-01-29 18:43:42 +00:00
|
|
|
m_qtwi_elmt_hash.insert(qtwi, elmt);
|
|
|
|
m_qtwi_strl_hash.insert(qtwi, search_list);
|
2017-01-26 10:09:07 +00:00
|
|
|
}
|
2017-01-30 14:29:01 +00:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
|
2017-01-30 14:29:01 +00:00
|
|
|
QVariant v = settings.value("link-element-widget/slave-state");
|
|
|
|
if(!v.isNull())
|
|
|
|
ui->m_tree_widget->header()->restoreState(v.toByteArray());
|
2017-01-29 18:43:42 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 20:46:22 +02:00
|
|
|
else if (m_element->elementData().m_type & ElementData::AllReport)
|
2017-01-29 18:43:42 +00:00
|
|
|
{
|
2022-06-13 20:46:22 +02:00
|
|
|
for(const auto &elmt : elmt_vector)
|
2017-01-26 10:09:07 +00:00
|
|
|
{
|
2017-01-29 18:43:42 +00:00
|
|
|
QStringList search_list;
|
|
|
|
QStringList str_list;
|
|
|
|
|
|
|
|
if (elmt->conductors().size())
|
|
|
|
{
|
|
|
|
ConductorProperties cp = elmt->conductors().first()->properties();
|
|
|
|
str_list << cp.text;
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
|
|
|
str_list << cp.m_function;
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
|
|
|
str_list << cp.m_tension_protocol;
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
2020-05-25 12:06:27 +02:00
|
|
|
str_list << cp.m_wire_color;
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
|
|
|
str_list << cp.m_wire_section;
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
2017-01-29 18:43:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
str_list << "" << "" << "";
|
|
|
|
|
|
|
|
if (Diagram *diag = elmt->diagram())
|
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
if (settings.value("genericpanel/folio", false).toBool())
|
|
|
|
{
|
|
|
|
autonum::sequentialNumbers seq;
|
|
|
|
QString F =autonum::AssignVariables::formulaToLabel(diag->border_and_titleblock.folio(), seq, diag, elmt);
|
|
|
|
str_list << F;
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
str_list << QString::number(diag->folioIndex() + 1);
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
str_list << diag->convertPosition(elmt->scenePos()).toString();
|
|
|
|
str_list << diag->title();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-15 16:10:07 +00:00
|
|
|
qDebug() << "In method void LinkSingleElementWidget::updateUi(), provided element must be in a diagram";
|
2017-01-29 18:43:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree_widget, str_list);
|
2017-01-29 18:43:42 +00:00
|
|
|
m_qtwi_elmt_hash.insert(qtwi, elmt);
|
|
|
|
m_qtwi_strl_hash.insert(qtwi, search_list);
|
2017-01-26 10:09:07 +00:00
|
|
|
}
|
2017-01-30 14:29:01 +00:00
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
QVariant v = settings.value("link-element-widget/report-state");
|
|
|
|
if(!v.isNull())
|
|
|
|
ui->m_tree_widget->header()->restoreState(v.toByteArray());
|
2017-01-26 10:09:07 +00:00
|
|
|
}
|
2020-07-15 20:20:07 +02:00
|
|
|
|
2017-01-29 18:43:42 +00:00
|
|
|
setUpCompleter();
|
2015-05-27 07:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::setLiveEdit
|
|
|
|
@param live_edit
|
|
|
|
@return
|
|
|
|
*/
|
2015-05-27 07:22:50 +00:00
|
|
|
bool LinkSingleElementWidget::setLiveEdit(bool live_edit)
|
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
if (m_live_edit == live_edit)
|
|
|
|
return true;
|
|
|
|
|
2015-05-27 07:22:50 +00:00
|
|
|
m_live_edit = live_edit;
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-27 07:22:50 +00:00
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::availableElements
|
|
|
|
@return A QList with all available element
|
|
|
|
to be linked with the edited element.
|
|
|
|
This methode take care of the combo box "find in diagram"
|
|
|
|
*/
|
2022-06-13 20:46:22 +02:00
|
|
|
QVector <QPointer<Element>> LinkSingleElementWidget::availableElements()
|
2017-01-26 10:09:07 +00:00
|
|
|
{
|
2022-06-13 20:46:22 +02:00
|
|
|
QVector <QPointer<Element>> elmt_vector;
|
2020-07-15 20:20:07 +02:00
|
|
|
//if element isn't free and unlink isn't pressed, return an empty list
|
2017-01-26 10:09:07 +00:00
|
|
|
if (!m_element->isFree() && !m_unlink)
|
2022-06-13 20:46:22 +02:00
|
|
|
return elmt_vector;
|
2020-07-15 20:20:07 +02:00
|
|
|
|
2022-06-13 20:46:22 +02:00
|
|
|
if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_vector;
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
ElementProvider ep(m_element->diagram()->project());
|
2022-06-13 20:22:10 +02:00
|
|
|
if (m_filter & ElementData::AllReport)
|
2022-06-13 20:46:22 +02:00
|
|
|
elmt_vector = ep.freeElement(m_filter);
|
2015-05-27 07:22:50 +00:00
|
|
|
else
|
2022-06-13 20:46:22 +02:00
|
|
|
elmt_vector = ep.find(m_filter);
|
2017-01-26 10:09:07 +00:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
//If element is linked, remove is parent from the list
|
2022-06-13 20:46:22 +02:00
|
|
|
if(!m_element->isFree()) elmt_vector.removeAll(m_element->linkedElements().first());
|
2020-07-15 20:20:07 +02:00
|
|
|
|
2022-06-13 20:46:22 +02:00
|
|
|
return elmt_vector;
|
2015-05-27 07:22:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 18:43:42 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::setUpCompleter
|
|
|
|
Setup the completer of search_field
|
|
|
|
*/
|
2017-01-29 18:43:42 +00:00
|
|
|
void LinkSingleElementWidget::setUpCompleter()
|
|
|
|
{
|
|
|
|
ui->m_search_field->clear();
|
|
|
|
if(ui->m_search_field->completer())
|
|
|
|
delete ui->m_search_field->completer();
|
|
|
|
|
|
|
|
QStringList search;
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QStringList strl , m_qtwi_strl_hash.values())
|
2017-01-29 18:43:42 +00:00
|
|
|
search.append(strl);
|
|
|
|
|
2018-07-30 15:24:29 +00:00
|
|
|
QCompleter *c = new QCompleter(search, ui->m_search_field);
|
2017-01-29 18:43:42 +00:00
|
|
|
c->setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
ui->m_search_field->setCompleter(c);
|
|
|
|
}
|
2017-01-26 10:09:07 +00:00
|
|
|
|
2015-05-27 07:22:50 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::clearTreeWidget
|
|
|
|
Clear the tree widget.
|
|
|
|
Delete all QTreeWidget (in the tree widget and in the hash).
|
|
|
|
Clear the hash.
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::clearTreeWidget()
|
2015-05-27 07:22:50 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
while(ui->m_tree_widget->topLevelItemCount())
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *qtwi = ui->m_tree_widget->takeTopLevelItem(0);
|
|
|
|
if (!m_qtwi_elmt_hash.contains(qtwi))
|
|
|
|
delete qtwi;
|
|
|
|
}
|
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys())
|
2017-01-26 10:09:07 +00:00
|
|
|
delete qtwi;
|
|
|
|
|
|
|
|
m_qtwi_elmt_hash.clear();
|
2017-01-29 18:43:42 +00:00
|
|
|
m_qtwi_strl_hash.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkSingleElementWidget::setUpHeaderLabels()
|
|
|
|
{
|
|
|
|
QStringList list;
|
2017-02-02 18:00:53 +00:00
|
|
|
QSettings settings;
|
2017-02-15 16:10:07 +00:00
|
|
|
|
|
|
|
if (m_element->linkType() == Element::Slave)
|
|
|
|
{
|
|
|
|
if (settings.value("genericpanel/folio", false).toBool())
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
list << tr("Label")
|
|
|
|
<< tr("Commentaire")
|
|
|
|
<< tr("Label de folio")
|
|
|
|
<< tr("Position")
|
|
|
|
<< tr("Titre de folio");
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
list << tr("Label")
|
|
|
|
<< tr("Commentaire")
|
|
|
|
<< tr("N° de folio")
|
|
|
|
<< tr("Position")
|
|
|
|
<< tr("Titre de folio");
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 16:10:07 +00:00
|
|
|
if (m_element->linkType() & Element::AllReport)
|
|
|
|
{
|
|
|
|
if (settings.value("genericpanel/folio", false).toBool())
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
list << tr("N° de fil")
|
|
|
|
<< tr("Fonction")
|
|
|
|
<< tr("Tension / Protocole")
|
|
|
|
<< tr("Couleur du conducteur")
|
|
|
|
<< tr("Section du conducteur")
|
|
|
|
<< tr("Label de folio")
|
|
|
|
<< tr("Position")
|
|
|
|
<< tr("Titre de folio");
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
list << tr("N° de fil")
|
|
|
|
<< tr("Fonction")
|
|
|
|
<< tr("Tension / Protocole")
|
|
|
|
<< tr("Couleur du conducteur")
|
|
|
|
<< tr("Section du conducteur")
|
|
|
|
<< tr("N° de folio")
|
|
|
|
<< tr("Position")
|
|
|
|
<< tr("Titre de folio");
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
|
|
|
|
ui->m_tree_widget->setHeaderLabels(list);
|
2015-05-27 07:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::diagramWasRemovedFromProject
|
2020-08-16 14:23:59 +02:00
|
|
|
This slot is called when a diagram
|
|
|
|
is removed from the parent project of edited element
|
2020-08-16 11:19:36 +02:00
|
|
|
to update the content of this widget
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::diagramWasRemovedFromProject()
|
2015-05-27 07:22:50 +00:00
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
// We use a timer because if the removed diagram
|
|
|
|
// contain the master element linked to the edited element
|
|
|
|
// we must to wait for this elements be unlinked,
|
|
|
|
// else the list of available master isn't up to date
|
2017-01-26 10:09:07 +00:00
|
|
|
QTimer::singleShot(10, this, SLOT(updateUi()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkSingleElementWidget::showedElementWasDeleted()
|
|
|
|
{
|
|
|
|
m_showed_element = nullptr;
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::linkTriggered
|
|
|
|
Action linkis triggered
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::linkTriggered()
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
if(!m_qtwi_at_context_menu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_element_to_link = m_qtwi_elmt_hash.value(m_qtwi_at_context_menu);
|
|
|
|
|
|
|
|
if(m_live_edit)
|
2015-05-21 20:46:23 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
apply();
|
|
|
|
updateUi();
|
2015-05-21 20:46:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
//In no live edit mode, we set the background of the qtwi green,
|
|
|
|
// to inform the user
|
|
|
|
// which element will be linked when he press the apply button
|
2017-01-26 10:09:07 +00:00
|
|
|
if (m_pending_qtwi)
|
|
|
|
{
|
|
|
|
for(int i=0 ; i<6 ; i++)
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
m_pending_qtwi->setBackground(i,
|
|
|
|
QBrush(
|
|
|
|
Qt::white,
|
|
|
|
Qt::NoBrush));
|
2017-01-26 10:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0 ; i<6 ; i++)
|
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
m_qtwi_at_context_menu->setBackground(i,
|
|
|
|
QBrush(Qt::green,
|
|
|
|
Qt::SolidPattern));
|
2017-01-26 10:09:07 +00:00
|
|
|
}
|
|
|
|
m_pending_qtwi = m_qtwi_at_context_menu;
|
2015-05-21 20:46:23 +00:00
|
|
|
}
|
2017-01-26 10:09:07 +00:00
|
|
|
|
2014-03-15 20:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::hideButtons
|
|
|
|
Hide the button displayed when element is already linked
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::hideButtons()
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
ui->m_label->hide();
|
|
|
|
ui->m_unlink_pb->hide();
|
|
|
|
ui->m_show_linked_pb->hide();
|
|
|
|
ui->m_show_this_pb->hide();
|
2017-01-29 18:43:42 +00:00
|
|
|
ui->m_search_field->show();
|
2014-03-15 20:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::showButtons
|
|
|
|
Show the button displayed when element is already linked
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::showButtons()
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
ui->m_label->show();
|
|
|
|
ui->m_unlink_pb->show();
|
|
|
|
ui->m_show_linked_pb->show();
|
|
|
|
ui->m_show_this_pb->show();
|
2017-01-29 18:43:42 +00:00
|
|
|
ui->m_search_field->hide();
|
2017-01-26 10:09:07 +00:00
|
|
|
}
|
2014-03-12 09:32:56 +00:00
|
|
|
|
2020-08-16 14:23:59 +02:00
|
|
|
void LinkSingleElementWidget::headerCustomContextMenuRequested(
|
|
|
|
const QPoint &pos)
|
2017-01-30 14:29:01 +00:00
|
|
|
{
|
|
|
|
m_context_menu->clear();
|
|
|
|
m_context_menu->addAction(m_save_header_state);
|
|
|
|
m_context_menu->popup(ui->m_tree_widget->header()->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::on_m_unlink_pb_clicked()
|
|
|
|
{
|
|
|
|
m_unlink = true;
|
|
|
|
|
|
|
|
if(m_live_edit)
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
apply();
|
|
|
|
updateUi();
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
2015-05-09 11:35:00 +00:00
|
|
|
else
|
2017-01-26 10:09:07 +00:00
|
|
|
buildTree();
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked
|
2020-08-18 21:28:52 +02:00
|
|
|
Highlight the element represented by item
|
2020-08-16 11:19:36 +02:00
|
|
|
@param item
|
|
|
|
@param column
|
|
|
|
*/
|
2020-08-16 14:23:59 +02:00
|
|
|
void LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked(
|
|
|
|
QTreeWidgetItem *item,
|
|
|
|
int column)
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
Q_UNUSED(column);
|
|
|
|
|
|
|
|
if (m_showed_element)
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
disconnect(m_showed_element, SIGNAL(destroyed()),
|
|
|
|
this, SLOT(showedElementWasDeleted()));
|
2017-01-26 10:09:07 +00:00
|
|
|
m_showed_element->setHighlighted(false);
|
2014-03-15 20:49:05 +00:00
|
|
|
}
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
Element *elmt = m_qtwi_elmt_hash.value(item);
|
|
|
|
elmt->diagram()->showMe();
|
|
|
|
elmt->setHighlighted(true);
|
|
|
|
m_showed_element = elmt;
|
2020-08-16 14:23:59 +02:00
|
|
|
connect(m_showed_element, SIGNAL(destroyed()),
|
|
|
|
this, SLOT(showedElementWasDeleted()));
|
2020-07-15 20:20:07 +02:00
|
|
|
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 14:23:59 +02:00
|
|
|
void LinkSingleElementWidget::on_m_tree_widget_customContextMenuRequested(
|
|
|
|
const QPoint &pos)
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2020-08-16 14:23:59 +02:00
|
|
|
//add the size of the header to display the topleft of the QMenu
|
|
|
|
//at the position of the mouse.
|
|
|
|
//See doc about QWidget::customContextMenuRequested
|
|
|
|
//section related to QAbstractScrollArea
|
2017-01-26 10:09:07 +00:00
|
|
|
QPoint point = pos;
|
|
|
|
point.ry()+=ui->m_tree_widget->header()->height();
|
|
|
|
point = ui->m_tree_widget->mapToGlobal(point);
|
|
|
|
|
|
|
|
m_context_menu->clear();
|
|
|
|
|
|
|
|
if (ui->m_tree_widget->currentItem())
|
|
|
|
{
|
|
|
|
m_qtwi_at_context_menu = ui->m_tree_widget->currentItem();
|
|
|
|
m_context_menu->addAction(m_link_action);
|
|
|
|
m_context_menu->addAction(m_show_qtwi);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_context_menu->addAction(m_show_element);
|
|
|
|
m_context_menu->popup(point);
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::on_m_show_linked_pb_clicked()
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
if (!m_element->isFree())
|
|
|
|
{
|
|
|
|
Element *elmt = m_element->linkedElements().first();
|
|
|
|
elmt->diagram()->showMe();
|
|
|
|
elmt->setHighlighted(true);
|
|
|
|
}
|
2015-05-21 20:46:23 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::on_m_show_this_pb_clicked()
|
2015-05-21 20:46:23 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
m_show_element->trigger();
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief LinkSingleElementWidget::on_m_search_field_textEdited
|
2020-08-16 14:23:59 +02:00
|
|
|
Search all items which match with arg1 and shows it,
|
|
|
|
other items is hidden.
|
|
|
|
If arg1 is empty, show all items.
|
2020-08-16 11:19:36 +02:00
|
|
|
@param arg1
|
|
|
|
*/
|
2017-01-29 18:43:42 +00:00
|
|
|
void LinkSingleElementWidget::on_m_search_field_textEdited(const QString &arg1)
|
|
|
|
{
|
2020-07-15 20:20:07 +02:00
|
|
|
//Show all items if arg1 is empty, if not hide all items
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys())
|
2017-01-29 18:43:42 +00:00
|
|
|
qtwi->setHidden(!arg1.isEmpty());
|
|
|
|
|
|
|
|
QList <QTreeWidgetItem *> qtwi_list;
|
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QTreeWidgetItem *qtwi, m_qtwi_strl_hash.keys())
|
2017-01-29 18:43:42 +00:00
|
|
|
{
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QString str, m_qtwi_strl_hash.value(qtwi))
|
2017-01-29 18:43:42 +00:00
|
|
|
{
|
|
|
|
if(str.contains(arg1, Qt::CaseInsensitive))
|
|
|
|
{
|
|
|
|
qtwi_list << qtwi;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
//Show items which match with arg1
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(QTreeWidgetItem *qtwi, qtwi_list)
|
2017-01-29 18:43:42 +00:00
|
|
|
qtwi->setHidden(false);
|
|
|
|
}
|