From ec626a59a71a27fadaf8dc6cb8a4f61b075c65dc Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 15 Oct 2022 03:22:51 -0400 Subject: [PATCH] Display custom header values according to type --- include/core/map.h | 2 +- src/editor.cpp | 2 +- src/mainwindow.cpp | 20 +++++++++++++++++++- src/project.cpp | 4 ++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/core/map.h b/include/core/map.h index f87dec07..fb898317 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -53,7 +53,7 @@ public: QString battle_scene; QString sharedEventsMap = ""; QString sharedScriptsMap = ""; - QMap customHeaders; + QMap customHeaders; MapLayout *layout; bool isPersistedToFile = true; bool hasUnsavedDataChanges = false; diff --git a/src/editor.cpp b/src/editor.cpp index 61cf2fad..290a30b6 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1958,7 +1958,7 @@ void Editor::updateCustomMapHeaderValues(QTableWidget *table) if (value) valueStr = value->text(); fields[keyStr] = valueStr; } - map->customHeaders = fields; + //map->customHeaders = fields; emit editedMapData(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 41d0a7a2..cba737f0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -803,11 +803,29 @@ void MainWindow::displayMapProperties() { ui->tableWidget_CustomHeaderFields->blockSignals(true); ui->tableWidget_CustomHeaderFields->setRowCount(0); for (auto it = map->customHeaders.begin(); it != map->customHeaders.end(); it++) { + QTableWidgetItem * tableItem; + QJsonValue value = it.value(); + switch (value.type()) + { + case QJsonValue::String: + case QJsonValue::Double: + tableItem = new QTableWidgetItem(ParseUtil::jsonToQString(value)); + break; + case QJsonValue::Bool: + tableItem = new QTableWidgetItem(""); + tableItem->setCheckState(value.toBool() ? Qt::Checked : Qt::Unchecked); + break; + default: + tableItem = new QTableWidgetItem("This value cannot be edited from this table"); + tableItem->setFlags(Qt::NoItemFlags); + break; + } int rowIndex = ui->tableWidget_CustomHeaderFields->rowCount(); ui->tableWidget_CustomHeaderFields->insertRow(rowIndex); ui->tableWidget_CustomHeaderFields->setItem(rowIndex, 0, new QTableWidgetItem(it.key())); - ui->tableWidget_CustomHeaderFields->setItem(rowIndex, 1, new QTableWidgetItem(it.value())); + ui->tableWidget_CustomHeaderFields->setItem(rowIndex, 1, tableItem); } + ui->tableWidget_CustomHeaderFields->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->tableWidget_CustomHeaderFields->blockSignals(false); } diff --git a/src/project.cpp b/src/project.cpp index 7632191e..7b41350e 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -412,7 +412,7 @@ bool Project::loadMapData(Map* map) { QSet baseFields = this->getTopLevelMapFields(); for (QString key : mapObj.keys()) { if (!baseFields.contains(key)) { - map->customHeaders.insert(key, ParseUtil::jsonToQString(mapObj[key])); + map->customHeaders.insert(key, mapObj[key]); } } @@ -1440,7 +1440,7 @@ void Project::saveMap(Map *map) { // Custom header fields. for (QString key : map->customHeaders.keys()) { - mapObj[key] = map->customHeaders[key]; + //mapObj[key] = map->customHeaders[key]; } OrderedJson mapJson(mapObj);