Link single element widget : revamp the widget (use a QTreeWidget instead of a list of widgets) and add the variable %F to the value displayed

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4874 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-01-26 10:09:07 +00:00
parent 73dd8b6b57
commit 0b943ed52d
7 changed files with 385 additions and 716 deletions

View File

@@ -1,279 +0,0 @@
/*
Copyright 2006-2017 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 "elementselectorwidget.h"
#include "ui_elementselectorwidget.h"
#include "diagramposition.h"
#include "qeticons.h"
#include "diagram.h"
#include "element.h"
#include "terminal.h"
#include "conductor.h"
#include "qet.h"
#include "assignvariables.h"
/**
* @brief ElementSelectorWidget::ElementSelectorWidget
* Default constructor
* @param elmt_list
* List of element to be displayed by the selector
* @param parent
* Parent widget
*/
ElementSelectorWidget::ElementSelectorWidget(QList <Element *> elmt_list, QWidget *parent) :
QWidget(parent),
ui(new Ui::ElementSelectorWidget),
elements_list(elmt_list),
selected_element (nullptr),
showed_element (nullptr),
m_button_group (nullptr)
{
qSort(elements_list.begin(), elements_list.end(), comparPos);
ui->setupUi(this);
buildInterface();
}
/**
* @brief ElementSelectorWidget::~ElementSelectorWidget
* Default destructor
*/
ElementSelectorWidget::~ElementSelectorWidget()
{
if (showed_element) showed_element->setHighlighted(false);
delete ui;
}
/**
* @brief ElementSelectorWidget::showElement
* Show the element given by parametre
* @param elmt
*/
void ElementSelectorWidget::showElement(Element *elmt) {
if (showed_element)
{
disconnect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
showed_element->setHighlighted(false);
}
elmt->diagram()->showMe();
elmt->setHighlighted(true);
showed_element = elmt;
connect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
}
/**
* @brief ElementSelectorWidget::clear
* Clear the curent list and the widget
*/
void ElementSelectorWidget::clear() {
elements_list.clear();
in_filter.clear();
out_filter.clear();
selected_element = nullptr;
if(showed_element) showed_element->setHighlighted(false);
foreach(QWidget *w, content_list) {
ui->scroll_layout_->removeWidget(w);
delete w;
}
content_list.clear();
delete sm_;
delete sm_show_;
delete m_button_group;
}
/**
* @brief ElementSelectorWidget::setList
* Set new list of elements
* @param elmt_list the new elements list
*/
void ElementSelectorWidget::setList(QList<Element *> elmt_list) {
clear();
elements_list << elmt_list;
qSort(elements_list.begin(), elements_list.end(), comparPos);
buildInterface();
}
/**
* @brief ElementSelectorWidget::buildInterface
* Build interface of this widget (fill all available element)
*/
void ElementSelectorWidget::buildInterface() {
//Setup the signal mapper
int map_id = 0; //this int is used to map the signal
sm_ = new QSignalMapper(this);
connect(sm_, SIGNAL(mapped(int)), this, SLOT(setSelectedElement(int)));
sm_show_ = new QSignalMapper(this);
connect(sm_show_, SIGNAL(mapped(int)), this, SLOT(showElementFromList(int)));
m_button_group = new QButtonGroup(this);
//Build the list
foreach (Element *elmt, elements_list) {
//label for the button
QString button_text;
/*
* If element is master and have label,
* we add label and comment to the button text
*/
if (elmt->linkType() & Element::Master) {
DiagramContext dc = elmt -> elementInformations();
if (!dc["label"].toString().isEmpty())
button_text = autonum::AssignVariables::formulaToLabel(dc["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + " ";
if (!dc["comment"].toString().isEmpty())
button_text = autonum::AssignVariables::formulaToLabel(dc["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
if (!dc["location"].toString().isEmpty())
button_text = autonum::AssignVariables::formulaToLabel(dc["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
if (!button_text.isEmpty())
button_text += "\n";
//Add the string for filter this widget
QString filter;
foreach(QString str, elmt->elementInformations().keys()){
QString filter_str = elmt->elementInformations()[str].toString();
filter += filter_str;
out_filter << filter_str;
}
in_filter << filter;
}
/*
* If element is a folio report, have conductors docked to his terminal,
* and each conductor have the same text,
* we add this text to the button label and provide it through the filter
*/
if (elmt -> linkType() & Element::AllReport) {
//Add empty string to keep the same index with content_list
//see how work filtered for more detail why we need this
in_filter << "";
//Report have one terminal, but we check it to prevent assert.
if (!elmt -> terminals().isEmpty()) {
//We must to have at least one conductor
if (!elmt -> terminals().first() -> conductors().isEmpty()) {
Conductor *cond = elmt->terminals().first()->conductors().first();
QSet <Conductor *> cdr_set = cond -> relatedPotentialConductors();
cdr_set << cond;
QStringList str_list;
foreach (Conductor* c, cdr_set)
str_list << c->properties().text;
if (QET::eachStrIsEqual(str_list)) {
button_text = tr("N° fil : ") + str_list.first() + "\n";
//Replace the last empty string by the conductor text
in_filter.pop_back();
in_filter << str_list.first();
out_filter << str_list.first();
}
}
}
}
QString title = elmt->diagram()->title();
if (title.isEmpty()) title = tr("Sans titre");
button_text += QString("Folio %1 (%2), position %3.").arg(elmt->diagram()->folioIndex() + 1)
.arg(title)
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
//Widget that contain the buttons
QWidget *widget = new QWidget(this);
content_list << widget;
//Radio button for select element
QRadioButton *rb = new QRadioButton(button_text , widget);
m_button_group -> addButton(rb);
//Push button to highlight element
QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", widget);
pb -> setToolTip(tr("Voir l'élément"));
QHBoxLayout *hl = new QHBoxLayout(widget);
hl -> setContentsMargins(0,0,0,0);
hl -> addWidget(rb);
hl -> addStretch();
hl -> addWidget(pb);
ui -> scroll_layout_ -> insertWidget(map_id, widget);
//map the radio button signal
connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
sm_ -> setMapping(rb, map_id);
//map the push button show diagram
connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map()));
sm_show_->setMapping(pb, map_id);
map_id++; //increase the map_id for next button.
}
}
void ElementSelectorWidget::setSelectedElement(const int i)
{
selected_element = elements_list.at(i);
emit elementSelected(selected_element);
}
/**
* @brief ElementSelectorWidget::showElementFromList
* Show the element at the position i in @elements_list
* @param i
*/
void ElementSelectorWidget::showElementFromList(const int i) {
if (elements_list.size() >= i)
showElement(elements_list.at(i));
}
/**
* @brief ElementSelectorWidget::showedElementWasDeleted
* Set to nullptr the current showed element when he was deleted
*/
void ElementSelectorWidget::showedElementWasDeleted() {
showed_element = nullptr;
}
/**
* @brief ElementSelectorWidget::filter
* @return A stringlist with all available value
* to filter the content of this widget;
*/
QStringList ElementSelectorWidget::filter() const {
return out_filter;
}
/**
* @brief ElementSelectorWidget::filter
* Filter the content of the list.
* Give an empty string remove all filter.
* @param str string to filter
*/
void ElementSelectorWidget::filtered(const QString &str) {
if(str.isEmpty()) {
foreach (QWidget *w, content_list) w->setHidden(false);
}
else {
for (int i = 0; i<in_filter.size(); i++) {
if (in_filter.at(i).contains(str, Qt::CaseInsensitive)) {
content_list.at(i)->setHidden(false);
}
else
content_list.at(i)->setHidden(true);
}
}
}

View File

@@ -1,79 +0,0 @@
/*
Copyright 2006-2017 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/>.
*/
#ifndef ELEMENTSELECTORWIDGET_H
#define ELEMENTSELECTORWIDGET_H
#include <QWidget>
class Element;
class QSignalMapper;
class QButtonGroup;
namespace Ui {
class ElementSelectorWidget;
}
/**
* @brief The ElementSelectorWidget class
* This class provide a widget with a list of element.
* User can select an element in the list and higligth it.
* For know what element is selected, call selectedElement.
*/
class ElementSelectorWidget : public QWidget
{
Q_OBJECT
///Methods
public:
explicit ElementSelectorWidget(QList <Element *> elmt_list, QWidget *parent = 0);
~ElementSelectorWidget();
Element * selectedElement () const{return selected_element;}
void showElement(Element *elmt);
void clear();
void setList(QList <Element *> elmt_list);
QStringList filter () const;
signals:
void elementSelected (Element *element);
public slots:
void filtered(const QString &str);
private:
void buildInterface();
private slots:
void setSelectedElement (const int i);
void showElementFromList (const int i);
void showedElementWasDeleted ();
///Attributes
private:
Ui::ElementSelectorWidget *ui;
QList <Element *> elements_list;
QSignalMapper *sm_, *sm_show_;
Element *selected_element, *showed_element;
QList <QWidget *> content_list;
QStringList in_filter, //In filter is used inside this class to filter the content of this widget
out_filter; //Out filter is used to return (with the method filter) a list of
//available string to filter the content of this widget
QButtonGroup *m_button_group;
};
#endif // ELEMENTSELECTORWIDGET_H

View File

@@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ElementSelectorWidget</class>
<widget class="QWidget" name="ElementSelectorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>400</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>400</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>280</width>
<height>380</height>
</rect>
</property>
<layout class="QVBoxLayout" name="scroll_layout_">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -19,8 +19,10 @@
#include "ui_linksingleelementwidget.h" #include "ui_linksingleelementwidget.h"
#include "diagram.h" #include "diagram.h"
#include "elementprovider.h" #include "elementprovider.h"
#include "elementselectorwidget.h"
#include "linkelementcommand.h" #include "linkelementcommand.h"
#include "diagramposition.h"
#include <QTreeWidgetItem>
/** /**
* @brief LinkSingleElementWidget::LinkSingleElementWidget * @brief LinkSingleElementWidget::LinkSingleElementWidget
@@ -32,14 +34,27 @@
*/ */
LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) : LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) :
AbstractElementPropertiesEditorWidget(parent), AbstractElementPropertiesEditorWidget(parent),
ui(new Ui::LinkSingleElementWidget), ui(new Ui::LinkSingleElementWidget)
esw_(nullptr),
unlink_(false),
search_field(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(setNewList()));
connect(ui->m_unlink_pb, SIGNAL(clicked()), this, SLOT(unlinkClicked())); 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);
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);
});
setElement(elmt); setElement(elmt);
} }
@@ -47,7 +62,15 @@ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent)
* @brief LinkSingleElementWidget::~LinkSingleElementWidget * @brief LinkSingleElementWidget::~LinkSingleElementWidget
* Default destructor * Default destructor
*/ */
LinkSingleElementWidget::~LinkSingleElementWidget() { 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);
delete ui; delete ui;
} }
@@ -58,26 +81,34 @@ LinkSingleElementWidget::~LinkSingleElementWidget() {
*/ */
void LinkSingleElementWidget::setElement(Element *element) void LinkSingleElementWidget::setElement(Element *element)
{ {
if (m_element == element) return; if (m_element == element)
return;
//Remove connection of previous edited element //Remove connection of previous edited element
if (m_element) if (m_element)
{ {
disconnect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject); disconnect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
disconnect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi); disconnect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi);
diagram_list.clear(); m_element->setHighlighted(false);
} }
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;
//Setup the new element, connection and ui //Setup the new element, connection and ui
m_element = element; m_element = element;
diagram_list << m_element->diagram()->project()->diagrams();
if (m_element->linkType() & Element::Slave) if (m_element->linkType() & Element::Slave)
filter_ = Element::Master; m_filter = Element::Master;
else if (m_element->linkType() & Element::AllReport) else if (m_element->linkType() & Element::AllReport)
filter_ = m_element->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport; m_filter = m_element->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport;
else else
filter_ = Element::Simple; m_filter = Element::Simple;
connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject); connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
connect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection); connect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection);
@@ -95,6 +126,10 @@ void LinkSingleElementWidget::apply()
QUndoCommand *undo = associatedUndo(); QUndoCommand *undo = associatedUndo();
if (undo) if (undo)
m_element->diagram()->undoStack().push(undo); m_element->diagram()->undoStack().push(undo);
m_unlink = false;
m_element_to_link = nullptr;
m_pending_qtwi = nullptr;
} }
/** /**
@@ -103,14 +138,14 @@ void LinkSingleElementWidget::apply()
* if there isn't change, return nulptr * if there isn't change, return nulptr
*/ */
QUndoCommand *LinkSingleElementWidget::associatedUndo() const QUndoCommand *LinkSingleElementWidget::associatedUndo() const
{
if (esw_->selectedElement() || unlink_)
{ {
LinkElementCommand *undo = new LinkElementCommand(m_element); LinkElementCommand *undo = new LinkElementCommand(m_element);
if (esw_->selectedElement()) if (m_element_to_link || m_unlink)
undo->setLink(esw_->selectedElement()); {
else if (unlink_) if (m_element_to_link)
undo->setLink(m_element_to_link);
else if (m_unlink)
undo->unlinkAll(); undo->unlinkAll();
return undo; return undo;
@@ -137,33 +172,47 @@ QString LinkSingleElementWidget::title() const
*/ */
void LinkSingleElementWidget::updateUi() void LinkSingleElementWidget::updateUi()
{ {
//Fill the combo box for filter the result by folio m_unlink = false;
ui->folio_combo_box->blockSignals(true);
ui->folio_combo_box->clear();
ui->folio_combo_box->addItem(tr("Tous"));
foreach (Diagram *d, diagram_list)
{
QString title = d->title();
if (title.isEmpty()) title = tr("Sans titre");
title.prepend(QString::number(d->folioIndex() + 1) + " ");
ui->folio_combo_box->addItem(title);
}
ui->folio_combo_box->blockSignals(false);
unlink_ = false;
buildList();
//Update the behavior of link/unlink button //Update the behavior of link/unlink button
if (m_element->isFree()) if (m_element->isFree())
hideButtons();
else
showButtons();
buildTree();
}
/**
* @brief LinkSingleElementWidget::buildTree
* Build the content of the QTreeWidget
*/
void LinkSingleElementWidget::buildTree()
{ {
ui->button_linked->setDisabled(true); clearTreeWidget();
ui->m_unlink_widget->hide(); foreach(Element *elmt, availableElements())
{
QStringList str_list;
str_list << elmt->elementInformations()["label"].toString();
str_list << elmt->elementInformations()["comment"].toString();
if (Diagram *diag = elmt->diagram())
{
str_list << QString::number(diag->folioIndex() + 1);
autonum::sequentialNumbers seq;
QString F =autonum::AssignVariables::formulaToLabel(diag->border_and_titleblock.folio(), seq, diag, elmt);
str_list << F;
str_list << diag->title();
str_list << diag->convertPosition(elmt->scenePos()).toString();
} }
else else
ui->m_unlink_widget->show(); {
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);
}
buildSearchField(); //setUpCompleter();
} }
/** /**
@@ -173,86 +222,14 @@ void LinkSingleElementWidget::updateUi()
*/ */
bool LinkSingleElementWidget::setLiveEdit(bool live_edit) bool LinkSingleElementWidget::setLiveEdit(bool live_edit)
{ {
if (m_live_edit == live_edit) return true; if (m_live_edit == live_edit)
return true;
m_live_edit = live_edit; m_live_edit = live_edit;
if (m_live_edit)
enableLiveEdit();
else
disableLiveEdit();
return true; return true;
} }
/**
* @brief LinkSingleElementWidget::enableLiveEdit
*/
void LinkSingleElementWidget::enableLiveEdit()
{
if (!esw_) return;
connect(esw_, &ElementSelectorWidget::elementSelected, this, &LinkSingleElementWidget::apply, Qt::QueuedConnection);
connect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply, Qt::QueuedConnection);
}
/**
* @brief LinkSingleElementWidget::disableLiveEdit
*/
void LinkSingleElementWidget::disableLiveEdit()
{
if (!esw_) return;
disconnect(esw_, &ElementSelectorWidget::elementSelected, this, &LinkSingleElementWidget::apply);
disconnect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply);
}
/**
* @brief LinkSingleElementWidget::buildList
* Build the element list of this widget,
* the list is fill with the element find in the
* required folio (folio selected with the combo box)
*/
void LinkSingleElementWidget::buildList()
{
if (!esw_)
{
esw_ = new ElementSelectorWidget(availableElements(), this);
ui->content_layout->addWidget(esw_);
}
else
{
esw_->setList(availableElements());
}
buildSearchField();
}
/**
* @brief LinkSingleElementWidget::buildSearchField
* Build a line edit for search element by they information,
* like label or information
*/
void LinkSingleElementWidget::buildSearchField()
{
//If there isn't string to filter, we remove the search field
if (esw_->filter().isEmpty())
{
if (search_field)
{
ui -> header_layout -> removeWidget(search_field);
delete search_field;
search_field = nullptr;
}
return;
}
if(!search_field)
{
search_field = new QLineEdit(this);
search_field -> setPlaceholderText(tr("Rechercher"));
connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filtered(QString)));
ui->header_layout->addWidget(search_field);
}
setUpCompleter();
}
/** /**
* @brief LinkSingleElementWidget::availableElements * @brief LinkSingleElementWidget::availableElements
* @return A QList with all available element * @return A QList with all available element
@@ -263,30 +240,16 @@ QList <Element *> LinkSingleElementWidget::availableElements()
{ {
QList <Element *> elmt_list; QList <Element *> elmt_list;
//if element isn't free and unlink isn't pressed, return an empty list //if element isn't free and unlink isn't pressed, return an empty list
if (!m_element->isFree() && !unlink_) return elmt_list; if (!m_element->isFree() && !m_unlink)
return elmt_list;
int i = ui->folio_combo_box->currentIndex();
//find in all diagram of this project
if (i == 0)
{
if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_list; if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_list;
ElementProvider ep(m_element->diagram()->project()); ElementProvider ep(m_element->diagram()->project());
if (filter_ & Element::AllReport) if (m_filter & Element::AllReport)
elmt_list = ep.freeElement(filter_); elmt_list = ep.freeElement(m_filter);
else else
elmt_list = ep.find(filter_); elmt_list = ep.find(m_filter);
}
//find in single diagram
else
{
ElementProvider ep (diagram_list.at(i-1));
if (filter_ & Element::AllReport)
elmt_list = ep.freeElement(filter_);
else
elmt_list = ep.find(filter_);
}
//If element is linked, remove is parent from the list //If element is linked, remove is parent from the list
if(!m_element->isFree()) elmt_list.removeAll(m_element->linkedElements().first()); if(!m_element->isFree()) elmt_list.removeAll(m_element->linkedElements().first());
@@ -294,62 +257,46 @@ QList <Element *> LinkSingleElementWidget::availableElements()
return elmt_list; return elmt_list;
} }
/** ///**
* @brief LinkSingleElementWidget::setUpCompleter // * @brief LinkSingleElementWidget::setUpCompleter
* Setup the completer of search_field // * Setup the completer of search_field
*/ // */
void LinkSingleElementWidget::setUpCompleter() //void LinkSingleElementWidget::setUpCompleter()
{ //{
if (search_field) // ui->m_search_field->clear();
{ // if(ui->m_search_field->completer())
search_field -> clear(); // delete ui->m_search_field->completer();
delete search_field -> completer();
QStringList filter = esw_->filter(); // QStringList filter;
filter.sort(); // foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys())
QCompleter *comp = new QCompleter(filter, search_field); // {
comp -> setCaseSensitivity(Qt::CaseInsensitive); // filter << qtwi->data(0, Qt::DisplayRole).toString();
search_field -> setCompleter(comp); // filter << qtwi->data(1, Qt::DisplayRole).toString();
} // }
} // QCompleter *c = new QCompleter(filter, ui->m_search_field);
// c->setCaseSensitivity(Qt::CaseInsensitive);
// ui->m_search_field->setCompleter(c);
//}
/** /**
* @brief LinkSingleElementWidget::setNewList * @brief LinkSingleElementWidget::clearTreeWidget
* Set the list according to the selected diagram in the combo_box * Clear the tree widget.
* Delete all QTreeWidget (in the tree widget and in the hash).
* Clear the hash.
*/ */
void LinkSingleElementWidget::setNewList() void LinkSingleElementWidget::clearTreeWidget()
{ {
esw_->setList(availableElements()); while(ui->m_tree_widget->topLevelItemCount())
buildSearchField(); {
QTreeWidgetItem *qtwi = ui->m_tree_widget->takeTopLevelItem(0);
if (!m_qtwi_elmt_hash.contains(qtwi))
delete qtwi;
} }
/** foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys())
* @brief LinkSingleElementWidget::unlinkClicked delete qtwi;
* Action when 'unlink' button is clicked
*/
void LinkSingleElementWidget::unlinkClicked()
{
ui->m_unlink_widget->hide();
unlink_ = true;
setNewList();
}
/** m_qtwi_elmt_hash.clear();
* @brief FolioReportProperties::on_button_this_clicked
* Action when push button "this report" is clicked
*/
void LinkSingleElementWidget::on_button_this_clicked() {
esw_->showElement(m_element);
}
/**
* @brief FolioReportProperties::on_button_linked_clicked
* Action when push button "linked report" is clicked
*/
void LinkSingleElementWidget::on_button_linked_clicked()
{
if (m_element->isFree()) return;
esw_->showElement(m_element->linkedElements().first());
} }
/** /**
@@ -359,9 +306,147 @@ void LinkSingleElementWidget::on_button_linked_clicked()
*/ */
void LinkSingleElementWidget::diagramWasRemovedFromProject() void LinkSingleElementWidget::diagramWasRemovedFromProject()
{ {
diagram_list.clear();
diagram_list << m_element->diagram()->project()->diagrams();
//We use a timer because if the removed diagram contain the master element linked to the edited element //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 //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())); QTimer::singleShot(10, this, SLOT(updateUi()));
} }
void LinkSingleElementWidget::showedElementWasDeleted()
{
m_showed_element = nullptr;
}
/**
* @brief LinkSingleElementWidget::linkTriggered
* Action linkis triggered
*/
void LinkSingleElementWidget::linkTriggered()
{
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)
{
apply();
updateUi();
}
else
{
//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;
}
}
/**
* @brief LinkSingleElementWidget::hideButtons
* Hide the button displayed when element is already linked
*/
void LinkSingleElementWidget::hideButtons()
{
ui->m_label->hide();
ui->m_unlink_pb->hide();
ui->m_show_linked_pb->hide();
ui->m_show_this_pb->hide();
}
/**
* @brief LinkSingleElementWidget::showButtons
* Show the button displayed when element is already linked
*/
void LinkSingleElementWidget::showButtons()
{
ui->m_label->show();
ui->m_unlink_pb->show();
ui->m_show_linked_pb->show();
ui->m_show_this_pb->show();
}
void LinkSingleElementWidget::on_m_unlink_pb_clicked()
{
m_unlink = true;
if(m_live_edit)
{
apply();
updateUi();
}
else
buildTree();
}
/**
* @brief LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked
* Highlight the element represented by @item
* @param item
* @param column
*/
void LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column)
{
Q_UNUSED(column);
if (m_showed_element)
{
disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
m_showed_element->setHighlighted(false);
}
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()));
}
void LinkSingleElementWidget::on_m_tree_widget_customContextMenuRequested(const QPoint &pos)
{
//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);
}
void LinkSingleElementWidget::on_m_show_linked_pb_clicked()
{
if (!m_element->isFree())
{
Element *elmt = m_element->linkedElements().first();
elmt->diagram()->showMe();
elmt->setHighlighted(true);
}
}
void LinkSingleElementWidget::on_m_show_this_pb_clicked()
{
m_show_element->trigger();
}

