diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index 495d07a42..2a5d88b24 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -44,16 +44,16 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : QGraphicsScene(parent), m_elmt_type("simple"), - qgi_manager(this), - element_editor(editor) + m_qgi_manager(this), + m_element_editor(editor) { - behavior = Normal; + m_behavior = Normal; setItemIndexMethod(NoIndex); setGrid(1, 1); initPasteArea(); - undo_stack.setClean(); + m_undo_stack.setClean(); m_decorator_lock = new QMutex(QMutex::NonRecursive); - connect(&undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups())); + connect(&m_undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups())); connect(this, SIGNAL(selectionChanged()), this, SLOT(managePrimitivesGroups())); } @@ -63,7 +63,7 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : ElementScene::~ElementScene() { //Disconnect to avoid crash, see bug report N° 122. - disconnect(&undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups())); + disconnect(&m_undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups())); delete m_decorator_lock; if (m_event_interface) @@ -92,10 +92,10 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { if (!(e -> modifiers() & Qt::ControlModifier)) event_pos = snapToGrid(event_pos); - if (behavior == PasteArea) { - QRectF current_rect(paste_area_ -> rect()); + if (m_behavior == PasteArea) { + QRectF current_rect(m_paste_area -> rect()); current_rect.moveCenter(event_pos); - paste_area_ -> setRect(current_rect); + m_paste_area -> setRect(current_rect); return; } @@ -135,11 +135,11 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { } } - if (behavior == PasteArea) { - defined_paste_area_ = paste_area_ -> rect(); - removeItem(paste_area_); - emit(pasteAreaDefined(defined_paste_area_)); - behavior = Normal; + if (m_behavior == PasteArea) { + m_defined_paste_area = m_paste_area -> rect(); + removeItem(m_paste_area); + emit(pasteAreaDefined(m_defined_paste_area)); + m_behavior = Normal; return; } @@ -189,8 +189,8 @@ void ElementScene::keyPressEvent(QKeyEvent *event) { */ void ElementScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - if (behavior == ElementScene::Normal) - element_editor -> contextMenu(event->screenPos()); + if (m_behavior == ElementScene::Normal) + m_element_editor -> contextMenu(event->screenPos()); } /** @@ -221,8 +221,10 @@ void ElementScene::drawForeground(QPainter *p, const QRectF &rect) { * Set a new event interface * @param interface */ -void ElementScene::setEventInterface(ESEventInterface *event_interface) { - if (m_event_interface) { +void ElementScene::setEventInterface(ESEventInterface *event_interface) +{ + if (m_event_interface) + { delete m_event_interface; //We must to re-init because previous interface //Reset his own init when deleted @@ -231,6 +233,19 @@ void ElementScene::setEventInterface(ESEventInterface *event_interface) { m_event_interface = event_interface; } +/** + * @brief ElementScene::clearEventInterface + * Clear the current event interface + */ +void ElementScene::clearEventInterface() +{ + if(m_event_interface) + { + delete m_event_interface; + m_event_interface = nullptr; + } +} + /** * @brief ElementScene::setBehavior * Modifie the current behavior of this scene @@ -238,21 +253,21 @@ void ElementScene::setEventInterface(ESEventInterface *event_interface) { */ void ElementScene::setBehavior(ElementScene::Behavior b) { - behavior = b; + m_behavior = b; } /** @return la taille horizontale de la grille */ int ElementScene::xGrid() const { - return(x_grid); + return(m_x_grid); } /** @return la taille verticale de la grille */ int ElementScene::yGrid() const { - return(y_grid); + return(m_y_grid); } /** @@ -260,8 +275,8 @@ int ElementScene::yGrid() const { @param y_g Taille verticale de la grille */ void ElementScene::setGrid(int x_g, int y_g) { - x_grid = x_g ? x_g : 1; - y_grid = y_g ? y_g : 1; + m_x_grid = x_g ? x_g : 1; + m_y_grid = y_g ? y_g : 1; } /** @@ -315,7 +330,7 @@ const QDomDocument ElementScene::toXml(bool all_parts) root.appendChild(uuid); //names of element - root.appendChild(_names.toXml(xml_document)); + root.appendChild(m_names_list.toXml(xml_document)); if (m_elmt_type == "slave" || m_elmt_type == "master") { @@ -444,14 +459,14 @@ bool ElementScene::containsTerminals() const { @return la pile d'annulations de cet editeur d'element */ QUndoStack &ElementScene::undoStack() { - return(undo_stack); + return(m_undo_stack); } /** @return le gestionnaire de QGraphicsItem de cet editeur d'element */ QGIManager &ElementScene::qgiManager() { - return(qgi_manager); + return(m_qgi_manager); } /** @@ -469,7 +484,7 @@ bool ElementScene::clipboardMayContainElement() { @return true si clipboard_content a ete copie depuis cet element. */ bool ElementScene::wasCopiedFromThisElement(const QString &clipboard_content) { - return(clipboard_content == last_copied_); + return(clipboard_content == m_last_copied); } /** @@ -501,11 +516,11 @@ void ElementScene::copy() { clipboard -> setText(clipboard_content); // retient le dernier contenu copie - last_copied_ = clipboard_content; + m_last_copied = clipboard_content; } QETElementEditor* ElementScene::editor() const { - return element_editor; + return m_element_editor; } /** @@ -553,7 +568,7 @@ void ElementScene::slot_delete() { if (selected_items.isEmpty()) return; // efface tout ce qui est selectionne - undo_stack.push(new DeletePartsCommand(this, selected_items)); + m_undo_stack.push(new DeletePartsCommand(this, selected_items)); // removing items does not trigger QGraphicsScene::selectionChanged() emit(partsRemoved()); @@ -566,10 +581,10 @@ void ElementScene::slot_delete() { sur l'auteur de l'element, sa licence, etc. */ void ElementScene::slot_editAuthorInformations() { - bool is_read_only = element_editor && element_editor -> isReadOnly(); + bool is_read_only = m_element_editor && m_element_editor -> isReadOnly(); // cree un dialogue - QDialog dialog_author(element_editor); + QDialog dialog_author(m_element_editor); dialog_author.setModal(true); #ifdef Q_OS_MAC dialog_author.setWindowFlags(Qt::Sheet); @@ -623,10 +638,10 @@ void ElementScene::slot_editProperties() { Lance un dialogue pour editer les noms de cet element */ void ElementScene::slot_editNames() { - bool is_read_only = element_editor && element_editor -> isReadOnly(); + bool is_read_only = m_element_editor && m_element_editor -> isReadOnly(); // cree un dialogue - QDialog dialog(element_editor); + QDialog dialog(m_element_editor); #ifdef Q_OS_MAC dialog.setWindowFlags(Qt::Sheet); #endif @@ -643,7 +658,7 @@ void ElementScene::slot_editNames() { // ajoute un NamesListWidget au dialogue NamesListWidget *names_widget = new NamesListWidget(); - names_widget -> setNames(_names); + names_widget -> setNames(m_names_list); names_widget -> setReadOnly(is_read_only); dialog_layout -> addWidget(names_widget); @@ -657,7 +672,7 @@ void ElementScene::slot_editNames() { // lance le dialogue if (dialog.exec() == QDialog::Accepted && !is_read_only) { NamesList new_names(names_widget -> names()); - if (new_names != _names) undoStack().push(new ChangeNamesCommand(this, _names, new_names)); + if (new_names != m_names_list) undoStack().push(new ChangeNamesCommand(this, m_names_list, new_names)); } } @@ -780,11 +795,11 @@ ElementContent ElementScene::selectedContent() const { */ void ElementScene::getPasteArea(const QRectF &to_paste) { // on le dessine sur la scene - paste_area_ -> setRect(to_paste); - addItem(paste_area_); + m_paste_area -> setRect(to_paste); + addItem(m_paste_area); // on passe la scene en mode "recherche de zone pour copier/coller" - behavior = PasteArea; + m_behavior = PasteArea; } /** @@ -846,7 +861,7 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document, QString * m_elmt_kindInfo.fromXml(root.firstChildElement("kindInformations"), "kindInformation"); //Extract names of xml definition - _names.fromXml(root); + m_names_list.fromXml(root); //extract additional informations setInformations(QString()); @@ -893,15 +908,15 @@ ElementContent ElementScene::loadContent(const QDomDocument &xml_document, QStri QDomElement qde = n.toElement(); if (qde.isNull()) continue; CustomElementPart *cep; - if (qde.tagName() == "line") cep = new PartLine (element_editor); - else if (qde.tagName() == "rect") cep = new PartRectangle(element_editor); - else if (qde.tagName() == "ellipse") cep = new PartEllipse (element_editor); - else if (qde.tagName() == "circle") cep = new PartEllipse (element_editor); - else if (qde.tagName() == "polygon") cep = new PartPolygon (element_editor); - else if (qde.tagName() == "terminal") cep = new PartTerminal (element_editor); - else if (qde.tagName() == "text") cep = new PartText (element_editor); - else if (qde.tagName() == "input") cep = new PartTextField(element_editor); - else if (qde.tagName() == "arc") cep = new PartArc (element_editor); + if (qde.tagName() == "line") cep = new PartLine (m_element_editor); + else if (qde.tagName() == "rect") cep = new PartRectangle(m_element_editor); + else if (qde.tagName() == "ellipse") cep = new PartEllipse (m_element_editor); + else if (qde.tagName() == "circle") cep = new PartEllipse (m_element_editor); + else if (qde.tagName() == "polygon") cep = new PartPolygon (m_element_editor); + else if (qde.tagName() == "terminal") cep = new PartTerminal (m_element_editor); + else if (qde.tagName() == "text") cep = new PartText (m_element_editor); + else if (qde.tagName() == "input") cep = new PartTextField(m_element_editor); + else if (qde.tagName() == "arc") cep = new PartArc (m_element_editor); else continue; if (QGraphicsItem *qgi = dynamic_cast(cep)) { if (!qgi -> zValue()) qgi -> setZValue(z++); @@ -967,8 +982,8 @@ void ElementScene::addPrimitive(QGraphicsItem *primitive) { Initialise la zone de collage */ void ElementScene::initPasteArea() { - paste_area_ = new QGraphicsRectItem(); - paste_area_ -> setZValue(1000000); + m_paste_area = new QGraphicsRectItem(); + m_paste_area -> setZValue(1000000); QPen paste_area_pen; paste_area_pen.setStyle(Qt::DashDotLine); @@ -978,8 +993,8 @@ void ElementScene::initPasteArea() { paste_area_brush.setStyle(Qt::SolidPattern); paste_area_brush.setColor(QColor(90, 167, 255, 64)); - paste_area_ -> setPen(paste_area_pen); - paste_area_ -> setBrush(paste_area_brush); + m_paste_area -> setPen(paste_area_pen); + m_paste_area -> setBrush(paste_area_brush); } /** @@ -989,8 +1004,8 @@ void ElementScene::initPasteArea() { */ QPointF ElementScene::snapToGrid(QPointF point) { - point.rx() = qRound(point.x() / x_grid) * x_grid; - point.ry() = qRound(point.y() / y_grid) * y_grid; + point.rx() = qRound(point.x() / m_x_grid) * m_x_grid; + point.ry() = qRound(point.y() / m_y_grid) * m_y_grid; return point; } diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index 91d2163bb..0211edaa5 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -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 primitives() const; - virtual QList 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 primitives() const; + virtual QList 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 diff --git a/sources/editor/qetelementeditor.cpp b/sources/editor/qetelementeditor.cpp index ced331314..f1c4574d7 100644 --- a/sources/editor/qetelementeditor.cpp +++ b/sources/editor/qetelementeditor.cpp @@ -160,8 +160,8 @@ void QETElementEditor::setupActions() { edit_author = new QAction(QET::Icons::UserInformations, tr("Éditer les informations sur l'auteur"), this); m_edit_properties = new QAction(QET::Icons::ElementEdit, tr("Éditer les propriétés de l'élément"), this); - undo = ce_scene -> undoStack().createUndoAction(this, tr("Annuler")); - redo = ce_scene -> undoStack().createRedoAction(this, tr("Refaire")); + undo = m_elmt_scene -> undoStack().createUndoAction(this, tr("Annuler")); + redo = m_elmt_scene -> undoStack().createRedoAction(this, tr("Refaire")); undo -> setIcon(QET::Icons::EditUndo); redo -> setIcon(QET::Icons::EditRedo); undo -> setShortcuts(QKeySequence::Undo); @@ -199,19 +199,19 @@ void QETElementEditor::setupActions() { connect(save_as_file, SIGNAL(triggered()), this, SLOT(slot_saveAsFile())); connect(reload, SIGNAL(triggered()), this, SLOT(slot_reload())); connect(quit, SIGNAL(triggered()), this, SLOT(close())); - connect(selectall, SIGNAL(triggered()), ce_scene, SLOT(slot_selectAll())); - connect(deselectall, SIGNAL(triggered()), ce_scene, SLOT(slot_deselectAll())); - connect(inv_select, SIGNAL(triggered()), ce_scene, SLOT(slot_invertSelection())); + connect(selectall, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_selectAll())); + connect(deselectall, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_deselectAll())); + connect(inv_select, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_invertSelection())); connect(cut, SIGNAL(triggered()), ce_view, SLOT(cut())); connect(copy, SIGNAL(triggered()), ce_view, SLOT(copy())); connect(paste, SIGNAL(triggered()), ce_view, SLOT(paste())); connect(paste_in_area, SIGNAL(triggered()), ce_view, SLOT(pasteInArea())); connect(paste_from_file, SIGNAL(triggered()), this, SLOT(pasteFromFile())); connect(paste_from_elmt, SIGNAL(triggered()), this, SLOT(pasteFromElement())); - connect(edit_delete, SIGNAL(triggered()), ce_scene, SLOT(slot_delete())); - connect(edit_names, SIGNAL(triggered()), ce_scene, SLOT(slot_editNames())); - connect(edit_author, SIGNAL(triggered()), ce_scene, SLOT(slot_editAuthorInformations())); - connect(m_edit_properties, SIGNAL(triggered()), ce_scene, SLOT(slot_editProperties())); + connect(edit_delete, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_delete())); + connect(edit_names, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_editNames())); + connect(edit_author, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_editAuthorInformations())); + connect(m_edit_properties, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_editProperties())); /* @@ -229,10 +229,10 @@ void QETElementEditor::setupActions() { edit_backward -> setShortcut(QKeySequence(tr("Ctrl+Shift+End"))); edit_forward -> setShortcut(QKeySequence(tr("Ctrl+Shift+Home"))); - connect(edit_forward, SIGNAL(triggered()), ce_scene, SLOT(slot_bringForward() )); - connect(edit_raise, SIGNAL(triggered()), ce_scene, SLOT(slot_raise() )); - connect(edit_lower, SIGNAL(triggered()), ce_scene, SLOT(slot_lower() )); - connect(edit_backward, SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward() )); + connect(edit_forward, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_bringForward() )); + connect(edit_raise, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_raise() )); + connect(edit_lower, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_lower() )); + connect(edit_backward, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_sendBackward() )); depth_toolbar = addToolBar(tr("Profondeur", "toolbar title")); depth_toolbar -> setObjectName("depth_toolbar"); @@ -264,7 +264,7 @@ void QETElementEditor::setupActions() { /* * Action related to primitive creation */ - connect (ce_scene, SIGNAL(partsAdded()), this, SLOT(UncheckAddPrimitive())); + connect (m_elmt_scene, SIGNAL(partsAdded()), this, SLOT(UncheckAddPrimitive())); parts = new QActionGroup(this); QAction *add_line = new QAction(QET::Icons::PartLine, tr("Ajouter une ligne"), parts); @@ -323,19 +323,19 @@ void QETElementEditor::setupActions() { addToolBar(Qt::TopToolBarArea, view_toolbar); addToolBar(Qt::TopToolBarArea, element_toolbar); - connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateInformations()), Qt::QueuedConnection); - connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateMenus())); + connect(m_elmt_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateInformations()), Qt::QueuedConnection); + connect(m_elmt_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateMenus())); connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slot_updateMenus())); - connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateMenus())); - connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateTitle())); + connect(&(m_elmt_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateMenus())); + connect(&(m_elmt_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateTitle())); // Annuler ou refaire une action met a jour la liste des primitives ; cela sert notamment pour les // ajouts et suppressions de primitives ainsi que pour les actions entrainant un change - connect(&(ce_scene -> undoStack()), SIGNAL(indexChanged(int)), this, SLOT(slot_updatePartsList())); + connect(&(m_elmt_scene -> undoStack()), SIGNAL(indexChanged(int)), this, SLOT(slot_updatePartsList())); // Annuler ou refaire une action met a jour les informations affichees sur les primitives selectionnees, // celles-ci etant potentiellement impactees - connect(&(ce_scene -> undoStack()), SIGNAL(indexChanged(int)), this, SLOT(slot_updateInformations())); + connect(&(m_elmt_scene -> undoStack()), SIGNAL(indexChanged(int)), this, SLOT(slot_updateInformations())); } /** @@ -429,7 +429,7 @@ void QETElementEditor::contextMenu(QPoint p) { Met a jour les menus */ void QETElementEditor::slot_updateMenus() { - bool selected_items = !read_only && !ce_scene -> selectedItems().isEmpty(); + bool selected_items = !read_only && !m_elmt_scene -> selectedItems().isEmpty(); bool clipboard_elmt = !read_only && ElementScene::clipboardMayContainElement(); // actions dependant seulement de l'etat "lecture seule" de l'editeur @@ -455,9 +455,9 @@ void QETElementEditor::slot_updateMenus() { paste_in_area -> setEnabled(clipboard_elmt); // actions dependant de l'etat de la pile d'annulation - save -> setEnabled(!read_only && !ce_scene -> undoStack().isClean()); - undo -> setEnabled(!read_only && ce_scene -> undoStack().canUndo()); - redo -> setEnabled(!read_only && ce_scene -> undoStack().canRedo()); + save -> setEnabled(!read_only && !m_elmt_scene -> undoStack().isClean()); + undo -> setEnabled(!read_only && m_elmt_scene -> undoStack().canUndo()); + redo -> setEnabled(!read_only && m_elmt_scene -> undoStack().canRedo()); } /** @@ -465,9 +465,9 @@ void QETElementEditor::slot_updateMenus() { */ void QETElementEditor::slot_updateTitle() { QString title = min_title; - title += " - " + ce_scene -> names().name() + " "; + title += " - " + m_elmt_scene -> names().name() + " "; if (!filename_.isEmpty() || !location_.isNull()) { - if (!ce_scene -> undoStack().isClean()) title += tr("[Modifié]", "window title tag"); + if (!m_elmt_scene -> undoStack().isClean()) title += tr("[Modifié]", "window title tag"); } if (isReadOnly()) title += tr(" [lecture seule]", "window title tag"); setWindowTitle(title); @@ -478,8 +478,8 @@ void QETElementEditor::slot_updateTitle() { */ void QETElementEditor::setupInterface() { // editeur - ce_scene = new ElementScene(this, this); - ce_view = new ElementView(ce_scene, this); + m_elmt_scene = new ElementScene(this, this); + ce_view = new ElementView(m_elmt_scene, this); slot_setRubberBandToView(); setCentralWidget(ce_view); @@ -523,17 +523,17 @@ void QETElementEditor::setupInterface() { undo_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures); undo_dock -> setMinimumWidth(290); addDockWidget(Qt::RightDockWidgetArea, undo_dock); - QUndoView* undo_view = new QUndoView(&(ce_scene -> undoStack()), this); + QUndoView* undo_view = new QUndoView(&(m_elmt_scene -> undoStack()), this); undo_view -> setEmptyLabel(tr("Aucune modification")); undo_dock -> setWidget(undo_view); // panel sur le cote pour la liste des parties parts_list = new QListWidget(this); parts_list -> setSelectionMode(QAbstractItemView::ExtendedSelection); - connect(ce_scene, SIGNAL(partsAdded()), this, SLOT(slot_createPartsList())); - connect(ce_scene, SIGNAL(partsRemoved()), this, SLOT(slot_createPartsList())); - connect(ce_scene, SIGNAL(partsZValueChanged()), this, SLOT(slot_createPartsList())); - connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updatePartsList())); + connect(m_elmt_scene, SIGNAL(partsAdded()), this, SLOT(slot_createPartsList())); + connect(m_elmt_scene, SIGNAL(partsRemoved()), this, SLOT(slot_createPartsList())); + connect(m_elmt_scene, SIGNAL(partsZValueChanged()), this, SLOT(slot_createPartsList())); + connect(m_elmt_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updatePartsList())); connect(parts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slot_updateSelectionFromPartsList())); parts_dock = new QDockWidget(tr("Parties", "dock title"), this); parts_dock -> setObjectName("parts_list"); @@ -571,7 +571,7 @@ void QETElementEditor::slot_setNoDragToView() { affichee. Sinon, un widget d'edition approprie est mis en place. */ void QETElementEditor::slot_updateInformations() { - QList selected_qgis = ce_scene -> selectedItems(); + QList selected_qgis = m_elmt_scene -> selectedItems(); QList cep_list; bool style_editable = false; @@ -652,7 +652,7 @@ void QETElementEditor::xmlPreview() { QET::QetMessageBox::information( this, "Export XML", - ce_scene -> toXml().toString(4) + m_elmt_scene -> toXml().toString(4) ); } @@ -670,7 +670,7 @@ bool QETElementEditor::checkElement() /// Warning #1: Element haven't got terminal /// (except for report, because report must have one terminal and this checking is do below) - if (!ce_scene -> containsTerminals() && !ce_scene -> elementType().contains("report")) + if (!m_elmt_scene -> containsTerminals() && !m_elmt_scene -> elementType().contains("report")) { warnings << qMakePair( tr("Absence de borne", "warning title"), @@ -683,13 +683,13 @@ bool QETElementEditor::checkElement() } /// Check master, slave, simple and report element - if(ce_scene -> elementType() == "master" || - ce_scene -> elementType() == "slave" || - ce_scene -> elementType() == "simple") + if(m_elmt_scene -> elementType() == "master" || + m_elmt_scene -> elementType() == "slave" || + m_elmt_scene -> elementType() == "simple") { bool wrng = true; - foreach (CustomElementPart *cep, ce_scene->primitives()) + foreach (CustomElementPart *cep, m_elmt_scene->primitives()) if (cep->property("tagg").toString() == "label") wrng = false; ///Error #1: element is master, slave or simple but havent got input tagged 'label' @@ -704,11 +704,11 @@ bool QETElementEditor::checkElement() } /// Check folio report element - if (ce_scene -> elementType().contains("report")) + if (m_elmt_scene -> elementType().contains("report")) { int text =0, terminal =0; - foreach(QGraphicsItem *qgi, ce_scene->items()) + foreach(QGraphicsItem *qgi, m_elmt_scene->items()) { if (qgraphicsitem_cast(qgi)) terminal ++; else if (qgraphicsitem_cast(qgi)) text ++; @@ -803,7 +803,7 @@ void QETElementEditor::fromFile(const QString &filepath) { } // chargement de l'element - ce_scene -> fromXml(document_xml); + m_elmt_scene -> fromXml(document_xml); slot_createPartsList(); // gestion de la lecture seule @@ -825,12 +825,16 @@ void QETElementEditor::fromFile(const QString &filepath) { } /** - Enregistre l'element vers un fichier - @param fn Chemin du fichier a enregistrer - @return true en cas de reussite, false sinon -*/ -bool QETElementEditor::toFile(const QString &fn) { - QDomDocument element_xml = ce_scene -> toXml(); + * @brief QETElementEditor::toFile + * Save to file the drawed element. + * @param fn : path of the file + * @return : true if succesfully save. + */ +bool QETElementEditor::toFile(const QString &fn) +{ + m_elmt_scene->clearEventInterface(); + m_elmt_scene->clearSelection(); + QDomDocument element_xml = m_elmt_scene->toXml(); bool writing = QET::writeXmlFile(element_xml, fn); if (!writing) { QET::QetMessageBox::warning( @@ -851,7 +855,10 @@ bool QETElementEditor::toFile(const QString &fn) { */ bool QETElementEditor::toLocation(const ElementsLocation &location) { - if (!location.setXml(ce_scene->toXml())) + m_elmt_scene->clearEventInterface(); + m_elmt_scene->clearSelection(); + + if (!location.setXml(m_elmt_scene->toXml())) { QET::QetMessageBox::critical(this, tr("Erreur", "message box title"), @@ -926,7 +933,7 @@ bool QETElementEditor::isReadOnly() const { * Set line creation interface to scene */ void QETElementEditor::addLine() { - ce_scene -> setEventInterface(new ESEventAddLine(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddLine(m_elmt_scene)); } /** @@ -934,7 +941,7 @@ void QETElementEditor::addLine() { * Set rectangle creation interface to scene */ void QETElementEditor::addRect() { - ce_scene -> setEventInterface(new ESEventAddRect(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddRect(m_elmt_scene)); } /** @@ -942,7 +949,7 @@ void QETElementEditor::addRect() { * Set ellipse creation interface to scene */ void QETElementEditor::addEllipse() { - ce_scene -> setEventInterface(new ESEventAddEllipse(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddEllipse(m_elmt_scene)); } /** @@ -950,7 +957,7 @@ void QETElementEditor::addEllipse() { * Set polygon creation interface to scene */ void QETElementEditor::addPolygon() { - ce_scene -> setEventInterface(new ESEventAddPolygon(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddPolygon(m_elmt_scene)); } /** @@ -958,7 +965,7 @@ void QETElementEditor::addPolygon() { * Set arc creation interface to scene */ void QETElementEditor::addArc() { - ce_scene -> setEventInterface(new ESEventAddArc(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddArc(m_elmt_scene)); } /** @@ -966,7 +973,7 @@ void QETElementEditor::addArc() { * Set text creation interface to scene */ void QETElementEditor::addText() { - ce_scene -> setEventInterface(new ESEventAddText(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddText(m_elmt_scene)); } /** @@ -974,7 +981,7 @@ void QETElementEditor::addText() { * Set text field creation interface to scene */ void QETElementEditor::addTextField() { - ce_scene -> setEventInterface(new ESEventAddTextField(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddTextField(m_elmt_scene)); } /** @@ -982,7 +989,7 @@ void QETElementEditor::addTextField() { * Set terminal creation interface to scene */ void QETElementEditor::addTerminal() { - ce_scene -> setEventInterface(new ESEventAddTerminal(ce_scene)); + m_elmt_scene -> setEventInterface(new ESEventAddTerminal(m_elmt_scene)); } /** @@ -1088,7 +1095,7 @@ void QETElementEditor::openElement(const QString &filepath) { void QETElementEditor::slot_reload() { //If user already edit the element, ask confirmation to reload - if (!ce_scene -> undoStack().isClean()) + if (!m_elmt_scene -> undoStack().isClean()) { QMessageBox::StandardButton answer = QET::QetMessageBox::question(this, tr("Recharger l'élément", "dialog title"), @@ -1099,7 +1106,7 @@ void QETElementEditor::slot_reload() } //Reload the element - ce_scene -> reset(); + m_elmt_scene -> reset(); if (opened_from_file) fromFile(filename_); else @@ -1125,7 +1132,7 @@ bool QETElementEditor::slot_save() //Else wa save to the file at filename_ path bool result_save = toFile(filename_); - if (result_save) ce_scene -> undoStack().setClean(); + if (result_save) m_elmt_scene -> undoStack().setClean(); return(result_save); } else @@ -1136,7 +1143,7 @@ bool QETElementEditor::slot_save() //Else save to the known location bool result_save = toLocation(location_); if (result_save) { - ce_scene -> undoStack().setClean(); + m_elmt_scene -> undoStack().setClean(); emit saveToLocation(location_); } return(result_save); @@ -1153,17 +1160,21 @@ bool QETElementEditor::slot_save() * to this location * @return true if save with success */ -bool QETElementEditor::slot_saveAs() { +bool QETElementEditor::slot_saveAs() +{ // Check element befor writing - if (checkElement()) { + if (checkElement()) + { //Ask a location to user ElementsLocation location = ElementDialog::getSaveElementLocation(this); - if (location.isNull()) return(false); + if (location.isNull()) + return(false); bool result_save = toLocation(location); - if (result_save) { + if (result_save) + { setLocation(location); - ce_scene -> undoStack().setClean(); + m_elmt_scene->undoStack().setClean(); emit saveToLocation(location); } @@ -1178,9 +1189,11 @@ bool QETElementEditor::slot_saveAs() { * Ask a file to user and save the current edited element to this file * @return true if save with success */ -bool QETElementEditor::slot_saveAsFile() { +bool QETElementEditor::slot_saveAsFile() +{ // Check element befor writing - if (checkElement()) { + if (checkElement()) + { //Ask a filename to user, for save the element QString fn = QFileDialog::getSaveFileName( this, @@ -1201,10 +1214,11 @@ bool QETElementEditor::slot_saveAsFile() { bool result_save = toFile(fn); //If the save success, the filename is keep - if (result_save) { + if (result_save) + { setFileName(fn); QETApp::elementsRecentFiles() -> fileWasOpened(fn); - ce_scene -> undoStack().setClean(); + m_elmt_scene -> undoStack().setClean(); } return(result_save); @@ -1220,7 +1234,7 @@ bool QETElementEditor::slot_saveAsFile() { l'utilisateur. */ bool QETElementEditor::canClose() { - if (ce_scene -> undoStack().isClean()) return(true); + if (m_elmt_scene -> undoStack().isClean()) return(true); // demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours QMessageBox::StandardButton answer = QET::QetMessageBox::question( this, @@ -1230,7 +1244,7 @@ bool QETElementEditor::canClose() { "Voulez-vous enregistrer l'élément %1 ?", "dialog content - %1 is an element name" ) - ).arg(ce_scene -> names().name()), + ).arg(m_elmt_scene -> names().name()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel ); @@ -1287,7 +1301,7 @@ void QETElementEditor::closeEvent(QCloseEvent *qce) { if (canClose()) { writeSettings(); setAttribute(Qt::WA_DeleteOnClose); - ce_scene -> reset(); + m_elmt_scene -> reset(); qce -> accept(); } else qce -> ignore(); } @@ -1306,7 +1320,7 @@ void QETElementEditor::firstActivation(QEvent *event) { void QETElementEditor::slot_createPartsList() { parts_list -> blockSignals(true); parts_list -> clear(); - QList qgis = ce_scene -> zItems(); + QList qgis = m_elmt_scene -> zItems(); // on ne construit plus la liste a partir de 200 primitives // c'est ingerable : la maj de la liste prend trop de temps et le resultat @@ -1334,13 +1348,13 @@ void QETElementEditor::slot_createPartsList() { Met a jour la selection dans la liste des parties */ void QETElementEditor::slot_updatePartsList() { - int items_count = ce_scene -> items().count(); + int items_count = m_elmt_scene -> items().count(); if (parts_list -> count() != items_count) { slot_createPartsList(); } else if (items_count <= QET_MAX_PARTS_IN_ELEMENT_EDITOR_LIST) { parts_list -> blockSignals(true); int i = 0; - QList items = ce_scene -> zItems(); + QList items = m_elmt_scene -> zItems(); for (int j = items.count() - 1 ; j >= 0 ; -- j) { QGraphicsItem *qgi = items[j]; QListWidgetItem *qlwi = parts_list -> item(i); @@ -1356,7 +1370,7 @@ void QETElementEditor::slot_updatePartsList() { parties */ void QETElementEditor::slot_updateSelectionFromPartsList() { - ce_scene -> blockSignals(true); + m_elmt_scene -> blockSignals(true); parts_list -> blockSignals(true); for (int i = 0 ; i < parts_list -> count() ; ++ i) { QListWidgetItem *qlwi = parts_list -> item(i); @@ -1366,7 +1380,7 @@ void QETElementEditor::slot_updateSelectionFromPartsList() { } } parts_list -> blockSignals(false); - ce_scene -> blockSignals(false); + m_elmt_scene -> blockSignals(false); slot_updateInformations(); slot_updateMenus(); } @@ -1388,7 +1402,7 @@ void QETElementEditor::readSettings() if (state.isValid()) restoreState(state.toByteArray()); // informations complementaires de l'element : valeur par defaut - ce_scene -> setInformations(settings.value("elementeditor/default-informations", "").toString()); + m_elmt_scene -> setInformations(settings.value("elementeditor/default-informations", "").toString()); } /** @@ -1464,7 +1478,7 @@ void QETElementEditor::fromLocation(const ElementsLocation &location) document_xml.appendChild(node); //Load the element - ce_scene -> fromXml(document_xml); + m_elmt_scene -> fromXml(document_xml); slot_createPartsList(); //location is read only diff --git a/sources/editor/qetelementeditor.h b/sources/editor/qetelementeditor.h index 06662a294..0c356955a 100644 --- a/sources/editor/qetelementeditor.h +++ b/sources/editor/qetelementeditor.h @@ -53,7 +53,7 @@ class QETElementEditor : public QETMainWindow { /// view widget for the editing scene ElementView *ce_view; /// editing scene - ElementScene *ce_scene; + ElementScene *m_elmt_scene; /// container for widgets dedicated to primitive edition QDockWidget *tools_dock; /// Stack of widgets for tools_dock @@ -164,7 +164,7 @@ class QETElementEditor : public QETMainWindow { @param nameslist the new list of names for the currently edited element */ inline void QETElementEditor::setNames(const NamesList &nameslist) { - ce_scene -> setNames(nameslist); + m_elmt_scene -> setNames(nameslist); } /** @@ -185,7 +185,7 @@ inline QString QETElementEditor::fileName() const { @return the editing scene */ inline ElementScene *QETElementEditor::elementScene() const { - return(ce_scene); + return(m_elmt_scene); } #endif