10 #include "DocumentSerialize.h" 11 #include "EngaugeAssert.h" 12 #include "GraphicsItemType.h" 13 #include "GraphicsView.h" 15 #include "MainWindow.h" 16 #include <QGraphicsItem> 17 #include <QtToString.h> 18 #include <QXmlStreamReader> 23 const QPointF &deltaScreen,
24 const QString &moveText,
25 const QStringList &selectedPointIdentifiers) :
29 m_deltaScreen (deltaScreen)
32 QStringList::const_iterator itr;
33 for (itr = selectedPointIdentifiers.begin (); itr != selectedPointIdentifiers.end (); itr++) {
35 QString selectedPointIdentifier = *itr;
37 selected << selectedPointIdentifier;
38 m_movedPoints.
setKeyValue (selectedPointIdentifier,
true);
41 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::CmdMoveBy" 42 <<
" deltaScreen=" << QPointFToString (deltaScreen).toLatin1 ().data ()
43 <<
" selected=" << selected.join (
", ").toLatin1 ().data () <<
")";
48 const QString &cmdDescription,
49 QXmlStreamReader &reader) :
54 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::CmdMoveBy";
56 QXmlStreamAttributes attributes = reader.attributes();
58 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X_DELTA) ||
59 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y_DELTA) ) {
60 xmlExitWithError (reader,
61 QString (
"%1 %2 %3 %4")
62 .arg (QObject::tr (
"Missing attribute(s)"))
63 .arg (DOCUMENT_SERIALIZE_SCREEN_X_DELTA)
64 .arg (QObject::tr (
"and/or"))
65 .arg (DOCUMENT_SERIALIZE_SCREEN_Y_DELTA));
68 m_deltaScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X_DELTA).toDouble());
69 m_deltaScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y_DELTA).toDouble());
73 CmdMoveBy::~CmdMoveBy ()
79 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::cmdRedo" 80 <<
" deltaScreen=" << QPointFToString (m_deltaScreen).toLatin1().data()
81 <<
" moving=" << m_movedPoints.
count ();
83 moveBy (m_deltaScreen);
90 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::cmdUndo" 91 <<
" deltaScreen=" << QPointFToString (-1.0 * m_deltaScreen).toLatin1().data()
92 <<
" moving=" << m_movedPoints.
count ();
94 moveBy (-1.0 * m_deltaScreen);
99 void CmdMoveBy::moveBy (
const QPointF &deltaScreen)
101 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdMoveBy::moveBy";
104 for (
int i = 0; i < m_movedPoints.
count(); i++) {
106 QString pointIdentifier = m_movedPoints.
getKey (i);
113 QList<QGraphicsItem *>::iterator itrS;
114 for (itrS = items.begin (); itrS != items.end (); itrS++) {
116 QGraphicsItem *item = *itrS;
117 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {
119 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
121 if (m_movedPoints.
contains (pointIdentifier)) {
126 if (item->pos () != posScreen) {
129 item->setPos (posScreen);
143 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
144 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_MOVE_BY);
145 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
146 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X_DELTA, QString::number (m_deltaScreen.x()));
147 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y_DELTA, QString::number (m_deltaScreen.y()));
148 m_movedPoints.
saveXml (writer);
149 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 resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
Since the set of selected points has probably changed, changed that set back to the specified set...
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.