4 #include "DocumentSerialize.h"
5 #include "EngaugeAssert.h"
6 #include "GraphicsItemType.h"
7 #include "GraphicsScene.h"
8 #include "GraphicsView.h"
10 #include "MainWindow.h"
11 #include <QGraphicsItem>
12 #include <QtToString.h>
13 #include <QXmlStreamReader>
17 const QPointF &deltaScreen,
18 const QString &moveText,
19 const QStringList &selectedPointIdentifiers) :
23 m_deltaScreen (deltaScreen)
26 QStringList::const_iterator itr;
27 for (itr = selectedPointIdentifiers.begin (); itr != selectedPointIdentifiers.end (); itr++) {
29 QString selectedPointIdentifier = *itr;
31 selected << selectedPointIdentifier;
32 m_movedPoints.
setKeyValue (selectedPointIdentifier,
true);
35 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::CmdMoveBy"
36 <<
" deltaScreen=" << QPointFToString (deltaScreen).toLatin1 ().data ()
37 <<
" selected=" << selected.join (
", ").toLatin1 ().data () <<
")";
42 const QString &cmdDescription,
43 QXmlStreamReader &reader) :
48 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::CmdMoveBy";
50 QXmlStreamAttributes attributes = reader.attributes();
52 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X_DELTA) ||
53 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y_DELTA) ) {
54 ENGAUGE_ASSERT (
false);
57 m_deltaScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X_DELTA).toDouble());
58 m_deltaScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y_DELTA).toDouble());
62 CmdMoveBy::~CmdMoveBy ()
68 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::cmdRedo"
69 <<
" deltaScreen=" << QPointFToString (m_deltaScreen).toLatin1().data()
70 <<
" moving=" << m_movedPoints.
count ();
72 moveBy (m_deltaScreen);
78 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::cmdUndo"
79 <<
" deltaScreen=" << QPointFToString (-1.0 * m_deltaScreen).toLatin1().data()
80 <<
" moving=" << m_movedPoints.
count ();
82 moveBy (-1.0 * m_deltaScreen);
86 void CmdMoveBy::moveBy (
const QPointF &deltaScreen)
88 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::moveBy";
91 for (
int i = 0; i < m_movedPoints.
count(); i++) {
93 QString pointIdentifier = m_movedPoints.
getKey (i);
100 QList<QGraphicsItem *>::iterator itrS;
101 for (itrS = items.begin (); itrS != items.end (); itrS++) {
103 QGraphicsItem *item = *itrS;
104 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {
106 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
108 if (m_movedPoints.
contains (pointIdentifier)) {
113 if (item->pos () != posScreen) {
116 item->setPos (posScreen);
130 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
131 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_MOVE_BY);
132 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
133 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X_DELTA, QString::number (m_deltaScreen.x()));
134 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y_DELTA, QString::number (m_deltaScreen.y()));
135 m_movedPoints.
saveXml (writer);
136 writer.writeEndElement();
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
See Curve::movePoint.
CmdMoveBy(MainWindow &mainWindow, Document &document, const QPointF &deltaScreen, const QString &moveText, const QStringList &selectedPointIdentifiers)
Constructor for normal creation.
void saveXml(QXmlStreamWriter &writer) const
Serialize table to xml.
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
QString getKey(int i) const
Get key for index.
bool contains(const QString &pointIdentifier) const
True if specified entry exists in the table.
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
void setKeyValue(const QString &pointIdentifier, bool value)
Set key/value pair.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
void loadXml(QXmlStreamReader &reader)
Load from serialized xml.
int count() const
Number of entries.
Document & document()
Return the Document that this command will modify during redo and undo.
void updateGraphicsLinesToMatchGraphicsPoints()
Update the graphics lines so they follow the graphics points, after a drag, addition, removal, and such.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.