[qet] qet/qet: [5394] Diagram editor : add 4 tools for edit the depth (Z value) of items. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5394
Author: blacksun
Date: 2018-06-17 20:21:56 +0200 (Sun, 17 Jun 2018)
Log Message:
-----------
Diagram editor : add 4 tools for edit the depth (Z value) of items.
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagram.h
trunk/sources/qet.h
trunk/sources/qetdiagrameditor.cpp
trunk/sources/qetdiagrameditor.h
trunk/sources/qetgraphicsitem/customelement.cpp
trunk/sources/qetgraphicsitem/diagramimageitem.cpp
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/qetshapeitem.cpp
trunk/sources/qetgraphicsitem/terminal.cpp
trunk/sources/qetgraphicsitem/terminal.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/diagram.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -38,6 +38,7 @@
#include "dynamicelementtextitem.h"
#include "elementtextitemgroup.h"
#include "undocommand/addelementtextcommand.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10;
@@ -1269,6 +1270,62 @@
}
/**
+ * @brief Diagram::changeZValue
+ * Change the Z value of the current selected item, according to @option
+ */
+void Diagram::changeZValue(QET::DepthOption option)
+{
+ DiagramContent dc(this);
+ QUndoCommand *undo = new QUndoCommand(tr("Modifier la profondeur"));
+ QList<QGraphicsItem *> l = dc.items(DiagramContent::SelectedOnly | \
+ DiagramContent::Elements | \
+ DiagramContent::Shapes | \
+ DiagramContent::Images);
+ QList<QGraphicsObject *> list;
+ for(QGraphicsItem *item : l)
+ list << item->toGraphicsObject();
+
+ qreal maxz=0,
+ minz=0;
+ for(QGraphicsItem *item : this->items())
+ {
+ qreal z = item->zValue();
+ if(z >= Terminal::Z-2)
+ continue;
+ maxz = std::max(maxz,z);
+ minz = std::min(minz,z);
+ }
+
+ if(option == QET::Raise)
+ {
+ for(QGraphicsObject *qgo : list)
+ if(qgo->zValue() < (Terminal::Z-2)) //Ensure item is always below terminal
+ new QPropertyUndoCommand(qgo, "z", qgo->zValue(), qgo->zValue()+1, undo);
+ }
+ else if(option == QET::Lower)
+ {
+ for(QGraphicsObject *qgo : list)
+ if(qgo->zValue() < (Terminal::Z-2)) //Ensure item is always below terminal
+ new QPropertyUndoCommand(qgo, "z", qgo->zValue(), qgo->zValue()-1, undo);
+ }
+ else if (option == QET::BringForward)
+ {
+ for(QGraphicsObject *qgo : list)
+ new QPropertyUndoCommand(qgo, "z", qgo->zValue(), maxz+1, undo);
+ }
+ else if(option == QET::SendBackward)
+ {
+ for(QGraphicsObject *qgo : list)
+ new QPropertyUndoCommand(qgo, "z", qgo->zValue(), minz-1, undo);
+ }
+
+ if(undo->childCount())
+ this->undoStack().push(undo);
+ else
+ delete undo;
+}
+
+/**
* @brief Diagram::loadElmtFolioSeq
* This class loads all folio sequential variables related
* to the current autonum
Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/diagram.h 2018-06-17 18:21:56 UTC (rev 5394)
@@ -212,8 +212,8 @@
//methods related to insertion and loading of folio sequential
void insertFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc);
void loadFolioSeqHash (QHash<QString, QStringList> *hash, QString title, QString seq, NumerotationContext *nc);
+ void changeZValue(QET::DepthOption option);
-
public slots:
void adjustSceneRect ();
void titleChanged(const QString &);
Modified: trunk/sources/qet.h
===================================================================
--- trunk/sources/qet.h 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qet.h 2018-06-17 18:21:56 UTC (rev 5394)
@@ -30,6 +30,14 @@
const QString displayedVersion = "0.70-dev";
QString license();
+ /// List the various kind of changes for the zValue
+ enum DepthOption {
+ BringForward, ///< Bring item to the foreground so they have the highest zValue
+ Raise, ///< Raise item one layer above their current one; zValues are incremented
+ Lower, ///< Send item one layer below their current one; zValues are decremented
+ SendBackward ///< Send item to the background so they have the lowest zValue
+ };
+
/// Oriented movements
enum OrientedMovement {
ToNorth,
@@ -165,6 +173,8 @@
bool eachStrIsEqual (const QStringList &qsl);
}
+Q_DECLARE_METATYPE(QET::DepthOption)
+
class Qet : public QObject {
Q_OBJECT
public:
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetdiagrameditor.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -513,56 +513,84 @@
connect(prev_window, SIGNAL(triggered()), &workspace, SLOT(activatePreviousSubWindow()) );
connect(m_conductor_reset, SIGNAL(triggered()), this, SLOT(slot_resetConductors()) );
connect(infos_diagram, SIGNAL(triggered()), this, SLOT(editCurrentDiagramProperties()));
+
+ //Depth action
+ m_depth_action_group = new QActionGroup(this);
+
+ QAction *edit_forward = new QAction(QET::Icons::BringForward, tr("Amener au premier plan"), m_depth_action_group);
+ QAction *edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), m_depth_action_group);
+ QAction *edit_lower = new QAction(QET::Icons::Lower, tr("Éloigner"), m_depth_action_group);
+ QAction *edit_backward = new QAction(QET::Icons::SendBackward, tr("Envoyer au fond"), m_depth_action_group);
+
+ edit_raise ->setShortcut(QKeySequence(tr("Ctrl+Shift+Up")));
+ edit_lower ->setShortcut(QKeySequence(tr("Ctrl+Shift+Down")));
+ edit_backward->setShortcut(QKeySequence(tr("Ctrl+Shift+End")));
+ edit_forward ->setShortcut(QKeySequence(tr("Ctrl+Shift+Home")));
+
+ edit_forward ->setData(QET::BringForward);
+ edit_raise ->setData(QET::Raise);
+ edit_lower ->setData(QET::Lower);
+ edit_backward->setData(QET::SendBackward);
+ m_depth_action_group->setDisabled(true);
+
+ connect(m_depth_action_group, &QActionGroup::triggered, [this](QAction *action) {
+ this->currentDiagramView()->diagram()->changeZValue(action->data().value<QET::DepthOption>());
+ });
}
/**
* @brief QETDiagramEditor::setUpToolBar
*/
-void QETDiagramEditor::setUpToolBar() {
- main_bar = new QToolBar(tr("Outils"), this);
- main_bar -> setObjectName("toolbar");
+void QETDiagramEditor::setUpToolBar()
+{
+ main_tool_bar = new QToolBar(tr("Outils"), this);
+ main_tool_bar -> setObjectName("toolbar");
- view_bar = new QToolBar(tr("Affichage"), this);
- view_bar -> setObjectName("display");
+ view_tool_bar = new QToolBar(tr("Affichage"), this);
+ view_tool_bar -> setObjectName("display");
- diagram_bar = new QToolBar(tr("Schéma"), this);
- diagram_bar -> setObjectName("diagram");
+ diagram_tool_bar = new QToolBar(tr("Schéma"), this);
+ diagram_tool_bar -> setObjectName("diagram");
- main_bar -> addActions(m_file_actions_group.actions());
- main_bar -> addAction(print);
- main_bar -> addSeparator();
- main_bar -> addAction(undo);
- main_bar -> addAction(redo);
- main_bar -> addSeparator();
- main_bar -> addAction(m_cut);
- main_bar -> addAction(m_copy);
- main_bar -> addAction(paste);
- main_bar -> addSeparator();
- main_bar -> addAction(m_delete_selection);
- main_bar -> addAction(m_rotate_selection);
+ main_tool_bar -> addActions(m_file_actions_group.actions());
+ main_tool_bar -> addAction(print);
+ main_tool_bar -> addSeparator();
+ main_tool_bar -> addAction(undo);
+ main_tool_bar -> addAction(redo);
+ main_tool_bar -> addSeparator();
+ main_tool_bar -> addAction(m_cut);
+ main_tool_bar -> addAction(m_copy);
+ main_tool_bar -> addAction(paste);
+ main_tool_bar -> addSeparator();
+ main_tool_bar -> addAction(m_delete_selection);
+ main_tool_bar -> addAction(m_rotate_selection);
// Modes selection / visualisation et zoom
- view_bar -> addAction(mode_selection);
- view_bar -> addAction(mode_visualise);
- view_bar -> addSeparator();
- view_bar -> addAction(m_draw_grid);
- view_bar -> addAction (m_grey_background);
- view_bar -> addSeparator();
- view_bar -> addActions(m_zoom_action_toolBar);
+ view_tool_bar -> addAction(mode_selection);
+ view_tool_bar -> addAction(mode_visualise);
+ view_tool_bar -> addSeparator();
+ view_tool_bar -> addAction(m_draw_grid);
+ view_tool_bar -> addAction (m_grey_background);
+ view_tool_bar -> addSeparator();
+ view_tool_bar -> addActions(m_zoom_action_toolBar);
- diagram_bar -> addAction (infos_diagram);
- diagram_bar -> addAction (m_conductor_reset);
- diagram_bar -> addAction (m_auto_conductor);
+ diagram_tool_bar -> addAction (infos_diagram);
+ diagram_tool_bar -> addAction (m_conductor_reset);
+ diagram_tool_bar -> addAction (m_auto_conductor);
- m_add_item_toolBar = new QToolBar(tr("Ajouter"), this);
- m_add_item_toolBar->setObjectName("adding");
- m_add_item_toolBar->addActions(m_add_item_actions_group.actions());
+ m_add_item_tool_bar = new QToolBar(tr("Ajouter"), this);
+ m_add_item_tool_bar->setObjectName("adding");
+ m_add_item_tool_bar->addActions(m_add_item_actions_group.actions());
+
+ m_depth_tool_bar = new QToolBar(tr("Profondeur", "toolbar title"));
+ m_depth_tool_bar->setObjectName("diagram_depth_toolbar");
+ m_depth_tool_bar->addActions(m_depth_action_group->actions());
- // ajout de la barre d'outils a la fenetre principale
- addToolBar(Qt::TopToolBarArea, main_bar);
- addToolBar(Qt::TopToolBarArea, view_bar);
- addToolBar(Qt::TopToolBarArea, diagram_bar);
- addToolBar(Qt::TopToolBarArea, m_add_item_toolBar);
+ addToolBar(Qt::TopToolBarArea, main_tool_bar);
+ addToolBar(Qt::TopToolBarArea, view_tool_bar);
+ addToolBar(Qt::TopToolBarArea, diagram_tool_bar);
+ addToolBar(Qt::TopToolBarArea, m_add_item_tool_bar);
+ addToolBar(Qt::TopToolBarArea, m_depth_tool_bar);
}
/**
@@ -612,6 +640,8 @@
menu_edition -> addSeparator();
menu_edition -> addAction(infos_diagram);
menu_edition -> addActions(m_row_column_actions_group.actions());
+ menu_edition -> addSeparator();
+ menu_edition -> addActions(m_depth_action_group->actions());
// menu Projet
menu_project -> addAction(prj_edit_prop);
@@ -623,9 +653,9 @@
menu_project -> addAction(prj_nomenclature);
menu_project -> addAction(prj_terminalBloc);
- main_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils principale"));
- view_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils Affichage"));
- diagram_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils Schéma"));
+ main_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils principale"));
+ view_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils Affichage"));
+ diagram_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils Schéma"));
qdw_pa -> toggleViewAction() -> setStatusTip(tr("Affiche ou non le panel d'appareils"));
qdw_undo -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la liste des modifications"));
@@ -1513,6 +1543,13 @@
m_edit_selection -> setIcon(QET::Icons::ElementEdit);
m_edit_selection -> setEnabled(false);
}
+
+ //Actions for edit Z value
+ QList<QGraphicsItem *> list = dc.items(DiagramContent::SelectedOnly | \
+ DiagramContent::Elements | \
+ DiagramContent::Shapes | \
+ DiagramContent::Images);
+ m_depth_action_group->setEnabled(list.isEmpty()? false : true);
}
/**
Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetdiagrameditor.h 2018-06-17 18:21:56 UTC (rev 5394)
@@ -205,6 +205,7 @@
public:
QActionGroup m_row_column_actions_group; /// Action related to add/remove rows/column in diagram
QActionGroup m_selection_actions_group; ///Action related to edit a selected item
+ QActionGroup *m_depth_action_group = nullptr;
private:
QAction *m_delete_selection; ///< Delete selection
QAction *m_rotate_selection; ///< Rotate selected elements and text items by 90 degrees
@@ -219,22 +220,25 @@
QMdiArea workspace;
QSignalMapper windowMapper;
- /// Directory to use for file dialogs such as File > save
+ /// Directory to use for file dialogs such as File > save
QDir open_dialog_dir;
- /// Dock for the elements panel
+ /// Dock for the elements panel
QDockWidget *qdw_pa;
QDockWidget *m_qdw_elmt_collection;
ElementsCollectionWidget *m_element_collection_widget;
- /// Dock for the undo list
+ /// Dock for the undo list
QDockWidget *qdw_undo;
DiagramPropertiesEditorDockWidget *m_selection_properties_editor;
- /// Elements panel
+ /// Elements panel
ElementsPanelWidget *pa;
QMenu *windows_menu;
- QToolBar *main_bar;
- QToolBar *view_bar;
- QToolBar *diagram_bar;
- QToolBar *m_add_item_toolBar;
+
+ QToolBar *main_tool_bar = nullptr,
+ *view_tool_bar = nullptr,
+ *diagram_tool_bar = nullptr,
+ *m_add_item_tool_bar = nullptr,
+ *m_depth_tool_bar = nullptr;
+
QUndoGroup undo_group;
// AutoNumbering Selection Dock
AutoNumberingDockWidget *m_autonumbering_dock;
Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetgraphicsitem/customelement.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -810,7 +810,6 @@
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
Modified: trunk/sources/qetgraphicsitem/diagramimageitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramimageitem.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetgraphicsitem/diagramimageitem.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -124,19 +124,27 @@
}
/**
- 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 @@
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 @@
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
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetgraphicsitem/element.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -421,6 +421,7 @@
//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 @@
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;
Modified: trunk/sources/qetgraphicsitem/qetshapeitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetshapeitem.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetgraphicsitem/qetshapeitem.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -44,6 +44,12 @@
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 @@
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 @@
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 @@
}
result.appendChild(points);
}
+ result.setAttribute("z", QString::number(this->zValue()));
return(result);
}
Modified: trunk/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.cpp 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetgraphicsitem/terminal.cpp 2018-06-17 18:21:56 UTC (rev 5394)
@@ -28,6 +28,7 @@
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 @@
setAcceptedMouseButtons(Qt::LeftButton);
hovered_ = false;
setToolTip(QObject::tr("Borne", "tooltip"));
+ setZValue(Z);
}
/**
Modified: trunk/sources/qetgraphicsitem/terminal.h
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.h 2018-06-10 15:17:11 UTC (rev 5393)
+++ trunk/sources/qetgraphicsitem/terminal.h 2018-06-17 18:21:56 UTC (rev 5394)
@@ -89,22 +89,22 @@
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
- // attributes
+ // attributes
public:
- enum { Type = UserType + 1002 };
- /// terminal length
- static const qreal terminalSize;
+ 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;
- // 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;
QGraphicsLineItem *m_help_line;