mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
element editor bug fix:
at save, if element aren't drawn at the origin point (red cross), we move element to the nearest point of origin git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2553 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -385,9 +385,17 @@ void ElementScene::setGrid(int x_g, int y_g) {
|
|||||||
representer tout l'element ou seulement les elements selectionnes
|
representer tout l'element ou seulement les elements selectionnes
|
||||||
@return un document XML decrivant l'element
|
@return un document XML decrivant l'element
|
||||||
*/
|
*/
|
||||||
const QDomDocument ElementScene::toXml(bool all_parts) const {
|
const QDomDocument ElementScene::toXml(bool all_parts) {
|
||||||
//define the size of the element by the upper multiple of 10
|
|
||||||
QRectF size= elementSceneGeometricRect();
|
QRectF size= elementSceneGeometricRect();
|
||||||
|
//if the element doesn't contains the origin point of the scene
|
||||||
|
//we move the element to the origin for solve this default before saving
|
||||||
|
if (!size.contains(0,0) && all_parts) {
|
||||||
|
centerElementToOrigine();
|
||||||
|
//recalcul the size after movement
|
||||||
|
size= elementSceneGeometricRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
//define the size of the element by the upper multiple of 10
|
||||||
int upwidth = ((qRound(size.width())/10)*10)+10;
|
int upwidth = ((qRound(size.width())/10)*10)+10;
|
||||||
if ((qRound(size.width())%10) > 6) upwidth+=10;
|
if ((qRound(size.width())%10) > 6) upwidth+=10;
|
||||||
|
|
||||||
@@ -1148,6 +1156,33 @@ bool ElementScene::zValueLessThan(QGraphicsItem *item1, QGraphicsItem *item2) {
|
|||||||
return(item1-> zValue() < item2 -> zValue());
|
return(item1-> zValue() < item2 -> zValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ElementScene::centerElementToOrigine
|
||||||
|
* try to center better is possible the element to the scene
|
||||||
|
* (the calcul isn't optimal but work good)
|
||||||
|
*/
|
||||||
|
void ElementScene::centerElementToOrigine() {
|
||||||
|
QRectF size= elementSceneGeometricRect();
|
||||||
|
int center_x = qRound(size.center().x());
|
||||||
|
int center_y = qRound(size.center().y());
|
||||||
|
|
||||||
|
//define the movement of translation
|
||||||
|
int move_x = center_x - (qRound(center_x) %10);
|
||||||
|
if (center_x < 0) move_x -= 10;
|
||||||
|
int move_y = center_y - (qRound(center_y) %10);
|
||||||
|
if (center_y < 0) move_y -= 10;
|
||||||
|
|
||||||
|
//move each primitive by @move
|
||||||
|
foreach (QGraphicsItem *qgi, items()) {
|
||||||
|
if (qgi -> type() == ElementPrimitiveDecorator::Type) continue;
|
||||||
|
if (qgi -> type() == QGraphicsRectItem::Type) continue;
|
||||||
|
//deselect item for disable decorator
|
||||||
|
qgi -> setSelected(false);
|
||||||
|
qgi -> moveBy(-(move_x), -(move_y));
|
||||||
|
}
|
||||||
|
emit (needZoomFit());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ensure the decorator is adequately shown, hidden or updated so it always
|
Ensure the decorator is adequately shown, hidden or updated so it always
|
||||||
represents the current selection.
|
represents the current selection.
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
virtual int xGrid() const;
|
virtual int xGrid() const;
|
||||||
virtual int yGrid() const;
|
virtual int yGrid() const;
|
||||||
virtual void setGrid(int, int);
|
virtual void setGrid(int, int);
|
||||||
virtual const QDomDocument toXml(bool = true) const;
|
virtual const QDomDocument toXml(bool = true);
|
||||||
virtual QRectF boundingRectFromXml(const QDomDocument &);
|
virtual QRectF boundingRectFromXml(const QDomDocument &);
|
||||||
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
|
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
@@ -159,6 +159,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
|
bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
|
||||||
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
||||||
QMutex *decorator_lock_;
|
QMutex *decorator_lock_;
|
||||||
|
void centerElementToOrigine();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_move();
|
void slot_move();
|
||||||
@@ -200,6 +201,8 @@ class ElementScene : public QGraphicsScene {
|
|||||||
void partsZValueChanged();
|
void partsZValueChanged();
|
||||||
/// Signal emitted when users have defined the copy/paste area
|
/// Signal emitted when users have defined the copy/paste area
|
||||||
void pasteAreaDefined(const QRectF &);
|
void pasteAreaDefined(const QRectF &);
|
||||||
|
/// Signal emitted when need zoomFit
|
||||||
|
void needZoomFit();
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ ElementView::ElementView(ElementScene *scene, QWidget *parent) :
|
|||||||
zoomReset();
|
zoomReset();
|
||||||
connect(scene_, SIGNAL(pasteAreaDefined(const QRectF &)), this, SLOT(pasteAreaDefined(const QRectF &)));
|
connect(scene_, SIGNAL(pasteAreaDefined(const QRectF &)), this, SLOT(pasteAreaDefined(const QRectF &)));
|
||||||
connect(scene_, SIGNAL(partsAdded()), this, SLOT(adjustSceneRect()));
|
connect(scene_, SIGNAL(partsAdded()), this, SLOT(adjustSceneRect()));
|
||||||
|
connect(scene_, SIGNAL(needZoomFit()), this, SLOT(zoomFit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
|
|||||||
Reference in New Issue
Block a user