mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
widget upadte they're content when a diagram is removed from project
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3978 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -33,13 +33,20 @@
|
|||||||
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
||||||
PropertiesEditorWidget(parent),
|
PropertiesEditorWidget(parent),
|
||||||
ui(new Ui::MasterPropertiesWidget),
|
ui(new Ui::MasterPropertiesWidget),
|
||||||
element_(elmt),
|
m_element(elmt),
|
||||||
m_showed_element (nullptr)
|
m_showed_element (nullptr),
|
||||||
|
m_project(nullptr)
|
||||||
{
|
{
|
||||||
|
if(Q_LIKELY(elmt->diagram() && elmt->diagram()->project()))
|
||||||
|
{
|
||||||
|
m_project = elmt->diagram()->project();
|
||||||
|
connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
|
||||||
|
}
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
buildInterface();
|
|
||||||
connect(ui->free_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
|
connect(ui->free_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
|
||||||
connect(ui->linked_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
|
connect(ui->linked_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
|
||||||
|
buildInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,10 +56,22 @@ MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
|
|||||||
MasterPropertiesWidget::~MasterPropertiesWidget()
|
MasterPropertiesWidget::~MasterPropertiesWidget()
|
||||||
{
|
{
|
||||||
if (m_showed_element) m_showed_element->setHighlighted(false);
|
if (m_showed_element) m_showed_element->setHighlighted(false);
|
||||||
//foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::setElement
|
||||||
|
* Set the element to be edited
|
||||||
|
* @param element
|
||||||
|
*/
|
||||||
|
void MasterPropertiesWidget::setElement(Element *element)
|
||||||
|
{
|
||||||
|
if (m_element == element) return;
|
||||||
|
if (m_showed_element) {m_showed_element->setHighlighted(false); m_showed_element = nullptr;}
|
||||||
|
m_element = element;
|
||||||
|
buildInterface();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MasterPropertiesWidget::apply
|
* @brief MasterPropertiesWidget::apply
|
||||||
* If link betwen edited element and other change,
|
* If link betwen edited element and other change,
|
||||||
@@ -62,7 +81,7 @@ MasterPropertiesWidget::~MasterPropertiesWidget()
|
|||||||
*/
|
*/
|
||||||
void MasterPropertiesWidget::apply() {
|
void MasterPropertiesWidget::apply() {
|
||||||
if (QUndoCommand *undo = associatedUndo())
|
if (QUndoCommand *undo = associatedUndo())
|
||||||
element_ -> diagram() -> undoStack().push(undo);
|
m_element -> diagram() -> undoStack().push(undo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +105,7 @@ void MasterPropertiesWidget::reset() {
|
|||||||
*/
|
*/
|
||||||
QUndoCommand* MasterPropertiesWidget::associatedUndo() const {
|
QUndoCommand* MasterPropertiesWidget::associatedUndo() const {
|
||||||
QList <Element *> to_link;
|
QList <Element *> to_link;
|
||||||
QList <Element *> linked_ = element_->linkedElements();
|
QList <Element *> linked_ = m_element->linkedElements();
|
||||||
|
|
||||||
for (int i=0; i<ui->linked_list->count(); i++) {
|
for (int i=0; i<ui->linked_list->count(); i++) {
|
||||||
to_link << lwi_hash[ui->linked_list->item(i)];
|
to_link << lwi_hash[ui->linked_list->item(i)];
|
||||||
@@ -95,7 +114,7 @@ QUndoCommand* MasterPropertiesWidget::associatedUndo() const {
|
|||||||
//If same element are find in to_link and linked, that means
|
//If same element are find in to_link and linked, that means
|
||||||
// element are already linked, so we remove element on the two list
|
// element are already linked, so we remove element on the two list
|
||||||
//if linked_ contains element at the end of the operation,
|
//if linked_ contains element at the end of the operation,
|
||||||
//that means this element must be unlinked from @element_
|
//that means this element must be unlinked from @m_element
|
||||||
foreach (Element *elmt, to_link) {
|
foreach (Element *elmt, to_link) {
|
||||||
if(linked_.contains(elmt)) {
|
if(linked_.contains(elmt)) {
|
||||||
to_link.removeAll(elmt);
|
to_link.removeAll(elmt);
|
||||||
@@ -103,20 +122,20 @@ QUndoCommand* MasterPropertiesWidget::associatedUndo() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if two list, contain element, we link and unlink @element_ with corresponding
|
// if two list, contain element, we link and unlink @m_element with corresponding
|
||||||
//undo command, and add first command for parent of the second, user see only one
|
//undo command, and add first command for parent of the second, user see only one
|
||||||
//undo command
|
//undo command
|
||||||
if (linked_.count() && to_link.count()) {
|
if (linked_.count() && to_link.count()) {
|
||||||
LinkElementsCommand *lec = new LinkElementsCommand(element_, to_link);
|
LinkElementsCommand *lec = new LinkElementsCommand(m_element, to_link);
|
||||||
new unlinkElementsCommand(element_, linked_, lec);
|
new unlinkElementsCommand(m_element, linked_, lec);
|
||||||
return lec;
|
return lec;
|
||||||
}
|
}
|
||||||
//Else do the single undo command corresponding to the link.
|
//Else do the single undo command corresponding to the link.
|
||||||
else if (to_link.count()) {
|
else if (to_link.count()) {
|
||||||
return (new LinkElementsCommand(element_, to_link));
|
return (new LinkElementsCommand(m_element, to_link));
|
||||||
}
|
}
|
||||||
else if (linked_.count()) {
|
else if (linked_.count()) {
|
||||||
return (new unlinkElementsCommand(element_, linked_));
|
return (new unlinkElementsCommand(m_element, linked_));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -127,11 +146,19 @@ QUndoCommand* MasterPropertiesWidget::associatedUndo() const {
|
|||||||
* @brief MasterPropertiesWidget::buildInterface
|
* @brief MasterPropertiesWidget::buildInterface
|
||||||
* Build the interface of the widget
|
* Build the interface of the widget
|
||||||
*/
|
*/
|
||||||
void MasterPropertiesWidget::buildInterface() {
|
void MasterPropertiesWidget::buildInterface()
|
||||||
//build the free list
|
{
|
||||||
ElementProvider elmt_prov(element_->diagram()->project());
|
ui->free_list->clear();
|
||||||
|
ui->linked_list->clear();
|
||||||
|
lwi_hash.clear();
|
||||||
|
|
||||||
foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) {
|
if (Q_UNLIKELY(!m_project)) return;
|
||||||
|
|
||||||
|
ElementProvider elmt_prov(m_project);
|
||||||
|
|
||||||
|
//Build the list of free available element
|
||||||
|
foreach(Element *elmt, elmt_prov.freeElement(Element::Slave))
|
||||||
|
{
|
||||||
//label for list widget
|
//label for list widget
|
||||||
QString widget_text;
|
QString widget_text;
|
||||||
QString title = elmt->diagram()->title();
|
QString title = elmt->diagram()->title();
|
||||||
@@ -144,8 +171,9 @@ void MasterPropertiesWidget::buildInterface() {
|
|||||||
ui->free_list->addItem(lwi_);
|
ui->free_list->addItem(lwi_);
|
||||||
}
|
}
|
||||||
|
|
||||||
//build the linked list
|
//Build the list of already linked element
|
||||||
foreach(Element *elmt, element_->linkedElements()) {
|
foreach(Element *elmt, m_element->linkedElements())
|
||||||
|
{
|
||||||
//label for list widget
|
//label for list widget
|
||||||
QString widget_text;
|
QString widget_text;
|
||||||
QString title = elmt->diagram()->title();
|
QString title = elmt->diagram()->title();
|
||||||
@@ -207,3 +235,15 @@ void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi)
|
|||||||
void MasterPropertiesWidget::showedElementWasDeleted() {
|
void MasterPropertiesWidget::showedElementWasDeleted() {
|
||||||
m_showed_element = nullptr;
|
m_showed_element = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MasterPropertiesWidget::diagramWasdeletedFromProject
|
||||||
|
* This slot is called when a diagram is removed from the parent project of edited element
|
||||||
|
* to update the content of this widget
|
||||||
|
*/
|
||||||
|
void MasterPropertiesWidget::diagramWasdeletedFromProject()
|
||||||
|
{
|
||||||
|
//We use a timer because if the removed diagram contain slave element linked to the edited element
|
||||||
|
//we must to wait for this elements be unlinked, else the linked list provide deleted elements.
|
||||||
|
QTimer::singleShot(10, this, SLOT(buildInterface()));
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
class QListWidgetItem;
|
class QListWidgetItem;
|
||||||
class Element;
|
class Element;
|
||||||
class QUndoCommand;
|
class QUndoCommand;
|
||||||
|
class QETProject;
|
||||||
|
class Diagram;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MasterPropertiesWidget;
|
class MasterPropertiesWidget;
|
||||||
@@ -44,25 +46,26 @@ class MasterPropertiesWidget : public PropertiesEditorWidget
|
|||||||
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
|
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
|
||||||
~MasterPropertiesWidget();
|
~MasterPropertiesWidget();
|
||||||
|
|
||||||
|
void setElement (Element *element);
|
||||||
void apply();
|
void apply();
|
||||||
void reset();
|
void reset();
|
||||||
QUndoCommand *associatedUndo () const;
|
QUndoCommand *associatedUndo () const;
|
||||||
QString title() const {return tr("Référence croisée (maitre)");}
|
QString title() const {return tr("Référence croisée (maitre)");}
|
||||||
|
|
||||||
private:
|
|
||||||
void buildInterface();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void buildInterface();
|
||||||
void on_link_button_clicked();
|
void on_link_button_clicked();
|
||||||
void on_unlink_button_clicked();
|
void on_unlink_button_clicked();
|
||||||
void showElementFromLWI(QListWidgetItem *lwi);
|
void showElementFromLWI(QListWidgetItem *lwi);
|
||||||
void showedElementWasDeleted ();
|
void showedElementWasDeleted ();
|
||||||
|
void diagramWasdeletedFromProject();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MasterPropertiesWidget *ui;
|
Ui::MasterPropertiesWidget *ui;
|
||||||
Element *element_;
|
Element *m_element;
|
||||||
QHash <QListWidgetItem *, Element *> lwi_hash;
|
QHash <QListWidgetItem *, Element *> lwi_hash;
|
||||||
Element *m_showed_element;
|
Element *m_showed_element;
|
||||||
|
QETProject *m_project;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MASTERPROPERTIESWIDGET_H
|
#endif // MASTERPROPERTIESWIDGET_H
|
||||||
|
|||||||
Reference in New Issue
Block a user