View File

@@ -21,10 +21,7 @@
#include "element.h" #include "element.h"
#include "abstractelementpropertieseditorwidget.h" #include "abstractelementpropertieseditorwidget.h"
class QTreeWidgetItem;
class Diagram;
class QLineEdit;
class ElementSelectorWidget;
namespace Ui { namespace Ui {
class LinkSingleElementWidget; class LinkSingleElementWidget;
@@ -56,33 +53,47 @@ class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget
public slots: public slots:
void updateUi(); void updateUi();
void buildTree();
public: public:
bool setLiveEdit(bool live_edit); bool setLiveEdit(bool live_edit);
private : private :
void enableLiveEdit();
void disableLiveEdit();
void buildList();
void buildSearchField();
QList <Element *> availableElements(); QList <Element *> availableElements();
void setUpCompleter(); // void setUpCompleter();
void clearTreeWidget();
private slots: private slots:
void setNewList();
void unlinkClicked();
void on_button_this_clicked();
void on_button_linked_clicked();
void diagramWasRemovedFromProject(); void diagramWasRemovedFromProject();
void showedElementWasDeleted();
void linkTriggered();
void hideButtons();
void showButtons();
void on_m_unlink_pb_clicked();
void on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column);
void on_m_tree_widget_customContextMenuRequested(const QPoint &pos);
void on_m_show_linked_pb_clicked();
void on_m_show_this_pb_clicked();
///Attributes
private: private:
Ui::LinkSingleElementWidget *ui; Ui::LinkSingleElementWidget *ui;
ElementSelectorWidget *esw_;
QList <Diagram *> diagram_list; bool m_unlink = false;
bool unlink_; Element::kind m_filter;
Element::kind filter_;
QLineEdit *search_field; QHash <QTreeWidgetItem*, Element*> m_qtwi_elmt_hash;
QTreeWidgetItem *m_qtwi_at_context_menu = nullptr,
*m_pending_qtwi = nullptr;
Element *m_showed_element = nullptr,
*m_element_to_link = nullptr;
QMenu *m_context_menu;
QAction *m_link_action,
*m_show_qtwi,
*m_show_element;
}; };
#endif // LINKSINGLEELEMENTWIDGET_H #endif // LINKSINGLEELEMENTWIDGET_H

