From 522cb00edd9f365280833ad6499db37f338fc3a0 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 03:03:44 +0400 Subject: [PATCH 1/7] Fix crash related to zeros stored in settings --- mapeditor/windownewmap.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index 7cc7a124b..35a6dcc4f 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -37,8 +37,10 @@ WindowNewMap::WindowNewMap(QWidget *parent) : show(); //setup initial parameters - mapGenOptions.setWidth(ui->widthTxt->text().toInt()); - mapGenOptions.setHeight(ui->heightTxt->text().toInt()); + int width = ui->widthTxt->text().toInt(); + int height = ui->heightTxt->text().toInt(); + mapGenOptions.setWidth(width ? width : 1); + mapGenOptions.setHeight(height ? height : 1); bool twoLevel = ui->twoLevelCheck->isChecked(); mapGenOptions.setHasTwoLevels(twoLevel); updateTemplateList(); From c290153cd05a7263375ea4f1db11f1f31238602c Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 03:56:57 +0400 Subject: [PATCH 2/7] Fix crash related to unblocked menu item --- mapeditor/mainwindow.ui | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index f23450ca9..0b1dc5b95 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -1010,6 +1010,9 @@ + + false + Players settings From 40300972bc91e5d242aaf98f2c0dd825a5495289 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 19:52:36 +0400 Subject: [PATCH 3/7] Add undo/redo icons --- mapeditor/icons/edit-redo.png | Bin 0 -> 1502 bytes mapeditor/icons/edit-undo.png | Bin 0 -> 1601 bytes mapeditor/mainwindow.ui | 11 +++++++++++ 3 files changed, 11 insertions(+) create mode 100644 mapeditor/icons/edit-redo.png create mode 100644 mapeditor/icons/edit-undo.png diff --git a/mapeditor/icons/edit-redo.png b/mapeditor/icons/edit-redo.png new file mode 100644 index 0000000000000000000000000000000000000000..3eb7b05c84809454c095bcb61b27d83585540bb2 GIT binary patch literal 1502 zcmV<41tI#0P)HR%3`p(HB`no_vu~6N}ZlRFC*?c+Y%$zyD-}&au z&JZ)>K^AeZ6L@^ummZ&X*Yn)70D$d6!LJ^l=6+BDv~c!{RYJijk54Ok5CT{{e~oil z-TFEbX!ZECIrm*akb>H(dS&g?FP4)K%^sh&_`V4c2m&fb&2G#rtri=XzfzzG^{B_E zHQpZqA_x*72n38CJd|Gu&#E_aHK*$b&n|7-ZLgos|A5D*S!OO3tj^fh z_!0W`3$WRQ%?5InVvwcc=cez&6S48H4!ouBxMu;6Pg_j_`(_qbYqix+<`vH*0k)O-56 zud&1uzgHhmFx075FBE*UbpHBBSI%oxLe?+@Zf!Q;*6vT#lyW3w4JY9MkgFEMG%bvd zj938nr^2Tc@c6W~RmHXIm(1Ou1kFAG0Fw%UlRqSTi54)VcO>U1an?Yy3vuG~@rZ85 z-uG|Ozewj~6o}vV-Rqv(Ci;8JElAxFv;gud8$jGKcnWCQ?Erp*KC zIXKaBJYt&WcE4BOor#q#1Dk6q78K>?<|1J9K#&Rskgt}(!EXFJ*vh>lSE3{1Loyf| z&3UuoJ;5w7Y;*zuDqMB2!UCtx{28%r>ovbu_h-v=W&y&2n({i=gf#-m76=0Q&NB3m zb>eW#zGx^K*vpKg0NMp9e=$o8=`Dj;l=Lz_SWyF}Y_f*liLBCL1t~h-HRlkcb2k zDMX|u0swmZd)fkBa>Y+ujj{N7B|et!O2BRM{{EheXKZP~kP#GW?m+0WbOJ~ZO^HPi?D-I-Z@Rh)4kw5h(x^0Lp=##*zNcjveFS!C+x=g(!SP+wgD|a?&Pu zP7Fa!$fU164o-xU8bl<3l(%90fD)HVwznQAX`EZL=V6*OcF^rX8}#?vph{K*-aJ52Fh0c1LTj{jN5&vp3=Xo2yjp{$HjMoWQ8Y47Fs_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ui index 0b1dc5b95..1b266eaec 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -123,6 +123,9 @@ + + + @@ -1021,6 +1024,10 @@ false + + + icons:edit-undo.pngicons:edit-undo.png + Undo @@ -1038,6 +1045,10 @@ false + + + icons:edit-redo.pngicons:edit-redo.png + Redo From 00789cb0d702b6e4540dc039404fab293175b1ea Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 19:52:56 +0400 Subject: [PATCH 4/7] Cleanup undo stack for new map --- mapeditor/mapcontroller.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index d90279691..21eb65384 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -214,6 +214,7 @@ void MapController::setMap(std::unique_ptr cmap) main->enableRedo(allowRedo); } ); + _map->getEditManager()->getUndoManager().clearAll(); } void MapController::sceneForceUpdate() From fc6026969f8e95ea167070d387cdfb68f373aa6a Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 20:22:43 +0400 Subject: [PATCH 5/7] Fix town building inspector --- mapeditor/inspector/townbulidingswidget.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mapeditor/inspector/townbulidingswidget.cpp b/mapeditor/inspector/townbulidingswidget.cpp index 04dbfdbdd..6164c92cd 100644 --- a/mapeditor/inspector/townbulidingswidget.cpp +++ b/mapeditor/inspector/townbulidingswidget.cpp @@ -172,11 +172,22 @@ void TownBulidingsWidget::addBuildings(const CTown & ctown) std::set TownBulidingsWidget::getBuildingsFromModel(int modelColumn, Qt::CheckState checkState) { std::set result; - for(int i = 0; i < model.rowCount(); ++i) + std::vector stack; + stack.push_back(QModelIndex()); + while(!stack.empty()) { - if(auto * item = model.item(i, modelColumn)) - if(item->checkState() == checkState) - result.emplace(item->data(Qt::UserRole).toInt()); + auto pindex = stack.back(); + stack.pop_back(); + for(int i = 0; i < model.rowCount(pindex); ++i) + { + QModelIndex index = model.index(i, modelColumn, pindex); + if(auto * item = model.itemFromIndex(index)) + if(item->checkState() == checkState) + result.emplace(item->data(Qt::UserRole).toInt()); + index = model.index(i, 0, pindex); //children are linked to first column of the model + if(model.hasChildren(index)) + stack.push_back(index); + } } return result; From 2f2c980a0cfd952c12163ed1e1502e27d59804d8 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 20:47:03 +0400 Subject: [PATCH 6/7] Fix crash on map destroying --- lib/mapping/CMap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index d5f3fee82..4d55bc0b7 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -256,6 +256,8 @@ CMap::CMap() CMap::~CMap() { + getEditManager()->getUndoManager().clearAll(); + if(terrain) { for(int z = 0; z < levels(); z++) From 8d1024fcfc30d7b196fef7e49723b1121bb11354 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 3 Dec 2022 20:52:27 +0400 Subject: [PATCH 7/7] Clear error message --- lib/mapObjects/CObjectClassesHandler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index f6d5dbcaf..08aada91e 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -308,8 +308,9 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(si32 type, si32 subtype) if (objects.at(type)->subObjects.count(subtype)) return objects.at(type)->subObjects.at(subtype); } - logGlobal->error("Failed to find object of type %d:%d", type, subtype); - throw std::runtime_error("Object type handler not found"); + std::string errorString = "Failed to find object of type " + std::to_string(type) + "::" + std::to_string(subtype); + logGlobal->error(errorString); + throw std::runtime_error(errorString); } TObjectTypeHandler CObjectClassesHandler::getHandlerFor(std::string scope, std::string type, std::string subtype) const @@ -325,8 +326,9 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(std::string scope, std:: return object->subObjects.at(subId); } } - logGlobal->error("Failed to find object of type %s::%s", type, subtype); - throw std::runtime_error("Object type handler not found"); + std::string errorString = "Failed to find object of type " + type + "::" + subtype; + logGlobal->error(errorString); + throw std::runtime_error(errorString); } TObjectTypeHandler CObjectClassesHandler::getHandlerFor(CompoundMapObjectID compoundIdentifier) const