mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-01 17:30:52 +01:00
merge
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
@@ -16,15 +16,16 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "dynamicelementtextitem.h"
|
||||
#include "qet.h"
|
||||
#include "element.h"
|
||||
#include "qetapp.h"
|
||||
#include "diagram.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
#include "terminal.h"
|
||||
#include "conductor.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
|
||||
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
#include "../diagram.h"
|
||||
#include "../qetapp.h"
|
||||
#include "../qetgraphicsitem/conductor.h"
|
||||
#include "../qetgraphicsitem/terminal.h"
|
||||
#include "../qetinformation.h"
|
||||
#include "crossrefitem.h"
|
||||
#include "element.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
@@ -44,6 +45,7 @@ DynamicElementTextItem::DynamicElementTextItem(Element *parent_element) :
|
||||
setParentItem(parent_element);
|
||||
QSettings settings;
|
||||
setRotation(settings.value("dynamic_text_rotation", 0).toInt());
|
||||
setKeepVisualRotation(true);
|
||||
setTextWidth(settings.value("dynamic_text_widht", -1).toInt());
|
||||
connect(this, &DynamicElementTextItem::textEdited, [this](const QString &old_str, const QString &new_str)
|
||||
{
|
||||
@@ -95,6 +97,7 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
|
||||
root_element.setAttribute("frame", m_frame? "true" : "false");
|
||||
root_element.setAttribute("text_width", QString::number(m_text_width));
|
||||
root_element.setAttribute("font", font().toString());
|
||||
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
|
||||
|
||||
QMetaEnum me = textFromMetaEnum();
|
||||
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
||||
@@ -159,6 +162,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
|
||||
}
|
||||
|
||||
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
|
||||
setKeepVisualRotation(dom_elmt.attribute("keep_visual_rotation", "true") == "true"? true : false);
|
||||
|
||||
if (dom_elmt.hasAttribute("font"))
|
||||
{
|
||||
@@ -1150,13 +1154,13 @@ void DynamicElementTextItem::conductorPropertiesChanged()
|
||||
{
|
||||
if(m_text_from == ElementInfo)
|
||||
{
|
||||
if(m_info_name == "function")
|
||||
if(m_info_name == QETInformation::COND_FUNCTION)
|
||||
setPlainText(m_watched_conductor? m_watched_conductor.data()->properties().m_function : "");
|
||||
else if (m_info_name == "tension_protocol")
|
||||
else if (m_info_name == QETInformation::COND_TENSION_PROTOCOL)
|
||||
setPlainText(m_watched_conductor? m_watched_conductor.data()->properties().m_tension_protocol : "");
|
||||
else if (m_info_name == "conductor_color")
|
||||
else if (m_info_name == QETInformation::COND_COLOR)
|
||||
setPlainText(m_watched_conductor? m_watched_conductor.data()->properties().m_wire_color : "");
|
||||
else if (m_info_name == "conductor_section")
|
||||
else if (m_info_name == QETInformation::COND_SECTION)
|
||||
setPlainText(m_watched_conductor? m_watched_conductor.data()->properties().m_wire_section : "");
|
||||
}
|
||||
else if (m_text_from == CompositeText) {
|
||||
@@ -1248,6 +1252,32 @@ void DynamicElementTextItem::zoomToLinkedElement()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DynamicElementTextItem::parentElementRotationChanged
|
||||
* Called when the parent element is rotated
|
||||
*/
|
||||
void DynamicElementTextItem::parentElementRotationChanged()
|
||||
{
|
||||
if (m_parent_element && m_keep_visual_rotation)
|
||||
{
|
||||
//We temporally disconnect for not change m_visual_rotation value.
|
||||
//We don't use block signal, because rotationChanged signal is used in other place.
|
||||
disconnect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
this->setRotation(QET::correctAngle(m_visual_rotation_ref - m_parent_element->rotation(), true));
|
||||
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DynamicElementTextItem::thisRotationChanged
|
||||
* This function is called when user change the rotation of the text
|
||||
* and "keep visual rotation" is to true
|
||||
* to keep in memory the visual rotation wanted by the user.
|
||||
*/
|
||||
void DynamicElementTextItem::thisRotationChanged() {
|
||||
m_visual_rotation_ref = this->rotation() + m_parent_element->rotation();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief DynamicElementTextItem::updateXref
|
||||
Create or delete the Xref according to the current properties of the project
|
||||
@@ -1422,3 +1452,22 @@ void DynamicElementTextItem::setXref_item(Qt::AlignmentFlag m_exHrefPos)
|
||||
return;
|
||||
}
|
||||
|
||||
void DynamicElementTextItem::setKeepVisualRotation(bool set)
|
||||
{
|
||||
m_keep_visual_rotation = set;
|
||||
emit keepVisualRotationChanged(set);
|
||||
if (set) {
|
||||
m_visual_rotation_ref = this->rotation() + m_parent_element->rotation();
|
||||
connect(m_parent_element, &Element::rotationChanged, this, &DynamicElementTextItem::parentElementRotationChanged);
|
||||
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
}
|
||||
else {
|
||||
disconnect(m_parent_element, &Element::rotationChanged, this, &DynamicElementTextItem::parentElementRotationChanged);
|
||||
disconnect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
}
|
||||
}
|
||||
|
||||
bool DynamicElementTextItem::keepVisualRotation() const {
|
||||
return m_keep_visual_rotation;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user