mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Element info widget : enable the use of live edit mode
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3996 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
1
dev_doc/ID_of_QUndoCommand.txt
Executable file
1
dev_doc/ID_of_QUndoCommand.txt
Executable file
@@ -0,0 +1 @@
|
|||||||
|
ChangeElementInformationCommand = 1
|
||||||
@@ -415,7 +415,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
|||||||
uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
|
uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
|
||||||
|
|
||||||
//load informations
|
//load informations
|
||||||
element_informations_.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
|
m_element_informations.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
|
||||||
|
|
||||||
//Position and selection.
|
//Position and selection.
|
||||||
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
||||||
@@ -498,9 +498,9 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
}
|
}
|
||||||
|
|
||||||
//save information of this element
|
//save information of this element
|
||||||
if (! element_informations_.keys().isEmpty()) {
|
if (! m_element_informations.keys().isEmpty()) {
|
||||||
QDomElement infos = document.createElement("elementInformations");
|
QDomElement infos = document.createElement("elementInformations");
|
||||||
element_informations_.toXml(infos, "elementInformation");
|
m_element_informations.toXml(infos, "elementInformation");
|
||||||
element.appendChild(infos);
|
element.appendChild(infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,13 +556,15 @@ void Element::initLink(QETProject *prj)
|
|||||||
/**
|
/**
|
||||||
* @brief Element::setElementInformations
|
* @brief Element::setElementInformations
|
||||||
* Set new information for this element.
|
* Set new information for this element.
|
||||||
* This method emit @elementInfoChange
|
* If new information is different of current infotmation emit @elementInfoChange
|
||||||
* @param dc
|
* @param dc
|
||||||
*/
|
*/
|
||||||
void Element::setElementInformations(DiagramContext dc) {
|
void Element::setElementInformations(DiagramContext dc)
|
||||||
DiagramContext old_info = element_informations_;
|
{
|
||||||
element_informations_ = dc;
|
if (m_element_informations == dc) return;
|
||||||
emit elementInfoChange(old_info, element_informations_);
|
DiagramContext old_info = m_element_informations;
|
||||||
|
m_element_informations = dc;
|
||||||
|
emit elementInfoChange(old_info, m_element_informations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ class Element : public QetGraphicsItem {
|
|||||||
|
|
||||||
//METHODS related to information
|
//METHODS related to information
|
||||||
public:
|
public:
|
||||||
DiagramContext elementInformations ()const {return element_informations_;}
|
DiagramContext elementInformations ()const {return m_element_informations;}
|
||||||
DiagramContext& rElementInformations () {return element_informations_;}
|
DiagramContext& rElementInformations () {return m_element_informations;}
|
||||||
virtual void setElementInformations (DiagramContext dc);
|
virtual void setElementInformations (DiagramContext dc);
|
||||||
DiagramContext kindInformations () const {return kind_informations_;} //@kind_information_ is used to store more information
|
DiagramContext kindInformations () const {return kind_informations_;} //@kind_information_ is used to store more information
|
||||||
//about the herited class like contactelement for know
|
//about the herited class like contactelement for know
|
||||||
@@ -134,7 +134,7 @@ class Element : public QetGraphicsItem {
|
|||||||
|
|
||||||
//ATTRIBUTES
|
//ATTRIBUTES
|
||||||
protected:
|
protected:
|
||||||
DiagramContext element_informations_, kind_informations_;
|
DiagramContext m_element_informations, kind_informations_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Draw this element
|
Draw this element
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ ElementInfoPartWidget::ElementInfoPartWidget(QString key, QString translated_key
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->label_->setText(translated_key);
|
ui->label_->setText(translated_key);
|
||||||
if(key == "label") ui->checkBox->setChecked(true);
|
if(key == "label") ui->checkBox->setChecked(true);
|
||||||
|
|
||||||
|
connect(ui->line_edit, &QLineEdit::textEdited, this, &ElementInfoPartWidget::textEdited);
|
||||||
|
connect(ui->line_edit, &QLineEdit::textChanged, this, &ElementInfoPartWidget::textChanged);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ namespace Ui {
|
|||||||
class ElementInfoPartWidget;
|
class ElementInfoPartWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ElementInfoPartWidget : public QWidget {
|
class ElementInfoPartWidget : public QWidget
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
//METHODS
|
//METHODS
|
||||||
@@ -40,6 +41,10 @@ class ElementInfoPartWidget : public QWidget {
|
|||||||
void setHideShow (const bool &);
|
void setHideShow (const bool &);
|
||||||
void setFocusTolineEdit();
|
void setFocusTolineEdit();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void textEdited (const QString & text);
|
||||||
|
void textChanged(const QString & text);
|
||||||
|
|
||||||
//ATTRIBUTES
|
//ATTRIBUTES
|
||||||
private:
|
private:
|
||||||
Ui::ElementInfoPartWidget *ui;
|
Ui::ElementInfoPartWidget *ui;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) :
|
|||||||
*/
|
*/
|
||||||
ElementInfoWidget::~ElementInfoWidget()
|
ElementInfoWidget::~ElementInfoWidget()
|
||||||
{
|
{
|
||||||
qDeleteAll(eipw_list);
|
qDeleteAll(m_eipw_list);
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,9 +57,14 @@ ElementInfoWidget::~ElementInfoWidget()
|
|||||||
void ElementInfoWidget::setElement(Element *element)
|
void ElementInfoWidget::setElement(Element *element)
|
||||||
{
|
{
|
||||||
if (m_element == element) return;
|
if (m_element == element) return;
|
||||||
|
|
||||||
|
if (m_element)
|
||||||
|
disconnect(m_element, &Element::elementInfoChange, this, &ElementInfoWidget::updateUi);
|
||||||
|
|
||||||
m_element = element;
|
m_element = element;
|
||||||
m_element_info = m_element->elementInformations();
|
updateUi();
|
||||||
fillInfo();
|
|
||||||
|
connect(m_element, &Element::elementInfoChange, this, &ElementInfoWidget::updateUi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,11 +85,13 @@ void ElementInfoWidget::apply()
|
|||||||
* If no change return nullptr;
|
* If no change return nullptr;
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
QUndoCommand* ElementInfoWidget::associatedUndo() const {
|
QUndoCommand* ElementInfoWidget::associatedUndo() const
|
||||||
|
{
|
||||||
DiagramContext new_info;
|
DiagramContext new_info;
|
||||||
DiagramContext old_info = m_element -> elementInformations();
|
DiagramContext old_info = m_element -> elementInformations();
|
||||||
|
|
||||||
foreach (ElementInfoPartWidget *eipw, eipw_list) {
|
foreach (ElementInfoPartWidget *eipw, m_eipw_list)
|
||||||
|
{
|
||||||
//add value only if they're something to store
|
//add value only if they're something to store
|
||||||
if (!eipw->text().isEmpty())
|
if (!eipw->text().isEmpty())
|
||||||
new_info.addValue(eipw->key(),
|
new_info.addValue(eipw->key(),
|
||||||
@@ -92,12 +99,30 @@ QUndoCommand* ElementInfoWidget::associatedUndo() const {
|
|||||||
eipw->mustShow());
|
eipw->mustShow());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_info != new_info) {
|
if (old_info != new_info)
|
||||||
return (new ChangeElementInformationCommand(m_element, old_info, new_info));
|
return (new ChangeElementInformationCommand(m_element, old_info, new_info));
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementInfoWidget::setLiveEdit
|
||||||
|
* @param live_edit true : enable the live edit mode, false disable
|
||||||
|
* @return always true;
|
||||||
|
*/
|
||||||
|
bool ElementInfoWidget::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 ElementInfoWidget::event
|
* @brief ElementInfoWidget::event
|
||||||
* Reimplemented from QWidget::event
|
* Reimplemented from QWidget::event
|
||||||
@@ -119,38 +144,68 @@ bool ElementInfoWidget::event(QEvent *event)
|
|||||||
return(QWidget::event(event));
|
return(QWidget::event(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementInfoWidget::enableLiveEdit
|
||||||
|
* Enable the live edit mode
|
||||||
|
*/
|
||||||
|
void ElementInfoWidget::enableLiveEdit()
|
||||||
|
{
|
||||||
|
foreach (ElementInfoPartWidget *eipw, m_eipw_list)
|
||||||
|
connect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementInfoWidget::disableLiveEdit
|
||||||
|
* disable the live edit mode
|
||||||
|
*/
|
||||||
|
void ElementInfoWidget::disableLiveEdit()
|
||||||
|
{
|
||||||
|
foreach (ElementInfoPartWidget *eipw, m_eipw_list)
|
||||||
|
disconnect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementInfoWidget::buildInterface
|
* @brief ElementInfoWidget::buildInterface
|
||||||
* Build the widget
|
* Build the widget
|
||||||
*/
|
*/
|
||||||
void ElementInfoWidget::buildInterface() {
|
void ElementInfoWidget::buildInterface()
|
||||||
foreach (QString str, QETApp::elementInfoKeys()) {
|
{
|
||||||
|
foreach (QString str, QETApp::elementInfoKeys())
|
||||||
|
{
|
||||||
ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETApp::elementTranslatedInfoKey(str), this);
|
ElementInfoPartWidget *eipw = new ElementInfoPartWidget(str, QETApp::elementTranslatedInfoKey(str), this);
|
||||||
ui->scroll_vlayout->addWidget(eipw);
|
ui->scroll_vlayout->addWidget(eipw);
|
||||||
eipw_list << eipw;
|
m_eipw_list << eipw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementInfoWidget::fillInfo
|
* @brief ElementInfoWidget::updateUi
|
||||||
* fill information fetch in m_element_info to the
|
* fill information fetch in m_element_info to the
|
||||||
* corresponding line edit
|
* corresponding line edit
|
||||||
*/
|
*/
|
||||||
void ElementInfoWidget::fillInfo() {
|
void ElementInfoWidget::updateUi()
|
||||||
foreach (ElementInfoPartWidget *eipw, eipw_list) {
|
{
|
||||||
|
//We disable live edit to avoid wrong undo when we fill the line edit with new text
|
||||||
|
if (m_live_edit) disableLiveEdit();
|
||||||
|
|
||||||
eipw -> setText (m_element_info[eipw->key()].toString());
|
DiagramContext element_info = m_element->elementInformations();
|
||||||
eipw -> setShow (m_element_info.keyMustShow(eipw->key()));
|
foreach (ElementInfoPartWidget *eipw, m_eipw_list)
|
||||||
|
{
|
||||||
|
|
||||||
//If the current eipw is for label or comment and the text is empty
|
eipw -> setText (element_info[eipw->key()].toString());
|
||||||
//we force the checkbox to ckecked
|
eipw -> setShow (element_info.keyMustShow(eipw->key()));
|
||||||
|
|
||||||
|
//If the current eipw is for label or comment and the text is empty
|
||||||
|
//we force the checkbox to ckecked
|
||||||
if (eipw -> key() == "label" || eipw -> key() == "comment") {
|
if (eipw -> key() == "label" || eipw -> key() == "comment") {
|
||||||
if (m_element_info[eipw->key()].toString().isEmpty())
|
if (element_info[eipw->key()].toString().isEmpty())
|
||||||
eipw->setShow(true);
|
eipw->setShow(true);
|
||||||
}
|
}
|
||||||
else //< for other eipw we hide the checkbox
|
else //< for other eipw we hide the checkbox
|
||||||
eipw->setHideShow(true);
|
eipw->setHideShow(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_live_edit) enableLiveEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,5 +214,5 @@ void ElementInfoWidget::fillInfo() {
|
|||||||
* Set the focus to the first line edit provided by this widget
|
* Set the focus to the first line edit provided by this widget
|
||||||
*/
|
*/
|
||||||
void ElementInfoWidget::firstActivated() {
|
void ElementInfoWidget::firstActivated() {
|
||||||
eipw_list.first() -> setFocusTolineEdit();
|
m_eipw_list.first() -> setFocusTolineEdit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#define ELEMENTINFOWIDGET_H
|
#define ELEMENTINFOWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "diagramcontext.h"
|
|
||||||
#include "abstractelementpropertieseditorwidget.h"
|
#include "abstractelementpropertieseditorwidget.h"
|
||||||
|
|
||||||
class Element;
|
class Element;
|
||||||
@@ -48,13 +47,16 @@ class ElementInfoWidget : public AbstractElementPropertiesEditorWidget
|
|||||||
void apply();
|
void apply();
|
||||||
QUndoCommand *associatedUndo () const;
|
QUndoCommand *associatedUndo () const;
|
||||||
QString title() const {return tr("Informations");}
|
QString title() const {return tr("Informations");}
|
||||||
|
bool setLiveEdit(bool live_edit);
|
||||||
|
virtual void updateUi();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool event(QEvent *event);
|
virtual bool event(QEvent *event);
|
||||||
|
virtual void enableLiveEdit();
|
||||||
|
virtual void disableLiveEdit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildInterface();
|
void buildInterface();
|
||||||
void fillInfo();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void firstActivated();
|
void firstActivated();
|
||||||
@@ -62,8 +64,7 @@ class ElementInfoWidget : public AbstractElementPropertiesEditorWidget
|
|||||||
//ATTRIBUTES
|
//ATTRIBUTES
|
||||||
private:
|
private:
|
||||||
Ui::ElementInfoWidget *ui;
|
Ui::ElementInfoWidget *ui;
|
||||||
DiagramContext m_element_info;
|
QList <ElementInfoPartWidget *> m_eipw_list;
|
||||||
QList <ElementInfoPartWidget *> eipw_list;
|
|
||||||
bool m_first_activation;
|
bool m_first_activation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ ChangeElementInformationCommand::ChangeElementInformationCommand(Element *elmt,
|
|||||||
setText(QObject::tr("Modifier les informations de l'élément : %1").arg(elmt -> name()));
|
setText(QObject::tr("Modifier les informations de l'élément : %1").arg(elmt -> name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChangeElementInformationCommand::mergeWith(const QUndoCommand *other)
|
||||||
|
{
|
||||||
|
if (id() != other->id()) return false;
|
||||||
|
ChangeElementInformationCommand const *undo = static_cast<const ChangeElementInformationCommand*>(other);
|
||||||
|
if (m_element != undo->m_element) return false;
|
||||||
|
m_new_info = undo->m_new_info;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ChangeElementInformationCommand::undo
|
* @brief ChangeElementInformationCommand::undo
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ class ChangeElementInformationCommand : public QUndoCommand
|
|||||||
public:
|
public:
|
||||||
ChangeElementInformationCommand(Element *elmt, DiagramContext &old_info, DiagramContext &new_info, QUndoCommand *parent = nullptr);
|
ChangeElementInformationCommand(Element *elmt, DiagramContext &old_info, DiagramContext &new_info, QUndoCommand *parent = nullptr);
|
||||||
|
|
||||||
|
virtual int id() const {return 1;}
|
||||||
|
virtual bool mergeWith(const QUndoCommand *other);
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user