mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
extract PlayerColor to QString conversion to helper function
This commit is contained in:
parent
9baccdeeae
commit
514e81406d
mapeditor
@ -13,6 +13,7 @@
|
||||
#include "towneventdialog.h"
|
||||
#include "ui_towneventdialog.h"
|
||||
#include "mapeditorroles.h"
|
||||
#include "../mapsettings/eventsettings.h"
|
||||
#include "../../lib/entities/building/CBuilding.h"
|
||||
#include "../../lib/entities/faction/CTownHandler.h"
|
||||
#include "../../lib/constants/NumericConstants.h"
|
||||
@ -66,7 +67,7 @@ void TownEventDialog::initPlayers()
|
||||
auto playerList = params.value("players").toList();
|
||||
for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
|
||||
{
|
||||
bool isAffected = playerList.contains(QString::fromStdString(PlayerColor(i).toString()));
|
||||
bool isAffected = playerList.contains(toQString(PlayerColor(i)));
|
||||
auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i]));
|
||||
item->setData(MapEditorRoles::PlayerIDRole, QVariant::fromValue(i));
|
||||
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
|
||||
@ -219,7 +220,7 @@ QVariant TownEventDialog::playersToVariant()
|
||||
{
|
||||
auto * item = ui->playersAffected->item(i);
|
||||
if (item->checkState() == Qt::Checked)
|
||||
players.push_back(QString::fromStdString(PlayerColor(i).toString()));
|
||||
players.push_back(toQString(PlayerColor(i)));
|
||||
}
|
||||
return QVariant::fromValue(players);
|
||||
}
|
||||
|
@ -16,11 +16,16 @@
|
||||
#include "../../lib/constants/NumericConstants.h"
|
||||
#include "../../lib/constants/StringConstants.h"
|
||||
|
||||
QString toQString(const PlayerColor & player)
|
||||
{
|
||||
return QString::fromStdString(player.toString());
|
||||
}
|
||||
|
||||
QVariant toVariant(const std::set<PlayerColor> & players)
|
||||
{
|
||||
QVariantList result;
|
||||
for(auto const id : players)
|
||||
result.push_back(QString::fromStdString(id.toString()));
|
||||
result.push_back(toQString(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace Ui {
|
||||
class EventSettings;
|
||||
}
|
||||
|
||||
QString toQString(const PlayerColor & player);
|
||||
QVariant toVariant(const TResources & resources);
|
||||
QVariant toVariant(const std::set<PlayerColor> & players);
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "StdInc.h"
|
||||
#include "timedevent.h"
|
||||
#include "ui_timedevent.h"
|
||||
#include "eventsettings.h"
|
||||
#include "../../lib/constants/EntityIdentifiers.h"
|
||||
#include "../../lib/constants/StringConstants.h"
|
||||
|
||||
@ -33,7 +34,7 @@ TimedEvent::TimedEvent(QListWidgetItem * t, QWidget *parent) :
|
||||
auto playerList = params.value("players").toList();
|
||||
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
|
||||
{
|
||||
bool isAffected = playerList.contains(QString::fromStdString(PlayerColor(i).toString()));
|
||||
bool isAffected = playerList.contains(toQString(PlayerColor(i)));
|
||||
auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i]));
|
||||
item->setData(Qt::UserRole, QVariant::fromValue(i));
|
||||
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
|
||||
@ -75,7 +76,7 @@ void TimedEvent::on_TimedEvent_finished(int result)
|
||||
{
|
||||
auto * item = ui->playersAffected->item(i);
|
||||
if(item->checkState() == Qt::Checked)
|
||||
players.push_back(QString::fromStdString(PlayerColor(i).toString()));
|
||||
players.push_back(toQString(PlayerColor(i)));
|
||||
}
|
||||
descriptor["players"] = QVariant::fromValue(players);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user