1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

fix some sonarcloud issues

This commit is contained in:
godric3 2024-08-01 23:15:24 +02:00
parent 27f83449f2
commit e782d3984f
6 changed files with 23 additions and 23 deletions

View File

@ -69,7 +69,7 @@ std::string defaultBuildingIdConversion(BuildingID bId)
}
}
QStandardItem * getBuildingParentFromTreeModel(const CBuilding * building, QStandardItemModel & model)
QStandardItem * getBuildingParentFromTreeModel(const CBuilding * building, const QStandardItemModel & model)
{
QStandardItem * parent = nullptr;
std::vector<QModelIndex> stack(1);
@ -93,7 +93,7 @@ QStandardItem * getBuildingParentFromTreeModel(const CBuilding * building, QStan
return parent;
}
QVariantList getBuildingVariantsFromModel(QStandardItemModel & model, int modelColumn, Qt::CheckState checkState)
QVariantList getBuildingVariantsFromModel(const QStandardItemModel & model, int modelColumn, Qt::CheckState checkState)
{
QVariantList result;
std::vector<QModelIndex> stack(1);
@ -207,7 +207,7 @@ std::set<BuildingID> TownBuildingsWidget::getBuildingsFromModel(int modelColumn,
{
auto buildingVariants = getBuildingVariantsFromModel(model, modelColumn, checkState);
std::set<BuildingID> result;
for (auto buildingId : buildingVariants)
for (const auto & buildingId : buildingVariants)
{
result.insert(buildingId.toInt());
}
@ -255,7 +255,7 @@ void TownBuildingsWidget::on_disableAll_clicked()
}
void TownBuildingsWidget::setRowColumnCheckState(QStandardItem * item, Column column, Qt::CheckState checkState) {
void TownBuildingsWidget::setRowColumnCheckState(const QStandardItem * item, Column column, Qt::CheckState checkState) {
auto sibling = item->model()->sibling(item->row(), column, item->index());
model.itemFromIndex(sibling)->setCheckState(checkState);
}
@ -280,7 +280,7 @@ void TownBuildingsWidget::setAllRowsColumnCheckState(Column column, Qt::CheckSta
} while(!stack.empty());
}
void TownBuildingsWidget::onItemChanged(QStandardItem * item) {
void TownBuildingsWidget::onItemChanged(const QStandardItem * item) {
disconnect(&model, &QStandardItemModel::itemChanged, this, &TownBuildingsWidget::onItemChanged);
auto rowFirstColumnIndex = item->model()->sibling(item->row(), Column::TYPE, item->index());
QStandardItem * nextRow = model.itemFromIndex(rowFirstColumnIndex);

View File

@ -19,9 +19,9 @@ class TownBuildingsWidget;
std::string defaultBuildingIdConversion(BuildingID bId);
QStandardItem * getBuildingParentFromTreeModel(const CBuilding * building, QStandardItemModel & model);
QStandardItem * getBuildingParentFromTreeModel(const CBuilding * building, const QStandardItemModel & model);
QVariantList getBuildingVariantsFromModel(QStandardItemModel & model, int modelColumn, Qt::CheckState checkState);
QVariantList getBuildingVariantsFromModel(const QStandardItemModel & model, int modelColumn, Qt::CheckState checkState);
class TownBuildingsWidget : public QDialog
{
@ -54,11 +54,11 @@ private slots:
void on_disableAll_clicked();
void onItemChanged(QStandardItem * item);
void onItemChanged(const QStandardItem * item);
private:
std::set<BuildingID> getBuildingsFromModel(int modelColumn, Qt::CheckState checkState);
void setRowColumnCheckState(QStandardItem * item, Column column, Qt::CheckState checkState);
void setRowColumnCheckState(const QStandardItem * item, Column column, Qt::CheckState checkState);
void setAllRowsColumnCheckState(Column column, Qt::CheckState checkState);
Ui::TownBuildingsWidget *ui;

View File

@ -86,7 +86,7 @@ void TownEventDialog::initResources()
ui->resourcesTable->setItem(i, 0, item);
int val = resourcesMap.value(name).toInt();
QSpinBox * edit = new QSpinBox(ui->resourcesTable);
auto * edit = new QSpinBox(ui->resourcesTable);
edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE);
edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE);
edit->setSingleStep(i == GameResID::GOLD ? GOLD_STEP : RESOURCE_STEP);
@ -178,7 +178,7 @@ void TownEventDialog::initCreatures()
ui->creaturesTable->setItem(i, 0, item);
auto creatureNumber = creatures.size() > i ? creatures.at(i).toInt() : 0;
QSpinBox* edit = new QSpinBox(ui->creaturesTable);
auto * edit = new QSpinBox(ui->creaturesTable);
edit->setValue(creatureNumber);
edit->setMaximum(MAXIMUM_CREATURES_CHANGE);
ui->creaturesTable->setCellWidget(i, 1, edit);
@ -252,12 +252,12 @@ void TownEventDialog::on_okButton_clicked()
close();
}
void TownEventDialog::setRowColumnCheckState(QStandardItem * item, int column, Qt::CheckState checkState) {
void TownEventDialog::setRowColumnCheckState(const QStandardItem * item, int column, Qt::CheckState checkState) {
auto sibling = item->model()->sibling(item->row(), column, item->index());
buildingsModel.itemFromIndex(sibling)->setCheckState(checkState);
}
void TownEventDialog::onItemChanged(QStandardItem * item)
void TownEventDialog::onItemChanged(const QStandardItem * item)
{
disconnect(&buildingsModel, &QStandardItemModel::itemChanged, this, &TownEventDialog::onItemChanged);
auto rowFirstColumnIndex = item->model()->sibling(item->row(), 0, item->index());

View File

@ -27,10 +27,10 @@ public:
private slots:
void onItemChanged(QStandardItem * item);
void onItemChanged(const QStandardItem * item);
void on_TownEventDialog_finished(int result);
void on_okButton_clicked();
void setRowColumnCheckState(QStandardItem * item, int column, Qt::CheckState checkState);
void setRowColumnCheckState(const QStandardItem * item, int column, Qt::CheckState checkState);
private:
void initPlayers();

View File

@ -49,7 +49,7 @@ QVariant toVariant(const std::vector<si32> & creatures)
std::set<BuildingID> buildingsFromVariant(const QVariant& v)
{
std::set<BuildingID> result;
for (auto r : v.toList()) {
for (const auto & r : v.toList()) {
result.insert(BuildingID(r.toInt()));
}
return result;
@ -58,7 +58,7 @@ std::set<BuildingID> buildingsFromVariant(const QVariant& v)
std::vector<si32> creaturesFromVariant(const QVariant& v)
{
std::vector<si32> result;
for (auto r : v.toList()) {
for (const auto & r : v.toList()) {
result.push_back(r.toInt());
}
return result;
@ -81,7 +81,7 @@ QVariant toVariant(const CCastleEvent& event)
return QVariant(result);
}
CCastleEvent eventFromVariant(CMapHeader& map, CGTownInstance& town, const QVariant& variant)
CCastleEvent eventFromVariant(CMapHeader& map, const CGTownInstance& town, const QVariant& variant)
{
CCastleEvent result;
auto v = variant.toMap();
@ -143,13 +143,13 @@ void TownEventsWidget::on_eventsList_itemActivated(QListWidgetItem* item)
}
TownEventsDelegate::TownEventsDelegate(CGTownInstance & town, MapController & c) : town(town), controller(c), QStyledItemDelegate()
TownEventsDelegate::TownEventsDelegate(CGTownInstance & town, MapController & c) : QStyledItemDelegate(), town(town), controller(c)
{
}
QWidget* TownEventsDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
return new TownEventsWidget(town, parent);;
return new TownEventsWidget(town, parent);
}
void TownEventsDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const

View File

@ -98,11 +98,11 @@ void TownSpellsWidget::commitChanges()
}
auto updateTownSpellList = [](auto uiSpellLists, auto & townSpellList) {
for (QListWidget * spellList : uiSpellLists)
for (const QListWidget * spellList : uiSpellLists)
{
for (int i = 0; i < spellList->count(); ++i)
{
QListWidgetItem * item = spellList->item(i);
const auto * item = spellList->item(i);
if (item->checkState() == Qt::Checked)
{
townSpellList.push_back(item->data(MapEditorRoles::SpellIDRole).toInt());
@ -132,7 +132,7 @@ void TownSpellsWidget::on_customizeSpells_toggled(bool checked)
initSpellLists();
}
TownSpellsDelegate::TownSpellsDelegate(CGTownInstance & town) : town(town), QStyledItemDelegate()
TownSpellsDelegate::TownSpellsDelegate(CGTownInstance & town) : QStyledItemDelegate(), town(town)
{
}