2014-03-12 09:32:56 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 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"
|
|
|
|
#include "ui_linksingleelementwidget.h"
|
|
|
|
#include "diagram.h"
|
|
|
|
#include "elementprovider.h"
|
2015-06-08 18:18:35 +00:00
|
|
|
#include "linkelementcommand.h"
|
2017-01-26 10:09:07 +00:00
|
|
|
#include "diagramposition.h"
|
2017-01-29 18:43:42 +00:00
|
|
|
#include "conductor.h"
|
2017-01-26 10:09:07 +00:00
|
|
|
|
|
|
|
#include <QTreeWidgetItem>
|
2014-03-12 09:32:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::LinkSingleElementWidget
|
|
|
|
* Default constructor
|
|
|
|
* @param elmt
|
|
|
|
* the edited element
|
|
|
|
* @param parent
|
|
|
|
* the parent widget
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
connect(qhv, &QHeaderView::customContextMenuRequested, this, &LinkSingleElementWidget::headerCustomContextMenuRequested);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::~LinkSingleElementWidget
|
|
|
|
* Default destructor
|
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
LinkSingleElementWidget::~LinkSingleElementWidget()
|
|
|
|
{
|
|
|
|
if(m_showed_element)
|
|
|
|
m_showed_element->setHighlighted(false);
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::setElement
|
|
|
|
* Set element to be the edited element.
|
|
|
|
* @param element
|
|
|
|
*/
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
disconnect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
|
2015-05-27 07:22:50 +00:00
|
|
|
disconnect(m_element, &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;
|
|
|
|
|
|
|
|
if (m_element->linkType() & Element::Slave)
|
2017-01-26 10:09:07 +00:00
|
|
|
m_filter = Element::Master;
|
2015-05-21 20:46:23 +00:00
|
|
|
else if (m_element->linkType() & Element::AllReport)
|
2017-01-26 10:09:07 +00:00
|
|
|
m_filter = m_element->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport;
|
2015-05-21 20:46:23 +00:00
|
|
|
else
|
2017-01-26 10:09:07 +00:00
|
|
|
m_filter = Element::Simple;
|
2015-05-21 20:46:23 +00:00
|
|
|
|
|
|
|
connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
|
2015-05-27 07:22:50 +00:00
|
|
|
connect(m_element, &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
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::apply
|
2015-05-27 07:22:50 +00:00
|
|
|
* Apply the new property of the edited element by pushing
|
|
|
|
* the associated undo command to parent project undo stack
|
2014-03-12 09:32:56 +00:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::associatedUndo
|
|
|
|
* @return the undo command associated to the current edition
|
|
|
|
* if there isn't change, return nulptr
|
|
|
|
*/
|
|
|
|
QUndoCommand *LinkSingleElementWidget::associatedUndo() const
|
|
|
|
{
|
2017-01-26 10:09:07 +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
|
|
|
/**
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::buildTree
|
|
|
|
* Build the content of the QTreeWidget
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
if (m_element->linkType() == Element::Slave)
|
2017-01-26 10:09:07 +00:00
|
|
|
{
|
2017-02-04 21:43:23 +00:00
|
|
|
for (Element *elmt: availableElements())
|
2017-01-26 10:09:07 +00:00
|
|
|
{
|
2017-01-29 18:43:42 +00:00
|
|
|
QStringList search_list;
|
|
|
|
QStringList str_list;
|
|
|
|
str_list << elmt->elementInformations()["label"].toString();
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
|
|
|
|
|
|
|
str_list << elmt->elementInformations()["comment"].toString();
|
|
|
|
if (!str_list.last().isEmpty())
|
|
|
|
search_list << str_list.last();
|
|
|
|
|
|
|
|
if (Diagram *diag = elmt->diagram())
|
|
|
|
{
|
2017-02-02 18:00:53 +00:00
|
|
|
if (settings.value("genericpanel/folio", false).toBool()){
|
2017-01-29 18:43:42 +00:00
|
|
|
str_list << QString::number(diag->folioIndex() + 1);
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-29 18:43:42 +00:00
|
|
|
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
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
str_list << diag->convertPosition(elmt->scenePos()).toString();
|
|
|
|
str_list << diag->title();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "In method void LinkSingleElementWidget::updateUi(), provied element must have be in a diagram";
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree_widget, str_list);
|
|
|
|
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
|
|
|
|
2017-02-02 18:00:53 +00: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
|
|
|
}
|
|
|
|
|
|
|
|
else if (m_element->linkType() & Element::AllReport)
|
|
|
|
{
|
2017-02-04 21:43:23 +00:00
|
|
|
for (Element *elmt: availableElements())
|
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();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str_list << "" << "" << "";
|
|
|
|
|
|
|
|
if (Diagram *diag = elmt->diagram())
|
|
|
|
{
|
2017-02-02 18:00:53 +00:00
|
|
|
if (settings.value("genericpanel/folio", false).toBool()){
|
2017-01-29 18:43:42 +00:00
|
|
|
str_list << QString::number(diag->folioIndex() + 1);
|
2017-02-02 18:00:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-29 18:43:42 +00:00
|
|
|
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
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
str_list << diag->convertPosition(elmt->scenePos()).toString();
|
|
|
|
str_list << diag->title();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "In method void LinkSingleElementWidget::updateUi(), provied element must have be in a diagram";
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree_widget, str_list);
|
|
|
|
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
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
|
|
|
|
setUpCompleter();
|
2015-05-27 07:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::setLiveEdit
|
|
|
|
* @param live_edit
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @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"
|
|
|
|
*/
|
|
|
|
QList <Element *> LinkSingleElementWidget::availableElements()
|
|
|
|
{
|
|
|
|
QList <Element *> elmt_list;
|
|
|
|
//if element isn't free and unlink isn't pressed, return an empty list
|
|
|
|
if (!m_element->isFree() && !m_unlink)
|
|
|
|
return elmt_list;
|
|
|
|
|
|
|
|
if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_list;
|
|
|
|
|
|
|
|
ElementProvider ep(m_element->diagram()->project());
|
|
|
|
if (m_filter & Element::AllReport)
|
|
|
|
elmt_list = ep.freeElement(m_filter);
|
2015-05-27 07:22:50 +00:00
|
|
|
else
|
2017-01-26 10:09:07 +00:00
|
|
|
elmt_list = ep.find(m_filter);
|
|
|
|
|
|
|
|
//If element is linked, remove is parent from the list
|
|
|
|
if(!m_element->isFree()) elmt_list.removeAll(m_element->linkedElements().first());
|
2015-05-27 07:22:50 +00:00
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
return elmt_list;
|
2015-05-27 07:22:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 18:43:42 +00:00
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::setUpCompleter
|
|
|
|
* Setup the completer of search_field
|
|
|
|
*/
|
|
|
|
void LinkSingleElementWidget::setUpCompleter()
|
|
|
|
{
|
|
|
|
ui->m_search_field->clear();
|
|
|
|
if(ui->m_search_field->completer())
|
|
|
|
delete ui->m_search_field->completer();
|
|
|
|
|
|
|
|
QStringList search;
|
2017-02-04 21:43:23 +00:00
|
|
|
for (QStringList strl: m_qtwi_strl_hash.values())
|
2017-01-29 18:43:42 +00:00
|
|
|
search.append(strl);
|
|
|
|
|
|
|
|
QCompleter *c = new QCompleter(search, ui->m_search_field);
|
|
|
|
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
|
|
|
/**
|
2017-01-26 10:09:07 +00:00
|
|
|
* @brief LinkSingleElementWidget::clearTreeWidget
|
|
|
|
* Clear the tree widget.
|
|
|
|
* Delete all QTreeWidget (in the tree widget and in the hash).
|
|
|
|
* Clear the hash.
|
2015-05-27 07:22:50 +00:00
|
|
|
*/
|
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-04 21:43:23 +00:00
|
|
|
for (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;
|
|
|
|
if (m_element->linkType() == Element::Slave){
|
|
|
|
if (settings.value("genericpanel/folio", false).toBool()){
|
|
|
|
list << tr("Label") << tr("Commentaire") << tr("N° de folio") << tr("Position") << tr("Titre de folio");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list << tr("Label") << tr("Commentaire") << tr("Label de folio") << tr("Position") << tr("Titre de folio");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_element->linkType() & Element::AllReport){
|
|
|
|
if (settings.value("genericpanel/folio", false).toBool()){
|
|
|
|
list << tr("N° de fil") << tr("Fonction") << tr("Tension / Protocole") << tr("N° de folio") << tr("Position") << tr("Titre de folio");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list << tr("N° de fil") << tr("Fonction") << tr("Tension / Protocole") << tr("Label de folio") << tr("Position") << tr("Titre de folio");
|
|
|
|
}
|
|
|
|
}
|
2017-01-29 18:43:42 +00:00
|
|
|
|
|
|
|
ui->m_tree_widget->setHeaderLabels(list);
|
2015-05-27 07:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-26 10:09:07 +00:00
|
|
|
* @brief LinkSingleElementWidget::diagramWasRemovedFromProject
|
|
|
|
* * This slot is called when a diagram is removed from the parent project of edited element
|
|
|
|
* to update the content of this widget
|
2015-05-27 07:22:50 +00:00
|
|
|
*/
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::diagramWasRemovedFromProject()
|
2015-05-27 07:22:50 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00: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
|
|
|
|
QTimer::singleShot(10, this, SLOT(updateUi()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinkSingleElementWidget::showedElementWasDeleted()
|
|
|
|
{
|
|
|
|
m_showed_element = nullptr;
|
2014-03-12 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-26 10:09:07 +00:00
|
|
|
* @brief LinkSingleElementWidget::linkTriggered
|
|
|
|
* Action linkis triggered
|
2014-03-12 09:32:56 +00:00
|
|
|
*/
|
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
|
|
|
|
{
|
2017-01-26 10:09:07 +00: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
|
|
|
|
if (m_pending_qtwi)
|
|
|
|
{
|
|
|
|
QBrush brush(Qt::white, Qt::NoBrush);
|
|
|
|
for(int i=0 ; i<6 ; i++)
|
|
|
|
{
|
|
|
|
m_pending_qtwi->setBackground(i,brush);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0 ; i<6 ; i++)
|
|
|
|
{
|
|
|
|
m_qtwi_at_context_menu->setBackgroundColor(i, Qt::green);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-26 10:09:07 +00:00
|
|
|
* @brief LinkSingleElementWidget::hideButtons
|
|
|
|
* Hide the button displayed when element is already linked
|
2014-03-15 20:49:05 +00:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-26 10:09:07 +00:00
|
|
|
* @brief LinkSingleElementWidget::showButtons
|
|
|
|
* Show the button displayed when element is already linked
|
2014-03-15 20:49:05 +00:00
|
|
|
*/
|
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
|
|
|
|
2017-01-30 14:29:01 +00:00
|
|
|
void LinkSingleElementWidget::headerCustomContextMenuRequested(const QPoint &pos)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-26 10:09:07 +00:00
|
|
|
* @brief LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked
|
|
|
|
* Highlight the element represented by @item
|
|
|
|
* @param item
|
|
|
|
* @param column
|
2014-03-12 09:32:56 +00:00
|
|
|
*/
|
2017-01-26 10:09:07 +00: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
|
|
|
{
|
2017-01-26 10:09:07 +00:00
|
|
|
disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
|
|
|
|
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;
|
|
|
|
connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
|
2014-03-12 09:32:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-26 10:09:07 +00:00
|
|
|
void LinkSingleElementWidget::on_m_tree_widget_customContextMenuRequested(const QPoint &pos)
|
2015-05-09 11:35:00 +00:00
|
|
|
{
|
2017-01-26 10:09:07 +00: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
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief LinkSingleElementWidget::on_m_search_field_textEdited
|
|
|
|
* Search all items which match with @arg1 and shows it, other items is hidden.
|
|
|
|
* If @arg1 is empty, show all items.
|
|
|
|
* @param arg1
|
|
|
|
*/
|
|
|
|
void LinkSingleElementWidget::on_m_search_field_textEdited(const QString &arg1)
|
|
|
|
{
|
|
|
|
//Show all items if arg1 is empty, if not hide all items
|
2017-02-04 21:43:23 +00:00
|
|
|
for (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-04 21:43:23 +00:00
|
|
|
for (QTreeWidgetItem *qtwi: m_qtwi_strl_hash.keys())
|
2017-01-29 18:43:42 +00:00
|
|
|
{
|
2017-02-04 21:43:23 +00:00
|
|
|
for (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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show items which match with arg1
|
2017-02-04 21:43:23 +00:00
|
|
|
for (QTreeWidgetItem *qtwi: qtwi_list)
|
2017-01-29 18:43:42 +00:00
|
|
|
qtwi->setHidden(false);
|
|
|
|
}
|