2018-01-26 18:49:38 +00:00
|
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2017-08-03 17:36:08 +00:00
|
|
|
|
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 DYNAMICELEMENTTEXTITEM_H
|
|
|
|
|
#define DYNAMICELEMENTTEXTITEM_H
|
|
|
|
|
|
|
|
|
|
#include "diagramtextitem.h"
|
2019-08-31 07:37:34 +02:00
|
|
|
|
#include "xrefproperties.h"
|
2018-01-19 12:17:20 +00:00
|
|
|
|
#include "element.h"
|
2017-08-03 17:36:08 +00:00
|
|
|
|
#include <QUuid>
|
2017-08-16 13:52:15 +00:00
|
|
|
|
#include <QPointer>
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
class Element;
|
2017-09-13 16:38:16 +00:00
|
|
|
|
class Conductor;
|
2017-11-27 19:43:02 +00:00
|
|
|
|
class ElementTextItemGroup;
|
2018-01-19 12:17:20 +00:00
|
|
|
|
class CrossRefItem;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief The DynamicElementTextItem class
|
|
|
|
|
This class provide a simple text field of element who can be added or removed directly from the diagram editor.
|
|
|
|
|
This text is created to compensate a big lack of the ElementTextItem : ElementTextItem can't be added or removed directly in the diagram editor
|
|
|
|
|
|
|
|
|
|
*/
|
2017-08-03 17:36:08 +00:00
|
|
|
|
class DynamicElementTextItem : public DiagramTextItem
|
|
|
|
|
{
|
2017-09-13 16:38:16 +00:00
|
|
|
|
friend class DynamicTextItemDelegate;
|
|
|
|
|
friend class CompositeTextEditDialog;
|
2018-08-23 19:41:58 +00:00
|
|
|
|
friend class Element;
|
2017-09-13 16:38:16 +00:00
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
2017-08-16 13:52:15 +00:00
|
|
|
|
Q_PROPERTY(TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged)
|
|
|
|
|
Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged)
|
|
|
|
|
Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
|
2017-11-07 18:35:26 +00:00
|
|
|
|
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
|
2018-01-26 18:49:38 +00:00
|
|
|
|
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2019-03-18 19:49:12 +00:00
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
|
enum TextFrom {
|
|
|
|
|
UserText,
|
2017-08-16 13:52:15 +00:00
|
|
|
|
ElementInfo,
|
|
|
|
|
CompositeText
|
2017-08-03 17:36:08 +00:00
|
|
|
|
};
|
2019-03-18 19:49:12 +00:00
|
|
|
|
Q_ENUM (TextFrom)
|
2017-08-03 17:36:08 +00:00
|
|
|
|
enum {Type = UserType + 1010};
|
2017-08-05 02:10:01 +00:00
|
|
|
|
int type() const override {return Type;}
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void textChanged(QString text);
|
2017-08-16 13:52:15 +00:00
|
|
|
|
void textFromChanged(DynamicElementTextItem::TextFrom text_from);
|
|
|
|
|
void infoNameChanged(QString info);
|
|
|
|
|
void compositeTextChanged(QString text);
|
2017-11-07 18:35:26 +00:00
|
|
|
|
void frameChanged(bool frame);
|
2018-01-19 12:17:20 +00:00
|
|
|
|
void plainTextChanged();
|
2018-01-26 18:49:38 +00:00
|
|
|
|
void textWidthChanged(qreal width);
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DynamicElementTextItem(Element *parent_element);
|
2017-08-05 02:10:01 +00:00
|
|
|
|
~DynamicElementTextItem() override;
|
2017-09-25 17:44:02 +00:00
|
|
|
|
static QMetaEnum textFromMetaEnum();
|
2017-08-03 17:36:08 +00:00
|
|
|
|
private:
|
2017-09-25 17:44:02 +00:00
|
|
|
|
DynamicElementTextItem ();
|
2017-08-03 17:36:08 +00:00
|
|
|
|
DynamicElementTextItem(const DynamicElementTextItem &);
|
|
|
|
|
|
|
|
|
|
public:
|
2017-08-05 02:10:01 +00:00
|
|
|
|
QDomElement toXml(QDomDocument &dom_doc) const override;
|
|
|
|
|
void fromXml(const QDomElement &dom_elmt) override;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
2017-08-22 18:27:23 +00:00
|
|
|
|
Element *parentElement() const;
|
2017-11-27 19:43:02 +00:00
|
|
|
|
ElementTextItemGroup *parentGroup() const;
|
2017-08-29 14:54:27 +00:00
|
|
|
|
Element *elementUseForInfo() const;
|
2017-10-26 17:12:49 +00:00
|
|
|
|
void refreshLabelConnection();
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
DynamicElementTextItem::TextFrom textFrom() const;
|
|
|
|
|
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
|
|
|
|
QString text() const;
|
|
|
|
|
void setText(const QString &text);
|
2020-04-17 18:40:28 +02:00
|
|
|
|
static QString xmlTagName() {return QString("dynamic_elmt_text");}
|
2017-08-06 10:18:33 +00:00
|
|
|
|
void setInfoName(const QString &info_name);
|
|
|
|
|
QString infoName() const;
|
2017-08-16 13:52:15 +00:00
|
|
|
|
void setCompositeText(const QString &text);
|
|
|
|
|
QString compositeText() const;
|
2017-11-07 18:35:26 +00:00
|
|
|
|
void setFrame(const bool frame);
|
|
|
|
|
bool frame() const;
|
2017-11-27 19:43:02 +00:00
|
|
|
|
QUuid uuid() const;
|
2018-01-19 12:17:20 +00:00
|
|
|
|
void updateXref();
|
|
|
|
|
void setPlainText(const QString &text);
|
2018-01-26 18:49:38 +00:00
|
|
|
|
void setTextWidth(qreal width);
|
2019-08-31 07:37:34 +02:00
|
|
|
|
void setXref_item(Qt::AlignmentFlag m_exHrefPos);
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
2017-09-13 16:38:16 +00:00
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
2017-08-05 02:10:01 +00:00
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
2017-08-29 14:54:27 +00:00
|
|
|
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
2017-09-13 16:38:16 +00:00
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
|
2017-11-07 18:35:26 +00:00
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
2018-01-19 12:17:20 +00:00
|
|
|
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
|
|
|
|
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
2017-08-06 10:18:33 +00:00
|
|
|
|
private:
|
|
|
|
|
void elementInfoChanged();
|
2017-08-29 14:54:27 +00:00
|
|
|
|
void masterChanged();
|
2017-09-13 16:38:16 +00:00
|
|
|
|
void reportChanged();
|
|
|
|
|
void reportFormulaChanged();
|
|
|
|
|
void setConnectionForReportFormula(const QString &formula);
|
|
|
|
|
void removeConnectionForReportFormula(const QString &formula);
|
2017-10-26 17:12:49 +00:00
|
|
|
|
void setupFormulaConnection();
|
|
|
|
|
void clearFormulaConnection();
|
2017-09-13 16:38:16 +00:00
|
|
|
|
void updateReportFormulaConnection();
|
|
|
|
|
void updateReportText();
|
2017-10-26 17:12:49 +00:00
|
|
|
|
void updateLabel();
|
2017-09-13 16:38:16 +00:00
|
|
|
|
void conductorWasAdded(Conductor *conductor);
|
|
|
|
|
void conductorWasRemoved(Conductor *conductor);
|
|
|
|
|
void setPotentialConductor();
|
|
|
|
|
void conductorPropertiesChanged();
|
|
|
|
|
QString reportReplacedCompositeText() const;
|
2018-01-19 12:17:20 +00:00
|
|
|
|
void zoomToLinkedElement();
|
2018-05-11 18:14:41 +00:00
|
|
|
|
|
2017-08-06 10:18:33 +00:00
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
|
private:
|
2017-08-29 14:54:27 +00:00
|
|
|
|
QPointer <Element> m_parent_element,
|
2017-09-13 16:38:16 +00:00
|
|
|
|
m_master_element,
|
|
|
|
|
m_other_report;
|
|
|
|
|
QPointer <Conductor> m_watched_conductor;
|
2017-12-13 21:15:05 +00:00
|
|
|
|
QString m_text,
|
2017-08-16 13:52:15 +00:00
|
|
|
|
m_info_name,
|
2017-09-13 16:38:16 +00:00
|
|
|
|
m_composite_text,
|
|
|
|
|
m_report_formula,
|
|
|
|
|
m_F_str;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
DynamicElementTextItem::TextFrom m_text_from = UserText;
|
2017-09-13 16:38:16 +00:00
|
|
|
|
QUuid m_uuid;
|
|
|
|
|
QMetaObject::Connection m_report_formula_con;
|
2018-01-19 12:17:20 +00:00
|
|
|
|
QList<QMetaObject::Connection> m_formula_connection,
|
|
|
|
|
m_update_slave_Xref_connection;
|
2017-09-13 16:38:16 +00:00
|
|
|
|
QColor m_user_color;
|
2018-01-19 12:17:20 +00:00
|
|
|
|
bool m_frame = false,
|
|
|
|
|
m_first_scene_change = true;
|
|
|
|
|
CrossRefItem *m_Xref_item = nullptr;
|
|
|
|
|
QGraphicsTextItem *m_slave_Xref_item = nullptr;
|
2018-01-26 18:49:38 +00:00
|
|
|
|
qreal m_text_width = -1;
|
2018-01-28 11:16:09 +00:00
|
|
|
|
QPointF m_initial_position;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // DYNAMICELEMENTTEXTITEM_H
|