mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Merge and clean Stromie patch : feature set xref slave position
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "xrefproperties.h"
|
#include "xrefproperties.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief XRefProperties::XRefProperties
|
* @brief XRefProperties::XRefProperties
|
||||||
@@ -31,6 +32,7 @@ XRefProperties::XRefProperties()
|
|||||||
m_master_label = "%f-%l%c";
|
m_master_label = "%f-%l%c";
|
||||||
m_slave_label = "(%f-%l%c)";
|
m_slave_label = "(%f-%l%c)";
|
||||||
m_offset = 0;
|
m_offset = 0;
|
||||||
|
m_xref_pos = Qt::AlignBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +53,11 @@ void XRefProperties::toSettings(QSettings &settings, const QString prefix) const
|
|||||||
settings.setValue(prefix + "master_label", master_label);
|
settings.setValue(prefix + "master_label", master_label);
|
||||||
QString slave_label = m_slave_label;
|
QString slave_label = m_slave_label;
|
||||||
settings.setValue(prefix + "slave_label", slave_label);
|
settings.setValue(prefix + "slave_label", slave_label);
|
||||||
|
|
||||||
|
|
||||||
|
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||||
|
settings.setValue(prefix + "xrefpos", var.valueToKey(m_xref_pos));
|
||||||
|
|
||||||
foreach (QString key, m_prefix.keys()) {
|
foreach (QString key, m_prefix.keys()) {
|
||||||
settings.setValue(prefix + key + "prefix", m_prefix.value(key));
|
settings.setValue(prefix + key + "prefix", m_prefix.value(key));
|
||||||
}
|
}
|
||||||
@@ -71,6 +78,10 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi
|
|||||||
m_offset = settings.value(prefix + "offset", "0").toInt();
|
m_offset = settings.value(prefix + "offset", "0").toInt();
|
||||||
m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
|
m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
|
||||||
m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
|
m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
|
||||||
|
|
||||||
|
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||||
|
m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix + "xrefpos").toString()).toStdString().data()));
|
||||||
|
|
||||||
foreach (QString key, m_prefix_keys) {
|
foreach (QString key, m_prefix_keys) {
|
||||||
m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
|
m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
|
||||||
}
|
}
|
||||||
@@ -87,6 +98,12 @@ void XRefProperties::toXml(QDomElement &xml_element) const {
|
|||||||
xml_element.setAttribute("displayhas", display);
|
xml_element.setAttribute("displayhas", display);
|
||||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||||
xml_element.setAttribute("snapto", snap);
|
xml_element.setAttribute("snapto", snap);
|
||||||
|
|
||||||
|
QString xrefpos;
|
||||||
|
|
||||||
|
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||||
|
xml_element.setAttribute("xrefpos", var.valueToKey(m_xref_pos));
|
||||||
|
|
||||||
int offset = m_offset;
|
int offset = m_offset;
|
||||||
xml_element.setAttribute("offset", QString::number(offset));
|
xml_element.setAttribute("offset", QString::number(offset));
|
||||||
QString master_label = m_master_label;
|
QString master_label = m_master_label;
|
||||||
@@ -109,6 +126,16 @@ void XRefProperties::fromXml(const QDomElement &xml_element) {
|
|||||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||||
QString snap = xml_element.attribute("snapto", "label");
|
QString snap = xml_element.attribute("snapto", "label");
|
||||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||||
|
|
||||||
|
QString xrefpos = xml_element.attribute("xrefpos","Left");
|
||||||
|
|
||||||
|
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||||
|
|
||||||
|
if(xml_element.hasAttribute("xrefpos"))
|
||||||
|
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xml_element.attribute("xrefpos").toStdString().data()));
|
||||||
|
else
|
||||||
|
m_xref_pos = Qt::AlignBottom;
|
||||||
|
|
||||||
m_offset = xml_element.attribute("offset", "0").toInt();
|
m_offset = xml_element.attribute("offset", "0").toInt();
|
||||||
m_master_label = xml_element.attribute("master_label", "%f-%l%c");
|
m_master_label = xml_element.attribute("master_label", "%f-%l%c");
|
||||||
m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)");
|
m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)");
|
||||||
@@ -149,8 +176,8 @@ bool XRefProperties::operator ==(const XRefProperties &xrp) const{
|
|||||||
m_snap_to == xrp.m_snap_to &&
|
m_snap_to == xrp.m_snap_to &&
|
||||||
m_prefix == xrp.m_prefix &&
|
m_prefix == xrp.m_prefix &&
|
||||||
m_master_label == xrp.m_master_label &&
|
m_master_label == xrp.m_master_label &&
|
||||||
m_slave_label == xrp.m_slave_label &&
|
m_offset == xrp.m_offset &&
|
||||||
m_offset == xrp.m_offset);
|
m_xref_pos == xrp.m_xref_pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XRefProperties::operator !=(const XRefProperties &xrp) const {
|
bool XRefProperties::operator !=(const XRefProperties &xrp) const {
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ class XRefProperties : public PropertiesInterface
|
|||||||
void setSnapTo (const SnapTo st) {m_snap_to = st;}
|
void setSnapTo (const SnapTo st) {m_snap_to = st;}
|
||||||
SnapTo snapTo () const {return m_snap_to;}
|
SnapTo snapTo () const {return m_snap_to;}
|
||||||
|
|
||||||
|
void setXrefPos(const Qt::AlignmentFlag xref) {m_xref_pos = xref;}
|
||||||
|
Qt::AlignmentFlag getXrefPos() const {return m_xref_pos;}
|
||||||
void setPrefix (const QString &key, const QString &value) {m_prefix.insert(key, value);}
|
void setPrefix (const QString &key, const QString &value) {m_prefix.insert(key, value);}
|
||||||
QString prefix (const QString &key) const {return m_prefix.value(key);}
|
QString prefix (const QString &key) const {return m_prefix.value(key);}
|
||||||
|
|
||||||
@@ -75,6 +77,7 @@ class XRefProperties : public PropertiesInterface
|
|||||||
bool m_show_power_ctc;
|
bool m_show_power_ctc;
|
||||||
DisplayHas m_display;
|
DisplayHas m_display;
|
||||||
SnapTo m_snap_to;
|
SnapTo m_snap_to;
|
||||||
|
Qt::AlignmentFlag m_xref_pos;
|
||||||
QHash <QString, QString> m_prefix;
|
QHash <QString, QString> m_prefix;
|
||||||
QStringList m_prefix_keys;
|
QStringList m_prefix_keys;
|
||||||
QString m_master_label;
|
QString m_master_label;
|
||||||
|
|||||||
@@ -1287,11 +1287,7 @@ void DynamicElementTextItem::updateXref()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_slave_Xref_item->setPlainText(xref_label);
|
m_slave_Xref_item->setPlainText(xref_label);
|
||||||
|
setXref_item(xrp.getXrefPos());
|
||||||
QRectF r = boundingRect();
|
|
||||||
QPointF pos(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,
|
|
||||||
r.bottom());
|
|
||||||
m_slave_Xref_item->setPos(pos);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1316,7 +1312,8 @@ void DynamicElementTextItem::setPlainText(const QString &text)
|
|||||||
{
|
{
|
||||||
if (toPlainText() == text)
|
if (toPlainText() == text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
bool update_alignment = true;
|
bool update_alignment = true;
|
||||||
if (diagram() && (diagram()->project()->state() == QETProject::ProjectParsingRunning))
|
if (diagram() && (diagram()->project()->state() == QETProject::ProjectParsingRunning))
|
||||||
update_alignment = false;
|
update_alignment = false;
|
||||||
@@ -1352,10 +1349,9 @@ void DynamicElementTextItem::setPlainText(const QString &text)
|
|||||||
}
|
}
|
||||||
else if (m_slave_Xref_item)
|
else if (m_slave_Xref_item)
|
||||||
{
|
{
|
||||||
QRectF r = boundingRect();
|
|
||||||
QPointF pos(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,
|
XRefProperties xrp = diagram()->project()->defaultXRefProperties(m_master_element.data()->kindInformations()["type"].toString());
|
||||||
r.bottom());
|
setXref_item(xrp.getXrefPos());
|
||||||
m_slave_Xref_item->setPos(pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1365,3 +1361,49 @@ void DynamicElementTextItem::setTextWidth(qreal width)
|
|||||||
m_text_width = width;
|
m_text_width = width;
|
||||||
emit textWidthChanged(width);
|
emit textWidthChanged(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DynamicElementTextItem::setXref_item(Qt::AlignmentFlag m_exHrefPos)
|
||||||
|
{
|
||||||
|
QRectF r = boundingRect();
|
||||||
|
QPointF pos;
|
||||||
|
//QPointF pos(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,r.top());
|
||||||
|
if (m_exHrefPos == Qt::AlignBottom)
|
||||||
|
{
|
||||||
|
pos = QPointF(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,r.bottom());
|
||||||
|
}
|
||||||
|
else if (m_exHrefPos == Qt::AlignTop)
|
||||||
|
{
|
||||||
|
pos = QPointF(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,r.top() - m_slave_Xref_item->boundingRect().height());
|
||||||
|
}
|
||||||
|
else if (m_exHrefPos == Qt::AlignLeft) //
|
||||||
|
{
|
||||||
|
pos = QPointF(r.left() - m_slave_Xref_item->boundingRect().width(),r.center().y() - m_slave_Xref_item->boundingRect().height()/2);
|
||||||
|
}
|
||||||
|
else if (m_exHrefPos == Qt::AlignRight) //
|
||||||
|
{
|
||||||
|
pos = QPointF(r.right() ,r.center().y() - m_slave_Xref_item->boundingRect().height()/2);
|
||||||
|
}
|
||||||
|
else if (m_exHrefPos == Qt::AlignBaseline) //
|
||||||
|
{
|
||||||
|
if(this->alignment() &Qt::AlignBottom)
|
||||||
|
{
|
||||||
|
pos = QPointF(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,r.bottom());
|
||||||
|
}
|
||||||
|
else if(this->alignment() &Qt::AlignTop)
|
||||||
|
{
|
||||||
|
pos = QPointF(r.center().x() - m_slave_Xref_item->boundingRect().width()/2,r.top() - m_slave_Xref_item->boundingRect().height());
|
||||||
|
}
|
||||||
|
else if(this->alignment() &Qt::AlignLeft)
|
||||||
|
{
|
||||||
|
pos = QPointF(r.left() - m_slave_Xref_item->boundingRect().width(),r.center().y() - m_slave_Xref_item->boundingRect().height()/2);
|
||||||
|
}
|
||||||
|
else if(this->alignment() &Qt::AlignRight)
|
||||||
|
{
|
||||||
|
pos = QPointF(r.right() ,r.center().y() - m_slave_Xref_item->boundingRect().height()/2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_slave_Xref_item->setPos(pos);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#define DYNAMICELEMENTTEXTITEM_H
|
#define DYNAMICELEMENTTEXTITEM_H
|
||||||
|
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
|
#include "xrefproperties.h"
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@@ -90,7 +91,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
|||||||
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
void setTextFrom (DynamicElementTextItem::TextFrom text_from);
|
||||||
QString text() const;
|
QString text() const;
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
static QString xmlTaggName() {return QString("dynamic_elmt_text");}
|
static QString xmlTaggName() {return QString("dynamic_elmt_text");}
|
||||||
void setInfoName(const QString &info_name);
|
void setInfoName(const QString &info_name);
|
||||||
QString infoName() const;
|
QString infoName() const;
|
||||||
void setCompositeText(const QString &text);
|
void setCompositeText(const QString &text);
|
||||||
@@ -101,6 +102,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
|||||||
void updateXref();
|
void updateXref();
|
||||||
void setPlainText(const QString &text);
|
void setPlainText(const QString &text);
|
||||||
void setTextWidth(qreal width);
|
void setTextWidth(qreal width);
|
||||||
|
void setXref_item(Qt::AlignmentFlag m_exHrefPos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include "ui_xrefpropertieswidget.h"
|
#include "ui_xrefpropertieswidget.h"
|
||||||
#include "qdebug.h"
|
#include "qdebug.h"
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief XRefPropertiesWidget::XRefPropertiesWidget
|
* @brief XRefPropertiesWidget::XRefPropertiesWidget
|
||||||
@@ -100,6 +101,11 @@ void XRefPropertiesWidget::buildUi()
|
|||||||
ui -> m_snap_to_cb -> addItem(tr("En bas de page"), "bottom");
|
ui -> m_snap_to_cb -> addItem(tr("En bas de page"), "bottom");
|
||||||
ui -> m_snap_to_cb -> addItem(tr("Sous le label de l'élément"), "label");
|
ui -> m_snap_to_cb -> addItem(tr("Sous le label de l'élément"), "label");
|
||||||
|
|
||||||
|
ui -> m_xrefpos_cb -> addItem(tr("Top"),"top");
|
||||||
|
ui -> m_xrefpos_cb -> addItem(tr("Bottom"),"bottom");
|
||||||
|
ui -> m_xrefpos_cb -> addItem(tr("Left"),"left");
|
||||||
|
ui -> m_xrefpos_cb -> addItem(tr("Rigth"),"right");
|
||||||
|
ui -> m_xrefpos_cb -> addItem(tr("Text alignment"),"alignment");
|
||||||
m_previous_type_index = ui -> m_type_cb -> currentIndex();
|
m_previous_type_index = ui -> m_type_cb -> currentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +123,16 @@ void XRefPropertiesWidget::saveProperties(int index) {
|
|||||||
if (ui->m_snap_to_cb->itemData(ui->m_snap_to_cb->currentIndex()).toString() == "bottom")
|
if (ui->m_snap_to_cb->itemData(ui->m_snap_to_cb->currentIndex()).toString() == "bottom")
|
||||||
xrp.setSnapTo(XRefProperties::Bottom);
|
xrp.setSnapTo(XRefProperties::Bottom);
|
||||||
else xrp.setSnapTo(XRefProperties::Label);
|
else xrp.setSnapTo(XRefProperties::Label);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(ui->m_xrefpos_cb->itemData(ui->m_xrefpos_cb->currentIndex()).toString() == "bottom") xrp.setXrefPos(Qt::AlignBottom);
|
||||||
|
else if(ui->m_xrefpos_cb->itemData(ui->m_xrefpos_cb->currentIndex()).toString() == "top") xrp.setXrefPos(Qt::AlignTop);
|
||||||
|
else if(ui->m_xrefpos_cb->itemData(ui->m_xrefpos_cb->currentIndex()).toString() == "left") xrp.setXrefPos(Qt::AlignLeft);
|
||||||
|
else if(ui->m_xrefpos_cb->itemData(ui->m_xrefpos_cb->currentIndex()).toString() == "right") xrp.setXrefPos(Qt::AlignRight);
|
||||||
|
else if(ui->m_xrefpos_cb->itemData(ui->m_xrefpos_cb->currentIndex()).toString() == "alignment") xrp.setXrefPos(Qt::AlignBaseline);
|
||||||
xrp.setShowPowerContac(ui->m_show_power_cb->isChecked());
|
xrp.setShowPowerContac(ui->m_show_power_cb->isChecked());
|
||||||
xrp.setPrefix("power", ui->m_power_prefix_le->text());
|
xrp.setPrefix("power", ui->m_power_prefix_le->text());
|
||||||
xrp.setPrefix("delay", ui->m_delay_prefix_le->text());
|
xrp.setPrefix("delay", ui->m_delay_prefix_le->text());
|
||||||
@@ -161,6 +177,12 @@ void XRefPropertiesWidget::updateDisplay() {
|
|||||||
ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("label"));
|
ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("label"));
|
||||||
ui->m_offset_sb->setEnabled(false);
|
ui->m_offset_sb->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(xrp.getXrefPos() == Qt::AlignTop) ui->m_xrefpos_cb->setCurrentIndex(ui->m_xrefpos_cb->findData("top"));
|
||||||
|
else if(xrp.getXrefPos() == Qt::AlignLeft) ui->m_xrefpos_cb->setCurrentIndex(ui->m_xrefpos_cb->findData("left"));
|
||||||
|
else if(xrp.getXrefPos() == Qt::AlignRight) ui->m_xrefpos_cb->setCurrentIndex(ui->m_xrefpos_cb->findData("right"));
|
||||||
|
else if(xrp.getXrefPos() == Qt::AlignBaseline) ui->m_xrefpos_cb->setCurrentIndex(ui->m_xrefpos_cb->findData("alignment"));
|
||||||
|
else if(xrp.getXrefPos() == Qt::AlignBottom) ui->m_xrefpos_cb->setCurrentIndex(ui->m_xrefpos_cb->findData("bottom"));
|
||||||
ui->m_show_power_cb->setChecked(xrp.showPowerContact());
|
ui->m_show_power_cb->setChecked(xrp.showPowerContact());
|
||||||
ui->m_power_prefix_le-> setText(xrp.prefix("power"));
|
ui->m_power_prefix_le-> setText(xrp.prefix("power"));
|
||||||
ui->m_delay_prefix_le-> setText(xrp.prefix("delay"));
|
ui->m_delay_prefix_le-> setText(xrp.prefix("delay"));
|
||||||
|
|||||||
@@ -82,6 +82,20 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_10">
|
||||||
|
<property name="text">
|
||||||
|
<string>XRef slave position</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="m_xrefpos_cb"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
Reference in New Issue
Block a user