diff --git a/sources/ui/elementselectorwidget.cpp b/sources/ui/elementselectorwidget.cpp deleted file mode 100644 index 4b5a0b98a..000000000 --- a/sources/ui/elementselectorwidget.cpp +++ /dev/null @@ -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 . -*/ -#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 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 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 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; isetHidden(false); - } - else - content_list.at(i)->setHidden(true); - } - } -} diff --git a/sources/ui/elementselectorwidget.h b/sources/ui/elementselectorwidget.h deleted file mode 100644 index 475d29cf3..000000000 --- a/sources/ui/elementselectorwidget.h +++ /dev/null @@ -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 . -*/ -#ifndef ELEMENTSELECTORWIDGET_H -#define ELEMENTSELECTORWIDGET_H - -#include -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 elmt_list, QWidget *parent = 0); - ~ElementSelectorWidget(); - Element * selectedElement () const{return selected_element;} - void showElement(Element *elmt); - void clear(); - void setList(QList 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 elements_list; - QSignalMapper *sm_, *sm_show_; - Element *selected_element, *showed_element; - QList 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 diff --git a/sources/ui/elementselectorwidget.ui b/sources/ui/elementselectorwidget.ui deleted file mode 100644 index e0cb494bc..000000000 --- a/sources/ui/elementselectorwidget.ui +++ /dev/null @@ -1,62 +0,0 @@ - - - ElementSelectorWidget - - - - 0 - 0 - 300 - 400 - - - - - 300 - 400 - - - - Form - - - - - - true - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - - - 0 - 0 - 280 - 380 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - diff --git a/sources/ui/linksingleelementwidget.cpp b/sources/ui/linksingleelementwidget.cpp index a261bf6a9..cbbfe5f15 100644 --- a/sources/ui/linksingleelementwidget.cpp +++ b/sources/ui/linksingleelementwidget.cpp @@ -19,8 +19,10 @@ #include "ui_linksingleelementwidget.h" #include "diagram.h" #include "elementprovider.h" -#include "elementselectorwidget.h" #include "linkelementcommand.h" +#include "diagramposition.h" + +#include /** * @brief LinkSingleElementWidget::LinkSingleElementWidget @@ -32,14 +34,27 @@ */ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) : AbstractElementPropertiesEditorWidget(parent), - ui(new Ui::LinkSingleElementWidget), - esw_(nullptr), - unlink_(false), - search_field(nullptr) + ui(new Ui::LinkSingleElementWidget) { 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); } @@ -47,7 +62,15 @@ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) * @brief LinkSingleElementWidget::~LinkSingleElementWidget * 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; } @@ -58,26 +81,34 @@ LinkSingleElementWidget::~LinkSingleElementWidget() { */ void LinkSingleElementWidget::setElement(Element *element) { - if (m_element == element) return; + if (m_element == element) + return; //Remove connection of previous edited element if (m_element) { disconnect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject); 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 m_element = element; - diagram_list << m_element->diagram()->project()->diagrams(); if (m_element->linkType() & Element::Slave) - filter_ = Element::Master; + m_filter = Element::Master; 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 - filter_ = Element::Simple; + m_filter = Element::Simple; connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject); connect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection); @@ -95,6 +126,10 @@ void LinkSingleElementWidget::apply() QUndoCommand *undo = associatedUndo(); if (undo) m_element->diagram()->undoStack().push(undo); + + m_unlink = false; + m_element_to_link = nullptr; + m_pending_qtwi = nullptr; } /** @@ -104,13 +139,13 @@ void LinkSingleElementWidget::apply() */ QUndoCommand *LinkSingleElementWidget::associatedUndo() const { - if (esw_->selectedElement() || unlink_) - { - LinkElementCommand *undo = new LinkElementCommand(m_element); + LinkElementCommand *undo = new LinkElementCommand(m_element); - if (esw_->selectedElement()) - undo->setLink(esw_->selectedElement()); - else if (unlink_) + if (m_element_to_link || m_unlink) + { + if (m_element_to_link) + undo->setLink(m_element_to_link); + else if (m_unlink) undo->unlinkAll(); return undo; @@ -137,33 +172,47 @@ QString LinkSingleElementWidget::title() const */ void LinkSingleElementWidget::updateUi() { - //Fill the combo box for filter the result by folio - 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(); + m_unlink = false; //Update the behavior of link/unlink button if (m_element->isFree()) - { - ui->button_linked->setDisabled(true); - ui->m_unlink_widget->hide(); - } + hideButtons(); else - ui->m_unlink_widget->show(); + showButtons(); + + buildTree(); +} - buildSearchField(); +/** + * @brief LinkSingleElementWidget::buildTree + * Build the content of the QTreeWidget + */ +void LinkSingleElementWidget::buildTree() +{ + clearTreeWidget(); + 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 + { + 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); + } + + //setUpCompleter(); } /** @@ -173,86 +222,14 @@ void LinkSingleElementWidget::updateUi() */ 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; - - if (m_live_edit) - enableLiveEdit(); - else - disableLiveEdit(); - + 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 * @return A QList with all available element @@ -263,93 +240,63 @@ QList LinkSingleElementWidget::availableElements() { QList elmt_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; - - ElementProvider ep(m_element->diagram()->project()); - if (filter_ & Element::AllReport) - elmt_list = ep.freeElement(filter_); - else - elmt_list = ep.find(filter_); - } - //find in single diagram + 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); else - { - ElementProvider ep (diagram_list.at(i-1)); - if (filter_ & Element::AllReport) - elmt_list = ep.freeElement(filter_); - else - elmt_list = ep.find(filter_); - } - - + 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()); return elmt_list; } +///** +// * @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 filter; +// foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys()) +// { +// filter << qtwi->data(0, Qt::DisplayRole).toString(); +// 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::setUpCompleter - * Setup the completer of search_field + * @brief LinkSingleElementWidget::clearTreeWidget + * Clear the tree widget. + * Delete all QTreeWidget (in the tree widget and in the hash). + * Clear the hash. */ -void LinkSingleElementWidget::setUpCompleter() +void LinkSingleElementWidget::clearTreeWidget() { - if (search_field) + while(ui->m_tree_widget->topLevelItemCount()) { - search_field -> clear(); - delete search_field -> completer(); - - QStringList filter = esw_->filter(); - filter.sort(); - QCompleter *comp = new QCompleter(filter, search_field); - comp -> setCaseSensitivity(Qt::CaseInsensitive); - search_field -> setCompleter(comp); + QTreeWidgetItem *qtwi = ui->m_tree_widget->takeTopLevelItem(0); + if (!m_qtwi_elmt_hash.contains(qtwi)) + delete qtwi; } -} - -/** - * @brief LinkSingleElementWidget::setNewList - * Set the list according to the selected diagram in the combo_box - */ -void LinkSingleElementWidget::setNewList() -{ - esw_->setList(availableElements()); - buildSearchField(); -} - -/** - * @brief LinkSingleElementWidget::unlinkClicked - * Action when 'unlink' button is clicked - */ -void LinkSingleElementWidget::unlinkClicked() -{ - ui->m_unlink_widget->hide(); - unlink_ = true; - setNewList(); -} - -/** - * @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()); + + foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys()) + delete qtwi; + + m_qtwi_elmt_hash.clear(); } /** @@ -359,9 +306,147 @@ void LinkSingleElementWidget::on_button_linked_clicked() */ 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 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; +} + +/** + * @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(); +} diff --git a/sources/ui/linksingleelementwidget.h b/sources/ui/linksingleelementwidget.h index ef469858e..5cf6cbe97 100644 --- a/sources/ui/linksingleelementwidget.h +++ b/sources/ui/linksingleelementwidget.h @@ -21,10 +21,7 @@ #include "element.h" #include "abstractelementpropertieseditorwidget.h" - -class Diagram; -class QLineEdit; -class ElementSelectorWidget; +class QTreeWidgetItem; namespace Ui { class LinkSingleElementWidget; @@ -44,7 +41,7 @@ class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget { Q_OBJECT - ///Methods + ///Methods public: explicit LinkSingleElementWidget(Element *elmt, QWidget *parent = 0); ~LinkSingleElementWidget(); @@ -56,33 +53,47 @@ class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget public slots: void updateUi(); + void buildTree(); public: bool setLiveEdit(bool live_edit); private : - void enableLiveEdit(); - void disableLiveEdit(); - void buildList(); - void buildSearchField(); QList availableElements(); - void setUpCompleter(); +// void setUpCompleter(); + void clearTreeWidget(); private slots: - void setNewList(); - void unlinkClicked(); - void on_button_this_clicked(); - void on_button_linked_clicked(); void diagramWasRemovedFromProject(); - - ///Attributes + 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(); + private: Ui::LinkSingleElementWidget *ui; - ElementSelectorWidget *esw_; - QList diagram_list; - bool unlink_; - Element::kind filter_; - QLineEdit *search_field; + + bool m_unlink = false; + Element::kind m_filter; + + QHash 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 diff --git a/sources/ui/linksingleelementwidget.ui b/sources/ui/linksingleelementwidget.ui index 22f15d2ec..8597a37cb 100644 --- a/sources/ui/linksingleelementwidget.ui +++ b/sources/ui/linksingleelementwidget.ui @@ -6,94 +6,81 @@ 0 0 - 265 - 182 + 389 + 442 Form - - - - - - - - - - Cet élément est déjà lié - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Délier - - - - - - - - - - Rechercher dans le folio : - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + + + + + Cet élément est déjà lié + + - - + + + + 5 + + + true + + + + Label + + + + + Commentaire + + + + + N° de folio + + + + + Label de folio + + + + + Titre de folio + + + + + Position + + + - - - - - - Voir cet élément - - - - - - - Voir l'élément lié - - - - + + + + Voir cette élément + + + + + + + Voir l'élément lié + + + + + + + Délier + + diff --git a/sources/ui/masterpropertieswidget.ui b/sources/ui/masterpropertieswidget.ui index 90d052e9f..e3f33ece4 100644 --- a/sources/ui/masterpropertieswidget.ui +++ b/sources/ui/masterpropertieswidget.ui @@ -53,6 +53,9 @@ 32 + + 5 + true @@ -103,6 +106,9 @@ 32 + + 5 + true