View File

@@ -6,40 +6,76 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>265</width> <width>389</width>
<height>182</height> <height>442</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="main_layout"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="0" column="0">
<layout class="QVBoxLayout" name="header_layout"> <widget class="QLabel" name="m_label">
<item>
<widget class="QWidget" name="m_unlink_widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Cet élément est déjà lié</string> <string>Cet élément est déjà lié</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0" colspan="3">
<spacer name="horizontalSpacer_2"> <widget class="QTreeWidget" name="m_tree_widget">
<property name="orientation"> <property name="indentation">
<enum>Qt::Horizontal</enum> <number>5</number>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sortingEnabled">
<size> <bool>true</bool>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> <column>
<property name="text">
<string>Label</string>
</property>
</column>
<column>
<property name="text">
<string>Commentaire</string>
</property>
</column>
<column>
<property name="text">
<string>N° de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Label de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Titre de folio</string>
</property>
</column>
<column>
<property name="text">
<string>Position</string>
</property>
</column>
</widget>
</item> </item>
<item> <item row="1" column="2">
<widget class="QPushButton" name="m_show_this_pb">
<property name="text">
<string>Voir cette élément</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="m_show_linked_pb">
<property name="text">
<string>Voir l'élément lié</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="m_unlink_pb"> <widget class="QPushButton" name="m_unlink_pb">
<property name="text"> <property name="text">
<string>Délier</string> <string>Délier</string>
@@ -48,55 +84,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Rechercher dans le folio :</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="folio_combo_box"/>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="content_layout"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="button_this">
<property name="text">
<string>Voir cet élément</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_linked">
<property name="text">
<string>Voir l'élément lié</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@@ -53,6 +53,9 @@
<height>32</height> <height>32</height>
</size> </size>
</property> </property>
<property name="indentation">
<number>5</number>
</property>
<property name="uniformRowHeights"> <property name="uniformRowHeights">
<bool>true</bool> <bool>true</bool>
</property> </property>
@@ -103,6 +106,9 @@
<height>32</height> <height>32</height>
</size> </size>
</property> </property>
<property name="indentation">
<number>5</number>
</property>
<property name="uniformRowHeights"> <property name="uniformRowHeights">
<bool>true</bool> <bool>true</bool>
</property> </property>