From a0eff32f361cc9efab6b40a11fe9c042f9c8c959 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 16 Oct 2022 02:49:42 -0400 Subject: [PATCH] Remove more internal type conversions --- include/core/mapconnection.h | 2 +- include/core/maplayout.h | 8 +++---- include/ui/connectionpixmapitem.h | 2 +- src/core/map.cpp | 16 ++++++------- src/core/maplayout.cpp | 8 +++---- src/core/mapparser.cpp | 8 +++---- src/editor.cpp | 20 ++++++++-------- src/project.cpp | 38 +++++++++++++++---------------- src/ui/connectionpixmapitem.cpp | 2 +- src/ui/mapimageexporter.cpp | 2 +- src/ui/newmappopup.cpp | 24 +++++++++---------- 11 files changed, 65 insertions(+), 65 deletions(-) diff --git a/include/core/mapconnection.h b/include/core/mapconnection.h index b6be238e..11aa0e59 100644 --- a/include/core/mapconnection.h +++ b/include/core/mapconnection.h @@ -8,7 +8,7 @@ class MapConnection { public: QString direction; - QString offset; + int offset; QString map_name; }; diff --git a/include/core/maplayout.h b/include/core/maplayout.h index 888e5372..13215fff 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -14,10 +14,10 @@ public: static QString layoutConstantFromName(QString mapName); QString id; QString name; - QString width; - QString height; - QString border_width; - QString border_height; + int width; + int height; + int border_width; + int border_height; QString border_path; QString blockdata_path; QString tileset_primary_label; diff --git a/include/ui/connectionpixmapitem.h b/include/ui/connectionpixmapitem.h index a4cdf4e2..e12296af 100644 --- a/include/ui/connectionpixmapitem.h +++ b/include/ui/connectionpixmapitem.h @@ -15,7 +15,7 @@ public: setFlag(ItemSendsGeometryChanges); this->initialX = x; this->initialY = y; - this->initialOffset = connection->offset.toInt(); + this->initialOffset = connection->offset; this->baseMapWidth = baseMapWidth; this->baseMapHeight = baseMapHeight; } diff --git a/src/core/map.cpp b/src/core/map.cpp index 9bbe68c4..107033b3 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -310,10 +310,10 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool setNewDimensionsBlockdata(newWidth, newHeight); } - int oldWidth = layout->width.toInt(); - int oldHeight = layout->height.toInt(); - layout->width = QString::number(newWidth); - layout->height = QString::number(newHeight); + int oldWidth = layout->width; + int oldHeight = layout->height; + layout->width = newWidth; + layout->height = newHeight; if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) { Scripting::cb_MapResized(oldWidth, oldHeight, newWidth, newHeight); @@ -328,10 +328,10 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata, setNewBorderDimensionsBlockdata(newWidth, newHeight); } - int oldWidth = layout->border_width.toInt(); - int oldHeight = layout->border_height.toInt(); - layout->border_width = QString::number(newWidth); - layout->border_height = QString::number(newHeight); + int oldWidth = layout->border_width; + int oldHeight = layout->border_height; + layout->border_width = newWidth; + layout->border_height = newHeight; if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) { Scripting::cb_BorderResized(oldWidth, oldHeight, newWidth, newHeight); diff --git a/src/core/maplayout.cpp b/src/core/maplayout.cpp index 8b1a1d3f..310017be 100644 --- a/src/core/maplayout.cpp +++ b/src/core/maplayout.cpp @@ -16,17 +16,17 @@ QString MapLayout::layoutConstantFromName(QString mapName) { } int MapLayout::getWidth() { - return width.toInt(nullptr, 0); + return width; } int MapLayout::getHeight() { - return height.toInt(nullptr, 0); + return height; } int MapLayout::getBorderWidth() { - return border_width.toInt(nullptr, 0); + return border_width; } int MapLayout::getBorderHeight() { - return border_height.toInt(nullptr, 0); + return border_height; } diff --git a/src/core/mapparser.cpp b/src/core/mapparser.cpp index 88592ab0..986c2c24 100644 --- a/src/core/mapparser.cpp +++ b/src/core/mapparser.cpp @@ -70,10 +70,10 @@ MapLayout *MapParser::parse(QString filepath, bool *error, Project *project) } MapLayout *mapLayout = new MapLayout(); - mapLayout->width = QString::number(mapWidth); - mapLayout->height = QString::number(mapHeight); - mapLayout->border_width = (borderWidth == 0) ? QString::number(2) : QString::number(borderWidth); - mapLayout->border_height = (borderHeight == 0) ? QString::number(2) : QString::number(borderHeight); + mapLayout->width = mapWidth; + mapLayout->height = mapHeight; + mapLayout->border_width = (borderWidth == 0) ? DEFAULT_BORDER_WIDTH : borderWidth; + mapLayout->border_height = (borderHeight == 0) ? DEFAULT_BORDER_HEIGHT : borderHeight; QList tilesets = project->tilesetLabelsOrdered; diff --git a/src/editor.cpp b/src/editor.cpp index bf748b7c..b00a5539 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -177,7 +177,7 @@ void Editor::setEditingConnections() { bool controlsEnabled = selected_connection_item != nullptr; setConnectionEditControlsEnabled(controlsEnabled); if (selected_connection_item) { - onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt()); + onConnectionOffsetChanged(selected_connection_item->connection->offset); setConnectionMap(selected_connection_item->connection->map_name); setCurrentConnectionDirection(selected_connection_item->connection->direction); } @@ -775,7 +775,7 @@ void Editor::setCurrentConnectionDirection(QString curDirection) { selected_connection_item->connection->direction = curDirection; QPixmap pixmap = connected_map->renderConnection(*selected_connection_item->connection, map->layout); - int offset = selected_connection_item->connection->offset.toInt(nullptr, 0); + int offset = selected_connection_item->connection->offset; selected_connection_item->initialOffset = offset; int x = 0, y = 0; if (selected_connection_item->connection->direction == "up") { @@ -821,7 +821,7 @@ void Editor::updateCurrentConnectionDirection(QString curDirection) { void Editor::onConnectionMoved(MapConnection* connection) { updateMirroredConnectionOffset(connection); - onConnectionOffsetChanged(connection->offset.toInt()); + onConnectionOffsetChanged(connection->offset); maskNonVisibleConnectionTiles(); } @@ -835,7 +835,7 @@ void Editor::onConnectionOffsetChanged(int newOffset) { void Editor::setConnectionEditControlValues(MapConnection* connection) { QString mapName = connection ? connection->map_name : ""; QString direction = connection ? connection->direction : ""; - int offset = connection ? connection->offset.toInt() : 0; + int offset = connection ? connection->offset : 0; ui->comboBox_ConnectedMap->blockSignals(true); ui->comboBox_ConnectionDirection->blockSignals(true); @@ -884,7 +884,7 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) { setConnectionEditControlValues(selected_connection_item->connection); ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset()); ui->spinBox_ConnectionOffset->setMinimum(selected_connection_item->getMinOffset()); - onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt()); + onConnectionOffsetChanged(selected_connection_item->connection->offset); } void Editor::setSelectedConnectionFromMap(QString mapName) { @@ -1561,7 +1561,7 @@ void Editor::createConnectionItem(MapConnection* connection, bool hide) { } QPixmap pixmap = connected_map->renderConnection(*connection, map->layout); - int offset = connection->offset.toInt(nullptr, 0); + int offset = connection->offset; int x = 0, y = 0; if (connection->direction == "up") { x = offset * 16; @@ -1724,7 +1724,7 @@ void Editor::updateConnectionOffset(int offset) { selected_connection_item->blockSignals(true); offset = qMin(offset, selected_connection_item->getMaxOffset()); offset = qMax(offset, selected_connection_item->getMinOffset()); - selected_connection_item->connection->offset = QString::number(offset); + selected_connection_item->connection->offset = offset; if (selected_connection_item->connection->direction == "up" || selected_connection_item->connection->direction == "down") { selected_connection_item->setX(selected_connection_item->initialX + (offset - selected_connection_item->initialOffset) * 16); } else if (selected_connection_item->connection->direction == "left" || selected_connection_item->connection->direction == "right") { @@ -1779,7 +1779,7 @@ void Editor::addNewConnection() { MapConnection* newConnection = new MapConnection; newConnection->direction = minDirection; - newConnection->offset = "0"; + newConnection->offset = 0; newConnection->map_name = defaultMapName; map->connections.append(newConnection); createConnectionItem(newConnection, true); @@ -1847,7 +1847,7 @@ void Editor::updateMirroredConnection(MapConnection* connection, QString origina otherMap->connections.append(mirrorConnection); } - mirrorConnection->offset = QString::number(-connection->offset.toInt()); + mirrorConnection->offset = -connection->offset; } void Editor::removeCurrentConnection() { @@ -1905,7 +1905,7 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) { if (!connection) { connection = new MapConnection; connection->direction = direction; - connection->offset = "0"; + connection->offset = 0; connection->map_name = mapName; map->connections.append(connection); updateMirroredConnection(connection, connection->direction, connection->map_name); diff --git a/src/project.cpp b/src/project.cpp index 4df26f18..fb1e2800 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -567,29 +567,29 @@ bool Project::readMapLayouts() { logError(QString("Invalid layout 'width' value '%1' on layout %2 in %3. Must be greater than 0.").arg(lwidth).arg(i).arg(layoutsFilepath)); return false; } - layout->width = QString::number(lwidth); + layout->width = lwidth; int lheight = ParseUtil::jsonToInt(layoutObj["height"]); if (lheight <= 0) { logError(QString("Invalid layout 'height' value '%1' on layout %2 in %3. Must be greater than 0.").arg(lheight).arg(i).arg(layoutsFilepath)); return false; } - layout->height = QString::number(lheight); + layout->height = lheight; if (useCustomBorderSize) { int bwidth = ParseUtil::jsonToInt(layoutObj["border_width"]); if (bwidth <= 0) { // 0 is an expected border width/height that should be handled, GF used it for the RS layouts in FRLG logWarn(QString("Invalid layout 'border_width' value '%1' on layout %2 in %3. Must be greater than 0. Using default (%4) instead.").arg(bwidth).arg(i).arg(layoutsFilepath).arg(DEFAULT_BORDER_WIDTH)); bwidth = DEFAULT_BORDER_WIDTH; } - layout->border_width = QString::number(bwidth); + layout->border_width = bwidth; int bheight = ParseUtil::jsonToInt(layoutObj["border_height"]); if (bheight <= 0) { logWarn(QString("Invalid layout 'border_height' value '%1' on layout %2 in %3. Must be greater than 0. Using default (%4) instead.").arg(bheight).arg(i).arg(layoutsFilepath).arg(DEFAULT_BORDER_HEIGHT)); bheight = DEFAULT_BORDER_HEIGHT; } - layout->border_height = QString::number(bheight); + layout->border_height = bheight; } else { - layout->border_width = QString::number(DEFAULT_BORDER_WIDTH); - layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT); + layout->border_width = DEFAULT_BORDER_WIDTH; + layout->border_height = DEFAULT_BORDER_HEIGHT; } layout->tileset_primary_label = ParseUtil::jsonToQString(layoutObj["primary_tileset"]); if (layout->tileset_primary_label.isEmpty()) { @@ -641,11 +641,11 @@ void Project::saveMapLayouts() { OrderedJson::object layoutObj; layoutObj["id"] = layout->id; layoutObj["name"] = layout->name; - layoutObj["width"] = layout->width.toInt(nullptr, 0); - layoutObj["height"] = layout->height.toInt(nullptr, 0); + layoutObj["width"] = layout->width; + layoutObj["height"] = layout->height; if (useCustomBorderSize) { - layoutObj["border_width"] = layout->border_width.toInt(nullptr, 0); - layoutObj["border_height"] = layout->border_height.toInt(nullptr, 0); + layoutObj["border_width"] = layout->border_width; + layoutObj["border_height"] = layout->border_height; } layoutObj["primary_tileset"] = layout->tileset_primary_label; layoutObj["secondary_tileset"] = layout->tileset_secondary_label; @@ -672,10 +672,10 @@ void Project::setNewMapLayout(Map* map) { MapLayout *layout = new MapLayout(); layout->id = MapLayout::layoutConstantFromName(map->name); layout->name = QString("%1_Layout").arg(map->name); - layout->width = QString::number(getDefaultMapSize()); - layout->height = QString::number(getDefaultMapSize()); - layout->border_width = QString::number(DEFAULT_BORDER_WIDTH); - layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT); + layout->width = getDefaultMapSize(); + layout->height = getDefaultMapSize(); + layout->border_width = DEFAULT_BORDER_WIDTH; + layout->border_height = DEFAULT_BORDER_HEIGHT; layout->border_path = QString("%2%1/border.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders)); layout->blockdata_path = QString("%2%1/map.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders)); layout->tileset_primary_label = tilesetLabels["primary"].value(0, "gTileset_General"); @@ -1311,11 +1311,11 @@ void Project::saveMap(Map *map) { QJsonObject newLayoutObj; newLayoutObj["id"] = map->layout->id; newLayoutObj["name"] = map->layout->name; - newLayoutObj["width"] = map->layout->width.toInt(); - newLayoutObj["height"] = map->layout->height.toInt(); + newLayoutObj["width"] = map->layout->width; + newLayoutObj["height"] = map->layout->height; if (projectConfig.getUseCustomBorderSize()) { - newLayoutObj["border_width"] = map->layout->border_width.toInt(); - newLayoutObj["border_height"] = map->layout->border_height.toInt(); + newLayoutObj["border_width"] = map->layout->border_width; + newLayoutObj["border_height"] = map->layout->border_height; } newLayoutObj["primary_tileset"] = map->layout->tileset_primary_label; newLayoutObj["secondary_tileset"] = map->layout->tileset_secondary_label; @@ -1361,7 +1361,7 @@ void Project::saveMap(Map *map) { if (mapNamesToMapConstants.contains(connection->map_name)) { OrderedJson::object connectionObj; connectionObj["direction"] = connection->direction; - connectionObj["offset"] = connection->offset.toInt(); + connectionObj["offset"] = connection->offset; connectionObj["map"] = this->mapNamesToMapConstants.value(connection->map_name); connectionsArr.append(connectionObj); } else { diff --git a/src/ui/connectionpixmapitem.cpp b/src/ui/connectionpixmapitem.cpp index 221c1911..3fd09dda 100644 --- a/src/ui/connectionpixmapitem.cpp +++ b/src/ui/connectionpixmapitem.cpp @@ -56,7 +56,7 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari y = this->initialY; } - this->connection->offset = QString::number(newOffset); + this->connection->offset = newOffset; emit connectionMoved(this->connection); return QPointF(x, y); } diff --git a/src/ui/mapimageexporter.cpp b/src/ui/mapimageexporter.cpp index d78ac427..b8813258 100644 --- a/src/ui/mapimageexporter.cpp +++ b/src/ui/mapimageexporter.cpp @@ -241,7 +241,7 @@ QPixmap MapImageExporter::getStitchedImage(QProgressDialog *progress, bool inclu continue; int x = cur.x; int y = cur.y; - int offset = connection->offset.toInt(nullptr, 0); + int offset = connection->offset; Map *connectionMap = this->editor->project->loadMap(connection->map_name); if (connection->direction == "up") { x += offset; diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index 8cd41b5a..1165b416 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -118,8 +118,8 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { ui->comboBox_Song->addItems(project->songNames); if (existingLayout) { - ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width.toInt(nullptr, 0)); - ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutId)->height.toInt(nullptr, 0)); + ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width); + ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutId)->height); ui->comboBox_NewMap_Primary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_primary_label); ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_secondary_label); ui->spinBox_NewMap_Width->setDisabled(true); @@ -156,8 +156,8 @@ void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { ui->comboBox_Song->addItems(project->songNames); - ui->spinBox_NewMap_Width->setValue(mapLayout->width.toInt(nullptr, 0)); - ui->spinBox_NewMap_Height->setValue(mapLayout->height.toInt(nullptr, 0)); + ui->spinBox_NewMap_Width->setValue(mapLayout->width); + ui->spinBox_NewMap_Height->setValue(mapLayout->height); ui->comboBox_NewMap_Primary_Tileset->setCurrentText(mapLayout->tileset_primary_label); ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(mapLayout->tileset_secondary_label); @@ -208,8 +208,8 @@ void NewMapPopup::setDefaultValuesProjectConfig(bool importedMap, MapLayout *map } if (projectConfig.getUseCustomBorderSize()) { if (importedMap) { - ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width.toInt(nullptr, 0)); - ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height.toInt(nullptr, 0)); + ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width); + ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height); } ui->spinBox_NewMap_BorderWidth->setVisible(true); ui->spinBox_NewMap_BorderHeight->setVisible(true); @@ -278,14 +278,14 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() { layout = new MapLayout; layout->id = MapLayout::layoutConstantFromName(newMapName); layout->name = QString("%1_Layout").arg(newMap->name); - layout->width = QString::number(this->ui->spinBox_NewMap_Width->value()); - layout->height = QString::number(this->ui->spinBox_NewMap_Height->value()); + layout->width = this->ui->spinBox_NewMap_Width->value(); + layout->height = this->ui->spinBox_NewMap_Height->value(); if (projectConfig.getUseCustomBorderSize()) { - layout->border_width = QString::number(this->ui->spinBox_NewMap_BorderWidth->value()); - layout->border_height = QString::number(this->ui->spinBox_NewMap_BorderHeight->value()); + layout->border_width = this->ui->spinBox_NewMap_BorderWidth->value(); + layout->border_height = this->ui->spinBox_NewMap_BorderHeight->value(); } else { - layout->border_width = QString::number(DEFAULT_BORDER_WIDTH); - layout->border_height = QString::number(DEFAULT_BORDER_HEIGHT); + layout->border_width = DEFAULT_BORDER_WIDTH; + layout->border_height = DEFAULT_BORDER_HEIGHT; } layout->tileset_primary_label = this->ui->comboBox_NewMap_Primary_Tileset->currentText(); layout->tileset_secondary_label = this->ui->comboBox_NewMap_Secondary_Tileset->currentText();