mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-18 01:09:59 +01:00
Diagram editor : add 4 tools for edit the depth (Z value) of items.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5394 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -810,7 +810,6 @@ Terminal *CustomElement::parseTerminal(QDomElement &e) {
|
||||
else if (e.attribute("orientation") == "w") terminalo = Qet::West;
|
||||
else return(nullptr);
|
||||
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this);
|
||||
new_terminal -> setZValue(420); // valeur arbitraire pour maintenir les bornes au-dessus des champs de texte
|
||||
m_terminals << new_terminal;
|
||||
|
||||
//Sort from top to bottom and left to rigth
|
||||
|
||||
@@ -124,19 +124,27 @@ QString DiagramImageItem::name() const {
|
||||
}
|
||||
|
||||
/**
|
||||
Load the image from this xml element
|
||||
@param e xml element that define an image
|
||||
*/
|
||||
bool DiagramImageItem::fromXml(const QDomElement &e) {
|
||||
if (e.tagName() != "image") return (false);
|
||||
* @brief DiagramImageItem::fromXml
|
||||
* Load this image fro xml elemebt @e
|
||||
* @param e
|
||||
* @return true if succesfully load.
|
||||
*/
|
||||
bool DiagramImageItem::fromXml(const QDomElement &e)
|
||||
{
|
||||
if (e.tagName() != "image") {
|
||||
return (false);
|
||||
}
|
||||
|
||||
QDomNode image_node = e.firstChild();
|
||||
if (!image_node.isText()) return (false);
|
||||
if (!image_node.isText()) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
//load xml image to QByteArray
|
||||
//load xml image to QByteArray
|
||||
QByteArray array;
|
||||
array = QByteArray::fromBase64(e.text().toLatin1());
|
||||
|
||||
//Set QPixmap from the @array
|
||||
//Set QPixmap from the @array
|
||||
QPixmap pixmap;
|
||||
pixmap.loadFromData(array);
|
||||
setPixmap(pixmap);
|
||||
@@ -145,6 +153,7 @@ bool DiagramImageItem::fromXml(const QDomElement &e) {
|
||||
setRotation(e.attribute("rotation").toDouble());
|
||||
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
||||
QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||
setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
|
||||
is_movable_ = (e.attribute("is_movable").toInt());
|
||||
|
||||
return (true);
|
||||
@@ -157,10 +166,11 @@ bool DiagramImageItem::fromXml(const QDomElement &e) {
|
||||
QDomElement DiagramImageItem::toXml(QDomDocument &document) const {
|
||||
QDomElement result = document.createElement("image");
|
||||
//write some attribute
|
||||
result.setAttribute("x", QString("%1").arg(pos().x()));
|
||||
result.setAttribute("y", QString("%1").arg(pos().y()));
|
||||
result.setAttribute("rotation", QString("%1").arg(QET::correctAngle(rotation())));
|
||||
result.setAttribute("size", QString("%1").arg(scale()));
|
||||
result.setAttribute("x", QString::number(pos().x()));
|
||||
result.setAttribute("y", QString::number(pos().y()));
|
||||
result.setAttribute("z", QString::number(this->zValue()));
|
||||
result.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
|
||||
result.setAttribute("size", QString::number(scale()));
|
||||
result.setAttribute("is_movable", bool(is_movable_));
|
||||
|
||||
//write the pixmap in the xml element after he was been transformed to base64
|
||||
|
||||
@@ -421,6 +421,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
|
||||
//Position and selection.
|
||||
//We directly call setPos from QGraphicsObject, because QetGraphicsItem will snap to grid
|
||||
QGraphicsObject::setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
|
||||
setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
// orientation
|
||||
@@ -724,9 +725,10 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
||||
element.appendChild(seq);
|
||||
|
||||
// position, selection et orientation
|
||||
element.setAttribute("x", QString("%1").arg(pos().x()));
|
||||
element.setAttribute("y", QString("%1").arg(pos().y()));
|
||||
element.setAttribute("orientation", QString("%1").arg(orientation()));
|
||||
element.setAttribute("x", QString::number(pos().x()));
|
||||
element.setAttribute("y", QString::number(pos().y()));
|
||||
element.setAttribute("z", QString::number(this->zValue()));
|
||||
element.setAttribute("orientation", QString::number(orientation()));
|
||||
|
||||
/* recupere le premier id a utiliser pour les bornes de cet element */
|
||||
int id_terminal = 0;
|
||||
|
||||
@@ -44,6 +44,12 @@ QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, QGraphicsItem
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||
setAcceptHoverEvents(true);
|
||||
m_pen.setStyle(Qt::DashLine);
|
||||
//ensure handlers are always above this item
|
||||
connect(this, &QetShapeItem::zChanged, [this]()
|
||||
{
|
||||
for(QetGraphicsHandlerItem *qghi : m_handler_vector)
|
||||
qghi->setZValue(this->zValue()+1);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -356,6 +362,7 @@ QVariant QetShapeItem::itemChange(QGraphicsItem::GraphicsItemChange change, cons
|
||||
|
||||
for(QetGraphicsHandlerItem *handler : m_handler_vector)
|
||||
{
|
||||
handler->setZValue(this->zValue()+1);
|
||||
handler->setColor(Qt::blue);
|
||||
scene()->addItem(handler);
|
||||
handler->installSceneEventFilter(this);
|
||||
@@ -614,6 +621,7 @@ bool QetShapeItem::fromXml(const QDomElement &e)
|
||||
else
|
||||
foreach(QDomElement de, QET::findInDomElement(e, "points", "point"))
|
||||
m_polygon << QPointF(de.attribute("x", nullptr).toDouble(), de.attribute("y", nullptr).toDouble());
|
||||
setZValue(e.attribute("z", QString::number(this->zValue())).toDouble());
|
||||
|
||||
return (true);
|
||||
}
|
||||
@@ -656,6 +664,7 @@ QDomElement QetShapeItem::toXml(QDomDocument &document) const
|
||||
}
|
||||
result.appendChild(points);
|
||||
}
|
||||
result.setAttribute("z", QString::number(this->zValue()));
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ QColor Terminal::allowedColor = QColor(Qt::darkGreen);
|
||||
QColor Terminal::warningColor = QColor("#ff8000");
|
||||
QColor Terminal::forbiddenColor = QColor(Qt::red);
|
||||
const qreal Terminal::terminalSize = 4.0;
|
||||
const qreal Terminal::Z = 1000;
|
||||
|
||||
/**
|
||||
Methode privee pour initialiser la borne.
|
||||
@@ -68,6 +69,7 @@ void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name
|
||||
setAcceptedMouseButtons(Qt::LeftButton);
|
||||
hovered_ = false;
|
||||
setToolTip(QObject::tr("Borne", "tooltip"));
|
||||
setZValue(Z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -89,21 +89,21 @@ class Terminal : public QGraphicsObject
|
||||
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
||||
|
||||
// attributes
|
||||
// attributes
|
||||
public:
|
||||
enum { Type = UserType + 1002 };
|
||||
/// terminal length
|
||||
static const qreal terminalSize;
|
||||
|
||||
// Various static colors used for hover effects
|
||||
/// default color
|
||||
static QColor neutralColor;
|
||||
/// color for legal actions
|
||||
static QColor allowedColor;
|
||||
/// color for allowed but fuzzy or not recommended actions
|
||||
static QColor warningColor;
|
||||
/// color for forbidden actions
|
||||
static QColor forbiddenColor;
|
||||
enum { Type = UserType + 1002 };
|
||||
|
||||
static const qreal terminalSize;
|
||||
static const qreal Z;
|
||||
// Various static colors used for hover effects
|
||||
/// default color
|
||||
static QColor neutralColor;
|
||||
/// color for legal actions
|
||||
static QColor allowedColor;
|
||||
/// color for allowed but fuzzy or not recommended actions
|
||||
static QColor warningColor;
|
||||
/// color for forbidden actions
|
||||
static QColor forbiddenColor;
|
||||
|
||||
private:
|
||||
bool m_draw_help_line;
|
||||
|
||||
Reference in New Issue
Block a user