# HG changeset patch # User Teemu Piippo # Date 1658342096 -10800 # Node ID e07425ac5834635daa060c57347a3acfc239d2d4 # Parent c5830bce1c23207d197bbb1588821fb1e2bfbffe Draw mode and make unofficial tools now work again diff -r c5830bce1c23 -r e07425ac5834 src/ldrawalgorithm.cpp --- a/src/ldrawalgorithm.cpp Wed Jul 20 12:59:07 2022 +0300 +++ b/src/ldrawalgorithm.cpp Wed Jul 20 21:34:56 2022 +0300 @@ -1,3 +1,4 @@ +#include #include "src/ldrawalgorithm.h" std::pair splitTriangles( @@ -20,28 +21,25 @@ std::vector ldraw::makeUnofficial(const Model* model) { std::vector actions; -#if 0 - if (model->size() >= 4) { - if (const Comment* comment = std::get_if(&(*model)[3])) { - const QString& body = comment->text; - if (body.startsWith("!LDRAW_ORG ") and not body.startsWith("!LDRAW_ORG Unofficial_")) + constexpr int ldrawOrgLinePosition = 3; + const QTextBlock block = model->findBlockByLineNumber(ldrawOrgLinePosition); + if (block.isValid()) { + const QString body = block.text().simplified(); + if (body.startsWith("0 !LDRAW_ORG ") and not body.startsWith("0 !LDRAW_ORG Unofficial_")) { + // Add Unofficial_ to part type + QStringList tokens = body.split(" "); + tokens[2] = "Unofficial_" + tokens[2]; + // Remove the UPDATE tag if it's there + if (tokens.size() >= 5 && tokens[3] == "UPDATE") { - // Add Unofficial_ to part type - QStringList tokens = body.split(" "); - tokens[1] = "Unofficial_" + tokens[1]; - // Remove the UPDATE tag if it's there - if (tokens.size() >= 4 && tokens[2] == "UPDATE") - { - tokens.removeAt(3); - tokens.removeAt(2); - } - actions.push_back(ModifyModel{ - .position = 3, - .newElement = Comment{.text = tokens.join(" ")} - }); + tokens.removeAt(4); + tokens.removeAt(3); } + actions.push_back(ModifyModel{ + .position = ldrawOrgLinePosition, + .newElement = Comment{.text = tokens.mid(1).join(" ")} + }); } } -#endif return actions; } diff -r c5830bce1c23 -r e07425ac5834 src/main.cpp --- a/src/main.cpp Wed Jul 20 12:59:07 2022 +0300 +++ b/src/main.cpp Wed Jul 20 21:34:56 2022 +0300 @@ -471,19 +471,29 @@ const auto executeAction = [&]( Model* model, const ModelAction& action ) { - /* std::visit(overloaded{ [model](const AppendToModel& action){ - model->append(action.newElement); + QTextCursor cursor{model}; + cursor.movePosition(QTextCursor::End); + const QString newText = modelElementToString(action.newElement); + // Make sure we have an empty line + if (not model->lastBlock().text().isEmpty()) { + cursor.insertBlock(); + } + qDebug() << cursor.blockNumber(); + cursor.insertText(newText); }, - [model](const DeleteFromModel& action){ - model->remove(action.position); - }, + [](const DeleteFromModel&){}, [model](const ModifyModel& action){ - model->assignAt(action.position, action.newElement); + QTextBlock block = model->findBlockByLineNumber((int) action.position); + if (block.isValid()) { + QTextCursor cursor{block}; + cursor.select(QTextCursor::LineUnderCursor); + cursor.insertText(modelElementToString(action.newElement)); + } + //model->assignAt(action.position, action.newElement); }, }, action); - */ }; const auto restoreSettings = [&]{ diff -r c5830bce1c23 -r e07425ac5834 src/model.h --- a/src/model.h Wed Jul 20 12:59:07 2022 +0300 +++ b/src/model.h Wed Jul 20 21:34:56 2022 +0300 @@ -206,3 +206,5 @@ AppendToModel, DeleteFromModel, ModifyModel>; + +QString modelElementToString(const ModelElement &element);