[qet] qet/qet: [5402] Forget qet.cpp and qet.h from previous comit. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5402
Author: blacksun
Date: 2018-06-20 20:35:06 +0200 (Wed, 20 Jun 2018)
Log Message:
-----------
Forget qet.cpp and qet.h from previous comit.
Add new function for create QAction used for edit the depth of items.
Modified Paths:
--------------
trunk/sources/editor/editorcommands.cpp
trunk/sources/editor/editorcommands.h
trunk/sources/editor/elementscene.cpp
trunk/sources/editor/elementscene.h
trunk/sources/editor/qetelementeditor.cpp
trunk/sources/editor/qetelementeditor.h
trunk/sources/qet.cpp
trunk/sources/qet.h
Modified: trunk/sources/editor/editorcommands.cpp
===================================================================
--- trunk/sources/editor/editorcommands.cpp 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/editor/editorcommands.cpp 2018-06-20 18:35:06 UTC (rev 5402)
@@ -343,11 +343,11 @@
*/
ChangeZValueCommand::ChangeZValueCommand(
ElementScene *elmt,
- ChangeZValueCommand::Option o,
+ QET::DepthOption o,
QUndoCommand *parent
) :
ElementEditionCommand(elmt, nullptr, parent),
- option(o)
+ m_option(o)
{
// retrieve all primitives but terminals
QList<QGraphicsItem *> items_list = m_scene -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
@@ -356,16 +356,16 @@
foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue());
// choisit le nom en fonction du traitement
- if (option == BringForward) {
+ if (m_option == QET::BringForward) {
setText(QObject::tr("amener au premier plan", "undo caption"));
applyBringForward(items_list);
- } else if (option == Raise) {
+ } else if (m_option == QET::Raise) {
setText(QObject::tr("rapprocher", "undo caption"));
applyRaise(items_list);
- } else if (option == Lower) {
+ } else if (m_option == QET::Lower) {
setText(QObject::tr("éloigner", "undo caption"));
applyLower(items_list);
- } else if (option == SendBackward) {
+ } else if (m_option == QET::SendBackward) {
setText(QObject::tr("envoyer au fond", "undo caption"));
applySendBackward(items_list);
}
Modified: trunk/sources/editor/editorcommands.h
===================================================================
--- trunk/sources/editor/editorcommands.h 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/editor/editorcommands.h 2018-06-20 18:35:06 UTC (rev 5402)
@@ -197,17 +197,11 @@
This command changes the zValue of a set of primitives when editing an
electrical element.
*/
-class ChangeZValueCommand : public ElementEditionCommand {
- // constructors, destructor
+class ChangeZValueCommand : public ElementEditionCommand
+{
+ // constructors, destructor
public:
- /// List the various kind of changes for the zValue
- enum Option {
- BringForward, ///< Bring primitives to the foreground so they have the highest zValue
- Raise, ///< Raise primitives one layer above their current one; zValues are incremented
- Lower, ///< Send primitives one layer below their current one; zValues are decremented
- SendBackward ///< Send primitives to the background so they have the lowest zValue
- };
- ChangeZValueCommand(ElementScene *, Option, QUndoCommand * = nullptr);
+ ChangeZValueCommand(ElementScene *, QET::DepthOption , QUndoCommand * = nullptr);
~ChangeZValueCommand() override;
private:
ChangeZValueCommand(const ChangeZValueCommand &);
@@ -230,7 +224,7 @@
/// associates impacted primitives with their new zValues
QHash<QGraphicsItem *, qreal> redo_hash;
/// kind of treatment to apply
- Option option;
+ QET::DepthOption m_option;
};
/**
Modified: trunk/sources/editor/elementscene.cpp
===================================================================
--- trunk/sources/editor/elementscene.cpp 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/editor/elementscene.cpp 2018-06-20 18:35:06 UTC (rev 5402)
@@ -760,38 +760,6 @@
}
/**
- Amene les elements selectionnes au premier plan
-*/
-void ElementScene::slot_bringForward() {
- undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::BringForward));
- emit(partsZValueChanged());
-}
-
-/**
- Remonte les elements selectionnes d'un plan
-*/
-void ElementScene::slot_raise() {
- undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::Raise));
- emit(partsZValueChanged());
-}
-
-/**
- Descend les elements selectionnes d'un plan
-*/
-void ElementScene::slot_lower() {
- undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::Lower));
- emit(partsZValueChanged());
-}
-
-/**
- Envoie les elements selectionnes au fond
-*/
-void ElementScene::slot_sendBackward() {
- undoStack().push(new ChangeZValueCommand(this, ChangeZValueCommand::SendBackward));
- emit(partsZValueChanged());
-}
-
-/**
@return the list of primitives currently present on the scene.
*/
QList<CustomElementPart *> ElementScene::primitives() const {
Modified: trunk/sources/editor/elementscene.h
===================================================================
--- trunk/sources/editor/elementscene.h 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/editor/elementscene.h 2018-06-20 18:35:06 UTC (rev 5402)
@@ -152,10 +152,6 @@
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 *);
Modified: trunk/sources/editor/qetelementeditor.cpp
===================================================================
--- trunk/sources/editor/qetelementeditor.cpp 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/editor/qetelementeditor.cpp 2018-06-20 18:35:06 UTC (rev 5402)
@@ -27,6 +27,7 @@
#include "recentfiles.h"
#include "qeticons.h"
#include "qetmessagebox.h"
+#include "editorcommands.h"
// editeurs de primitives
#include "arceditor.h"
@@ -224,30 +225,17 @@
connect(edit_author, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_editAuthorInformations()));
connect(m_edit_properties, SIGNAL(triggered()), m_elmt_scene, SLOT(slot_editProperties()));
-
- /*
- * Action related to change depth of primitive
- */
- m_depth_ag = new QActionGroup(this);
-
- QAction *edit_forward = new QAction(QET::Icons::BringForward, tr("Amener au premier plan"), m_depth_ag);
- QAction *edit_raise = new QAction(QET::Icons::Raise, tr("Rapprocher"), m_depth_ag);
- QAction *edit_lower = new QAction(QET::Icons::Lower, tr("Éloigner"), m_depth_ag);
- QAction *edit_backward = new QAction(QET::Icons::SendBackward, tr("Envoyer au fond"), m_depth_ag);
-
- 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")));
-
- 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() ));
-
+ //Action related to change depth of primitive
+ m_depth_action_group = QET::depthActionGroup(this);
+
+ connect(m_depth_action_group, &QActionGroup::triggered, [this](QAction *action) {
+ this->elementScene()->undoStack().push(new ChangeZValueCommand(this->elementScene(), action->data().value<QET::DepthOption>()));
+ emit(this->elementScene()->partsZValueChanged());
+ });
+
depth_toolbar = addToolBar(tr("Profondeur", "toolbar title"));
depth_toolbar -> setObjectName("depth_toolbar");
- depth_toolbar -> addActions(m_depth_ag -> actions());
+ depth_toolbar -> addActions(m_depth_action_group -> actions());
addToolBar(Qt::TopToolBarArea, depth_toolbar);
@@ -402,7 +390,7 @@
edit_menu -> addAction(edit_author);
edit_menu -> addAction(m_edit_properties);
edit_menu -> addSeparator();
- edit_menu -> addActions(m_depth_ag -> actions());
+ edit_menu -> addActions(m_depth_action_group -> actions());
display_menu -> addActions(m_zoom_ag -> actions());
@@ -432,7 +420,7 @@
menu.addAction(paste_in_area);
menu.addMenu(paste_from_menu);
menu.addSeparator();
- menu.addActions(m_depth_ag -> actions());
+ menu.addActions(m_depth_action_group -> actions());
//Remove from the context menu the actions which are disabled.
const QList<QAction *>actions = menu.actions();
@@ -467,7 +455,7 @@
cut -> setEnabled(selected_items);
copy -> setEnabled(selected_items);
edit_delete -> setEnabled(selected_items);
- foreach (QAction *action, m_depth_ag -> actions())
+ foreach (QAction *action, m_depth_action_group -> actions())
action->setEnabled(selected_items);
// actions dependant du contenu du presse-papiers
Modified: trunk/sources/editor/qetelementeditor.h
===================================================================
--- trunk/sources/editor/qetelementeditor.h 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/editor/qetelementeditor.h 2018-06-20 18:35:06 UTC (rev 5402)
@@ -80,7 +80,7 @@
/// toolbars
QToolBar *parts_toolbar, *main_toolbar, *view_toolbar, *depth_toolbar, *element_toolbar;
/// Action group
- QActionGroup *parts, *m_zoom_ag, *m_depth_ag;
+ QActionGroup *parts, *m_zoom_ag, *m_depth_action_group;
/// minimum window title
QString min_title;
/// filename of the currently edited element
Modified: trunk/sources/qet.cpp
===================================================================
--- trunk/sources/qet.cpp 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/qet.cpp 2018-06-20 18:35:06 UTC (rev 5402)
@@ -16,8 +16,11 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qet.h"
+#include "qeticons.h"
+
#include <limits>
#include <QGraphicsSceneContextMenuEvent>
+#include <QAction>
/**
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
@@ -494,13 +497,6 @@
}
/**
- Round the coordinates of \a p to the nearest multiple of \a epsilon.
-*/
-QPointF QET::roundPoint(const QPointF &p, qreal epsilon) {
- return(QPointF(QET::round(p.x(), epsilon), QET::round(p.y(), epsilon)));
-}
-
-/**
@param angle Un angle quelconque
@return l'angle passe en parametre, mais ramene entre -360.0 + 360.0 degres
*/
@@ -535,19 +531,6 @@
}
/**
- @param icl an TitleBlockColumnLength object
- @see TitleBlockColumnLength
- @return a string describing the type of this TitleBlockColumnLength object
-*/
-QString QET::titleBlockColumnLengthToString(const TitleBlockColumnLength &icl) {
- QString type_str;
- if (icl== Absolute) type_str = "absolute";
- else if (icl == RelativeToTotalLength) type_str = "relative to total";
- else if (icl == RelativeToRemainingLength) type_str = "relative to remaining";
- return(type_str);
-}
-
-/**
Export an XML document to an UTF-8 text file indented with 4 spaces, with LF
end of lines and no BOM.
@param xml_doc An XML document to be exported
@@ -583,62 +566,6 @@
}
/**
- @return the scene position where \a event occurred, provided it is
- QGraphicsScene-related event; otherwise, this function returns a null
- QPointF.
-*/
-QPointF QET::graphicsSceneEventPos(QEvent *event) {
- QPointF event_scene_pos;
- if (event -> type() < QEvent::GraphicsSceneContextMenu) return(event_scene_pos);
- if (event -> type() > QEvent::GraphicsSceneWheel) return(event_scene_pos);
-
- switch (event -> type()) {
- case QEvent::GraphicsSceneContextMenu: {
- QGraphicsSceneContextMenuEvent *qgs_event = static_cast<QGraphicsSceneContextMenuEvent *>(event);
- event_scene_pos = qgs_event -> scenePos();
- break;
- }
- case QEvent::GraphicsSceneDragEnter:
- case QEvent::GraphicsSceneDragLeave:
- case QEvent::GraphicsSceneDragMove:
- case QEvent::GraphicsSceneDrop: {
- QGraphicsSceneDragDropEvent *qgs_event = static_cast<QGraphicsSceneDragDropEvent *>(event);
- event_scene_pos = qgs_event -> scenePos();
- break;
- }
- case QEvent::GraphicsSceneHelp: {
- QGraphicsSceneHelpEvent *qgs_event = static_cast<QGraphicsSceneHelpEvent *>(event);
- event_scene_pos = qgs_event -> scenePos();
- break;
- }
-
- case QEvent::GraphicsSceneHoverEnter:
- case QEvent::GraphicsSceneHoverLeave:
- case QEvent::GraphicsSceneHoverMove: {
- QGraphicsSceneHoverEvent *qgs_event = static_cast<QGraphicsSceneHoverEvent *>(event);
- event_scene_pos = qgs_event -> scenePos();
- break;
- }
- case QEvent::GraphicsSceneMouseDoubleClick:
- case QEvent::GraphicsSceneMouseMove:
- case QEvent::GraphicsSceneMousePress:
- case QEvent::GraphicsSceneMouseRelease: {
- QGraphicsSceneMouseEvent *qgs_event = static_cast<QGraphicsSceneMouseEvent *>(event);
- event_scene_pos = qgs_event -> scenePos();
- break;
- }
- case QEvent::GraphicsSceneWheel: {
- QGraphicsSceneWheelEvent *qgs_event = static_cast<QGraphicsSceneWheelEvent *>(event);
- event_scene_pos = qgs_event -> scenePos();
- break;
- }
- default:
- break;
- }
- return(event_scene_pos);
-}
-
-/**
* @brief QET::eachStrIsEqual
* @param qsl list of string to compare
* @return true if every string is identical, else false;
@@ -690,3 +617,31 @@
else
return QetCollection::Common;
}
+
+/**
+ * @brief QET::depthActionGroup
+ * @param parent
+ * @return an action group which contain 4 actions (forward, raise, lower, backward)
+ * already made with icon, shortcut and data (see QET::DepthOption)
+ */
+QActionGroup *QET::depthActionGroup(QObject *parent)
+{
+ QActionGroup *action_group = new QActionGroup(parent);
+
+ QAction *edit_forward = new QAction(QET::Icons::BringForward, QObject::tr("Amener au premier plan"), action_group);
+ QAction *edit_raise = new QAction(QET::Icons::Raise, QObject::tr("Rapprocher"), action_group);
+ QAction *edit_lower = new QAction(QET::Icons::Lower, QObject::tr("Éloigner"), action_group);
+ QAction *edit_backward = new QAction(QET::Icons::SendBackward, QObject::tr("Envoyer au fond"), action_group);
+
+ edit_raise ->setShortcut(QKeySequence(QObject::tr("Ctrl+Shift+Up")));
+ edit_lower ->setShortcut(QKeySequence(QObject::tr("Ctrl+Shift+Down")));
+ edit_backward->setShortcut(QKeySequence(QObject::tr("Ctrl+Shift+End")));
+ edit_forward ->setShortcut(QKeySequence(QObject::tr("Ctrl+Shift+Home")));
+
+ edit_forward ->setData(QET::BringForward);
+ edit_raise ->setData(QET::Raise);
+ edit_lower ->setData(QET::Lower);
+ edit_backward->setData(QET::SendBackward);
+
+ return action_group;
+}
Modified: trunk/sources/qet.h
===================================================================
--- trunk/sources/qet.h 2018-06-20 18:03:39 UTC (rev 5401)
+++ trunk/sources/qet.h 2018-06-20 18:35:06 UTC (rev 5402)
@@ -19,6 +19,8 @@
#define _QET_H
#include <QtXml>
#include <QObject>
+
+class QActionGroup;
/**
This file provides useful functions and enums that may be used from
anywhere else within the QElectroTech application.
@@ -155,7 +157,6 @@
QList<QDomElement> findInDomElement(const QDomElement &, const QString &);
QList<QDomElement> findInDomElement(const QDomElement &, const QString &, const QString &);
QList<QChar> forbiddenCharacters();
- QString forbiddenCharactersString(bool = false);
QString stringToFileName(const QString &);
QString escapeSpaces(const QString &);
QString unescapeSpaces(const QString &);
@@ -164,13 +165,11 @@
QString diagramAreaToString(const QET::DiagramArea &);
QET::DiagramArea diagramAreaFromString(const QString &);
qreal round(qreal, qreal);
- QPointF roundPoint(const QPointF &, qreal);
qreal correctAngle(const qreal &);
bool compareCanonicalFilePaths(const QString &, const QString &);
- QString titleBlockColumnLengthToString(const TitleBlockColumnLength &);
bool writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString * error_message= nullptr);
- QPointF graphicsSceneEventPos(QEvent *);
bool eachStrIsEqual (const QStringList &qsl);
+ QActionGroup *depthActionGroup(QObject *parent = nullptr);
}
Q_DECLARE_METATYPE(QET::DepthOption)