Element editor : clear the event interface befor save, to avoid the save of the primitive owned by the interface.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4996 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-07-31 17:41:48 +00:00
parent ecfb49c227
commit fbae3da33f
4 changed files with 260 additions and 236 deletions

View File

@@ -35,104 +35,99 @@ class QKeyEvent;
It displays the various primitives composing the drawing of the element, the
border due to its fixed size and its hotspot.
*/
class ElementScene : public QGraphicsScene {
class ElementScene : public QGraphicsScene
{
friend class ChangePropertiesCommand;
Q_OBJECT
// enum
// enum
public:
enum Behavior { Normal, PasteArea, AddPart };
enum ItemOption {
SortByZValue = 1,
IncludeTerminals = 2,
IncludeHelperItems = 4,
Selected = 8,
NonSelected = 16,
SelectedOrNot = 24
};
enum Behavior { Normal, PasteArea, AddPart };
enum ItemOption {
SortByZValue = 1,
IncludeTerminals = 2,
IncludeHelperItems = 4,
Selected = 8,
NonSelected = 16,
SelectedOrNot = 24
};
Q_DECLARE_FLAGS(ItemOptions, ItemOption)
// constructors, destructor
// constructors, destructor
public:
ElementScene(QETElementEditor *, QObject * = 0);
virtual ~ElementScene();
ElementScene(QETElementEditor *, QObject * = 0);
virtual ~ElementScene();
private:
ElementScene(const ElementScene &);
ElementScene(const ElementScene &);
// attributes
private:
/// List of localized names
NamesList _names;
NamesList m_names_list;
/// Extra informations
QString informations_;
QString m_informations;
/// element type
QString m_elmt_type;
/// element kind info
DiagramContext m_elmt_kindInfo;
/// QGraphicsItem manager
QGIManager qgi_manager;
QGIManager m_qgi_manager;
/// Undo stack
QUndoStack undo_stack;
/**
fsi_pos (first selected item pos) : Position of the forst selected item: used
to cancel mouse movements; also used to handle movements using keybard
arrwows.
*/
QPointF fsi_pos;
QPointF moving_press_pos;
QUndoStack m_undo_stack;
/// Variables related to drawing
ESEventInterface *m_event_interface = nullptr;
Behavior behavior;
QETElementEditor *element_editor = nullptr;
Behavior m_behavior;
QETElementEditor *m_element_editor = nullptr;
/// Variables to manage the paste area on the scene
QGraphicsRectItem *paste_area_;
QRectF defined_paste_area_;
QGraphicsRectItem *m_paste_area = nullptr;
QRectF m_defined_paste_area;
/// Variables to handle copy/paste with offset
QString last_copied_;
QString m_last_copied;
/// Decorator item displayed when at least one item is selected
ElementPrimitiveDecorator *m_decorator = nullptr;
///< Size of the horizontal grid step
int x_grid;
int m_x_grid;
///< Size of the vertical grid step
int y_grid;
int m_y_grid;
// methods
public:
void setEventInterface (ESEventInterface *event_interface);
void clearEventInterface();
void setBehavior (ElementScene::Behavior);
QPointF snapToGrid(QPointF point);
void setNames(const NamesList &);
NamesList names() const;
QString informations() const;
void setInformations(const QString &);
QString elementType () const {return m_elmt_type;}
DiagramContext elementKindInfo () const {return m_elmt_kindInfo;}
virtual int xGrid() const;
virtual int yGrid() const;
virtual void setGrid(int, int);
virtual const QDomDocument toXml(bool = true);
virtual QRectF boundingRectFromXml(const QDomDocument &);
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
virtual void reset();
virtual QList<CustomElementPart *> primitives() const;
virtual QList<QGraphicsItem *> zItems(ItemOptions options = ItemOptions(SortByZValue | IncludeTerminals | SelectedOrNot)) const;
virtual ElementContent selectedContent() const;
virtual void getPasteArea(const QRectF &);
QRectF elementSceneGeometricRect () const;
bool containsTerminals() const;
QUndoStack &undoStack();
QGIManager &qgiManager();
static bool clipboardMayContainElement();
bool wasCopiedFromThisElement(const QString &);
void cut();
void copy();
QETElementEditor* editor() const;
void setNames(const NamesList &);
NamesList names() const;
QString informations() const;
void setInformations(const QString &);
QString elementType () const {return m_elmt_type;}
DiagramContext elementKindInfo () const {return m_elmt_kindInfo;}
virtual int xGrid() const;
virtual int yGrid() const;
virtual void setGrid(int, int);
virtual const QDomDocument toXml(bool = true);
virtual QRectF boundingRectFromXml(const QDomDocument &);
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
virtual void reset();
virtual QList<CustomElementPart *> primitives() const;
virtual QList<QGraphicsItem *> zItems(ItemOptions options = ItemOptions(SortByZValue | IncludeTerminals | SelectedOrNot)) const;
virtual ElementContent selectedContent() const;
virtual void getPasteArea(const QRectF &);
QRectF elementSceneGeometricRect () const;
bool containsTerminals() const;
QUndoStack &undoStack();
QGIManager &qgiManager();
static bool clipboardMayContainElement();
bool wasCopiedFromThisElement(const QString &);
void cut();
void copy();
QETElementEditor* editor() const;
protected:
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *);
@@ -145,44 +140,44 @@ class ElementScene : public QGraphicsScene {
virtual void drawForeground(QPainter *, const QRectF &);
private:
QRectF elementContentBoundingRect(const ElementContent &) const;
bool applyInformations(const QDomDocument &, QString * = 0);
ElementContent loadContent(const QDomDocument &, QString * = 0);
ElementContent addContent(const ElementContent &, QString * = 0);
ElementContent addContentAtPos(const ElementContent &, const QPointF &, QString * = 0);
void addPrimitive(QGraphicsItem *);
void initPasteArea();
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
QMutex *m_decorator_lock;
void centerElementToOrigine();
QRectF elementContentBoundingRect(const ElementContent &) const;
bool applyInformations(const QDomDocument &, QString * = 0);
ElementContent loadContent(const QDomDocument &, QString * = 0);
ElementContent addContent(const ElementContent &, QString * = 0);
ElementContent addContentAtPos(const ElementContent &, const QPointF &, QString * = 0);
void addPrimitive(QGraphicsItem *);
void initPasteArea();
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
QMutex *m_decorator_lock;
void centerElementToOrigine();
public slots:
void slot_select(const ElementContent &);
void slot_selectAll();
void slot_deselectAll();
void slot_invertSelection();
void slot_delete();
void slot_editNames();
void slot_editAuthorInformations();
void slot_editProperties();
void slot_bringForward();
void slot_raise();
void slot_lower();
void slot_sendBackward();
void managePrimitivesGroups();
void stackAction(ElementEditionCommand *);
void slot_select(const ElementContent &);
void slot_selectAll();
void slot_deselectAll();
void slot_invertSelection();
void slot_delete();
void slot_editNames();
void slot_editAuthorInformations();
void slot_editProperties();
void slot_bringForward();
void slot_raise();
void slot_lower();
void slot_sendBackward();
void managePrimitivesGroups();
void stackAction(ElementEditionCommand *);
signals:
/// Signal emitted after one or several parts were added
void partsAdded();
/// Signal emitted after one or several parts were removed
void partsRemoved();
/// Signal emitted when the zValue of one or several parts change
void partsZValueChanged();
/// Signal emitted when users have defined the copy/paste area
void pasteAreaDefined(const QRectF &);
/// Signal emitted when need zoomFit
void needZoomFit();
/// Signal emitted after one or several parts were added
void partsAdded();
/// Signal emitted after one or several parts were removed
void partsRemoved();
/// Signal emitted when the zValue of one or several parts change
void partsZValueChanged();
/// Signal emitted when users have defined the copy/paste area
void pasteAreaDefined(const QRectF &);
/// Signal emitted when need zoomFit
void needZoomFit();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
@@ -192,28 +187,28 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
@param nameslist New set of naes for the currently edited element
*/
inline void ElementScene::setNames(const NamesList &nameslist) {
_names = nameslist;
m_names_list = nameslist;
}
/**
@return the list of names of the currently edited element
*/
inline NamesList ElementScene::names() const {
return(_names);
return(m_names_list);
}
/**
@return extra informations of the currently edited element
*/
inline QString ElementScene::informations() const {
return(informations_);
return(m_informations);
}
/**
@param infos new extra information for the currently edited element
*/
inline void ElementScene::setInformations(const QString &infos) {
informations_ = infos;
m_informations = infos;
}
#endif