From 097fe2584b14de22fec7a93cb01dc6e2bf3515dd Mon Sep 17 00:00:00 2001 From: nordsoft Date: Mon, 19 Sep 2022 03:17:39 +0400 Subject: [PATCH] Use ptr to identify rmg template --- mapeditor/StdInc.h | 18 ++++++++++++++++++ mapeditor/inspector/inspector.cpp | 5 +---- mapeditor/mainwindow.cpp | 5 +---- mapeditor/windownewmap.cpp | 8 ++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/mapeditor/StdInc.h b/mapeditor/StdInc.h index 8443e7820..5343f0bcf 100644 --- a/mapeditor/StdInc.h +++ b/mapeditor/StdInc.h @@ -13,6 +13,24 @@ #include #include +using NumericPointer = unsigned long long; + +template +NumericPointer data_cast(Type * _pointer) +{ + static_assert(sizeof(Type *) == sizeof(NumericPointer), + "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int"); + return reinterpret_cast(_pointer); +} + +template +Type * data_cast(NumericPointer _numeric) +{ + static_assert(sizeof(Type *) == sizeof(NumericPointer), + "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int"); + return reinterpret_cast(_numeric); +} + inline QString pathToQString(const boost::filesystem::path & path) { #ifdef VCMI_WINDOWS diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index 236abeb8b..59683de63 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -573,10 +573,7 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant //===============IMPLEMENT PROPERTY VALUE TYPE============================ QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value) { - using NumericPointer = unsigned long long; - static_assert(sizeof(CGObjectInstance *) == sizeof(NumericPointer), - "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int"); - return new QTableWidgetItem(QString::number(reinterpret_cast(value))); + return new QTableWidgetItem(QString::number(data_cast(value))); } QTableWidgetItem * Inspector::addProperty(Inspector::PropertyEditorPlaceholder value) diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index c41c8130b..9c8ae91a5 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -924,10 +924,7 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item) //get identifier auto identifier = tableWidget->item(0, 1)->text(); - static_assert(sizeof(CGObjectInstance *) == sizeof(decltype(identifier.toLongLong())), - "Compilied for 64 bit arcitecture. Use .toInt() method"); - - CGObjectInstance * obj = reinterpret_cast(identifier.toLongLong()); + CGObjectInstance * obj = data_cast(identifier.toLongLong()); //get parameter name auto param = tableWidget->item(r, c - 1)->text(); diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index 0ff16e6b8..5f8ccbcbd 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -350,8 +350,8 @@ void WindowNewMap::on_templateCombo_activated(int index) mapGenOptions.setMapTemplate(nullptr); return; } - - auto * templ = VLC->tplh->getTemplate(ui->templateCombo->currentText().toStdString()); + + auto * templ = data_cast(ui->templateCombo->currentData().toLongLong()); mapGenOptions.setMapTemplate(templ); } @@ -390,11 +390,11 @@ void WindowNewMap::updateTemplateList() if(templates.empty()) return; - ui->templateCombo->addItem("[default]"); + ui->templateCombo->addItem("[default]", 0); for(auto * templ : templates) { - ui->templateCombo->addItem(QString::fromStdString(templ->getName())); + ui->templateCombo->addItem(QString::fromStdString(templ->getName()), data_cast(templ)); } ui->templateCombo->setCurrentIndex(0);