From 68abac4181be61dd73169d996602a9a7cdb9f6fb Mon Sep 17 00:00:00 2001 From: Erik Andresen <e.andresen@uni-wuppertal.de> Date: Mon, 1 Feb 2016 12:21:38 +0100 Subject: [PATCH] Issue #25 Undo/Redo LineEdit --- CHANGELOG.md | 3 +- forms/HLine.png | Bin 0 -> 1634 bytes forms/Ressource.qrc | 1 + forms/mainwindow.ui | 12 ++++-- src/GraphicView.cpp | 67 ++++++++++++++++++++++++++----- src/GraphicView.h | 7 +++- src/UndoFramework/lineaction.cpp | 8 +++- src/UndoFramework/lineaction.h | 4 +- src/datamanager.cpp | 1 + src/mainWindow.cpp | 10 ++++- 10 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 forms/HLine.png diff --git a/CHANGELOG.md b/CHANGELOG.md index e9318ad..1af4217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ All notable changes to this project will be documented in this file. ## v0.8.0 [Unreleased] - ### Added #### JPSEDITOR +- 1.2.16 Create and save HLines - First approaches of an undo/redo framework - Undo/Redo working when line added or deleted - DXF import with different layers - Not working properly with AutoCAD ?! @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - Zooming - Line editing - Length of line is displayed + - Show origin - ... - Room and door declarations diff --git a/forms/HLine.png b/forms/HLine.png new file mode 100644 index 0000000000000000000000000000000000000000..81b9f3dce14be3bb072beb30858f16af605a42ff GIT binary patch literal 1634 zcmeAS@N?(olHy`uVBq!ia0y~yU}RxnVC3XrVqjqS`{i6S0|NtNage(c!@6@aFBupZ zSkfJR9T^xl_H+M9WMyDr;4JWnEM{O3Dgj}}duj3&3=FK_JzX3_D&pSWjGlC7hoD2? z$>^D1d&I5d`mYC_n<#l{#qM466ei5Hc-}7gL_fcQVSl{d^!x+c^Z#3|+hA*Wz>%jw zfLZ1U13QfQr)2Sd`+vVa$He*gbspZ%MSF5GDsI`rK7zdD=M?^k>Gd+}^3UEH#| z|A>SC_UkRHZ?hR*xDXugZr|CM_iow)lTO_|F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4sAQ~L0a{V56^y$#Ns3i4MxL1zML$E8jXkF8EQ1n-`3~I`RDRJLybm$vtCEe znr+EEUJq8iO$uO&zp2fpT5#CSP^0m7S*IiCovp4sUJnHSCI>L_XUR1SRm41(m~tTa z*0BXF^R61RseWi`Gt_9jUefKzxo1r%kJkg)+N1!c{4Aknp^Er+i75vJo+bw{Exyv{ z$jK98!KP{uc2#1^fdbX!0H*X6;>|)9o*N~m9H`tEuQxr}=Y1Zh(F57kFgDeKZBm9B zjhtLZ7O*@!A=fN4L#>p@D`D9lLyg9hla4K5d3IW&Stvp&md7h$YK);qW2?~71uWN2 z2{j8v=(+NEDKvjI)M!)@JHCMBQ-ox*kVk4HkC(!1Q$vl$7O^7>Sc+!JHVb)VXYqI` zY_2raXndk}bOFn!*@DeN8V|onOmPr>ery2?m!%<_YQX78Lyg8FzfMQa5EDB#)qpDx zB&ImTDkldpE#>WY<P0%aV^h6wph04a1ONMD3s`PdXtSwaIQiO8qcJV6$C2~PXD=SF z1xuGF2QbCjiZ=^oyy=vf;*j4DQd+ISrn;f|x1mO(@10IZ&Nq+4c)Sv{<Bu(1DJ!;R zQ{Avo+fbv?wzkKSGw1boi75xp)g4{HVpe`+0n3g}jsJW&-#n<}@k$UbPYPiAy+gEF z=*B6*!_U9RalU!>`)QHoG5LQ#Ui(XKSl(}VV4Iv(RI6+UBVSTOv&4h;{QLjd^M3u2 V{1CdPo`HdZ!PC{xWt~$(698djeyRWf literal 0 HcmV?d00001 diff --git a/forms/Ressource.qrc b/forms/Ressource.qrc index ecefdd3..239132d 100644 --- a/forms/Ressource.qrc +++ b/forms/Ressource.qrc @@ -41,5 +41,6 @@ <file>anglesnap.PNG</file> <file>Undo-icon.png</file> <file>Redo-Icon.png</file> + <file>HLine.png</file> </qresource> </RCC> diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 97af0c1..803f47c 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -53,8 +53,12 @@ </property> <addaction name="actionSelect_Mode"/> <addaction name="separator"/> + <addaction name="actionUndo"/> + <addaction name="actionRedo"/> + <addaction name="separator"/> <addaction name="actionWall"/> <addaction name="actionDoor"/> + <addaction name="actionHLine"/> <addaction name="separator"/> <addaction name="actiongridmode"/> <addaction name="actionObjectsnap"/> @@ -519,7 +523,7 @@ <string>Undo</string> </property> <property name="toolTip"> - <string>Undo</string> + <string>Undo PaintEvent</string> </property> <property name="shortcut"> <string>Ctrl+Z</string> @@ -537,10 +541,10 @@ <string>Redo</string> </property> <property name="toolTip"> - <string>Redo</string> + <string>Redo PaintEvent</string> </property> <property name="shortcut"> - <string>Ctrl+U</string> + <string>Ctrl+Y</string> </property> </action> <action name="actionHLine"> @@ -552,7 +556,7 @@ </property> <property name="icon"> <iconset resource="Ressource.qrc"> - <normaloff>:/Wall.png</normaloff>:/Wall.png</iconset> + <normaloff>:/HLine.png</normaloff>:/HLine.png</iconset> </property> <property name="text"> <string>HLine</string> diff --git a/src/GraphicView.cpp b/src/GraphicView.cpp index 352e1c7..0d8e51c 100644 --- a/src/GraphicView.cpp +++ b/src/GraphicView.cpp @@ -46,6 +46,7 @@ jpsGraphicsView::jpsGraphicsView(QWidget* parent):QGraphicsView(parent) translation_x=0; translation_y=0;//this->height(); anglesnap=false; + id_counter=0; _scaleFactor=1.0; _gridSize=1.0; gl_scale_f=.01*_scaleFactor; @@ -792,6 +793,8 @@ void jpsGraphicsView::drawLine() { jpsLineItem* lineItem= new jpsLineItem(current_line); + lineItem->set_id(id_counter); + id_counter++; // if there is already a drawn line if (line_vector.size()>=1) @@ -812,7 +815,7 @@ void jpsGraphicsView::drawLine() current_line=nullptr; //Undo - RecordUndoLineAction("LineAdded",lineItem->GetType(),lineItem->get_line()->line()); + RecordUndoLineAction("LineAdded",lineItem->GetType(),lineItem->get_id(),lineItem->get_line()->line()); //drawLine(); @@ -875,6 +878,8 @@ jpsLineItem* jpsGraphicsView::addLineItem(const qreal &x1,const qreal &y1,const current_line=Scene->addLine(x1,y1,x2,y2); current_line->setTransform(QTransform::fromTranslate(translation_x,translation_y), true); jpsLineItem* newLine = new jpsLineItem(current_line); + newLine->set_id(id_counter); + id_counter++; if (type=="Door") { @@ -979,6 +984,7 @@ void jpsGraphicsView::EditLine(QPointF* point) if (marked_lines.first()->get_line()->line().p1()==*point) { + RecordUndoLineAction("LineEdited",marked_lines.first()->GetType(),marked_lines.first()->get_id(),marked_lines.first()->get_line()->line()); current_line=marked_lines[0]->get_line(); marked_lines[0]->get_line()->setLine(marked_lines[0]->get_line()->line().x2(),marked_lines[0]->get_line()->line().y2(),translated_pos.x(),translated_pos.y()); //current_line=Scene->addLine(marked_lines[0]->get_line()->line().p2().x(), @@ -989,6 +995,7 @@ void jpsGraphicsView::EditLine(QPointF* point) else if (marked_lines.first()->get_line()->line().p2()==*point) { + RecordUndoLineAction("LineEdited",marked_lines.first()->GetType(),marked_lines.first()->get_id(),marked_lines.first()->get_line()->line()); current_line=marked_lines[0]->get_line(); marked_lines[0]->get_line()->setLine(marked_lines[0]->get_line()->line().x1(),marked_lines[0]->get_line()->line().y1(),translated_pos.x(),translated_pos.y()); @@ -1004,6 +1011,7 @@ void jpsGraphicsView::EditLine(QPointF* point) //line_tracked=1; RemoveIntersections(marked_lines.first()); _statLineEdit=true; + //delete_marked_lines(); en_disableWall(); @@ -1048,14 +1056,40 @@ bool jpsGraphicsView::show_hide_roomCaption(QString name, qreal x, qreal y) return true; } -void jpsGraphicsView::RecordUndoLineAction(const QString& name, const QString& type, const QLineF &oldLine) +void jpsGraphicsView::RecordUndoLineAction(const QString& name, const QString& type, const int& itemID, const QLineF &oldLine) +{ + _undoStack.PushNewAction(LineAction(name,type,itemID,oldLine)); +} + +void jpsGraphicsView::RecordRedoLineAction(const QString &name, const QString &type, const int& itemID, const QLineF &oldLine) { - _undoStack.PushNewAction(LineAction(name,type,oldLine)); + _redoStack.PushNewAction(LineAction(name,type,itemID,oldLine)); +} + +void jpsGraphicsView::UndoLineEdit(const int& lineID, const QLineF& old_line) +{ + for (jpsLineItem* lineItem:line_vector) + { + if (lineItem->get_id()==lineID) + { + RecordRedoLineAction("LineEdited",lineItem->GetType(),lineItem->get_id(),lineItem->get_line()->line()); + lineItem->get_line()->setLine(old_line); + break; + } + } } -void jpsGraphicsView::RecordRedoLineAction(const QString &name, const QString &type, const QLineF &oldLine) +void jpsGraphicsView::RedoLineEdit(const int &lineID, const QLineF &old_line) { - _redoStack.PushNewAction(LineAction(name,type,oldLine)); + for (jpsLineItem* lineItem:line_vector) + { + if (lineItem->get_id()==lineID) + { + RecordUndoLineAction("LineEdited",lineItem->GetType(),lineItem->get_id(),lineItem->get_line()->line()); + lineItem->get_line()->setLine(old_line); + break; + } + } } void jpsGraphicsView::Undo() @@ -1069,13 +1103,18 @@ void jpsGraphicsView::Undo() addLineItem(recentAction.GetOldLine().p1().x(),recentAction.GetOldLine().p1().y(),recentAction.GetOldLine().p2().x(), recentAction.GetOldLine().p2().y(),recentAction.GetType()); - RecordRedoLineAction("LineAdded",recentAction.GetType(),QLineF(0,0,0,0)); + RecordRedoLineAction("LineAdded",recentAction.GetType(),id_counter-1,QLineF(0,0,0,0)); } else if (recentAction.GetName()=="LineAdded") { - RecordRedoLineAction("LineDeleted",line_vector.back()->GetType(),line_vector.back()->get_line()->line()); + RecordRedoLineAction("LineDeleted",line_vector.back()->GetType(),line_vector.back()->get_id(), + line_vector.back()->get_line()->line()); RemoveLineItem(line_vector.back()); } + else if (recentAction.GetName()=="LineEdited") + { + UndoLineEdit(recentAction.GetItemID(),recentAction.GetOldLine()); + } } } @@ -1091,15 +1130,21 @@ void jpsGraphicsView::Redo() addLineItem(recentAction.GetOldLine().p1().x(),recentAction.GetOldLine().p1().y(),recentAction.GetOldLine().p2().x(), recentAction.GetOldLine().p2().y(),recentAction.GetType()); - RecordUndoLineAction("LineAdded",recentAction.GetType(),QLineF(0,0,0,0)); + RecordUndoLineAction("LineAdded",recentAction.GetType(),id_counter-1,QLineF(0,0,0,0)); } else if (recentAction.GetName()=="LineAdded") { - RecordUndoLineAction("LineDeleted",line_vector.back()->GetType(),line_vector.back()->get_line()->line()); + RecordUndoLineAction("LineDeleted",line_vector.back()->GetType(),line_vector.back()->get_id(), + line_vector.back()->get_line()->line()); RemoveLineItem(line_vector.back()); } + else if (recentAction.GetName()=="LineEdited") + { + RedoLineEdit(recentAction.GetItemID(),recentAction.GetOldLine()); + + } } @@ -1443,7 +1488,7 @@ void jpsGraphicsView::delete_marked_lines() for (int i=0; i<marked_lines.size(); ++i) { - RecordUndoLineAction("LineDeleted",marked_lines[i]->GetType(),marked_lines[i]->get_line()->line()); + RecordUndoLineAction("LineDeleted",marked_lines[i]->GetType(),marked_lines[i]->get_id(),marked_lines[i]->get_line()->line()); RemoveIntersections(marked_lines[i]); @@ -1571,6 +1616,8 @@ void jpsGraphicsView::take_l_from_lineEdit(const qreal &length) line.setLength(length); current_line->setLine(line); jpsLineItem* jpsline = new jpsLineItem(current_line); + jpsline->set_id(id_counter); + id_counter++; jpsline->set_type(statWall,statDoor,statExit); line_vector.push_back(jpsline); current_line=nullptr; diff --git a/src/GraphicView.h b/src/GraphicView.h index 06be9be..e72eb84 100644 --- a/src/GraphicView.h +++ b/src/GraphicView.h @@ -132,8 +132,10 @@ public: bool show_hide_roomCaption(QString name, qreal x, qreal y); //Undo Framework - void RecordUndoLineAction(const QString &name, const QString &type, const QLineF &oldLine); - void RecordRedoLineAction(const QString &name, const QString &type, const QLineF &oldLine); + void RecordUndoLineAction(const QString &name, const QString &type, const int &itemID, const QLineF &oldLine); + void RecordRedoLineAction(const QString &name, const QString &type, const int &itemID, const QLineF &oldLine); + void UndoLineEdit(const int &lineID, const QLineF &old_line); + void RedoLineEdit(const int &lineID, const QLineF &old_line); public slots: //Waypoints @@ -197,6 +199,7 @@ private: QList<jpsLineItem *> marked_lines; QGraphicsTextItem* current_caption; QList<QGraphicsTextItem* > caption_list; + int id_counter; //Landmark and waypoints QList<jpsLandmark* > LLandmarks; diff --git a/src/UndoFramework/lineaction.cpp b/src/UndoFramework/lineaction.cpp index a8cca4b..9bc9523 100644 --- a/src/UndoFramework/lineaction.cpp +++ b/src/UndoFramework/lineaction.cpp @@ -5,9 +5,10 @@ LineAction::LineAction() } -LineAction::LineAction(const QString &name, const QString &type, const QLineF &oldLine) : Action(name,type) +LineAction::LineAction(const QString &name, const QString &type, const int &itemID, const QLineF &oldLine) : Action(name,type) { _oldLine=oldLine; + _itemID=itemID; } LineAction::~LineAction() @@ -20,3 +21,8 @@ QLineF LineAction::GetOldLine() const return _oldLine; } +int LineAction::GetItemID() const +{ + return _itemID; +} + diff --git a/src/UndoFramework/lineaction.h b/src/UndoFramework/lineaction.h index 63e0cb7..e61f266 100644 --- a/src/UndoFramework/lineaction.h +++ b/src/UndoFramework/lineaction.h @@ -8,12 +8,14 @@ class LineAction : public Action { public: LineAction(); - LineAction(const QString& name, const QString& type, const QLineF& oldLine); + LineAction(const QString& name, const QString& type, const int& itemID, const QLineF& oldLine); ~LineAction(); QLineF GetOldLine() const; + int GetItemID() const; private: QLineF _oldLine; + int _itemID; }; #endif // PAINTACTION_H diff --git a/src/datamanager.cpp b/src/datamanager.cpp index 3b699f9..3b58cea 100644 --- a/src/datamanager.cpp +++ b/src/datamanager.cpp @@ -358,6 +358,7 @@ void jpsDatamanager::writeRoutingHeader(QXmlStreamWriter *stream) void jpsDatamanager::writeHLines(QXmlStreamWriter *stream, QList<jpsLineItem *> &hLines) { + // to be sure that id is unique (considering crossings, transitions) int id=1000; for (jpsLineItem *lineItem:hLines) { diff --git a/src/mainWindow.cpp b/src/mainWindow.cpp index e063547..7d9317f 100644 --- a/src/mainWindow.cpp +++ b/src/mainWindow.cpp @@ -183,6 +183,13 @@ void MWindow::AutoSave() dmanager->AutoSaveXML(file); //file.write(coord_string.toUtf8());//textEdit->toPlainText().toUtf8()); statusBar()->showMessage(tr("Backup file generated!"),10000); + + //routing (hlines) + QString fileNameRouting = file.fileName(); + fileNameRouting=fileNameRouting.split(".").first()+"_routing.xml"; + QFile routingFile(fileNameRouting); + if (routingFile.open(QIODevice::WriteOnly|QIODevice::Text)) + dmanager->writeRoutingXML(routingFile); } } @@ -339,7 +346,8 @@ void MWindow::saveFile(){ dmanager->writeXML(file); //routing (hlines) - QString fileNameRouting = fileName+"routing.xml"; + QString fileNameRouting=fileName.split(".").first()+"_routing.xml"; + QFile routingFile(fileNameRouting); if (routingFile.open(QIODevice::WriteOnly|QIODevice::Text)) dmanager->writeRoutingXML(routingFile); -- GitLab