mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Link single element widget, set live edit enable.
In properties dock widget, no need to click on apply button, change are apply immediately. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3992 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
c3ab81e9c3
commit
2242ebd16a
@ -120,6 +120,7 @@ class Element : public QetGraphicsItem {
|
||||
kind link_type_;
|
||||
|
||||
signals:
|
||||
void linkedElementChanged(); //This signal is emtied when the linked elements with this element change
|
||||
void elementInfoChange(DiagramContext old_info, DiagramContext new_info);
|
||||
|
||||
//METHODS related to information
|
||||
|
@ -49,9 +49,11 @@ MasterElement::~MasterElement() {
|
||||
* For this class element must be a slave
|
||||
* @param elmt
|
||||
*/
|
||||
void MasterElement::linkToElement(Element *elmt) {
|
||||
// check if element is slave and if isn't already linked
|
||||
if (elmt->linkType() == Slave && !connected_elements.contains(elmt)) {
|
||||
void MasterElement::linkToElement(Element *elmt)
|
||||
{
|
||||
// check if element is slave and if isn't already linked
|
||||
if (elmt->linkType() == Slave && !connected_elements.contains(elmt))
|
||||
{
|
||||
connected_elements << elmt;
|
||||
elmt->linkToElement(this);
|
||||
|
||||
@ -60,6 +62,7 @@ void MasterElement::linkToElement(Element *elmt) {
|
||||
connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
|
||||
connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
|
||||
cri_ -> updateLabel();
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,12 +70,14 @@ void MasterElement::linkToElement(Element *elmt) {
|
||||
* @brief MasterElement::unlinkAllElements
|
||||
* Unlink all of the element in the QList connected_elements
|
||||
*/
|
||||
void MasterElement::unlinkAllElements() {
|
||||
// if this element is free no need to do something
|
||||
if (!isFree()) {
|
||||
foreach(Element *elmt, connected_elements) {
|
||||
void MasterElement::unlinkAllElements()
|
||||
{
|
||||
// if this element is free no need to do something
|
||||
if (!isFree())
|
||||
{
|
||||
foreach(Element *elmt, connected_elements)
|
||||
unlinkElement(elmt);
|
||||
}
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,6 +101,7 @@ void MasterElement::unlinkElement(Element *elmt)
|
||||
|
||||
cri_ -> updateLabel();
|
||||
aboutDeleteXref();
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,7 @@ void ReportElement::linkToElement(Element * elmt)
|
||||
updateLabel();
|
||||
|
||||
elmt -> linkToElement(this);
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +91,8 @@ void ReportElement::linkToElement(Element * elmt)
|
||||
*/
|
||||
void ReportElement::unlinkAllElements()
|
||||
{
|
||||
if (!isFree()){
|
||||
if (!isFree())
|
||||
{
|
||||
QList <Element *> tmp_elmt = connected_elements;
|
||||
|
||||
foreach(Element *elmt, connected_elements)
|
||||
@ -107,6 +109,7 @@ void ReportElement::unlinkAllElements()
|
||||
elmt -> setHighlighted(false);
|
||||
elmt -> unlinkAllElements();
|
||||
}
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -50,9 +50,11 @@ SlaveElement::~SlaveElement() {
|
||||
* For this class element must be a master
|
||||
* @param elmt
|
||||
*/
|
||||
void SlaveElement::linkToElement(Element *elmt) {
|
||||
// check if element is master and if isn't already linked
|
||||
if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
|
||||
void SlaveElement::linkToElement(Element *elmt)
|
||||
{
|
||||
// check if element is master and if isn't already linked
|
||||
if (elmt->linkType() == Master && !connected_elements.contains(elmt))
|
||||
{
|
||||
if(!isFree()) unlinkAllElements();
|
||||
connected_elements << elmt;
|
||||
|
||||
@ -64,6 +66,7 @@ void SlaveElement::linkToElement(Element *elmt) {
|
||||
|
||||
updateLabel();
|
||||
elmt -> linkToElement(this);
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,12 +74,14 @@ void SlaveElement::linkToElement(Element *elmt) {
|
||||
* @brief SlaveElement::unlinkAllElements
|
||||
* Unlink all of the element in the QList connected_elements
|
||||
*/
|
||||
void SlaveElement::unlinkAllElements() {
|
||||
// if this element is free no need to do something
|
||||
if (!isFree()) {
|
||||
foreach(Element *elmt, connected_elements) {
|
||||
void SlaveElement::unlinkAllElements()
|
||||
{
|
||||
// if this element is free no need to do something
|
||||
if (!isFree())
|
||||
{
|
||||
foreach(Element *elmt, connected_elements)
|
||||
unlinkElement(elmt);
|
||||
}
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,6 +108,7 @@ void SlaveElement::unlinkElement(Element *elmt)
|
||||
updateLabel();
|
||||
elmt -> unlinkElement (this) ;
|
||||
elmt -> setHighlighted (false);
|
||||
emit linkedElementChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,7 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
|
||||
{
|
||||
QGraphicsItem *item = m_diagram->selectedItems().first();
|
||||
|
||||
//Edit an element
|
||||
if (Element *elmt = dynamic_cast<Element*>(item))
|
||||
{
|
||||
if (m_edited_qgi_type == ElementQGIType && editors().size() == 1)
|
||||
@ -93,17 +94,22 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
|
||||
m_edited_qgi_type = ElementQGIType;
|
||||
addEditor(new ElementPropertiesWidget(elmt, this));
|
||||
}
|
||||
//Edit an image
|
||||
else if (DiagramImageItem *image = dynamic_cast<DiagramImageItem *>(item))
|
||||
{
|
||||
clear();
|
||||
m_edited_qgi_type = ImageQGIType;
|
||||
addEditor(new ImagePropertiesWidget(image, this));
|
||||
}
|
||||
//Unknow type, we clear the dock
|
||||
else
|
||||
clear();
|
||||
}
|
||||
else
|
||||
clear();
|
||||
|
||||
foreach(PropertiesEditorWidget *pew, editors())
|
||||
pew->setLiveEdit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,6 +107,17 @@ void ElementPropertiesWidget::reset() {
|
||||
foreach (PropertiesEditorWidget *pew, m_list_editor) pew->reset();
|
||||
}
|
||||
|
||||
bool ElementPropertiesWidget::setLiveEdit(bool live_edit)
|
||||
{
|
||||
if (m_live_edit == live_edit) return true;
|
||||
m_live_edit = live_edit;
|
||||
|
||||
foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
|
||||
aepew->setLiveEdit(m_live_edit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementPropertiesWidget::findInPanel
|
||||
* If m_element is a custom element, emit findElementRequired
|
||||
@ -158,7 +169,7 @@ void ElementPropertiesWidget::updateUi()
|
||||
qDeleteAll(m_list_editor); m_list_editor.clear();
|
||||
if(m_general_widget) delete m_general_widget; m_general_widget = nullptr;
|
||||
|
||||
//Add tab according to the element
|
||||
//Create editor according to the type of element
|
||||
switch (m_element -> linkType())
|
||||
{
|
||||
case Element::Simple:
|
||||
@ -183,9 +194,15 @@ void ElementPropertiesWidget::updateUi()
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (PropertiesEditorWidget *pew, m_list_editor) m_tab->addTab(pew, pew->title());
|
||||
//Add each editors in tab widget
|
||||
foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
|
||||
{
|
||||
aepew->setLiveEdit(m_live_edit);
|
||||
m_tab->addTab(aepew, aepew->title());
|
||||
}
|
||||
addGeneralWidget();
|
||||
|
||||
//Go to the tab, edited at the beginning of this method
|
||||
if (!tab_text.isEmpty())
|
||||
{
|
||||
for(int i=0 ; i<m_tab->count() ; ++i)
|
||||
|
@ -35,6 +35,7 @@ class ElementPropertiesWidget : public AbstractElementPropertiesEditorWidget
|
||||
void setElement(Element *element);
|
||||
void apply();
|
||||
void reset();
|
||||
bool setLiveEdit(bool live_edit);
|
||||
|
||||
public slots:
|
||||
void findInPanel ();
|
||||
|
@ -220,6 +220,12 @@ void ElementSelectorWidget::buildInterface() {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -48,14 +48,17 @@ class ElementSelectorWidget : public QWidget
|
||||
|
||||
QStringList filter () const;
|
||||
|
||||
signals:
|
||||
void elementSelected (Element *element);
|
||||
|
||||
public slots:
|
||||
void filtered(const QString &str);
|
||||
void filtered(const QString &str);
|
||||
|
||||
private:
|
||||
void buildInterface();
|
||||
void buildInterface();
|
||||
|
||||
private slots:
|
||||
void setSelectedElement (const int i) {selected_element = elements_list.at(i);}
|
||||
void setSelectedElement (const int i);
|
||||
void showElementFromList (const int i);
|
||||
void showedElementWasDeleted ();
|
||||
|
||||
|
@ -34,12 +34,12 @@ LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent)
|
||||
AbstractElementPropertiesEditorWidget(parent),
|
||||
ui(new Ui::LinkSingleElementWidget),
|
||||
esw_(0),
|
||||
unlink_widget(0),
|
||||
unlink_(false),
|
||||
search_field(0)
|
||||
search_field(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(setNewList()));
|
||||
connect(ui->m_unlink_pb, SIGNAL(clicked()), this, SLOT(unlinkClicked()));
|
||||
setElement(elmt);
|
||||
}
|
||||
|
||||
@ -59,12 +59,16 @@ LinkSingleElementWidget::~LinkSingleElementWidget() {
|
||||
void LinkSingleElementWidget::setElement(Element *element)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
//Setup the new element, connection and ui
|
||||
m_element = element;
|
||||
diagram_list << m_element->diagram()->project()->diagrams();
|
||||
|
||||
@ -76,13 +80,15 @@ void LinkSingleElementWidget::setElement(Element *element)
|
||||
filter_ = Element::Simple;
|
||||
|
||||
connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
|
||||
connect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection);
|
||||
|
||||
buildInterface();
|
||||
updateUi();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::apply
|
||||
* Apply the new property of the edited element
|
||||
* Apply the new property of the edited element by pushing
|
||||
* the associated undo command to parent project undo stack
|
||||
*/
|
||||
void LinkSingleElementWidget::apply()
|
||||
{
|
||||
@ -106,6 +112,10 @@ QUndoCommand *LinkSingleElementWidget::associatedUndo() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::title
|
||||
* @return the title used for this editor
|
||||
*/
|
||||
QString LinkSingleElementWidget::title() const
|
||||
{
|
||||
if (m_element->linkType() == Element::AllReport)
|
||||
@ -118,8 +128,73 @@ QString LinkSingleElementWidget::title() const
|
||||
* @brief LinkSingleElementWidget::updateUi
|
||||
* Update the content of this widget
|
||||
*/
|
||||
void LinkSingleElementWidget::updateUi() {
|
||||
buildInterface();
|
||||
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();
|
||||
|
||||
//Update the behavior of link/unlink button
|
||||
if (m_element->isFree())
|
||||
{
|
||||
ui->button_linked->setDisabled(true);
|
||||
ui->m_unlink_widget->hide();
|
||||
}
|
||||
else
|
||||
ui->m_unlink_widget->show();
|
||||
|
||||
buildSearchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::setLiveEdit
|
||||
* @param live_edit
|
||||
* @return
|
||||
*/
|
||||
bool LinkSingleElementWidget::setLiveEdit(bool live_edit)
|
||||
{
|
||||
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);
|
||||
connect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,38 +217,6 @@ void LinkSingleElementWidget::buildList()
|
||||
buildSearchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::buildLinkUnlinkButton
|
||||
* Build the button link or unlink according to the current edited
|
||||
* element, if is already linked with a master element or not
|
||||
*/
|
||||
void LinkSingleElementWidget::buildLinkUnlinkButton()
|
||||
{
|
||||
if (m_element->isFree())
|
||||
{
|
||||
ui->button_linked->setDisabled(true);
|
||||
if (unlink_widget)
|
||||
{
|
||||
ui->main_layout->removeWidget(unlink_widget);
|
||||
delete unlink_widget; unlink_widget = nullptr;
|
||||
}
|
||||
}
|
||||
else if (!unlink_widget)
|
||||
{
|
||||
ui->button_linked->setEnabled(true);
|
||||
unlink_widget = new QWidget(this);
|
||||
QHBoxLayout *unlink_layout = new QHBoxLayout(unlink_widget);
|
||||
QLabel *lb = new QLabel(tr("Cet élément est déjà lié."), unlink_widget);
|
||||
QPushButton *pb = new QPushButton(tr("Délier"), unlink_widget);
|
||||
connect(pb, SIGNAL(clicked()), this, SLOT(unlinkClicked()));
|
||||
unlink_layout->addWidget(lb);
|
||||
unlink_layout->addStretch();
|
||||
unlink_layout->addWidget(pb);
|
||||
ui->main_layout->insertWidget(0, unlink_widget);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::buildSearchField
|
||||
* Build a line edit for search element by they information,
|
||||
@ -182,8 +225,10 @@ void LinkSingleElementWidget::buildLinkUnlinkButton()
|
||||
void LinkSingleElementWidget::buildSearchField()
|
||||
{
|
||||
//If there isn't string to filter, we remove the search field
|
||||
if (esw_->filter().isEmpty()) {
|
||||
if (search_field) {
|
||||
if (esw_->filter().isEmpty())
|
||||
{
|
||||
if (search_field)
|
||||
{
|
||||
ui -> header_layout -> removeWidget(search_field);
|
||||
delete search_field;
|
||||
search_field = nullptr;
|
||||
@ -257,32 +302,6 @@ void LinkSingleElementWidget::setUpCompleter()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::buildInterface
|
||||
* Build the interface of this widget
|
||||
*/
|
||||
void LinkSingleElementWidget::buildInterface()
|
||||
{
|
||||
ui->folio_combo_box->blockSignals(true);
|
||||
ui->folio_combo_box->clear();
|
||||
ui->folio_combo_box->addItem(tr("Tous"));
|
||||
|
||||
//Fill the combo box for filter the result by folio
|
||||
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();
|
||||
buildLinkUnlinkButton();
|
||||
buildSearchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LinkSingleElementWidget::setNewList
|
||||
* Set the list according to the selected diagram in the combo_box
|
||||
@ -299,8 +318,7 @@ void LinkSingleElementWidget::setNewList()
|
||||
*/
|
||||
void LinkSingleElementWidget::unlinkClicked()
|
||||
{
|
||||
ui->main_layout->removeWidget(unlink_widget);
|
||||
delete unlink_widget; unlink_widget = nullptr;
|
||||
ui->m_unlink_widget->hide();
|
||||
unlink_ = true;
|
||||
setNewList();
|
||||
}
|
||||
@ -334,5 +352,5 @@ void LinkSingleElementWidget::diagramWasRemovedFromProject()
|
||||
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(buildInterface()));
|
||||
QTimer::singleShot(10, this, SLOT(updateUi()));
|
||||
}
|
||||
|
@ -53,17 +53,22 @@ class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget
|
||||
void apply();
|
||||
QUndoCommand *associatedUndo() const;
|
||||
QString title() const;
|
||||
|
||||
public slots:
|
||||
void updateUi();
|
||||
|
||||
private:
|
||||
public:
|
||||
bool setLiveEdit(bool live_edit);
|
||||
|
||||
private :
|
||||
void enableLiveEdit();
|
||||
void disableLiveEdit();
|
||||
void buildList();
|
||||
void buildLinkUnlinkButton();
|
||||
void buildSearchField();
|
||||
QList <Element *> availableElements();
|
||||
void setUpCompleter();
|
||||
|
||||
private slots:
|
||||
void buildInterface();
|
||||
void setNewList();
|
||||
void unlinkClicked();
|
||||
void on_button_this_clicked();
|
||||
@ -75,7 +80,6 @@ class LinkSingleElementWidget : public AbstractElementPropertiesEditorWidget
|
||||
Ui::LinkSingleElementWidget *ui;
|
||||
ElementSelectorWidget *esw_;
|
||||
QList <Diagram *> diagram_list;
|
||||
QWidget *unlink_widget;
|
||||
bool unlink_;
|
||||
Element::kind filter_;
|
||||
QLineEdit *search_field;
|
||||
|
@ -16,6 +16,39 @@
|
||||
<layout class="QVBoxLayout" name="main_layout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="header_layout">
|
||||
<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">
|
||||
<string>Cet élément est déjà lié</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<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="QPushButton" name="m_unlink_pb">
|
||||
<property name="text">
|
||||
<string>Délier</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
|
Loading…
x
Reference in New Issue
Block a user